1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-12-26 02:55:02 +00:00

Improved robustness of page deleter and id system

This commit is contained in:
Starbeamrainbowlabs 2016-06-05 15:16:44 +01:00
parent 9f5e52d76f
commit 06653661a2
4 changed files with 43 additions and 21 deletions

View file

@ -1017,10 +1017,10 @@ class ids
global $idindex, $paths;
$nextid = count(array_keys(get_object_vars($idindex)));
if(isset($idindex->$nextid))
throw new Exception("The pageid is corrupt! Pepperminty Wiki generated the id $nextid, but that id is already in use.");
// Increment the generated id until it's unique
while(isset($idindex->nextid))
$nextid++;
// Update the id index
$idindex->$nextid = utf8_encode($pagename);
@ -3356,7 +3356,7 @@ register_module([
register_module([
"name" => "Page deleter",
"version" => "0.9",
"version" => "0.10",
"author" => "Starbeamrainbowlabs",
"description" => "Adds an action to allow administrators to delete pages.",
"id" => "page-delete",
@ -3374,19 +3374,24 @@ register_module([
global $pageindex, $settings, $env, $paths, $modules;
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>
exit(page_renderer::render_main("Error: Editing disabled - Deleting $env->page", "<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>
exit(page_renderer::render_main("Error: Insufficient permissions - Deleting $env->page", "<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($pageindex->{$env->page}))
{
exit(page_renderer::render_main("Error: Non-existent page - Deleting $env->page", "<p>You tried to delete $env->page, but that page doesn't appear to exist in the first page. <a href='?'>Go back</a> to the $settings->defaultpage.</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>
exit(page_renderer::render_main("Deleting $env->page", "<p>You are about to <strong>delete</strong> $env->page" . (module_exists("feature-history")?" and all its revisions":"") . ". 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>"));
}
@ -3397,6 +3402,12 @@ register_module([
unlink($env->storage_prefix . $pageindex->$page->uploadedfilepath);
}
// While we're at it, we should delete all the revisions too
foreach($pageindex->{$env->page}->history as $revisionData)
{
unlink($env->storage_prefix . $revisionData->filename);
}
// Delete the page from the page index
unset($pageindex->$page);
@ -4166,7 +4177,7 @@ register_module([
register_module([
"name" => "Page mover",
"version" => "0.8.1",
"version" => "0.9",
"author" => "Starbeamrainbowlabs",
"description" => "Adds an action to allow administrators to move pages.",
"id" => "page-move",

View file

@ -590,10 +590,10 @@ class ids
global $idindex, $paths;
$nextid = count(array_keys(get_object_vars($idindex)));
if(isset($idindex->$nextid))
throw new Exception("The pageid is corrupt! Pepperminty Wiki generated the id $nextid, but that id is already in use.");
// Increment the generated id until it's unique
while(isset($idindex->nextid))
$nextid++;
// Update the id index
$idindex->$nextid = utf8_encode($pagename);

View file

@ -100,11 +100,11 @@
},
{
"name": "Page deleter",
"version": "0.9",
"version": "0.10",
"author": "Starbeamrainbowlabs",
"description": "Adds an action to allow administrators to delete pages.",
"id": "page-delete",
"lastupdate": 1459694163,
"lastupdate": 1465136119,
"optional": false
},
{
@ -163,11 +163,11 @@
},
{
"name": "Page mover",
"version": "0.8.1",
"version": "0.9",
"author": "Starbeamrainbowlabs",
"description": "Adds an action to allow administrators to move pages.",
"id": "page-move",
"lastupdate": 1465133466,
"lastupdate": 1465133690,
"optional": false
},
{

View file

@ -1,7 +1,7 @@
<?php
register_module([
"name" => "Page deleter",
"version" => "0.9",
"version" => "0.10",
"author" => "Starbeamrainbowlabs",
"description" => "Adds an action to allow administrators to delete pages.",
"id" => "page-delete",
@ -19,19 +19,24 @@ register_module([
global $pageindex, $settings, $env, $paths, $modules;
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>
exit(page_renderer::render_main("Error: Editing disabled - Deleting $env->page", "<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>
exit(page_renderer::render_main("Error: Insufficient permissions - Deleting $env->page", "<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($pageindex->{$env->page}))
{
exit(page_renderer::render_main("Error: Non-existent page - Deleting $env->page", "<p>You tried to delete $env->page, but that page doesn't appear to exist in the first page. <a href='?'>Go back</a> to the $settings->defaultpage.</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>
exit(page_renderer::render_main("Deleting $env->page", "<p>You are about to <strong>delete</strong> $env->page" . (module_exists("feature-history")?" and all its revisions":"") . ". 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>"));
}
@ -42,6 +47,12 @@ register_module([
unlink($env->storage_prefix . $pageindex->$page->uploadedfilepath);
}
// While we're at it, we should delete all the revisions too
foreach($pageindex->{$env->page}->history as $revisionData)
{
unlink($env->storage_prefix . $revisionData->filename);
}
// Delete the page from the page index
unset($pageindex->$page);