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:
commit
e0f1165b6c
2 changed files with 12 additions and 0 deletions
|
@ -52,11 +52,13 @@ class WikiPage
|
||||||
public string $title;
|
public string $title;
|
||||||
public int $revision;
|
public int $revision;
|
||||||
public bool $locked;
|
public bool $locked;
|
||||||
|
public bool $exists;
|
||||||
public string $body;
|
public string $body;
|
||||||
|
|
||||||
public function __construct(array $row=null)
|
public function __construct(array $row=null)
|
||||||
{
|
{
|
||||||
//assert(!empty($row));
|
//assert(!empty($row));
|
||||||
|
global $database;
|
||||||
|
|
||||||
if (!is_null($row)) {
|
if (!is_null($row)) {
|
||||||
$this->id = (int)$row['id'];
|
$this->id = (int)$row['id'];
|
||||||
|
@ -66,6 +68,7 @@ class WikiPage
|
||||||
$this->title = $row['title'];
|
$this->title = $row['title'];
|
||||||
$this->revision = (int)$row['revision'];
|
$this->revision = (int)$row['revision'];
|
||||||
$this->locked = bool_escape($row['locked']);
|
$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'];
|
$this->body = $row['body'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,6 +82,11 @@ class WikiPage
|
||||||
{
|
{
|
||||||
return $this->locked;
|
return $this->locked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function exists(): bool
|
||||||
|
{
|
||||||
|
return $this->exists;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class WikiConfig
|
abstract class WikiConfig
|
||||||
|
|
|
@ -35,6 +35,10 @@ class WikiTheme extends Themelet
|
||||||
$title_html = $this->tagcategories->getTagHtml($title_html, $tag_category_dict);
|
$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_title(html_escape($wiki_page->title));
|
||||||
$page->set_heading(html_escape($wiki_page->title));
|
$page->set_heading(html_escape($wiki_page->title));
|
||||||
$page->add_block(new NavBlock());
|
$page->add_block(new NavBlock());
|
||||||
|
|
Reference in a new issue