2015-09-30 06:08:03 +00:00
< ? php
2020-09-23 22:22:39 +00:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License , v . 2.0 . If a copy of the MPL was not distributed with this
* file , You can obtain one at https :// mozilla . org / MPL / 2.0 /. */
2015-09-30 06:08:03 +00:00
register_module ([
" name " => " Page protection " ,
2019-06-01 14:55:48 +00:00
" version " => " 0.2.1 " ,
2015-09-30 06:08:03 +00:00
" author " => " Starbeamrainbowlabs " ,
" description " => " Exposes Pepperminty Wiki's new page protection mechanism and makes the protect button in the 'More...' menu on the top bar work. " ,
" id " => " action-protect " ,
" code " => function () {
2016-06-12 20:15:43 +00:00
/**
* @ api { get } ? action = protect & page = { pageName } Toggle the protection of a page .
* @ apiName Protect
* @ apiGroup Page
* @ apiPermission Moderator
*
* @ apiParam { string } page The page name to toggle the protection of .
*/
2015-12-26 12:55:19 +00:00
/*
* ██████ ██████ ██████ ████████ ███████ ██████ ████████
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
* ██████ ██████ ██ ██ ██ █████ ██ ██
* ██ ██ ██ ██ ██ ██ ██ ██ ██
* ██ ██ ██ ██████ ██ ███████ ██████ ██
*/
2015-09-30 06:08:03 +00:00
add_action ( " protect " , function () {
2015-11-12 09:29:16 +00:00
global $env , $pageindex , $paths , $settings ;
2015-11-08 21:15:08 +00:00
2015-09-30 06:08:03 +00:00
// Make sure that the user is logged in as an admin / mod.
if ( $env -> is_admin )
{
// They check out ok, toggle the page's protection.
$page = $env -> page ;
2015-11-12 10:01:21 +00:00
2015-09-30 06:08:03 +00:00
if ( ! isset ( $pageindex -> $page -> protect ))
{
$pageindex -> $page -> protect = true ;
}
2015-11-12 09:59:08 +00:00
else if ( $pageindex -> $page -> protect === true )
2015-09-30 06:08:03 +00:00
{
2015-11-12 09:31:50 +00:00
$pageindex -> $page -> protect = false ;
2015-09-30 06:08:03 +00:00
}
2015-11-12 09:59:08 +00:00
else if ( $pageindex -> $page -> protect === false )
2015-09-30 06:08:03 +00:00
{
2015-11-12 09:59:08 +00:00
$pageindex -> $page -> protect = true ;
2015-09-30 06:08:03 +00:00
}
2015-11-12 10:01:21 +00:00
2015-09-30 06:08:03 +00:00
// Save the pageindex
2019-06-01 14:55:48 +00:00
save_pageindex ();
2015-11-12 10:01:21 +00:00
2015-09-30 06:08:03 +00:00
$state = ( $pageindex -> $page -> protect ? " enabled " : " disabled " );
$title = " Page protection $state . " ;
2021-09-02 21:29:39 +00:00
exit ( page_renderer :: render_main ( $title , " <p>Page protection for $env->page_safe has been $state .</p><p><a href='?action= $settings->defaultaction &page= " . rawurlencode ( $env -> page ) . " '>Go back</a>. " ));
2015-09-30 06:08:03 +00:00
}
else
{
exit ( page_renderer :: render_main ( " Error protecting page " , " <p>You are not allowed to protect pages because you are not logged in as a mod or admin. Please try logging out if you are logged in and then try logging in as an administrator.</p> " ));
}
});
}
]);
?>