From a17e2eca15c7187c96885c7b335701006d1edcfa Mon Sep 17 00:00:00 2001 From: LaureeGrd Date: Mon, 30 Nov 2020 21:53:04 -0300 Subject: [PATCH] Added aliases and auto-tags to tag wiki pages Squashed commit of the following: commit 1bc42eeb1755e82d6596014acec0361c9141999b Author: LaureeGrd Date: Fri Sep 18 01:45:04 2020 -0300 Wiki author update commit 9c8b923abc5d987f688f23a81b5ba93d62c68571 Author: LaureeGrd Date: Fri Sep 18 00:50:49 2020 -0300 Rename config wiki_tag_page_formatting to template commit cf5c8d42d3c411c2413e700f1b51fd5ed6dd56cf Author: LaureeGrd Date: Fri Sep 18 00:06:38 2020 -0300 Improved tag wiki pages formatting and configuration. commit 53b91ff2febdb96fd9c7f4b05f9280859b199bf6 Author: LaureeGrd Date: Mon Sep 14 22:32:46 2020 -0300 Added aliases and auto-tags to tag wiki pages --- ext/wiki/info.php | 2 +- ext/wiki/main.php | 86 ++++++++++++++++++++++++++++++++++++++++++++++ ext/wiki/theme.php | 7 ++-- 3 files changed, 90 insertions(+), 5 deletions(-) diff --git a/ext/wiki/info.php b/ext/wiki/info.php index e2f9adbc..1948dc77 100644 --- a/ext/wiki/info.php +++ b/ext/wiki/info.php @@ -7,7 +7,7 @@ class WikiInfo extends ExtensionInfo public $key = self::KEY; public $name = "Simple Wiki"; public $url = self::SHIMMIE_URL; - public $authors = self::SHISH_AUTHOR; + public $authors = [self::SHISH_NAME=>self::SHISH_EMAIL, "LaureeGrd"=>"laureegrd@gmail.com"]; public $license = self::LICENSE_GPLV2; public $description = "A simple wiki, for those who don't want the hugeness of mediawiki"; public $documentation = "Standard formatting APIs are used (This will be BBCode by default)"; diff --git a/ext/wiki/main.php b/ext/wiki/main.php index c85eeeb5..5c63c97f 100644 --- a/ext/wiki/main.php +++ b/ext/wiki/main.php @@ -98,6 +98,8 @@ class WikiPage abstract class WikiConfig { + const TAG_PAGE_TEMPLATE = "wiki_tag_page_template"; + const EMPTY_TAGINFO = "wiki_empty_taginfo"; const TAG_SHORTWIKIS = "shortwikis_on_tags"; } @@ -109,6 +111,12 @@ class Wiki extends Extension public function onInitExt(InitExtEvent $event) { global $config; + $config->set_default_string(WikiConfig::TAG_PAGE_TEMPLATE, +"{body} + +[b]Aliases: [/b][i]{aliases}[/i] +[b]Auto tags: [/b][i]{autotags}[/i]"); + $config->set_default_string(WikiConfig::EMPTY_TAGINFO, "none"); $config->set_default_bool(WikiConfig::TAG_SHORTWIKIS, false); } @@ -116,6 +124,12 @@ class Wiki extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { $sb = new SetupBlock("Wiki"); + + $sb->start_table(); + $sb->add_longtext_option(WikiConfig::TAG_PAGE_TEMPLATE, "Tag page template", true); + $sb->add_text_option(WikiConfig::EMPTY_TAGINFO, "Empty list text", true); + $sb->end_table(); + $sb->add_bool_option(WikiConfig::TAG_SHORTWIKIS, "Show shortwiki entry when searching for a single tag: "); $event->panel->add_block($sb); @@ -332,6 +346,78 @@ class Wiki extends Extension return new WikiPage($row); } + public static function format_tag_wiki_page(WikiPage $page) { + global $database, $config; + + $row = $database->get_row(" + SELECT * + FROM tags + WHERE tag = :title + ", ["title"=>$page->title]); + + if (!empty($row)) { + $template = $config->get_string(WikiConfig::TAG_PAGE_TEMPLATE); + + //CATEGORIES + if (class_exists("TagCategories")) { + $tagcategories = new TagCategories; + $tag_category_dict = $tagcategories->getKeyedDict(); + } + + //ALIASES + $aliases = $database->get_col(" + SELECT oldtag + FROM aliases + WHERE newtag = :title + ORDER BY oldtag ASC + ", ["title"=>$row["tag"]]); + + if (!empty($aliases)) { + $template = str_replace("{aliases}", implode(", ", $aliases), $template); + } else { + $template = str_replace("{aliases}", $config->get_string(WikiConfig::EMPTY_TAGINFO), $template); + } + + //Things before this line will be passed through html_escape. + $template = format_text($template); + //Things after this line will NOT be escaped!!! Be careful what you add. + + if (class_exists("AutoTagger")) { + $auto_tags = $database->get_one(" + SELECT additional_tags + FROM auto_tag + WHERE tag = :title + ", ["title"=>$row["tag"]]); + + if (!empty($auto_tags)) { + $auto_tags = Tag::explode($auto_tags); + $f_auto_tags = []; + + $tag_list_t = new TagListTheme; + + foreach ($auto_tags as $a_tag) { + $a_row = $database->get_row(" + SELECT * + FROM tags + WHERE tag = :title + ", ["title"=>$a_tag]); + + $tag_html = $tag_list_t->return_tag($a_row, $tag_category_dict ?? []); + array_push($f_auto_tags, $tag_html[1]); + } + + $template = str_replace("{autotags}", implode(", ", $f_auto_tags), $template); + } else { + $template = str_replace("{autotags}", format_text($config->get_string(WikiConfig::EMPTY_TAGINFO)), $template); + } + } + } + + //Insert page body AT LAST to avoid replacing its contents with the actions above. + $formatted = str_replace("{body}", format_text($page->body), $template ?? "{body}"); + return $formatted; + } + /** Diff implemented in pure php, written from scratch. Copyright (C) 2003 Daniel Unterberger diff --git a/ext/wiki/theme.php b/ext/wiki/theme.php index 7bf334b8..3038d10b 100644 --- a/ext/wiki/theme.php +++ b/ext/wiki/theme.php @@ -73,12 +73,11 @@ class WikiTheme extends Themelet protected function create_display_html(WikiPage $page) { - global $user; + global $user, $database, $config; $owner = $page->get_owner(); - $tfe = new TextFormattingEvent($page->body); - send_event($tfe); + $formatted_body = Wiki::format_tag_wiki_page($page); $edit = ""; $edit .= Wiki::can_edit($user, $page) ? @@ -107,7 +106,7 @@ class WikiTheme extends Themelet return "
- $tfe->formatted + $formatted_body