From dc860acfd3db082023b34fd769be7885c521b4cd Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Wed, 30 Jan 2019 21:34:24 +0000 Subject: [PATCH] Tidy up page-view module code --- build/index.php | 48 +++++++++++++++---------------------------- module_index.json | 2 +- modules/page-view.php | 46 ++++++++++++++--------------------------- 3 files changed, 32 insertions(+), 64 deletions(-) diff --git a/build/index.php b/build/index.php index 528acef..6f1fae1 100644 --- a/build/index.php +++ b/build/index.php @@ -409,7 +409,7 @@ if($settings->sessionprefix == "auto") ///////////////////////////////////////////////////////////////////////////// /** The version of Pepperminty Wiki currently running. */ $version = "v0.18-dev"; -$commit = "0ac2f24b5f84bf482ef420051a8c0b4e1a1c4d30"; +$commit = "1cb30b28ca8b7264041fc7a3660c12ac48f7819a"; /// Environment /// /** Holds information about the current request environment. */ $env = new stdClass(); @@ -8854,18 +8854,14 @@ register_module([ // Check to make sure that the page exists $page = $env->page; - if(!isset($pageindex->$page)) - { - // todo make this intelligent so we only redirect if the user is actually able to create the page - if($settings->editing) - { + if(!isset($pageindex->$page)) { + // TODO: make this intelligent so we only redirect if the user is actually able to create the page + if($settings->editing) { // Editing is enabled, redirect to the editing page http_response_code(307); // Temporary redirect header("location: index.php?action=edit&newpage=yes&page=" . rawurlencode($env->page)); exit(); - } - else - { + } else { // Editing is disabled, show an error message http_response_code(404); exit(page_renderer::render_main("404: Page not found - $env->page - $settings->sitename", "

$env->page does not exist.

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.

")); @@ -8882,16 +8878,14 @@ register_module([ if(isset($_GET["redirect"]) && $_GET["redirect"] == "no") $send_redirect = false; - if($send_redirect) - { - // Todo send an explanatory page along with the redirect + if($send_redirect) { + // TODO: Send an explanatory page along with the redirect http_response_code(307); $redirectUrl = "?action=$env->action&redirected_from=" . rawurlencode($env->page); $hashCode = ""; $newPage = $pageindex->$page->redirect_target; - if(strpos($newPage, "#") !== false) - { + if(strpos($newPage, "#") !== false) { // Extract the part after the hash symbol $hashCode = substr($newPage, strpos($newPage, "#") + 1); // Remove the hash from the new page name @@ -8914,16 +8908,14 @@ register_module([ $content = ""; if(!$env->is_history_revision) $content .= "

$env->page

\n"; - else - { + else { $content .= "

Revision #{$env->history->revision_number} of $env->page

\n"; $content .= "

(Revision saved by {$env->history->revision_data->editor} " . render_timestamp($env->history->revision_data->timestamp) . ". Jump to the current revision or see a list of all revisions for this page.)

\n"; } // Add a visit parent page link if we're a subpage - if(get_page_parent($env->page) !== false) { + if(get_page_parent($env->page) !== false) $content .= "\n"; - } // Add an extra message if the requester was redirected from another page if(isset($_GET["redirected_from"])) @@ -8934,13 +8926,10 @@ register_module([ $rawRenderedSource = parse_page_source(file_get_contents($env->page_filename)); $content .= $rawRenderedSource; - if(!empty($pageindex->$page->tags)) - { + if(!empty($pageindex->$page->tags)) { $content .= "\n"; } /*else @@ -8948,18 +8937,14 @@ register_module([ $content .= "\n"; }*/ - if($settings->show_subpages) - { + if($settings->show_subpages) { $subpages = get_object_vars(get_subpages($pageindex, $env->page)); - if(count($subpages) > 0) - { + if(count($subpages) > 0) { $content .= "
"; $content .= "Subpages: "; - foreach($subpages as $subpage => $times_removed) - { - if($times_removed <= $settings->subpages_display_depth) - { + foreach($subpages as $subpage => $times_removed) { + if($times_removed <= $settings->subpages_display_depth) { $content .= "$subpage, "; } } @@ -8979,8 +8964,7 @@ register_module([ $settings->footer_message = "$env->page was last edited by {$pageindex->{$env->page}->lasteditor} at " . date('h:ia T \o\n j F Y', $pageindex->{$env->page}->lastmodified) . ".

\n

