Page MenuHomePhabricator

Protect.php

Authored By
bzimport
Nov 21 2014, 9:00 PM
Size
2 KB
Referenced Files
None
Subscribers
None

Protect.php

<?php
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# http://www.gnu.org/copyleft/gpl.html
#
#
# Author: thomasv1@gmx.de
$wgGroupPermissions['sysop']['protectsection'] = true;
$wgGroupPermissions['bureaucrat']['protectsection'] = true;
$wgExtensionFunctions[] = 'protectSetup';
$wgHooks['ParserBeforeStrip'][] = 'stripProtectTags' ;
$wgHooks['EditFilter'][] = 'checkProtect' ;
function protectSetup() {
global $wgMessageCache;
$wgMessageCache->addMessages( array(
'add_remove_protected_section' =>
"You tried to add or remove a protected section",
'modify_protected_section' =>
"You tried to modify protected text",
'forbidden' => "Forbidden",
) );
}
function stripProtectTags ( &$parser , &$text, &$x ) {
$text = str_replace("<protect>","",$text);
$text = str_replace("</protect>","",$text);
return true;
}
function checkProtect ( $editpage, $textbox1, $section ) {
# check for partial protection
global $wgUser;
if ( !$wgUser->isAllowed( 'protectsection' ) ) {
$modifyProtect = false;
$text1 = $editpage->mArticle->getContent(true);
$text2 = $textbox1 ;
preg_match_all( "/<protect>(.*?)<\/protect>/im", $text1, $list1, PREG_SET_ORDER );
preg_match_all( "/<protect>(.*?)<\/protect>/im", $text2, $list2, PREG_SET_ORDER );
if( count($list1) != count($list2)) {
$msg = wfMsg( 'add_remove_protected_section');
$modifyProtect = true;
}
else for ( $i=0 ; $i < count( $list1 ); $i++ ) {
if( $list1[$i][0] != $list2[$i][0]) {
$msg = wfMsg( 'modify_protected_section' );
$modifyProtect = true;
break;
}
}
if( $modifyProtect ) {
global $wgOut;
$wgOut->setPageTitle( wfMsg( 'forbidden' ) );
$wgOut->addWikiText($msg);
return false;
}
}
return true;
}
?>

File Metadata

Mime Type
text/x-php
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2128
Default Alt Text
Protect.php (2 KB)

Event Timeline