From 4f378c4bb2ec3d3726d0dd4435cc578cc09ae93c Mon Sep 17 00:00:00 2001 From: Hamatoma Date: Sat, 28 Dec 2024 16:28:42 +0100 Subject: [PATCH] V 0.4.13: Page: wiki pages - enable wiki pages --- CHANGELOG.md | 4 ++ app/Http/Controllers/PageController.php | 85 ++++++++++++++++++++++++- 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c13a0a3..ba27345 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/app/Http/Controllers/PageController.php b/app/Http/Controllers/PageController.php index 8f4ec36..ca78fe8 100644 --- a/app/Http/Controllers/PageController.php +++ b/app/Http/Controllers/PageController.php @@ -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 = '

' . str_replace('/\r?\n/', "

\n

", $contents) . "

"; + 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); } } } -- 2.39.5