]> gitweb.hamatoma.de Git - gadeku.git/commitdiff
V 0.4.13: Page: wiki pages
authorHamatoma <author@hamatoma.de>
Sat, 28 Dec 2024 15:28:42 +0000 (16:28 +0100)
committerHamatoma <author@hamatoma.de>
Sat, 28 Dec 2024 15:28:42 +0000 (16:28 +0100)
- enable wiki pages

CHANGELOG.md
app/Http/Controllers/PageController.php

index c13a0a39eb0375dd1355a193dc42b3abd08770c7..ba27345585693232da55d52a5bd58d71a67cd5d5 100644 (file)
@@ -1,3 +1,7 @@
+# V 0.4.13: Page: wiki pages
+
+- enable wiki pages
+
 # V 0.4.12: Page Account Mandator Transaction ViewHelperLocal
 
 - new: module Change + Person
index 8f4ec36fbf71935715718997caea3546664ffe15..ca78fe8526b87d9475c5afdc4893703ffb1c38e7 100644 (file)
@@ -27,6 +27,25 @@ class PageController extends Controller
         $rc = ViewHelper::asHtml($contents, $page->markup_scope);
         return $rc;
     }
+    private function asPreview(Page &$page, ?string $contents = null): string
+    {
+        $contents ??= $page->contents;
+        $type = $page->markup_scope;
+        switch ($type) {
+            case 1122: // mediawiki
+                $wiki = new MediaWiki();
+                $text = $wiki->toHtml($contents);
+                break;
+            case 1223: // html
+                $text = $contents;
+                break;
+            default:
+            case 1121: // plain text
+                $text = '<p>' . str_replace('/\r?\n/', "</p>\n<p>", $contents) . "</p>";
+                break;
+        }
+        return $text;
+    }
     /**
      * Show the form for creating a new resource.
      */
@@ -168,6 +187,70 @@ $sep
         }
         return $rc;
     }
+    /**
+     * Show the form for editing the specified resource.
+     */
+    public function editWiki(Page $page, Request $request)
+    {
+        if ($request->btnSubmit === 'btnCancel') {
+            $rc = redirect('/page-showpretty/' . $page->id);
+        } else {
+            $fields = $request->all();
+            if (count($fields) <= 3) {
+                $fields = [
+                    'title' => $page->title,
+                    'name' => $page->name,
+                    'columns' => $page->columns,
+                    'contents' => $page->contents,
+                    'info' => $page->info,
+                    'pagetype_scope' => $page->pagetype_scope,
+                    'markup_scope' => $page->markup_scope,
+                    'language_scope' => $page->language_scope,
+                    'order' => $page->order ?? '0',
+                    'audio_id' => $page->audio_id,
+                    'previous_id' => $page->previous_id,
+                    'next_id' => $page->next_id,
+                    'up_id' => $page->up_id,
+                    'message' => ''
+                ];
+            } else {
+                if (strpos($fields['title'], '"') !== false) {
+                    $fields['title'] = str_replace('"', "\u{201F}", $fields['title']);
+                }
+                $fields['markup_scope'] = $page->markup_scope;
+                $fields['language_scope'] = $page->language_scope;
+            }
+            $fields['contents'] = MediaWiki::expandStarItems($fields['contents']);
+            if ($request->btnSubmit === 'btnStore') {
+                $this->update($page, $request, $fields);
+            }
+            $optionsPagetype = SProperty::optionsByScope('pagetype', $page->pagetype_scope, '');
+            $optionsMarkup = SProperty::optionsByScope('markup', $page->markup_scope, '');
+            $optionsLanguage = SProperty::optionsByScope('localization', $page->language_scope, '');
+            if ($request->btnSubmit === 'btnPreview') {
+                $wiki = new MediaWiki();
+                //$wiki->setClozeParameters('preview');
+                $wikiText = $fields['contents'];
+                $fields['preview'] = $wiki->toHtml($wikiText);
+                if ($wikiText !== $page->contents) {
+                    $page->contents = $wikiText;
+                    $fields['message'] = '+++ ' . __('There are corrections:') . $wiki->corrections;
+                }
+            }
+            if ($page->audio_id != null) {
+                $file = File::find($page->audio_id);
+                $fields['audio'] = $file->filename;
+            }
+            $context = new ContextLaraKnife($request, $fields, $page);
+            $rc = view('page.editwiki', [
+                'context' => $context,
+                'optionsPagetype' => $optionsPagetype,
+                'optionsMarkup' => $optionsMarkup,
+                'optionsLanguage' => $optionsLanguage,
+            ]);
+        }
+        return $rc;
+    }
     /**
      * Remove the specified resource from storage.
      */
@@ -261,7 +344,6 @@ LEFT JOIN users t4 ON t4.id=t0.owner_id
         ];
         if ($isCreate) {
             $rc['markup_scope'] = 'required';
-            $rc['pagetype_scope'] = '';
             $rc['language_scope'] = 'required';
         }
         return $rc;
@@ -491,6 +573,7 @@ LEFT JOIN users t4 ON t4.id=t0.owner_id
                 $validated['audio_id'] = $fileId;
             }
             $page->update($validated);
+            Change::createFromFields($validated, Change::$UPDATE, 'Page', $page->id);
         }
     }
 }