Added aliases and auto-tags to tag wiki pages

Squashed commit of the following:

commit 1bc42eeb1755e82d6596014acec0361c9141999b
Author: LaureeGrd <laureegrd@gmail.com>
Date:   Fri Sep 18 01:45:04 2020 -0300

    Wiki author update

commit 9c8b923abc5d987f688f23a81b5ba93d62c68571
Author: LaureeGrd <laureegrd@gmail.com>
Date:   Fri Sep 18 00:50:49 2020 -0300

    Rename config wiki_tag_page_formatting to template

commit cf5c8d42d3c411c2413e700f1b51fd5ed6dd56cf
Author: LaureeGrd <laureegrd@gmail.com>
Date:   Fri Sep 18 00:06:38 2020 -0300

    Improved tag wiki pages formatting and configuration.

commit 53b91ff2febdb96fd9c7f4b05f9280859b199bf6
Author: LaureeGrd <laureegrd@gmail.com>
Date:   Mon Sep 14 22:32:46 2020 -0300

    Added aliases and auto-tags to tag wiki pages
This commit is contained in:
LaureeGrd 2020-11-30 21:53:04 -03:00
parent 8871591cab
commit a17e2eca15
3 changed files with 90 additions and 5 deletions

View File

@ -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)";

View File

@ -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.phpnet@holomind.de>

View File

@ -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 = "<table><tr>";
$edit .= Wiki::can_edit($user, $page) ?
@ -107,7 +106,7 @@ class WikiTheme extends Themelet
return "
<div class='wiki-page'>
$tfe->formatted
$formatted_body
<hr>
<p class='wiki-footer'>
Revision {$page->revision}