mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-29 06:23:01 +00:00
44 lines
2 KiB
PHP
44 lines
2 KiB
PHP
<?php
|
|
register_module([
|
|
"name" => "Page deleter",
|
|
"version" => "0.7",
|
|
"author" => "Starbeamrainbowlabs",
|
|
"description" => "Adds an action to allow administrators to delete pages.",
|
|
"id" => "page-delete",
|
|
"code" => function() {
|
|
add_action("delete", function() {
|
|
global $pageindex, $settings, $env;
|
|
if(!$settings->editing)
|
|
{
|
|
exit(page_renderer::render_main("Deleting $env->page - error", "<p>You tried to delete $env->page, but editing is disabled on this wiki.</p>
|
|
<p>If you wish to delete this page, please re-enable editing on this wiki first.</p>
|
|
<p><a href='index.php?page=$env->page'>Go back to $env->page</a>.</p>
|
|
<p>Nothing has been changed.</p>"));
|
|
}
|
|
if(!$env->is_admin)
|
|
{
|
|
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>
|
|
<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")
|
|
{
|
|
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>"));
|
|
}
|
|
$page = $env->page;
|
|
// Delete the associated file if it exists
|
|
if(!empty($pageindex->$page->uploadedfile))
|
|
{
|
|
unlink($pageindex->$page->uploadedfilepath);
|
|
}
|
|
unset($pageindex->$page); //delete the page from the page index
|
|
file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT)); //save the new page index
|
|
unlink("./$env->page.md"); //delete the page from the disk
|
|
|
|
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>"));
|
|
});
|
|
}
|
|
]);
|
|
|
|
?>
|