Merge pull request #851 from jellykells/jellykells/wiki_return_not_found

Add option to return 404 code for nonexistent wiki pages
This commit is contained in:
Shish 2022-01-01 10:27:27 +00:00 committed by GitHub
commit e0f1165b6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View file

@ -52,11 +52,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'];
@ -66,6 +68,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'];
}
}
@ -79,6 +82,11 @@ class WikiPage
{
return $this->locked;
}
public function exists(): bool
{
return $this->exists;
}
}
abstract class WikiConfig

View file

@ -35,6 +35,10 @@ class WikiTheme extends Themelet
$title_html = $this->tagcategories->getTagHtml($title_html, $tag_category_dict);
}
if (!$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());