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

Tidy up page-view module code

This commit is contained in:
Starbeamrainbowlabs 2019-01-30 21:34:24 +00:00
parent 1cb30b28ca
commit dc860acfd3
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
3 changed files with 32 additions and 64 deletions

View file

@ -409,7 +409,7 @@ if($settings->sessionprefix == "auto")
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
/** The version of Pepperminty Wiki currently running. */ /** The version of Pepperminty Wiki currently running. */
$version = "v0.18-dev"; $version = "v0.18-dev";
$commit = "0ac2f24b5f84bf482ef420051a8c0b4e1a1c4d30"; $commit = "1cb30b28ca8b7264041fc7a3660c12ac48f7819a";
/// Environment /// /// Environment ///
/** Holds information about the current request environment. */ /** Holds information about the current request environment. */
$env = new stdClass(); $env = new stdClass();
@ -8854,18 +8854,14 @@ register_module([
// Check to make sure that the page exists // Check to make sure that the page exists
$page = $env->page; $page = $env->page;
if(!isset($pageindex->$page)) if(!isset($pageindex->$page)) {
{ // TODO: make this intelligent so we only redirect if the user is actually able to create the page
// todo make this intelligent so we only redirect if the user is actually able to create the page if($settings->editing) {
if($settings->editing)
{
// Editing is enabled, redirect to the editing page // Editing is enabled, redirect to the editing page
http_response_code(307); // Temporary redirect http_response_code(307); // Temporary redirect
header("location: index.php?action=edit&newpage=yes&page=" . rawurlencode($env->page)); header("location: index.php?action=edit&newpage=yes&page=" . rawurlencode($env->page));
exit(); exit();
} } else {
else
{
// Editing is disabled, show an error message // Editing is disabled, show an error message
http_response_code(404); http_response_code(404);
exit(page_renderer::render_main("404: Page not found - $env->page - $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>")); exit(page_renderer::render_main("404: Page not found - $env->page - $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>"));
@ -8882,16 +8878,14 @@ register_module([
if(isset($_GET["redirect"]) && $_GET["redirect"] == "no") if(isset($_GET["redirect"]) && $_GET["redirect"] == "no")
$send_redirect = false; $send_redirect = false;
if($send_redirect) if($send_redirect) {
{ // TODO: Send an explanatory page along with the redirect
// Todo send an explanatory page along with the redirect
http_response_code(307); http_response_code(307);
$redirectUrl = "?action=$env->action&redirected_from=" . rawurlencode($env->page); $redirectUrl = "?action=$env->action&redirected_from=" . rawurlencode($env->page);
$hashCode = ""; $hashCode = "";
$newPage = $pageindex->$page->redirect_target; $newPage = $pageindex->$page->redirect_target;
if(strpos($newPage, "#") !== false) if(strpos($newPage, "#") !== false) {
{
// Extract the part after the hash symbol // Extract the part after the hash symbol
$hashCode = substr($newPage, strpos($newPage, "#") + 1); $hashCode = substr($newPage, strpos($newPage, "#") + 1);
// Remove the hash from the new page name // Remove the hash from the new page name
@ -8914,16 +8908,14 @@ register_module([
$content = ""; $content = "";
if(!$env->is_history_revision) if(!$env->is_history_revision)
$content .= "<h1>$env->page</h1>\n"; $content .= "<h1>$env->page</h1>\n";
else else {
{
$content .= "<h1>Revision #{$env->history->revision_number} of $env->page</h1>\n"; $content .= "<h1>Revision #{$env->history->revision_number} of $env->page</h1>\n";
$content .= "<p class='revision-note'><em>(Revision saved by {$env->history->revision_data->editor} " . render_timestamp($env->history->revision_data->timestamp) . ". <a href='?page=" . rawurlencode($env->page) . "'>Jump to the current revision</a> or see a <a href='?action=history&page=" . rawurlencode($env->page) . "'>list of all revisions</a> for this page.)</em></p>\n"; $content .= "<p class='revision-note'><em>(Revision saved by {$env->history->revision_data->editor} " . render_timestamp($env->history->revision_data->timestamp) . ". <a href='?page=" . rawurlencode($env->page) . "'>Jump to the current revision</a> or see a <a href='?action=history&page=" . rawurlencode($env->page) . "'>list of all revisions</a> for this page.)</em></p>\n";
} }
// Add a visit parent page link if we're a subpage // 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 .= "<p class='link-parent-page'><em><a href='?action=view&page=" . rawurlencode(get_page_parent($env->page)) . "'>&laquo; " . htmlentities(get_page_parent($env->page)) . "</a></em></p>\n"; $content .= "<p class='link-parent-page'><em><a href='?action=view&page=" . rawurlencode(get_page_parent($env->page)) . "'>&laquo; " . htmlentities(get_page_parent($env->page)) . "</a></em></p>\n";
}
// Add an extra message if the requester was redirected from another page // Add an extra message if the requester was redirected from another page
if(isset($_GET["redirected_from"])) if(isset($_GET["redirected_from"]))
@ -8934,13 +8926,10 @@ register_module([
$rawRenderedSource = parse_page_source(file_get_contents($env->page_filename)); $rawRenderedSource = parse_page_source(file_get_contents($env->page_filename));
$content .= $rawRenderedSource; $content .= $rawRenderedSource;
if(!empty($pageindex->$page->tags)) if(!empty($pageindex->$page->tags)) {
{
$content .= "<ul class='page-tags-display'>\n"; $content .= "<ul class='page-tags-display'>\n";
foreach($pageindex->$page->tags as $tag) foreach($pageindex->$page->tags as $tag)
{
$content .= "<li><a href='?action=list-tags&tag=" . rawurlencode($tag) . "'>$tag</a></li>\n"; $content .= "<li><a href='?action=list-tags&tag=" . rawurlencode($tag) . "'>$tag</a></li>\n";
}
$content .= "\n</ul>\n"; $content .= "\n</ul>\n";
} }
/*else /*else
@ -8948,18 +8937,14 @@ register_module([
$content .= "<aside class='page-tags-display'><small><em>(No tags yet! Add some by <a href='?action=edit&page=" . rawurlencode($env->page) . "'>editing this page</a>!)</em></small></aside>\n"; $content .= "<aside class='page-tags-display'><small><em>(No tags yet! Add some by <a href='?action=edit&page=" . rawurlencode($env->page) . "'>editing this page</a>!)</em></small></aside>\n";
}*/ }*/
if($settings->show_subpages) if($settings->show_subpages) {
{
$subpages = get_object_vars(get_subpages($pageindex, $env->page)); $subpages = get_object_vars(get_subpages($pageindex, $env->page));
if(count($subpages) > 0) if(count($subpages) > 0) {
{
$content .= "<hr />"; $content .= "<hr />";
$content .= "Subpages: "; $content .= "Subpages: ";
foreach($subpages as $subpage => $times_removed) foreach($subpages as $subpage => $times_removed) {
{ if($times_removed <= $settings->subpages_display_depth) {
if($times_removed <= $settings->subpages_display_depth)
{
$content .= "<a href='?action=view&page=" . rawurlencode($subpage) . "'>$subpage</a>, "; $content .= "<a href='?action=view&page=" . rawurlencode($subpage) . "'>$subpage</a>, ";
} }
} }
@ -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) . ".</p>\n<p>" . $settings->footer_message; // Add the last edited time to the footer $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) . ".</p>\n<p>" . $settings->footer_message; // Add the last edited time to the footer
$mode = isset($_GET["mode"]) ? strtolower(trim($_GET["mode"])) : "normal"; $mode = isset($_GET["mode"]) ? strtolower(trim($_GET["mode"])) : "normal";
switch($mode) switch($mode) {
{
case "contentonly": case "contentonly":
// Content only mode: Send only the content of the page // Content only mode: Send only the content of the page
exit($content); exit($content);

View file

@ -266,7 +266,7 @@
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Allows you to view pages. You really should include this one.", "description": "Allows you to view pages. You really should include this one.",
"id": "page-view", "id": "page-view",
"lastupdate": 1518647294, "lastupdate": 1548884009,
"optional": false "optional": false
}, },
{ {

View file

@ -32,18 +32,14 @@ register_module([
// Check to make sure that the page exists // Check to make sure that the page exists
$page = $env->page; $page = $env->page;
if(!isset($pageindex->$page)) if(!isset($pageindex->$page)) {
{ // TODO: make this intelligent so we only redirect if the user is actually able to create the page
// todo make this intelligent so we only redirect if the user is actually able to create the page if($settings->editing) {
if($settings->editing)
{
// Editing is enabled, redirect to the editing page // Editing is enabled, redirect to the editing page
http_response_code(307); // Temporary redirect http_response_code(307); // Temporary redirect
header("location: index.php?action=edit&newpage=yes&page=" . rawurlencode($env->page)); header("location: index.php?action=edit&newpage=yes&page=" . rawurlencode($env->page));
exit(); exit();
} } else {
else
{
// Editing is disabled, show an error message // Editing is disabled, show an error message
http_response_code(404); http_response_code(404);
exit(page_renderer::render_main("404: Page not found - $env->page - $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>")); exit(page_renderer::render_main("404: Page not found - $env->page - $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>"));
@ -60,16 +56,14 @@ register_module([
if(isset($_GET["redirect"]) && $_GET["redirect"] == "no") if(isset($_GET["redirect"]) && $_GET["redirect"] == "no")
$send_redirect = false; $send_redirect = false;
if($send_redirect) if($send_redirect) {
{ // TODO: Send an explanatory page along with the redirect
// Todo send an explanatory page along with the redirect
http_response_code(307); http_response_code(307);
$redirectUrl = "?action=$env->action&redirected_from=" . rawurlencode($env->page); $redirectUrl = "?action=$env->action&redirected_from=" . rawurlencode($env->page);
$hashCode = ""; $hashCode = "";
$newPage = $pageindex->$page->redirect_target; $newPage = $pageindex->$page->redirect_target;
if(strpos($newPage, "#") !== false) if(strpos($newPage, "#") !== false) {
{
// Extract the part after the hash symbol // Extract the part after the hash symbol
$hashCode = substr($newPage, strpos($newPage, "#") + 1); $hashCode = substr($newPage, strpos($newPage, "#") + 1);
// Remove the hash from the new page name // Remove the hash from the new page name
@ -92,16 +86,14 @@ register_module([
$content = ""; $content = "";
if(!$env->is_history_revision) if(!$env->is_history_revision)
$content .= "<h1>$env->page</h1>\n"; $content .= "<h1>$env->page</h1>\n";
else else {
{
$content .= "<h1>Revision #{$env->history->revision_number} of $env->page</h1>\n"; $content .= "<h1>Revision #{$env->history->revision_number} of $env->page</h1>\n";
$content .= "<p class='revision-note'><em>(Revision saved by {$env->history->revision_data->editor} " . render_timestamp($env->history->revision_data->timestamp) . ". <a href='?page=" . rawurlencode($env->page) . "'>Jump to the current revision</a> or see a <a href='?action=history&page=" . rawurlencode($env->page) . "'>list of all revisions</a> for this page.)</em></p>\n"; $content .= "<p class='revision-note'><em>(Revision saved by {$env->history->revision_data->editor} " . render_timestamp($env->history->revision_data->timestamp) . ". <a href='?page=" . rawurlencode($env->page) . "'>Jump to the current revision</a> or see a <a href='?action=history&page=" . rawurlencode($env->page) . "'>list of all revisions</a> for this page.)</em></p>\n";
} }
// Add a visit parent page link if we're a subpage // 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 .= "<p class='link-parent-page'><em><a href='?action=view&page=" . rawurlencode(get_page_parent($env->page)) . "'>&laquo; " . htmlentities(get_page_parent($env->page)) . "</a></em></p>\n"; $content .= "<p class='link-parent-page'><em><a href='?action=view&page=" . rawurlencode(get_page_parent($env->page)) . "'>&laquo; " . htmlentities(get_page_parent($env->page)) . "</a></em></p>\n";
}
// Add an extra message if the requester was redirected from another page // Add an extra message if the requester was redirected from another page
if(isset($_GET["redirected_from"])) if(isset($_GET["redirected_from"]))
@ -112,13 +104,10 @@ register_module([
$rawRenderedSource = parse_page_source(file_get_contents($env->page_filename)); $rawRenderedSource = parse_page_source(file_get_contents($env->page_filename));
$content .= $rawRenderedSource; $content .= $rawRenderedSource;
if(!empty($pageindex->$page->tags)) if(!empty($pageindex->$page->tags)) {
{
$content .= "<ul class='page-tags-display'>\n"; $content .= "<ul class='page-tags-display'>\n";
foreach($pageindex->$page->tags as $tag) foreach($pageindex->$page->tags as $tag)
{
$content .= "<li><a href='?action=list-tags&tag=" . rawurlencode($tag) . "'>$tag</a></li>\n"; $content .= "<li><a href='?action=list-tags&tag=" . rawurlencode($tag) . "'>$tag</a></li>\n";
}
$content .= "\n</ul>\n"; $content .= "\n</ul>\n";
} }
/*else /*else
@ -126,18 +115,14 @@ register_module([
$content .= "<aside class='page-tags-display'><small><em>(No tags yet! Add some by <a href='?action=edit&page=" . rawurlencode($env->page) . "'>editing this page</a>!)</em></small></aside>\n"; $content .= "<aside class='page-tags-display'><small><em>(No tags yet! Add some by <a href='?action=edit&page=" . rawurlencode($env->page) . "'>editing this page</a>!)</em></small></aside>\n";
}*/ }*/
if($settings->show_subpages) if($settings->show_subpages) {
{
$subpages = get_object_vars(get_subpages($pageindex, $env->page)); $subpages = get_object_vars(get_subpages($pageindex, $env->page));
if(count($subpages) > 0) if(count($subpages) > 0) {
{
$content .= "<hr />"; $content .= "<hr />";
$content .= "Subpages: "; $content .= "Subpages: ";
foreach($subpages as $subpage => $times_removed) foreach($subpages as $subpage => $times_removed) {
{ if($times_removed <= $settings->subpages_display_depth) {
if($times_removed <= $settings->subpages_display_depth)
{
$content .= "<a href='?action=view&page=" . rawurlencode($subpage) . "'>$subpage</a>, "; $content .= "<a href='?action=view&page=" . rawurlencode($subpage) . "'>$subpage</a>, ";
} }
} }
@ -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) . ".</p>\n<p>" . $settings->footer_message; // Add the last edited time to the footer $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) . ".</p>\n<p>" . $settings->footer_message; // Add the last edited time to the footer
$mode = isset($_GET["mode"]) ? strtolower(trim($_GET["mode"])) : "normal"; $mode = isset($_GET["mode"]) ? strtolower(trim($_GET["mode"])) : "normal";
switch($mode) switch($mode) {
{
case "contentonly": case "contentonly":
// Content only mode: Send only the content of the page // Content only mode: Send only the content of the page
exit($content); exit($content);