1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-22 04:23:01 +00:00

Fix redirect sending conditions

This commit is contained in:
Starbeamrainbowlabs 2015-10-03 13:29:07 +01:00
parent 00940645c7
commit f1824243f5
3 changed files with 31 additions and 26 deletions

View file

@ -838,7 +838,7 @@ $save_preprocessors = [];
function register_save_preprocessor($func) function register_save_preprocessor($func)
{ {
global $save_preprocessors; global $save_preprocessors;
$save_processessors[] = $func; $save_preprocessors[] = $func;
} }
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
@ -1055,7 +1055,6 @@ function render_sidebar($pageindex, $root_pagename = "")
error_log("Initialising redirect page support");
register_module([ register_module([
"name" => "Redirect pages", "name" => "Redirect pages",
"version" => "0.1", "version" => "0.1",
@ -1064,10 +1063,10 @@ register_module([
"id" => "feature-redirect", "id" => "feature-redirect",
"code" => function() { "code" => function() {
register_save_preprocessor(function(&$index_entry, &$pagedata) { register_save_preprocessor(function(&$index_entry, &$pagedata) {
error_log("Running redirect check");
$matches = []; $matches = [];
if(preg_match("/^# ?REDIRECT ?\[\[([^\]]+)\]\]/i", $pagedata) === 1) if(preg_match("/^# ?REDIRECT ?\[\[([^\]]+)\]\]/i", $pagedata, $matches) === 1)
{ {
error_log("matches: " . var_export($matches, true));
// We have found a redirect page! // We have found a redirect page!
// Update the metadata to reflect this. // Update the metadata to reflect this.
$index_entry->redirect = true; $index_entry->redirect = true;
@ -1347,7 +1346,7 @@ register_module([
else else
http_response_code(200); http_response_code(200);
header("location: index.php?page=$env->page&edit_status=success"); header("location: index.php?page=$env->page&edit_status=success&redirect=no");
exit(); exit();
} }
else else
@ -1793,16 +1792,19 @@ register_module([
// Perform a redirect if the requested page is a redirect page // Perform a redirect if the requested page is a redirect page
if(isset($pageindex->$page->redirect) && if(isset($pageindex->$page->redirect) &&
$pageindex->$page->redirect === true && $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 $send_redirect = true;
http_response_code(307); if(isset($_GET["redirect"]) && $_GET["redirect"] == "no")
header("location: ?action=view&page=" . $pageindex->$page->redirect_target . "&redirected_from=$env->page"); $send_redirect = false;
exit();
if($send_redirect)
{
// 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"; $title = "$env->page - $settings->sitename";

View file

@ -41,7 +41,7 @@
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Adds support for redirect pages. Uses the same syntax that Mediawiki does.", "description": "Adds support for redirect pages. Uses the same syntax that Mediawiki does.",
"id": "feature-redirect", "id": "feature-redirect",
"lastupdate": 1443872212, "lastupdate": 1443874989,
"optional": false "optional": false
}, },
{ {
@ -68,7 +68,7 @@
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.", "description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
"id": "page-edit", "id": "page-edit",
"lastupdate": 1443872342, "lastupdate": 1443874970,
"optional": false "optional": false
}, },
{ {
@ -140,7 +140,7 @@
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Allows you to view pages. You reallyshould include this one.", "description": "Allows you to view pages. You reallyshould include this one.",
"id": "page-view", "id": "page-view",
"lastupdate": 1443871241, "lastupdate": 1443875269,
"optional": false "optional": false
}, },
{ {

View file

@ -31,16 +31,19 @@ register_module([
// Perform a redirect if the requested page is a redirect page // Perform a redirect if the requested page is a redirect page
if(isset($pageindex->$page->redirect) && if(isset($pageindex->$page->redirect) &&
$pageindex->$page->redirect === true && $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 $send_redirect = true;
http_response_code(307); if(isset($_GET["redirect"]) && $_GET["redirect"] == "no")
header("location: ?action=view&page=" . $pageindex->$page->redirect_target . "&redirected_from=$env->page"); $send_redirect = false;
exit();
if($send_redirect)
{
// 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"; $title = "$env->page - $settings->sitename";