$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.
*/
}
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.
*/
];
if ($isCreate) {
$rc['markup_scope'] = 'required';
- $rc['pagetype_scope'] = '';
$rc['language_scope'] = 'required';
}
return $rc;
$validated['audio_id'] = $fileId;
}
$page->update($validated);
+ Change::createFromFields($validated, Change::$UPDATE, 'Page', $page->id);
}
}
}