From e114079b9660c60b282087aed15692f7d1d70cc8 Mon Sep 17 00:00:00 2001
From: jellykells <42573508+jellykells@users.noreply.github.com>
Date: Sun, 21 Nov 2021 08:10:03 -0600
Subject: [PATCH 1/3] add option to return 404 code for nonexistent wiki pages
---
ext/wiki/main.php | 11 +++++++++++
ext/wiki/theme.php | 4 ++++
2 files changed, 15 insertions(+)
diff --git a/ext/wiki/main.php b/ext/wiki/main.php
index 8ea892d8..b3d4469d 100644
--- a/ext/wiki/main.php
+++ b/ext/wiki/main.php
@@ -50,11 +50,13 @@ class WikiPage
public string $title;
public int $revision;
public bool $locked;
+ public bool $exists;
public string $body;
public function __construct(array $row=null)
{
//assert(!empty($row));
+ global $database;
if (!is_null($row)) {
$this->id = (int)$row['id'];
@@ -64,6 +66,7 @@ class WikiPage
$this->title = $row['title'];
$this->revision = (int)$row['revision'];
$this->locked = bool_escape($row['locked']);
+ $this->exists = $database->exists("SELECT id FROM wiki_pages WHERE title = :title", ["title"=>$this->title]);
$this->body = $row['body'];
}
}
@@ -77,6 +80,11 @@ class WikiPage
{
return $this->locked;
}
+
+ public function exists(): bool
+ {
+ return $this->exists;
+ }
}
abstract class WikiConfig
@@ -85,6 +93,7 @@ abstract class WikiConfig
const EMPTY_TAGINFO = "wiki_empty_taginfo";
const TAG_SHORTWIKIS = "shortwikis_on_tags";
const ENABLE_REVISIONS = "wiki_revisions";
+ const RETURN_NOT_FOUND = "wiki_return_not_found";
}
class Wiki extends Extension
@@ -105,6 +114,7 @@ class Wiki extends Extension
$config->set_default_string(WikiConfig::EMPTY_TAGINFO, "none");
$config->set_default_bool(WikiConfig::TAG_SHORTWIKIS, false);
$config->set_default_bool(WikiConfig::ENABLE_REVISIONS, true);
+ $config->set_default_bool(WikiConfig::RETURN_NOT_FOUND, false);
}
// Add a block to the Board Config / Setup
@@ -115,6 +125,7 @@ class Wiki extends Extension
$sb->add_longtext_option(WikiConfig::TAG_PAGE_TEMPLATE, "Tag page template: ");
$sb->add_text_option(WikiConfig::EMPTY_TAGINFO, "Empty list text: ");
$sb->add_bool_option(WikiConfig::TAG_SHORTWIKIS, "Show shortwiki entry when searching for a single tag: ");
+ $sb->add_bool_option(WikiConfig::RETURN_NOT_FOUND, "
Return '404 Not Found' code for wiki pages that don't exist: ");
}
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event)
diff --git a/ext/wiki/theme.php b/ext/wiki/theme.php
index 6125de16..a7c073e9 100644
--- a/ext/wiki/theme.php
+++ b/ext/wiki/theme.php
@@ -33,6 +33,10 @@ class WikiTheme extends Themelet
$title_html = $this->tagcategories->getTagHtml($title_html, $tag_category_dict);
}
+ if ($config->get_bool(WikiConfig::RETURN_NOT_FOUND) && !$wiki_page->exists) {
+ $page->set_code(404);
+ }
+
$page->set_title(html_escape($wiki_page->title));
$page->set_heading(html_escape($wiki_page->title));
$page->add_block(new NavBlock());
From 1b7e505f191023c2f197a830c5769c0aa717da5c Mon Sep 17 00:00:00 2001
From: jellykells <42573508+jellykells@users.noreply.github.com>
Date: Sun, 21 Nov 2021 08:25:41 -0600
Subject: [PATCH 2/3] add global to display_page function
---
ext/wiki/theme.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ext/wiki/theme.php b/ext/wiki/theme.php
index a7c073e9..d533fa62 100644
--- a/ext/wiki/theme.php
+++ b/ext/wiki/theme.php
@@ -10,7 +10,7 @@ class WikiTheme extends Themelet
*/
public function display_page(Page $page, WikiPage $wiki_page, ?WikiPage $nav_page=null)
{
- global $user;
+ global $config, $user;
if (is_null($nav_page)) {
$nav_page = new WikiPage();
From f83588fdcd0033a066d8e8c5069e5ef7a240a96f Mon Sep 17 00:00:00 2001
From: jellykells <42573508+jellykells@users.noreply.github.com>
Date: Thu, 30 Dec 2021 22:06:39 -0600
Subject: [PATCH 3/3] always return 404 code for nonexistent wiki pages
---
ext/wiki/main.php | 3 ---
ext/wiki/theme.php | 4 ++--
2 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/ext/wiki/main.php b/ext/wiki/main.php
index b3d4469d..bd4e56c8 100644
--- a/ext/wiki/main.php
+++ b/ext/wiki/main.php
@@ -93,7 +93,6 @@ abstract class WikiConfig
const EMPTY_TAGINFO = "wiki_empty_taginfo";
const TAG_SHORTWIKIS = "shortwikis_on_tags";
const ENABLE_REVISIONS = "wiki_revisions";
- const RETURN_NOT_FOUND = "wiki_return_not_found";
}
class Wiki extends Extension
@@ -114,7 +113,6 @@ class Wiki extends Extension
$config->set_default_string(WikiConfig::EMPTY_TAGINFO, "none");
$config->set_default_bool(WikiConfig::TAG_SHORTWIKIS, false);
$config->set_default_bool(WikiConfig::ENABLE_REVISIONS, true);
- $config->set_default_bool(WikiConfig::RETURN_NOT_FOUND, false);
}
// Add a block to the Board Config / Setup
@@ -125,7 +123,6 @@ class Wiki extends Extension
$sb->add_longtext_option(WikiConfig::TAG_PAGE_TEMPLATE, "Tag page template: ");
$sb->add_text_option(WikiConfig::EMPTY_TAGINFO, "Empty list text: ");
$sb->add_bool_option(WikiConfig::TAG_SHORTWIKIS, "Show shortwiki entry when searching for a single tag: ");
- $sb->add_bool_option(WikiConfig::RETURN_NOT_FOUND, "
Return '404 Not Found' code for wiki pages that don't exist: ");
}
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event)
diff --git a/ext/wiki/theme.php b/ext/wiki/theme.php
index d533fa62..1feb3494 100644
--- a/ext/wiki/theme.php
+++ b/ext/wiki/theme.php
@@ -10,7 +10,7 @@ class WikiTheme extends Themelet
*/
public function display_page(Page $page, WikiPage $wiki_page, ?WikiPage $nav_page=null)
{
- global $config, $user;
+ global $user;
if (is_null($nav_page)) {
$nav_page = new WikiPage();
@@ -33,7 +33,7 @@ class WikiTheme extends Themelet
$title_html = $this->tagcategories->getTagHtml($title_html, $tag_category_dict);
}
- if ($config->get_bool(WikiConfig::RETURN_NOT_FOUND) && !$wiki_page->exists) {
+ if (!$wiki_page->exists) {
$page->set_code(404);
}