mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-12-22 01:35:02 +00:00
Tidy up page-view module code
This commit is contained in:
parent
1cb30b28ca
commit
dc860acfd3
3 changed files with 32 additions and 64 deletions
|
@ -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", "<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")
|
||||
$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 .= "<h1>$env->page</h1>\n";
|
||||
else
|
||||
{
|
||||
else {
|
||||
$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";
|
||||
}
|
||||
|
||||
// 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)) . "'>« " . htmlentities(get_page_parent($env->page)) . "</a></em></p>\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 .= "<ul class='page-tags-display'>\n";
|
||||
foreach($pageindex->$page->tags as $tag)
|
||||
{
|
||||
$content .= "<li><a href='?action=list-tags&tag=" . rawurlencode($tag) . "'>$tag</a></li>\n";
|
||||
}
|
||||
$content .= "\n</ul>\n";
|
||||
}
|
||||
/*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";
|
||||
}*/
|
||||
|
||||
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 .= "<hr />";
|
||||
$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 .= "<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
|
||||
|
||||
$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);
|
||||
|
|
|
@ -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
|
||||
},
|
||||
{
|
||||
|
|
|
@ -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", "<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")
|
||||
$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 .= "<h1>$env->page</h1>\n";
|
||||
else
|
||||
{
|
||||
else {
|
||||
$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";
|
||||
}
|
||||
|
||||
// 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)) . "'>« " . htmlentities(get_page_parent($env->page)) . "</a></em></p>\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 .= "<ul class='page-tags-display'>\n";
|
||||
foreach($pageindex->$page->tags as $tag)
|
||||
{
|
||||
$content .= "<li><a href='?action=list-tags&tag=" . rawurlencode($tag) . "'>$tag</a></li>\n";
|
||||
}
|
||||
$content .= "\n</ul>\n";
|
||||
}
|
||||
/*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";
|
||||
}*/
|
||||
|
||||
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 .= "<hr />";
|
||||
$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 .= "<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
|
||||
|
||||
$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);
|
||||
|
|
Loading…
Reference in a new issue