mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-12-22 13:45:02 +00:00
124 lines
4.8 KiB
PHP
124 lines
4.8 KiB
PHP
<?php
|
|
register_module([
|
|
"name" => "Page viewer",
|
|
"version" => "0.13",
|
|
"author" => "Starbeamrainbowlabs",
|
|
"description" => "Allows you to view pages. You really should include this one.",
|
|
"id" => "page-view",
|
|
"code" => function() {
|
|
/*
|
|
* ██ ██ ██ ███████ ██ ██
|
|
* ██ ██ ██ ██ ██ ██
|
|
* ██ ██ ██ █████ ██ █ ██
|
|
* ██ ██ ██ ██ ██ ███ ██
|
|
* ████ ██ ███████ ███ ███
|
|
*/
|
|
add_action("view", function() {
|
|
global $pageindex, $settings, $env;
|
|
|
|
// 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 acutally 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
|
|
{
|
|
// Editing is disabled, show an error message
|
|
http_response_code(404);
|
|
exit(page_renderer::render_main("$env->page - 404 - $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>"));
|
|
}
|
|
}
|
|
|
|
// Perform a redirect if the requested page is a redirect page
|
|
if(isset($pageindex->$page->redirect) &&
|
|
$pageindex->$page->redirect === true)
|
|
{
|
|
$send_redirect = true;
|
|
if(isset($_GET["redirect"]) && $_GET["redirect"] == "no")
|
|
$send_redirect = false;
|
|
|
|
if($send_redirect)
|
|
{
|
|
// 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");
|
|
exit();
|
|
}
|
|
}
|
|
|
|
$title = "$env->page - $settings->sitename";
|
|
if(isset($pageindex->$page->protect) && $pageindex->$page->protect === true)
|
|
$title = $settings->protectedpagechar . $title;
|
|
$content = "<h1>$env->page</h1>\n";
|
|
|
|
// Add an extra message if the requester was redirected from another page
|
|
if(isset($_GET["redirected_from"]))
|
|
$content .= "<p><em>Redirected from <a href='?page=" . rawurlencode($_GET["redirected_from"]) . "&redirect=no'>" . $_GET["redirected_from"] . "</a>.</em></p>";
|
|
|
|
$parsing_start = microtime(true);
|
|
|
|
$content .= parse_page_source(file_get_contents("$env->storage_prefix$env->page.md"));
|
|
|
|
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=$tag'>$tag</a></li>\n";
|
|
}
|
|
$content .= "\n</ul>\n";
|
|
}
|
|
/*else
|
|
{
|
|
$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)
|
|
{
|
|
$subpages = get_object_vars(get_subpages($pageindex, $env->page));
|
|
|
|
if(count($subpages) > 0)
|
|
{
|
|
$content .= "<hr />";
|
|
$content .= "Subpages: ";
|
|
foreach($subpages as $subpage => $times_removed)
|
|
{
|
|
if($times_removed <= $settings->subpages_display_depth)
|
|
{
|
|
$content .= "<a href='?action=view&page=" . rawurlencode($subpage) . "'>$subpage</a>, ";
|
|
}
|
|
}
|
|
// Remove the last comma from the content
|
|
$content = substr($content, 0, -2);
|
|
}
|
|
}
|
|
|
|
$content .= "\n\t\t<!-- Took " . round((microtime(true) - $parsing_start) * 1000, 2) . "ms to parse page source -->\n";
|
|
|
|
// Prevent indexing of this page if it's still within the noindex
|
|
// time period
|
|
if(isset($settings->delayed_indexing_time) and
|
|
time() - $pageindex->{$env->page}->lastmodified < $settings->delayed_indexing_time)
|
|
header("x-robots-tag: noindex");
|
|
|
|
// Content only mode: Send only the raw rendered page
|
|
if(isset($_GET["contentonly"]) and $_GET["contentonly"] === "yes")
|
|
exit(parse_page_source($content));
|
|
// Printable: Sends a printable version of the page
|
|
if(isset($_GET["printable"]) and $_GET["printable"] === "yes")
|
|
exit(page_renderer::render_minimal($title, $content));
|
|
// Normal page
|
|
$settings->footer_message = "Last edited at " . date('h:ia T \o\n j F Y', $pageindex->{$env->page}->lastmodified) . ".</p>\n<p>"; // Add the last edited time to the footer
|
|
exit(page_renderer::render_main($title, $content));
|
|
});
|
|
}
|
|
]);
|
|
|
|
?>
|