2015-09-19 09:19:56 +00:00
< ? php
register_module ([
" name " => " Page viewer " ,
2015-10-04 08:10:14 +00:00
" version " => " 0.11 " ,
2015-09-19 09:19:56 +00:00
" author " => " Starbeamrainbowlabs " ,
2015-09-30 06:08:03 +00:00
" description " => " Allows you to view pages. You reallyshould include this one. " ,
2015-09-19 09:19:56 +00:00
" id " => " page-view " ,
" code " => function () {
add_action ( " view " , function () {
2015-10-04 08:10:14 +00:00
global $pageindex , $settings , $env ;
2015-09-19 09:19:56 +00:00
// Check to make sure that the page exists
2015-09-22 13:34:18 +00:00
$page = $env -> page ;
2015-09-19 09:19:56 +00:00
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
2015-09-22 13:34:18 +00:00
header ( " location: index.php?action=edit&newpage=yes&page= " . rawurlencode ( $env -> page ));
2015-09-19 09:19:56 +00:00
exit ();
}
else
{
// Editing is disabled, show an error message
http_response_code ( 404 );
2015-09-22 13:34:18 +00:00
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> " ));
2015-09-19 09:19:56 +00:00
}
}
2015-10-03 11:26:46 +00:00
// Perform a redirect if the requested page is a redirect page
if ( isset ( $pageindex -> $page -> redirect ) &&
2015-10-03 12:29:07 +00:00
$pageindex -> $page -> redirect === true )
2015-10-03 11:26:46 +00:00
{
2015-10-03 12:29:07 +00:00
$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 );
2015-10-03 12:36:46 +00:00
header ( " location: ?action= $env->action &page= " . $pageindex -> $page -> redirect_target . " &redirected_from= $env->page " );
2015-10-03 12:29:07 +00:00
exit ();
}
2015-10-03 11:26:46 +00:00
}
2015-09-22 13:34:18 +00:00
$title = " $env->page - $settings->sitename " ;
2015-09-30 06:08:03 +00:00
if ( isset ( $pageindex -> $page -> protect ) && $pageindex -> $page -> protect === true )
$title = $settings -> protectedpagechar . $title ;
2015-10-03 12:35:44 +00:00
$content = " <h1> $env->page </h1> \n " ;
2015-10-25 14:10:56 +00:00
// Add an extra message if the requester was redirected from another page
2015-10-03 12:35:44 +00:00
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> " ;
2015-09-19 09:19:56 +00:00
$parsing_start = microtime ( true );
2015-10-04 08:10:14 +00:00
$content .= parse_page_source ( file_get_contents ( " $env->page .md " ));
2015-09-19 09:19:56 +00:00
2015-10-25 14:10:56 +00:00
// todo display tags here
if ( ! empty ( $pageindex -> $page -> tags ))
{
2015-10-25 15:45:25 +00:00
$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 " ;
2015-10-25 14:10:56 +00:00
}
2015-10-25 16:06:47 +00:00
/* else
2015-10-25 14:10:56 +00:00
{
2015-10-25 16:06:47 +00:00
$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 " ;
} */
2015-10-25 14:10:56 +00:00
2015-09-19 09:19:56 +00:00
if ( $settings -> show_subpages )
{
2015-09-22 13:34:18 +00:00
$subpages = get_object_vars ( get_subpages ( $pageindex , $env -> page ));
2015-09-19 09:19:56 +00:00
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 " . ( microtime ( true ) - $parsing_start ) . " seconds to parse page source --> \n " ;
if ( isset ( $_GET [ " printable " ]) and $_GET [ " printable " ] === " yes " )
exit ( page_renderer :: render_minimal ( $title , $content ));
else
exit ( page_renderer :: render_main ( $title , $content ));
});
}
]);
?>