2015-09-19 09:19:56 +00:00
< ? php
register_module ([
" name " => " Page deleter " ,
2015-11-08 21:15:08 +00:00
" version " => " 0.8 " ,
2015-09-19 09:19:56 +00:00
" author " => " Starbeamrainbowlabs " ,
" description " => " Adds an action to allow administrators to delete pages. " ,
" id " => " page-delete " ,
" code " => function () {
add_action ( " delete " , function () {
2015-11-09 07:25:28 +00:00
global $pageindex , $settings , $env , $paths ;
2015-09-19 09:19:56 +00:00
if ( ! $settings -> editing )
{
2015-09-22 13:34:18 +00:00
exit ( page_renderer :: render_main ( " Deleting $env->page - error " , " <p>You tried to delete $env->page , but editing is disabled on this wiki.</p>
2015-09-19 09:19:56 +00:00
< p > If you wish to delete this page , please re - enable editing on this wiki first .</ p >
2015-09-22 13:34:18 +00:00
< p >< a href = 'index.php?page=$env->page' > Go back to $env -> page </ a >.</ p >
2015-09-19 09:19:56 +00:00
< p > Nothing has been changed .</ p > " ));
}
2015-09-22 13:34:18 +00:00
if ( ! $env -> is_admin )
2015-09-19 09:19:56 +00:00
{
2015-09-22 13:34:18 +00:00
exit ( page_renderer :: render_main ( " Deleting $env->page - error " , " <p>You tried to delete $env->page , but you are not an admin so you don't have permission to do that.</p>
2015-09-19 09:19:56 +00:00
< p > You should try < a href = 'index.php?action=login' > logging in </ a > as an admin .</ p > " ));
}
if ( ! isset ( $_GET [ " delete " ]) or $_GET [ " delete " ] !== " yes " )
{
2015-09-22 13:34:18 +00:00
exit ( page_renderer :: render_main ( " Deleting $env->page " , " <p>You are about to <strong>delete</strong> $env->page . You can't undo this!</p>
< p >< a href = 'index.php?action=delete&page=$env->page&delete=yes' > Click here to delete $env -> page .</ a ></ p >
< p >< a href = 'index.php?action=view&page=$env->page' > Click here to go back .</ a > " ));
2015-09-19 09:19:56 +00:00
}
2015-09-22 13:39:59 +00:00
$page = $env -> page ;
2015-10-25 11:11:04 +00:00
// Delete the associated file if it exists
if ( ! empty ( $pageindex -> $page -> uploadedfile ))
{
2015-11-08 21:15:08 +00:00
unlink ( $env -> storage_prefix . $pageindex -> $page -> uploadedfilepath );
2015-10-25 11:11:04 +00:00
}
2015-11-11 19:24:40 +00:00
// Delete the page from the page index
unset ( $pageindex -> $page );
// Save the new page index
file_put_contents ( $paths -> pageindex , json_encode ( $pageindex , JSON_PRETTY_PRINT ));
// Remove the page's name from the id index
ids :: deletepagename ( $env -> page );
// Delete the page from the disk
unlink ( " $env->storage_prefix $env->page .md " );
2015-09-22 13:34:18 +00:00
exit ( page_renderer :: render_main ( " Deleting $env->page - $settings->sitename " , " <p> $env->page has been deleted. <a href='index.php'>Go back to the main page</a>.</p> " ));
2015-09-19 09:19:56 +00:00
});
}
]);
?>