From: Hamatoma Date: Sat, 27 Apr 2024 19:05:41 +0000 (+0200) Subject: V 0.2.2 MediaWiki Page X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=f037b7ccdf44ff3f704dbbe8e2955f1d0dd85e25;p=gadeku.git V 0.2.2 MediaWiki Page - MediaWiki: eigene Implementierung - Modul Page: eigene Implementierung --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c4ef2b..cd74f71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# V 0.2.2 MediaWiki Page + +## Added +- MediaWiki: eigene Implementierung +- Modul Page: eigene Implementierung + # V 0.2.1 Modul Page ## Added diff --git a/app/Helpers/MediaWiki.php b/app/Helpers/MediaWiki.php deleted file mode 120000 index d83989f..0000000 --- a/app/Helpers/MediaWiki.php +++ /dev/null @@ -1 +0,0 @@ -../../vendor/hamatoma/laraknife/resources/helpers/MediaWiki.php \ No newline at end of file diff --git a/app/Helpers/MediaWiki.php b/app/Helpers/MediaWiki.php new file mode 100644 index 0000000..f43f448 --- /dev/null +++ b/app/Helpers/MediaWiki.php @@ -0,0 +1,74 @@ +\*/', + '/\*-(\w[^*]+\w)-\*/', + '/\*\+(\w[^*]+\w)\+\*/' + ], + [ + '%trans($1)%', + '%field($1)%', + '%del($1)%', + '%add($1)%' + ], + $text + ); + return $rc; + } + function specialMacrosToHtml(string $body): string + { + $pos = 0; + // .............................1...1..2...23....3 + $body = preg_replace_callback('/%(\w+)\((.*?)(\|.*?)?\)%/', function ($matches) { + switch ($matches[1]) { + case 'date': + $rc = date('%Y.%m.%d'); + break; + case 'dateTime': + $rc = date('%Y.%m.%d %H:%M'); + break; + case 'trans': + $text = $matches[2]; + $info = count($matches) > 3 ? $text : substr($matches[3], 1); + $rc = "$text"; + break; + case 'color': + $rc = '' . $matches[2] . ''; + break; + case 'add': + $rc = '' . (count($matches) == 4 ? ($matches[2] . $matches[3]) : $matches[2]) . ''; + break; + case 'del': + $rc = '' . (count($matches) == 4 ? ($matches[2] . $matches[3]) : $matches[2]) . ''; + break; + case 'field': + $name = $matches[2]; + $value = ''; + $size = 8; + if (count($matches) > 3){ + $parts = explode('|', substr($matches[3], 1)); + $value = $parts[0]; + if (count($parts) > 1){ + $size = $parts[1]; + } + } + $rc = ""; + break; + default: + $rc = $matches[0]; + break; + } + return $rc; + }, $body); + return $body; + } +} diff --git a/app/Helpers/MediaWikiBase.php b/app/Helpers/MediaWikiBase.php new file mode 120000 index 0000000..5887466 --- /dev/null +++ b/app/Helpers/MediaWikiBase.php @@ -0,0 +1 @@ +../../vendor/hamatoma/laraknife/resources/helpers/MediaWikiBase.php \ No newline at end of file diff --git a/app/Helpers/dummy.html b/app/Helpers/dummy.html deleted file mode 100644 index 793860b..0000000 --- a/app/Helpers/dummy.html +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/Http/Controllers/PageController.php b/app/Http/Controllers/PageController.php deleted file mode 120000 index eefdef5..0000000 --- a/app/Http/Controllers/PageController.php +++ /dev/null @@ -1 +0,0 @@ -../../../vendor/hamatoma/laraknife/templates/Http/Controllers/PageController.php \ No newline at end of file diff --git a/app/Http/Controllers/PageController.php b/app/Http/Controllers/PageController.php new file mode 100644 index 0000000..5b507af --- /dev/null +++ b/app/Http/Controllers/PageController.php @@ -0,0 +1,356 @@ +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. + */ + public function create(Request $request) + { + if ($request->btnSubmit === 'btnCancel') { + $rc = redirect('/page-index'); + } else { + $fields = $request->all(); + if (count($fields) === 0) { + $fields = [ + 'title' => '', + 'name' => '', + 'contents' => '', + 'info' => '', + 'pagetype_scope' => '', + 'markup_scope' => '1122', + 'language_scope' => SProperty::idOfLocalization(auth()->user()->localization), + 'order' => '0', + 'columns' => '1', + 'audio_id' => '', + ]; + } + $optionsPagetype = SProperty::optionsByScope('pagetype', $fields['pagetype_scope'], '-'); + $optionsMarkup = SProperty::optionsByScope('markup', $fields['markup_scope'], '-'); + $optionsLanguage = SProperty::optionsByScope('localization', $fields['language_scope'], '-'); + $context = new ContextLaraKnife($request, $fields); + $rc = view('page.create', [ + 'context' => $context, + 'optionsPagetype' => $optionsPagetype, + 'optionsMarkup' => $optionsMarkup, + 'optionsLanguage' => $optionsLanguage, + ]); + } + return $rc; + } + /** + * Show the form for editing the specified resource. + */ + public function edit(Page $page, Request $request) + { + if ($request->btnSubmit === 'btnCancel') { + $rc = redirect('/page-index'); + } else { + $fields = $request->all(); + if (count($fields) === 0) { + $fields = [ + 'title' => $page->title, + 'name' => $page->title, + '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 + ]; + } else { + $fields['pagetype_scope'] = $page->pagetype_scope; + $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, ''); + $preview = $this->asPreview($page); + $fields = $request->btnSubmit !== 'btnPreview' ? null : ['preview' => $preview]; + $context = new ContextLaraKnife($request, $fields, $page); + $rc = view('page.edit', [ + 'context' => $context, + 'optionsPagetype' => $optionsPagetype, + 'optionsMarkup' => $optionsMarkup, + 'optionsLanguage' => $optionsLanguage, + ]); + } + return $rc; + } + /** + * Remove the specified resource from storage. + */ + public function destroy(Page $page, Request $request) + { + if ($request->btnSubmit === 'btnDelete') { + $page->delete(); + } + return redirect('/page-index'); + } + /** + * Display the database records of the resource. + */ + public function index(Request $request) + { + if ($request->btnSubmit === 'btnNew') { + return redirect('/page-create'); + } else { + $sql = " +SELECT t0.*, + t1.name as pagetype, + t2.name as markup, + t3.shortname as language, + t4.name as owner +FROM pages t0 +LEFT JOIN sproperties t1 ON t1.id=t0.pagetype_scope +LEFT JOIN sproperties t2 ON t2.id=t0.markup_scope +LEFT JOIN sproperties t3 ON t3.id=t0.language_scope +LEFT JOIN sproperties t4 ON t4.id=t0.owner_id +"; + $parameters = []; + $fields = $request->all(); + if (count($fields) == 0) { + $fields = [ + 'pagetype' => '', + 'markup' => '', + 'title' => '', + 'contents' => '', + 'owner' => '', + '_sortParams' => 'title:asc;id:asc' + ]; + } else { + $conditions = []; + ViewHelper::addConditionComparism($conditions, $parameters, 'pagetype_scope', 'pagetype'); + ViewHelper::addConditionComparism($conditions, $parameters, 'markup_scope', 'markup'); + ViewHelper::addConditionComparism($conditions, $parameters, 'language_scope', 'language'); + ViewHelper::addConditionComparism($conditions, $parameters, 'owner_id', 'owner'); + ViewHelper::addConditionPattern($conditions, $parameters, 'name,title,info', 'title'); + ViewHelper::addConditionPattern($conditions, $parameters, 'info,contents', 'contents'); + $sql = DbHelper::addConditions($sql, $conditions); + } + $sql = DbHelper::addOrderBy($sql, $fields['_sortParams']); + $pagination = new Pagination($sql, $parameters, $fields); + $records = $pagination->records; + $optionsPagetype = SProperty::optionsByScope('pagetype', $fields['pagetype'], 'all'); + $optionsMarkup = SProperty::optionsByScope('markup', $fields['markup'], 'all'); + $optionsLanguage = SProperty::optionsByScope('localization', $fields['markup'], 'all'); + $optionsOwner = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['owner']); + $context = new ContextLaraKnife($request, $fields); + return view('page.index', [ + 'context' => $context, + 'records' => $records, + 'optionsPagetype' => $optionsPagetype, + 'optionsMarkup' => $optionsMarkup, + 'optionsLanguage' => $optionsLanguage, + 'optionsOwner' => $optionsOwner, + 'pagination' => $pagination + ]); + } + } + /** + * Returns the validation rules. + * @return array The validation rules. + */ + private function rules(bool $isCreate = false): array + { + $rc = [ + 'title' => 'required', + 'name' => 'required', + 'contents' => 'required', + 'info' => '', + 'order' => 'integer|min:0|max:9999', + 'columns' => 'integer|min:1|max:4' + ]; + if ($isCreate) { + $rc['markup_scope'] = 'required'; + $rc['pagetype_scope'] = 'required'; + $rc['language_scope'] = 'required'; + } + return $rc; + } + public static function routes() + { + Route::get('/page-index', [PageController::class, 'index'])->middleware('auth'); + Route::post('/page-index', [PageController::class, 'index'])->middleware('auth'); + Route::get('/page-create', [PageController::class, 'create'])->middleware('auth'); + Route::put('/page-store', [PageController::class, 'store'])->middleware('auth'); + Route::post('/page-edit/{page}', [PageController::class, 'edit'])->middleware('auth'); + Route::get('/page-edit/{page}', [PageController::class, 'edit'])->middleware('auth'); + Route::get('/page-show/{page}/delete', [PageController::class, 'show'])->middleware('auth'); + Route::delete('/page-show/{page}/delete', [PageController::class, 'destroy'])->middleware('auth'); + Route::get('/page-showpretty/{page}', [PageController::class, 'showPretty'])->middleware('auth'); + Route::post('/page-showpretty/{page}', [PageController::class, 'showPretty'])->middleware('auth'); + Route::get('/page-showmenu/{title}', [PageController::class, 'showMenu'])->middleware('auth'); + Route::get('/page-showhelp/{title}', [PageController::class, 'showHelp'])->middleware('auth'); + Route::get('/page-showbyname/{name}/{pageType}', [PageController::class, 'showByName'])->middleware('auth'); + } + /** + * Display the specified resource. + */ + public function show(Page $page, Request $request) + { + if ($request->btnSubmit === 'btnCancel') { + $rc = redirect('/page-index')->middleware('auth'); + } else { + $optionsPagetype = SProperty::optionsByScope('pagetype', $page->pagetype_scope, ''); + $optionsMarkup = SProperty::optionsByScope('markup', $page->markup_scope, ''); + $context = new ContextLaraKnife($request, null, $page); + $rc = view('page.show', [ + 'context' => $context, + 'optionsPagetype' => $optionsPagetype, + 'optionsMarkup' => $optionsMarkup, + 'mode' => 'delete' + ]); + } + return $rc; + } + public function showPretty(Page $page, Request $request) + { + if ($request->btnSubmit === 'btnCancel') { + $rc = redirect('/page-index')->middleware('auth'); + } else { + $text = $this->asPreview($page); + $link = $page->audio_id == null ? null : File::relativeFileLink($page->audio_id); + $context = new ContextLaraKnife($request, ['text' => $text, 'link' => $link], $page); + $rc = view('page.showcol1', [ + 'context' => $context, + ]); + } + return $rc; + } + public function showByName(string $name, int $pageType, Request $request) + { + $page = Page::where(['name' => $name, 'pagetype_scope' => $pageType])->first(); + if ($page == null) { + $context = new ContextLaraKnife($request, ['text' => "invalid reference: $name $pageType"]); + $rc = $rc = view('page.unknown', [ + 'context' => $context, + ]); + } else { + $params = []; + $columns = $page->columns; + if ($columns <= 1) { + $params['text'] = $this->asPreview($page); + } else { + $cols = explode('----', $page->contents); + for ($no = 1; $no <= $columns; $no++) { + $params["text$no"] = $this->asPreview($page, $cols[$no - 1]); + } + } + $context = new ContextLaraKnife($request, $params, $page); + $rc = view("page.showcol$columns", [ + 'context' => $context, + ]); + } + return $rc; + } + public function showHelp(string $title, Request $request) + { + $rc = $this->showByName($title, 1142, $request); + return $rc; + } + + public function showMenu(string $title, Request $request) + { + $rc = $this->showByName($title, 1141, $request); + return $rc; + } + + /** + * Store a newly created resource in storage. + */ + public function store(Request $request) + { + $rc = null; + if ($request->btnSubmit === 'btnStore') { + $fields = $request->all(); + ViewHelper::addFieldIfMissing($fields, 'order', '0'); + ViewHelper::addFieldIfMissing($fields, 'owner_id', auth()->id()); + $fields['name'] = StringHelper::textToUrl(empty($fields['name']) ? $fields['title'] : $fields['name']); + $lang = auth()->user()->localization; + $lang2 = SProperty::byScopeAndName('localization', $lang, 'shortname'); + ViewHelper::addFieldIfMissing($fields, 'language_scope', $lang2); + $validator = Validator::make($fields, $this->rules(true)); + if ($validator->fails()) { + $errors = $validator->errors(); + $rc = back()->withErrors($validator)->withInput(); + } else { + $validated = $validator->validated(); + $validated['info'] = strip_tags($validated['info']); + $validated['owner_id'] = $fields['owner_id']; + $validated['contents'] = MediaWiki::expandStarItems($validated['contents']); + Page::create($validated); + } + } + if ($rc == null) { + $rc = redirect('/page-index'); + } + return $rc; + } + /** + * Update the specified resource in storage. + */ + public function update(Page $page, Request $request, array &$fields) + { + $validator = Validator::make($fields, $this->rules(false)); + if ($validator->fails()) { + $rc = back()->withErrors($validator)->withInput(); + } else { + $validated = $validator->validated(); + $validated['info'] = strip_tags($validated['info']); + if (empty($page->audio_id) && $request->file('file') != null) { + $filename = FileHelper::textToFilename($page->title); + $moduleId = Module::idOfModule('Page'); + $fileId = File::storeFile($request, $page->title, 1103, 1091, 'audio file of page', $filename, $moduleId, $page->id); + $validated['audio_id'] = $fileId; + } + $page->update($validated); + } + } +} diff --git a/app/Models/Page.php b/app/Models/Page.php deleted file mode 120000 index 765f596..0000000 --- a/app/Models/Page.php +++ /dev/null @@ -1 +0,0 @@ -../../vendor/hamatoma/laraknife/templates/Models/Page.php \ No newline at end of file diff --git a/app/Models/Page.php b/app/Models/Page.php new file mode 100644 index 0000000..f747dfa --- /dev/null +++ b/app/Models/Page.php @@ -0,0 +1,29 @@ +id(); + $table->timestamps(); + $table->string('title'); + $table->string('name', 32); + $table->text('contents'); + $table->text('info')->nullable(); + $table->integer('pagetype_scope'); + $table->integer('markup_scope'); + $table->integer('order')->nullable(); + $table->integer('language_scope'); + $table->integer('columns')->default(1); + $table->foreignId('audio_id')->nullable()->references('id')->on('files'); + $table->foreignId('cacheof_id')->nullable()->references('id')->on('pages'); + $table->foreignId('owner_id')->references('id')->on('users'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('pages'); + } +}; diff --git a/database/seeders/PageSeeder.php b/database/seeders/PageSeeder.php deleted file mode 120000 index edbe88b..0000000 --- a/database/seeders/PageSeeder.php +++ /dev/null @@ -1 +0,0 @@ -../../vendor/hamatoma/laraknife/templates/database/seeders/PageSeeder.php \ No newline at end of file diff --git a/database/seeders/PageSeeder.php b/database/seeders/PageSeeder.php new file mode 100644 index 0000000..61fc0e8 --- /dev/null +++ b/database/seeders/PageSeeder.php @@ -0,0 +1,28 @@ + + @csrf + @method('PUT') + + + + + + + + + + + +@endsection diff --git a/resources/views/page/edit.blade.php b/resources/views/page/edit.blade.php new file mode 100644 index 0000000..5014df3 --- /dev/null +++ b/resources/views/page/edit.blade.php @@ -0,0 +1,36 @@ +@extends('layouts.backend') + +@section('content') +
+ @csrf + + + + + + + + + + + + + + @if (!empty($context->valueOf('preview'))) + +
{!! $context->valueOf('preview') !!} +
+
+ @endif +
+@endsection diff --git a/resources/views/page/index.blade.php b/resources/views/page/index.blade.php new file mode 100644 index 0000000..61318f2 --- /dev/null +++ b/resources/views/page/index.blade.php @@ -0,0 +1,44 @@ +@extends('layouts.backend') + +@section('content') +
+ @csrf + + + + + + + + + + + + + + + {{__('Title')}} + {{__('Pagetype')}} + {{__('Markup')}} + {{__('Language')}} + {{__('Owner')}} + + + + +@foreach ($records as $page) + + + {{$page->title}} + {{ __($page->pagetype) }} + {{ __($page->markup) }} + {{ __($page->language) }} + {{$page->owner}} + + +@endforeach + + + +
+@endsection diff --git a/resources/views/page/show.blade.php b/resources/views/page/show.blade.php new file mode 100644 index 0000000..16e9096 --- /dev/null +++ b/resources/views/page/show.blade.php @@ -0,0 +1,17 @@ +@extends('layouts.backend') + +@section('content') +
+ @csrf + @if($mode === 'delete') + @method('DELETE') + @endif + + + + + + + +
+@endsection diff --git a/resources/views/page/showcol1.blade.php b/resources/views/page/showcol1.blade.php new file mode 100644 index 0000000..f853209 --- /dev/null +++ b/resources/views/page/showcol1.blade.php @@ -0,0 +1,17 @@ +@extends('layouts.backend') + +@section('content') +
+ @csrf + +
+ {!! $context->valueOf('text') !!} +
+
+ @if ($context->valueof('link') != null) +
+ +
+ @endif +
+@endsection diff --git a/resources/views/page/showcol2.blade.php b/resources/views/page/showcol2.blade.php new file mode 100644 index 0000000..5cae863 --- /dev/null +++ b/resources/views/page/showcol2.blade.php @@ -0,0 +1,22 @@ +@extends('layouts.backend') + +@section('content') +
+ @csrf + +
+
+ {!! $context->valueOf('text1') !!} +
+
+ {!! $context->valueOf('text2') !!} +
+
+
+ @if ($context->valueof('link') != null) +
+ +
+ @endif +
+@endsection diff --git a/resources/views/page/showcol3.blade.php b/resources/views/page/showcol3.blade.php new file mode 100644 index 0000000..ad334e3 --- /dev/null +++ b/resources/views/page/showcol3.blade.php @@ -0,0 +1,25 @@ +@extends('layouts.backend') + +@section('content') +
+ @csrf + +
+
+ {!! $context->valueOf('text1') !!} +
+
+ {!! $context->valueOf('text2') !!} +
+
+ {!! $context->valueOf('text3') !!} +
+
+
+ @if ($context->valueof('link') != null) +
+ +
+ @endif +
+@endsection diff --git a/resources/views/page/showcol4.blade.php b/resources/views/page/showcol4.blade.php new file mode 100644 index 0000000..6c1ccef --- /dev/null +++ b/resources/views/page/showcol4.blade.php @@ -0,0 +1,28 @@ +@extends('layouts.backend') + +@section('content') +
+ @csrf + +
+
+ {!! $context->valueOf('text1') !!} +
+
+ {!! $context->valueOf('text2') !!} +
+
+ {!! $context->valueOf('text3') !!} +
+
+ {!! $context->valueOf('text4') !!} +
+
+
+ @if ($context->valueof('link') != null) +
+ +
+ @endif +
+@endsection diff --git a/resources/views/page/unknown.blade.php b/resources/views/page/unknown.blade.php new file mode 100644 index 0000000..a9ad8eb --- /dev/null +++ b/resources/views/page/unknown.blade.php @@ -0,0 +1,10 @@ +@extends('layouts.backend') + +@section('content') +
+ @csrf + + + +
+@endsection