Bugfix: Make sure the page exists when checking for protection

This commit is contained in:
Starbeamrainbowlabs 2015-10-03 12:26:32 +01:00
parent 77027da111
commit f5fba6e431
3 changed files with 79 additions and 12 deletions

View File

@ -1054,6 +1054,39 @@ function render_sidebar($pageindex, $root_pagename = "")
register_module([
"name" => "Redirect pages",
"version" => "0.1",
"author" => "Starbeamrainbowlabs",
"description" => "Adds support for redirect pages. Uses the same syntax that Mediawiki does.",
"id" => "feature-redirect",
"code" => function() {
register_save_preprocessor(function(&$index_entry, &$pagedata) {
$matches = [];
if(preg_match("/^# ?REDIRECT ?\[\[([^\]]+)\]\]/i", $pagedata) === 1)
{
// We have found a redirect page!
// Update the metadata to reflect this.
$index_entry->redirect = true;
$index_entry->redirect_target = $matches[1];
}
else
{
// This page isn't a redirect. Unset the metadata just in case.
if(isseet($index_entry->redirect))
unset($index_entry->redirect);
if(isseet($index_entry->redirect_target))
unset($index_entry->redirect_target);
}
});
// Todo register a function somewhere else to detect reedirects in the front end
}
]);
register_module([
"name" => "Credits",
@ -1197,8 +1230,12 @@ register_module([
if((!$env->is_logged_in and !$settings->anonedits) or // if we aren't logged in and anonymous edits are disbled
!$settings->editing or// or editing is disabled
($pageindex->$page->protect and !$env->is_admin) // the page is protected and the user isn't an admin
)
( // the page exists and is protected and the user isn't an admin
isset($pageindex->$page) and
$pageindex->$page->protect and
!$env->is_admin
)
)
{
if(!$creatingpage)
{
@ -1269,12 +1306,6 @@ register_module([
$pagedata = htmlentities($_POST["content"], ENT_QUOTES);
// Execute all the preprocessors
foreach($save_preprocessors as $func)
{
$func($pagedata);
}
if(file_put_contents("$env->page.md", $pagedata) !== false)
{
$page = $env->page;
@ -1294,6 +1325,14 @@ register_module([
else
$pageindex->$page->lasteditor = utf8_encode("anonymous");
// Execute all the preprocessors
foreach($save_preprocessors as $func)
{
$func($pageindex->$page, $pagedata);
}
file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT));
if(isset($_GET["newpage"]))
@ -1744,6 +1783,21 @@ register_module([
exit(page_renderer::render_main("$env->page - 404 - $settings->sitename", "<p>$env->page does not exist.</p><p>Since editing is currently disabled on this wiki, you may not create this page. If you feel that this page should exist, try contacting this wiki's Administrator.</p>"));
}
}
// Perform a redirect if the requested page is a redirect page
if(isset($pageindex->$page->redirect) &&
$pageindex->$page->redirect === true &&
( // Make sure that the redirect GET paramter isn'tset to 'no'
isset($_GET["redirect"]) &&
$_GET["redirect"] !== "no"
))
{
// Todo send an explanatory page along with the redirect
http_response_code(307);
header("location: ?action=view&page=" . $pageindex->$page->redirect_target . "&redirected_from=$env->page");
exit();
}
$title = "$env->page - $settings->sitename";
if(isset($pageindex->$page->protect) && $pageindex->$page->protect === true)
$title = $settings->protectedpagechar . $title;

View File

@ -35,6 +35,15 @@
"lastupdate": 1438776654,
"optional": false
},
{
"name": "Redirect pages",
"version": "0.1",
"author": "Starbeamrainbowlabs",
"description": "Adds support for redirect pages. Uses the same syntax that Mediawiki does.",
"id": "feature-redirect",
"lastupdate": 1443871356,
"optional": false
},
{
"name": "Credits",
"version": "0.6",
@ -59,7 +68,7 @@
"author": "Starbeamrainbowlabs",
"description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
"id": "page-edit",
"lastupdate": 1443608755,
"lastupdate": 1443871529,
"optional": false
},
{
@ -131,7 +140,7 @@
"author": "Starbeamrainbowlabs",
"description": "Allows you to view pages. You reallyshould include this one.",
"id": "page-view",
"lastupdate": 1443592985,
"lastupdate": 1443871241,
"optional": false
},
{

View File

@ -39,8 +39,12 @@ register_module([
if((!$env->is_logged_in and !$settings->anonedits) or // if we aren't logged in and anonymous edits are disbled
!$settings->editing or// or editing is disabled
($pageindex->$page->protect and !$env->is_admin) // the page is protected and the user isn't an admin
)
( // the page exists and is protected and the user isn't an admin
isset($pageindex->$page) and
$pageindex->$page->protect and
!$env->is_admin
)
)
{
if(!$creatingpage)
{