"Page viewer", "version" => "0.14", "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("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.
")); } } // 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(); } } $isHistoryRevision = false; if(isset($_GET["revision"]) and is_numeric($_GET["revision"])) { // We have a revision number! $isHistoryRevision = true; $revisionNumber = intval($_GET["revision"]); $revisionData = $pageindex->{$env->page}->history[$revisionNumber]; // Make sure that the revision exists for later on if(!isset($pageindex->{$env->page}->history[$revisionNumber])) { http_response_code(404); exit(page_renderer::render_main("404: Revision Not Found - $env->page - $settings->sitename", "Revision #$revisionNumer of $env->page doesn't appear to exist. Try viewing the list of revisions for $env->page, or viewing the latest revision instead.
")); } } $title = "$env->page - $settings->sitename"; if(isset($pageindex->$page->protect) && $pageindex->$page->protect === true) $title = $settings->protectedpagechar . $title; $content = ""; if(!$isHistoryRevision) $content .= "(Revision created by $revisionData->editor " . render_rchange_timestamp($revisionData->timestamp) . ". Jump to the current revision or see a list of all revisions for this page.)
\n"; } // Add an extra message if the requester was redirected from another page if(isset($_GET["redirected_from"])) $content .= "Redirected from " . $_GET["redirected_from"] . ".
"; // Construct the filename $pageFilename = "$env->storage_prefix"; if($isHistoryRevision) { $pageFilename .= $pageindex->{$env->page}->history[$revisionNumber]->filename; } else $pageFilename .= $pageindex->{$env->page}->filename; $parsing_start = microtime(true); $content .= parse_page_source(file_get_contents($pageFilename)); if(!empty($pageindex->$page->tags)) { $content .= " \n"; } /*else { $content .= "\n"; }*/ if($settings->show_subpages) { $subpages = get_object_vars(get_subpages($pageindex, $env->page)); if(count($subpages) > 0) { $content .= ""; // Add the last edited time to the footer exit(page_renderer::render_main($title, $content)); }); } ]); ?>