" . $settings->footer_message; // Add the last edited time to the footer $mode = isset($_GET["mode"]) ? strtolower(trim($_GET["mode"])) : "normal"; - switch($mode) - { + switch($mode) { case "contentonly": // Content only mode: Send only the content of the page exit($content); diff --git a/module_index.json b/module_index.json index 3a255c3..83425e6 100755 --- a/module_index.json +++ b/module_index.json @@ -266,7 +266,7 @@ "author": "Starbeamrainbowlabs", "description": "Allows you to view pages. You really should include this one.", "id": "page-view", - "lastupdate": 1518647294, + "lastupdate": 1548884009, "optional": false }, { diff --git a/modules/page-view.php b/modules/page-view.php index 7166e26..7a3f9ab 100644 --- a/modules/page-view.php +++ b/modules/page-view.php @@ -32,18 +32,14 @@ register_module([ // Check to make sure that the page exists $page = $env->page; - if(!isset($pageindex->$page)) - { - // todo make this intelligent so we only redirect if the user is actually able to create the page - if($settings->editing) - { + if(!isset($pageindex->$page)) { + // TODO: make this intelligent so we only redirect if the user is actually able to create the page + if($settings->editing) { // Editing is enabled, redirect to the editing page http_response_code(307); // Temporary redirect header("location: index.php?action=edit&newpage=yes&page=" . rawurlencode($env->page)); exit(); - } - else - { + } else { // Editing is disabled, show an error message http_response_code(404); exit(page_renderer::render_main("404: Page not found - $env->page - $settings->sitename", "

$env->page does not exist.

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.

")); @@ -60,16 +56,14 @@ register_module([ if(isset($_GET["redirect"]) && $_GET["redirect"] == "no") $send_redirect = false; - if($send_redirect) - { - // Todo send an explanatory page along with the redirect + if($send_redirect) { + // TODO: Send an explanatory page along with the redirect http_response_code(307); $redirectUrl = "?action=$env->action&redirected_from=" . rawurlencode($env->page); $hashCode = ""; $newPage = $pageindex->$page->redirect_target; - if(strpos($newPage, "#") !== false) - { + if(strpos($newPage, "#") !== false) { // Extract the part after the hash symbol $hashCode = substr($newPage, strpos($newPage, "#") + 1); // Remove the hash from the new page name @@ -92,16 +86,14 @@ register_module([ $content = ""; if(!$env->is_history_revision) $content .= "

$env->page

\n"; - else - { + else { $content .= "

Revision #{$env->history->revision_number} of $env->page

\n"; $content .= "

(Revision saved by {$env->history->revision_data->editor} " . render_timestamp($env->history->revision_data->timestamp) . ". Jump to the current revision or see a list of all revisions for this page.)

\n"; } // Add a visit parent page link if we're a subpage - if(get_page_parent($env->page) !== false) { + if(get_page_parent($env->page) !== false) $content .= "\n"; - } // Add an extra message if the requester was redirected from another page if(isset($_GET["redirected_from"])) @@ -112,13 +104,10 @@ register_module([ $rawRenderedSource = parse_page_source(file_get_contents($env->page_filename)); $content .= $rawRenderedSource; - if(!empty($pageindex->$page->tags)) - { + if(!empty($pageindex->$page->tags)) { $content .= "\n"; } /*else @@ -126,18 +115,14 @@ register_module([ $content .= "\n"; }*/ - if($settings->show_subpages) - { + if($settings->show_subpages) { $subpages = get_object_vars(get_subpages($pageindex, $env->page)); - if(count($subpages) > 0) - { + if(count($subpages) > 0) { $content .= "
"; $content .= "Subpages: "; - foreach($subpages as $subpage => $times_removed) - { - if($times_removed <= $settings->subpages_display_depth) - { + foreach($subpages as $subpage => $times_removed) { + if($times_removed <= $settings->subpages_display_depth) { $content .= "$subpage, "; } } @@ -157,8 +142,7 @@ register_module([ $settings->footer_message = "$env->page was last edited by {$pageindex->{$env->page}->lasteditor} at " . date('h:ia T \o\n j F Y', $pageindex->{$env->page}->lastmodified) . ".

\n

" . $settings->footer_message; // Add the last edited time to the footer $mode = isset($_GET["mode"]) ? strtolower(trim($_GET["mode"])) : "normal"; - switch($mode) - { + switch($mode) { case "contentonly": // Content only mode: Send only the content of the page exit($content);