2015-09-19 09:19:56 +00:00
< ? php
register_module ([
" name " => " Page deleter " ,
2019-06-01 14:55:48 +00:00
" version " => " 0.10.1 " ,
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 () {
2015-12-21 08:45:38 +00:00
global $settings ;
2016-06-13 10:55:40 +00:00
/**
2016-06-15 18:20:03 +00:00
* @ api { post } ? action = delete Delete a page
2016-06-13 10:55:40 +00:00
* @ apiDescription Delete a page and all its associated data .
* @ apiName DeletePage
* @ apiGroup Page
* @ apiPermission Moderator
*
* @ apiParam { string } page The name of the page to delete .
* @ apiParam { string } delete Set to 'yes' to actually delete the page .
*
* @ apiUse UserNotModeratorError
* @ apiError PageNonExistentError The specified page doesn ' t exist
*/
2015-12-21 08:45:38 +00:00
2015-12-26 12:55:19 +00:00
/*
* ██████ ███████ ██ ███████ ████████ ███████
* ██ ██ ██ ██ ██ ██ ██
* ██ ██ █████ ██ █████ ██ █████
* ██ ██ ██ ██ ██ ██ ██
* ██████ ███████ ███████ ███████ ██ ███████
*/
2015-09-19 09:19:56 +00:00
add_action ( " delete " , function () {
2015-11-14 17:01:23 +00:00
global $pageindex , $settings , $env , $paths , $modules ;
2015-09-19 09:19:56 +00:00
if ( ! $settings -> editing )
{
2016-06-05 14:16:44 +00:00
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>
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
{
2017-07-25 19:09:54 +00:00
exit ( page_renderer :: render_main ( " Error: Insufficient permissions - Deleting $env->page " , " <p>You tried to delete $env->page , but you as aren't a moderator you don't have permission to do that.</p>
< p > You could try < a href = 'index.php?action=login' > logging in </ a > as an admin , or asking one of $settings -> sitename ' s friendly moderators ( find their names at the bottom of every page ! ) to delete it for you .</ p > " ));
2015-09-19 09:19:56 +00:00
}
2016-06-05 14:16:44 +00:00
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> " ));
}
2015-09-19 09:19:56 +00:00
if ( ! isset ( $_GET [ " delete " ]) or $_GET [ " delete " ] !== " yes " )
{
2017-07-25 19:09:54 +00:00
exit ( page_renderer :: render_main ( " Deleting $env->page " , " <p>You are about to <strong>delete</strong> <em> $env->page </em> " . ( module_exists ( " feature-history " ) ? " and all its revisions " : " " ) . ( module_exists ( " feature-comments " ) ? " and all its comments " : " " ) . " . You can't undo this!</p>
2015-09-22 13:34:18 +00:00
< 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-14 17:01:23 +00:00
2016-06-05 14:16:44 +00:00
// 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 );
}
2017-07-25 19:09:54 +00:00
// If the commenting module is installed and the page has comments,
// delete those too
if ( module_exists ( " feature-comments " ) and
file_exists ( get_comment_filename ( $env -> page )))
{
unlink ( get_comment_filename ( $env -> page ));
}
2015-11-11 19:24:40 +00:00
// Delete the page from the page index
unset ( $pageindex -> $page );
2015-11-12 09:29:16 +00:00
2015-11-11 19:24:40 +00:00
// Save the new page index
2019-06-01 14:55:48 +00:00
save_pageindex ();
2015-11-11 19:24:40 +00:00
// Remove the page's name from the id index
ids :: deletepagename ( $env -> page );
2015-11-14 17:01:23 +00:00
// Delete the page from the search index, if that module is installed
2015-12-05 18:59:23 +00:00
if ( module_exists ( " feature-search " ))
2015-11-14 17:01:23 +00:00
{
$pageid = ids :: getid ( $env -> page );
$invindex = search :: load_invindex ( $paths -> searchindex );
search :: delete_entry ( $invindex , $pageid );
search :: save_invindex ( $paths -> searchindex , $invindex );
}
2015-11-11 19:24:40 +00:00
// Delete the page from the disk
unlink ( " $env->storage_prefix $env->page .md " );
2016-04-03 14:43:40 +00:00
// Add a recent change announcing the deletion if the recent changes
// module is installed
if ( module_exists ( " feature-recent-changes " ))
{
add_recent_change ([
" type " => " deletion " ,
" timestamp " => time (),
" page " => $env -> page ,
" user " => $env -> user ,
]);
}
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
});
2015-12-21 08:45:38 +00:00
// Register a help section
add_help_section ( " 60-delete " , " Deleting Pages " , " <p>If you are logged in as an adminitrator, then you have the power to delete pages. To do this, click "Delete" in the "More..." menu when browsing the pge you wish to delete. When you are sure that you want to delete the page, click the given link.</p>
< p >< strong > Warning : Once a page has been deleted , you can ' t bring it back ! You will need to recover it from your backup , if you have one ( which you really should ) .</ strong ></ p > " );
2015-09-19 09:19:56 +00:00
}
]);
?>