1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-12-22 13:45:02 +00:00

Add absolute redirects

This commit is contained in:
Starbeamrainbowlabs 2020-07-07 21:10:38 +01:00
parent beb4e2e968
commit 1813fe73e2
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
5 changed files with 25 additions and 4 deletions

View file

@ -30,6 +30,7 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t
- Squashed a warning when using the fenced code block syntax
- If a redirect page sends you to create a page that doesn't exist, a link back to the redirect page itself is now displayed
- Really fix bots getting into infinite loops on the login page this time by marking all login pages as `noindex, nofollow` with a robots `<meta />` tag
- Navigating to a redirect page from a page list will no longer cause you to automatically follow the redirect
## v0.21

View file

@ -61,7 +61,7 @@ function url_stem( $s = false, bool $use_forwarded_host = false) : string {
*/
function human_filesize($bytes, $decimals = 2)
{
$sz = ["b", "kb", "mb", "gb", "tb", "pb", "eb", "yb", "zb"];
$sz = ["b", "kib", "mib", "gib", "tib", "pib", "eib", "yib", "zib"];
$factor = floor((strlen($bytes) - 1) / 3);
$result = round($bytes / pow(1024, $factor), $decimals);
return $result . @$sz[$factor];

View file

@ -10,8 +10,11 @@ register_module([
register_save_preprocessor("update_redirect_metadata");
$help_html = "<p>$settings->sitename supports redirect pages. To create a redirect page, enter something like <code># REDIRECT [[pagename]]</code> on the first line of the redirect page's content. This <em>must</em> appear as the first line of the page, with no whitespace before it. You can include content beneath the redirect if you want, too (such as a reason for redirecting the page).</p>";
if($settings->redirect_absolute_enabled == true) $help_html .= "<p>$settings->sitename also has absolute redirects enabled (e.g. if you want to make your main page point to the all pages list). To make a page an absolute redirect page, enter the following on the first line: <code># REDIRECT [all pages](?action=list)</code>. This example will cause the page to become a redirect to the all pages list. Of course, you can change the <code>?action=list</code> bit to be any regular URL you like (relative or absolute)</p>";
// Register a help section
add_help_section("25-redirect", "Redirect Pages", "<p>$settings->sitename supports redirect pages. To create a redirect page, enter something like <code># REDIRECT [[pagename]]</code> on the first line of the redirect page's content. This <em>must</em> appear as the first line of the page, with no whitespace before it. You can include content beneath the redirect if you want, too (such as a reason for redirecting the page).</p>");
add_help_section("25-redirect", "Redirect Pages", $help_html);
}
]);
@ -31,6 +34,13 @@ function update_redirect_metadata(&$index_entry, &$pagedata) {
// Update the metadata to reflect this.
$index_entry->redirect = true;
$index_entry->redirect_target = $matches[1];
$index_entry->redirect_absolute = false;
}
// We don't disable absolute redirects here, because it's the view action that processes them - we only register them here. Checking here would result in pages that are supposed to be redirects being missed if redirect_absolute_enabled is turned on after such a page is created.
elseif(preg_match("/^# ?REDIRECT ?\[[^\]]+\]\(([^)]+)\)/", $pagedata, $matches) === 1) {
$index_entry->redirect = true;
$index_entry->redirect_target = $matches[1];
$index_entry->redirect_absolute = true;
}
else
{
@ -39,6 +49,8 @@ function update_redirect_metadata(&$index_entry, &$pagedata) {
unset($index_entry->redirect);
if(isset($index_entry->redirect_target))
unset($index_entry->redirect_target);
if(isset($index_entry->redirect_absolute))
unset($index_entry->redirect_absolute);
}
}

View file

@ -56,8 +56,11 @@ register_module([
header("last-modified: " . gmdate('D, d M Y H:i:s T', $pageindex->{$env->page}->lastmodified));
// Perform a redirect if the requested page is a redirect page
if(isset($pageindex->$page->redirect) &&
$pageindex->$page->redirect === true)
if(isset($pageindex->$page->redirect) &&
$pageindex->$page->redirect === true && // If this is a redirect page.....
(isset($pageindex->$page->redirect_absolute) &&
$pageindex->$page->redirect_absolute == true && // ...and it's absolute....
$settings->redirect_absolute_enable === true)) // ...and absolute reedirects are enabled
{
$send_redirect = true;
if(isset($_GET["redirect"]) && $_GET["redirect"] == "no")
@ -82,6 +85,10 @@ register_module([
if(strlen($hashCode) > 0)
$redirectUrl .= "#$hashCode";
// Support absolute redirect URLs
if(isset($pageindex->$page->redirect_absolute) && $pageindex->$page->redirect_absolute === true)
$redirectUrl = $pageindex->$page->redirect_target;
header("location: $redirectUrl");
exit();
}

View file

@ -11,6 +11,7 @@
"subpages_display_depth": { "type": "text", "description": "The depth to which we should display when listing subpages at the bottom the page.", "default": 3},
"random_page_exclude": { "type": "text", "description": "The pages names matching this regular expression won't be chosen when a random page is being picked to send you to by the random action.", "default": "/^Files\\/.*$/i" },
"random_page_exclude_redirects": { "type": "checkbox", "description": "Causes the random action to avoid sending the user to a redirect page.", "default": true },
"redirect_absolute_enable": { "type": "checkbox", "description": "Whether to enable absolute redirects or not. Enable only if you trust everyone who has edit access to your wiki, as it is possible to redirect a page to <em>anywhere</em> on the Internet - including a malicious website - hence the reason why this is disabled by default for safety.", "default": false },
"footer_message": { "type": "textarea", "description": "A message that will appear at the bottom of every page. May contain HTML.", "default": "All content is under <a href='?page=License' target='_blank'>this license</a>. Please make sure that you read and understand the license, especially if you are thinking about copying some (or all) of this site's content, as it may restrict you from doing so." },
"editing_message": { "type": "textarea", "description": "A message that will appear just before the submit button on the editing page. May contain HTML.", "default": "<a href='?action=help#20-parser-default' target='_blank'>Formatting help</a> (<a href='https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet' target='_blank'>Markdown Cheatsheet</a>)<br />\nBy submitting your edit or uploading your file, you are agreeing to release your changes under <a href='?action=view&page=License' target='_blank'>this license</a>. Also note that if you don't want your work to be edited by other users of this site, please don't submit it here!" },
"editing_tags_autocomplete": { "type": "checkbox", "description": "Whether to enable autocomplete for the tags box in the page editor.", "default": true },