Skip to content

Commit

Permalink
Allow hashes in redirects. Also fix bug in page moving.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrl committed Aug 19, 2016
1 parent 16076a8 commit 63d0bdd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
19 changes: 16 additions & 3 deletions build/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4434,7 +4434,7 @@ function hash_password($pass)
$pageindex->$new_name->$key = $value;
}
unset($pageindex->$page);
$pageindex->$new_name->filename = $new_name;
$pageindex->$new_name->filename = "$new_name.md";

// If this page has an associated file, then we should move that too
if(!empty($pageindex->$new_name->uploadedfile))
Expand Down Expand Up @@ -4589,7 +4589,7 @@ function hash_password($pass)
* @apiParam {number} revision The revision number to display.
* @apiParam {string} printable Set to 'yes' to get a printable version of the specified page instead.
*
* @apiError NonExistentPageError The page doesn't exist and editing is disabled in the wiki's settings. If editing isn't disabled, you will be redirected to the edit apge instead.
* @apiError NonExistentPageError The page doesn't exist and editing is disabled in the wiki's settings. If editing isn't disabled, you will be redirected to the edit page instead.
* @apiError NonExistentRevisionError The specified revision was not found.
*/

Expand Down Expand Up @@ -4635,7 +4635,20 @@ function hash_password($pass)
{
// Todo send an explanatory page along with the redirect
http_response_code(307);
header("location: ?action=$env->action&page=" . $pageindex->$page->redirect_target . "&redirected_from=$env->page");
$redirectUrl = "?action=$env->action&redirected_from=$env->page";

$hashCode = "";
$newPage = $pageindex->$page->redirect_target;
if(strpos($newPage, "#") !== false)
{
$hashCode = substr($newPage, strpos($newPage, "#") + 1);
$newPage = substr($newPage, 0, strpos($newPage, "#"));
}
$newPage .= "&page=" . $pageindex->$page->redirect_target;
if(strlen($hashCode) > 0)
$newPage .= "#$hashCode";

header("location: $redirectUrl");
exit();
}
}
Expand Down
4 changes: 2 additions & 2 deletions module_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
"author": "Starbeamrainbowlabs",
"description": "Adds an action to allow administrators to move pages.",
"id": "page-move",
"lastupdate": 1466582736,
"lastupdate": 1471631964,
"optional": false
},
{
Expand All @@ -185,7 +185,7 @@
"author": "Starbeamrainbowlabs",
"description": "Allows you to view pages. You really should include this one.",
"id": "page-view",
"lastupdate": 1466969288,
"lastupdate": 1471632495,
"optional": false
},
{
Expand Down
17 changes: 15 additions & 2 deletions modules/page-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @apiParam {number} revision The revision number to display.
* @apiParam {string} printable Set to 'yes' to get a printable version of the specified page instead.
*
* @apiError NonExistentPageError The page doesn't exist and editing is disabled in the wiki's settings. If editing isn't disabled, you will be redirected to the edit apge instead.
* @apiError NonExistentPageError The page doesn't exist and editing is disabled in the wiki's settings. If editing isn't disabled, you will be redirected to the edit page instead.
* @apiError NonExistentRevisionError The specified revision was not found.
*/

Expand Down Expand Up @@ -62,7 +62,20 @@
{
// Todo send an explanatory page along with the redirect
http_response_code(307);
header("location: ?action=$env->action&page=" . $pageindex->$page->redirect_target . "&redirected_from=$env->page");
$redirectUrl = "?action=$env->action&redirected_from=$env->page";

$hashCode = "";
$newPage = $pageindex->$page->redirect_target;
if(strpos($newPage, "#") !== false)
{
$hashCode = substr($newPage, strpos($newPage, "#") + 1);
$newPage = substr($newPage, 0, strpos($newPage, "#"));
}
$newPage .= "&page=" . $pageindex->$page->redirect_target;
if(strlen($hashCode) > 0)
$newPage .= "#$hashCode";

header("location: $redirectUrl");
exit();
}
}
Expand Down

0 comments on commit 63d0bdd

Please sign in to comment.