http://www.mediawiki.org/wiki/Special:Code/MediaWiki/87408
Revision: 87408 Author: ashley Date: 2011-05-04 16:00:55 +0000 (Wed, 04 May 2011) Log Message: ----------- ProtectSite: follow-up to r87407: *general cleanup *change my email address *consistent capitalization of 'ProtectSite' (globals, function names, etc.) *removed wfLoadExtensionMessages cruft *bumped version number *set default values for all configuration globals Modified Paths: -------------- trunk/extensions/ProtectSite/ProtectSite.body.php trunk/extensions/ProtectSite/ProtectSite.i18n.php trunk/extensions/ProtectSite/ProtectSite.php Modified: trunk/extensions/ProtectSite/ProtectSite.body.php =================================================================== --- trunk/extensions/ProtectSite/ProtectSite.body.php 2011-05-04 15:52:05 UTC (rev 87407) +++ trunk/extensions/ProtectSite/ProtectSite.body.php 2011-05-04 16:00:55 UTC (rev 87408) @@ -22,37 +22,37 @@ public function execute( $par ) { global $wgOut, $wgUser, $wgRequest; - # If the user doesn't have 'protectsite' permission, display an error + // If the user doesn't have 'protectsite' permission, display an error if ( !$wgUser->isAllowed( 'protectsite' ) ) { $this->displayRestrictionError(); return; } - # Show a message if the database is in read-only mode + // Show a message if the database is in read-only mode if ( wfReadOnly() ) { $wgOut->readOnlyPage(); return; } - # If user is blocked, s/he doesn't need to access this page + // If user is blocked, s/he doesn't need to access this page if ( $wgUser->isBlocked() ) { $wgOut->blockedPage(); return; } - wfLoadExtensionMessages( 'ProtectSite' ); $this->setHeaders(); - $form = new ProtectsiteForm( $wgRequest ); + $form = new ProtectSiteForm( $wgRequest ); } } /** * Class that handles the actual Special:ProtectSite page - * This is a modified version of the old HTMLForm class. + * This is a modified version of the ancient HTMLForm class. + * @todo FIXME: could probably be rewritten to use the modern HTMLForm :) */ -class ProtectsiteForm { +class ProtectSiteForm { var $mRequest, $action, $persist_data; /* Constructor */ @@ -100,23 +100,23 @@ if( !$this->mRequest->wasPosted() ) { /* If $value is an array, protection is set, allow unsetting */ if( is_array( $prot ) ) { - $this->unProtectsiteForm( $prot ); + $this->unProtectSiteForm( $prot ); } else { /* If $value is not an array, protection is not set */ - $this->setProtectsiteForm(); + $this->setProtectSiteForm(); } } else { /* If this was a POST request, process the data sent */ if( $this->mRequest->getVal( 'protect' ) ) { - $this->setProtectsite(); + $this->setProtectSite(); } else { - $this->unProtectsite(); + $this->unProtectSite(); } } } - function setProtectsite() { - global $wgOut, $wgMemc, $wgProtectsiteLimit; + function setProtectSite() { + global $wgOut, $wgMemc, $wgProtectSiteLimit; /* Get the request data */ $request = $this->mRequest->getValues(); @@ -128,7 +128,7 @@ ( $until < $curr_time ) ) { $wgOut->addWikiMsg( 'protectsite-timeout-error' ); - $this->setProtectsiteForm(); + $this->setProtectSiteForm(); } else { /* Set the array values */ $prot['createaccount'] = $request['createaccount']; @@ -138,10 +138,10 @@ $prot['upload'] = $request['upload']; $prot['comment'] = isset( $request['comment'] ) ? $request['comment'] : ''; - if( isset( $wgProtectsiteLimit ) && - ( $until > strtotime( '+' . $wgProtectsiteLimit, $curr_time ) ) + if( isset( $wgProtectSiteLimit ) && + ( $until > strtotime( '+' . $wgProtectSiteLimit, $curr_time ) ) ) { - $request['timeout'] = $wgProtectsiteLimit; + $request['timeout'] = $wgProtectSiteLimit; } /* Set the limits */ @@ -162,12 +162,13 @@ ); /* Call the Unprotect Form function to display the current state. */ - $this->unProtectsiteForm( $prot ); + $this->unProtectSiteForm( $prot ); } } - function unProtectsite() { + function unProtectSite() { global $wgMemc; + /* Get the request data */ $request = $this->mRequest->getValues(); @@ -184,7 +185,7 @@ ); /* Call the Protect Form function to display the current state. */ - $this->setProtectsiteForm(); + $this->setProtectSiteForm(); } /** @@ -269,8 +270,8 @@ ); } - function setProtectsiteForm() { - global $wgOut, $wgProtectsiteDefaultTimeout, $wgProtectsiteLimit; + function setProtectSiteForm() { + global $wgOut, $wgProtectSiteDefaultTimeout, $wgProtectSiteLimit; $request = $this->mRequest->getValues(); $createaccount = array( 0 => false, 1 => false, 2 => false ); @@ -294,9 +295,9 @@ $this->radiobox( 'edit', $edit ) . $this->radiobox( 'move', $move ) . $this->radiobox( 'upload', $upload ) . - $this->textbox( 'timeout', $wgProtectsiteDefaultTimeout, - ( isset( $wgProtectsiteLimit ) ? - ' (' . wfMsg( 'protectsite-maxtimeout', $wgProtectsiteLimit ) . ')' : + $this->textbox( 'timeout', $wgProtectSiteDefaultTimeout, + ( isset( $wgProtectSiteLimit ) ? + ' (' . wfMsg( 'protectsite-maxtimeout', $wgProtectSiteLimit ) . ')' : '' )) . "\n<br />" . Modified: trunk/extensions/ProtectSite/ProtectSite.i18n.php =================================================================== --- trunk/extensions/ProtectSite/ProtectSite.i18n.php 2011-05-04 15:52:05 UTC (rev 87407) +++ trunk/extensions/ProtectSite/ProtectSite.i18n.php 2011-05-04 16:00:55 UTC (rev 87408) @@ -178,7 +178,7 @@ ); /** Finnish (Suomi) - * @author Jack Phoenix <j...@shoutwiki.com> + * @author Jack Phoenix <j...@countervandalism.net> */ $messages['fi'] = array( 'protectsite' => 'Suojaa sivusto', Modified: trunk/extensions/ProtectSite/ProtectSite.php =================================================================== --- trunk/extensions/ProtectSite/ProtectSite.php 2011-05-04 15:52:05 UTC (rev 87407) +++ trunk/extensions/ProtectSite/ProtectSite.php 2011-05-04 16:00:55 UTC (rev 87408) @@ -6,16 +6,16 @@ * * Knobs: * 'protectsite' - Group permission to use the special page. - * $wgProtectsiteLimit - Maximum time allowed for protection of the site. - * $wgProtectsiteDefaultTimeout - Default protection time. - * $wgProtectsiteExempt - Array of non-sysop usergroups to be not effected by rights changes + * $wgProtectSiteLimit - Maximum time allowed for protection of the site. + * $wgProtectSiteDefaultTimeout - Default protection time. + * $wgProtectSiteExempt - Array of non-sysop usergroups to be not effected by rights changes * * @file * @ingroup Extensions - * @version 0.3.3 + * @version 0.3.4 * @author Eric Johnston <e.wol...@gmail.com> * @author Chris Stafford <c.staff...@gmail.com> - * @author Jack Phoenix <j...@shoutwiki.com> + * @author Jack Phoenix <j...@countervandalism.net> * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later */ @@ -30,12 +30,22 @@ /* Extension Credits. Splarka wants me to be so UN:VAIN! Haet haet hat! */ $wgExtensionCredits['specialpage'][] = array( 'name' => 'Protect Site', - 'version' => '0.3.3', + 'version' => '0.3.4', 'author' => array( '[http://uncyclopedia.org/wiki/User:Dawg Eric Johnston]', 'Chris Stafford', 'Jack Phoenix' ), 'description' => 'Allows a site administrator to temporarily block various site modifications', 'url' => 'http://www.mediawiki.org/wiki/Extension:ProtectSite', ); +# Configuration settings +// Array of non-sysop user groups to be not effected by rights changes +$wgProtectSiteExempt = array(); + +/* Set the default timeout. */ +$wgProtectsiteDefaultTimeout = '1 hour'; + +// Maximum time allowed for protection of the site +$wgProtectSiteLimit = '1 week'; + /* Register the new user rights level */ $wgAvailableRights[] = 'protectsite'; @@ -43,16 +53,13 @@ $wgGroupPermissions['bureaucrat']['protectsite'] = true; $wgGroupPermissions['staff']['protectsite'] = true; -/* Add this Special page to the Special page listing array */ +/* Add this special page to the special page listing array */ $dir = dirname( __FILE__ ) . '/'; $wgExtensionMessagesFiles['ProtectSite'] = $dir . 'ProtectSite.i18n.php'; $wgExtensionAliasesFiles['ProtectSite'] = $dir . 'ProtectSite.alias.php'; $wgAutoloadClasses['ProtectSite'] = $dir . 'ProtectSite.body.php'; $wgSpecialPages['ProtectSite'] = 'ProtectSite'; -/* Set the default timeout. */ -$wgProtectsiteDefaultTimeout = '1 hour'; - /* Register initialization function */ $wgExtensionFunctions[] = 'wfSetupProtectsite'; @@ -65,16 +72,13 @@ */ function wfSetupProtectsite() { /* Globals */ - global $wgGroupPermissions, $wgMemc, $wgProtectsiteExempt, $wgCommandLineMode; + global $wgGroupPermissions, $wgMemc, $wgProtectSiteExempt, $wgCommandLineMode; // macbre: don't run code below when running in command line mode (memcache starts to act strange) if ( !empty( $wgCommandLineMode ) ) { return; } - /* Load i18n messages */ - wfLoadExtensionMessages( 'ProtectSite' ); - /* Initialize Object */ $persist_data = new MediaWikiBagOStuff(); @@ -95,28 +99,28 @@ } /* Protection-related code for MediaWiki 1.8+ */ - $wgGroupPermissions['*']['createaccount'] = !($prot['createaccount'] >= 1); - $wgGroupPermissions['user']['createaccount'] = !($prot['createaccount'] == 2); + $wgGroupPermissions['*']['createaccount'] = !( $prot['createaccount'] >= 1 ); + $wgGroupPermissions['user']['createaccount'] = !( $prot['createaccount'] == 2 ); - $wgGroupPermissions['*']['createpage'] = !($prot['createpage'] >= 1); - $wgGroupPermissions['*']['createtalk'] = !($prot['createpage'] >= 1); - $wgGroupPermissions['user']['createpage'] = !($prot['createpage'] == 2); - $wgGroupPermissions['user']['createtalk'] = !($prot['createpage'] == 2); + $wgGroupPermissions['*']['createpage'] = !( $prot['createpage'] >= 1 ); + $wgGroupPermissions['*']['createtalk'] = !( $prot['createpage'] >= 1 ); + $wgGroupPermissions['user']['createpage'] = !( $prot['createpage'] == 2 ); + $wgGroupPermissions['user']['createtalk'] = !( $prot['createpage'] == 2 ); - $wgGroupPermissions['*']['edit'] = !($prot['edit'] >= 1); - $wgGroupPermissions['user']['edit'] = !($prot['edit'] == 2); + $wgGroupPermissions['*']['edit'] = !( $prot['edit'] >= 1 ); + $wgGroupPermissions['user']['edit'] = !( $prot['edit'] == 2 ); $wgGroupPermissions['sysop']['edit'] = true; - $wgGroupPermissions['user']['move'] = !($prot['move'] == 1); - $wgGroupPermissions['user']['upload'] = !($prot['upload'] == 1); - $wgGroupPermissions['user']['reupload'] = !($prot['upload'] == 1); - $wgGroupPermissions['user']['reupload-shared'] = !($prot['upload'] == 1); + $wgGroupPermissions['user']['move'] = !( $prot['move'] == 1 ); + $wgGroupPermissions['user']['upload'] = !( $prot['upload'] == 1 ); + $wgGroupPermissions['user']['reupload'] = !( $prot['upload'] == 1 ); + $wgGroupPermissions['user']['reupload-shared'] = !( $prot['upload'] == 1 ); // are there any groups that should not get affected by ProtectSite's lockdown? - if( !empty( $wgProtectsiteExempt ) && is_array( $wgProtectsiteExempt ) ) { + if( !empty( $wgProtectSiteExempt ) && is_array( $wgProtectSiteExempt ) ) { // there are, so loop over them, and force these rights to be true // will resolve any problems from inheriting rights from 'user' or 'sysop' - foreach( $wgProtectsiteExempt as $exemptGroup ) { + foreach( $wgProtectSiteExempt as $exemptGroup ) { $wgGroupPermissions[$exemptGroup]['edit'] = 1; $wgGroupPermissions[$exemptGroup]['createpage'] = 1; $wgGroupPermissions[$exemptGroup]['createtalk'] = 1; _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs