r87408 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87407‎ | r87408 | r87409 >
Date:16:00, 4 May 2011
Author:ashley
Status:deferred
Tags:
Comment:
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 (modified) (history)
  • /trunk/extensions/ProtectSite/ProtectSite.i18n.php (modified) (history)
  • /trunk/extensions/ProtectSite/ProtectSite.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ProtectSite/ProtectSite.body.php
@@ -22,37 +22,37 @@
2323 public function execute( $par ) {
2424 global $wgOut, $wgUser, $wgRequest;
2525
26 - # If the user doesn't have 'protectsite' permission, display an error
 26+ // If the user doesn't have 'protectsite' permission, display an error
2727 if ( !$wgUser->isAllowed( 'protectsite' ) ) {
2828 $this->displayRestrictionError();
2929 return;
3030 }
3131
32 - # Show a message if the database is in read-only mode
 32+ // Show a message if the database is in read-only mode
3333 if ( wfReadOnly() ) {
3434 $wgOut->readOnlyPage();
3535 return;
3636 }
3737
38 - # If user is blocked, s/he doesn't need to access this page
 38+ // If user is blocked, s/he doesn't need to access this page
3939 if ( $wgUser->isBlocked() ) {
4040 $wgOut->blockedPage();
4141 return;
4242 }
4343
44 - wfLoadExtensionMessages( 'ProtectSite' );
4544 $this->setHeaders();
4645
47 - $form = new ProtectsiteForm( $wgRequest );
 46+ $form = new ProtectSiteForm( $wgRequest );
4847 }
4948
5049 }
5150
5251 /**
5352 * Class that handles the actual Special:ProtectSite page
54 - * This is a modified version of the old HTMLForm class.
 53+ * This is a modified version of the ancient HTMLForm class.
 54+ * @todo FIXME: could probably be rewritten to use the modern HTMLForm :)
5555 */
56 -class ProtectsiteForm {
 56+class ProtectSiteForm {
5757 var $mRequest, $action, $persist_data;
5858
5959 /* Constructor */
@@ -100,23 +100,23 @@
101101 if( !$this->mRequest->wasPosted() ) {
102102 /* If $value is an array, protection is set, allow unsetting */
103103 if( is_array( $prot ) ) {
104 - $this->unProtectsiteForm( $prot );
 104+ $this->unProtectSiteForm( $prot );
105105 } else {
106106 /* If $value is not an array, protection is not set */
107 - $this->setProtectsiteForm();
 107+ $this->setProtectSiteForm();
108108 }
109109 } else {
110110 /* If this was a POST request, process the data sent */
111111 if( $this->mRequest->getVal( 'protect' ) ) {
112 - $this->setProtectsite();
 112+ $this->setProtectSite();
113113 } else {
114 - $this->unProtectsite();
 114+ $this->unProtectSite();
115115 }
116116 }
117117 }
118118
119 - function setProtectsite() {
120 - global $wgOut, $wgMemc, $wgProtectsiteLimit;
 119+ function setProtectSite() {
 120+ global $wgOut, $wgMemc, $wgProtectSiteLimit;
121121
122122 /* Get the request data */
123123 $request = $this->mRequest->getValues();
@@ -128,7 +128,7 @@
129129 ( $until < $curr_time )
130130 ) {
131131 $wgOut->addWikiMsg( 'protectsite-timeout-error' );
132 - $this->setProtectsiteForm();
 132+ $this->setProtectSiteForm();
133133 } else {
134134 /* Set the array values */
135135 $prot['createaccount'] = $request['createaccount'];
@@ -138,10 +138,10 @@
139139 $prot['upload'] = $request['upload'];
140140 $prot['comment'] = isset( $request['comment'] ) ? $request['comment'] : '';
141141
142 - if( isset( $wgProtectsiteLimit ) &&
143 - ( $until > strtotime( '+' . $wgProtectsiteLimit, $curr_time ) )
 142+ if( isset( $wgProtectSiteLimit ) &&
 143+ ( $until > strtotime( '+' . $wgProtectSiteLimit, $curr_time ) )
144144 ) {
145 - $request['timeout'] = $wgProtectsiteLimit;
 145+ $request['timeout'] = $wgProtectSiteLimit;
146146 }
147147
148148 /* Set the limits */
@@ -162,12 +162,13 @@
163163 );
164164
165165 /* Call the Unprotect Form function to display the current state. */
166 - $this->unProtectsiteForm( $prot );
 166+ $this->unProtectSiteForm( $prot );
167167 }
168168 }
169169
170 - function unProtectsite() {
 170+ function unProtectSite() {
171171 global $wgMemc;
 172+
172173 /* Get the request data */
173174 $request = $this->mRequest->getValues();
174175
@@ -184,7 +185,7 @@
185186 );
186187
187188 /* Call the Protect Form function to display the current state. */
188 - $this->setProtectsiteForm();
 189+ $this->setProtectSiteForm();
189190 }
190191
191192 /**
@@ -269,8 +270,8 @@
270271 );
271272 }
272273
273 - function setProtectsiteForm() {
274 - global $wgOut, $wgProtectsiteDefaultTimeout, $wgProtectsiteLimit;
 274+ function setProtectSiteForm() {
 275+ global $wgOut, $wgProtectSiteDefaultTimeout, $wgProtectSiteLimit;
275276
276277 $request = $this->mRequest->getValues();
277278 $createaccount = array( 0 => false, 1 => false, 2 => false );
@@ -294,9 +295,9 @@
295296 $this->radiobox( 'edit', $edit ) .
296297 $this->radiobox( 'move', $move ) .
297298 $this->radiobox( 'upload', $upload ) .
298 - $this->textbox( 'timeout', $wgProtectsiteDefaultTimeout,
299 - ( isset( $wgProtectsiteLimit ) ?
300 - ' (' . wfMsg( 'protectsite-maxtimeout', $wgProtectsiteLimit ) . ')' :
 299+ $this->textbox( 'timeout', $wgProtectSiteDefaultTimeout,
 300+ ( isset( $wgProtectSiteLimit ) ?
 301+ ' (' . wfMsg( 'protectsite-maxtimeout', $wgProtectSiteLimit ) . ')' :
301302 ''
302303 )) .
303304 "\n<br />" .
Index: trunk/extensions/ProtectSite/ProtectSite.i18n.php
@@ -178,7 +178,7 @@
179179 );
180180
181181 /** Finnish (Suomi)
182 - * @author Jack Phoenix <jack@shoutwiki.com>
 182+ * @author Jack Phoenix <jack@countervandalism.net>
183183 */
184184 $messages['fi'] = array(
185185 'protectsite' => 'Suojaa sivusto',
Index: trunk/extensions/ProtectSite/ProtectSite.php
@@ -6,16 +6,16 @@
77 *
88 * Knobs:
99 * 'protectsite' - Group permission to use the special page.
10 - * $wgProtectsiteLimit - Maximum time allowed for protection of the site.
11 - * $wgProtectsiteDefaultTimeout - Default protection time.
12 - * $wgProtectsiteExempt - Array of non-sysop usergroups to be not effected by rights changes
 10+ * $wgProtectSiteLimit - Maximum time allowed for protection of the site.
 11+ * $wgProtectSiteDefaultTimeout - Default protection time.
 12+ * $wgProtectSiteExempt - Array of non-sysop usergroups to be not effected by rights changes
1313 *
1414 * @file
1515 * @ingroup Extensions
16 - * @version 0.3.3
 16+ * @version 0.3.4
1717 * @author Eric Johnston <e.wolfie@gmail.com>
1818 * @author Chris Stafford <c.stafford@gmail.com>
19 - * @author Jack Phoenix <jack@shoutwiki.com>
 19+ * @author Jack Phoenix <jack@countervandalism.net>
2020 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
2121 */
2222
@@ -30,12 +30,22 @@
3131 /* Extension Credits. Splarka wants me to be so UN:VAIN! Haet haet hat! */
3232 $wgExtensionCredits['specialpage'][] = array(
3333 'name' => 'Protect Site',
34 - 'version' => '0.3.3',
 34+ 'version' => '0.3.4',
3535 'author' => array( '[http://uncyclopedia.org/wiki/User:Dawg Eric Johnston]', 'Chris Stafford', 'Jack Phoenix' ),
3636 'description' => 'Allows a site administrator to temporarily block various site modifications',
3737 'url' => 'http://www.mediawiki.org/wiki/Extension:ProtectSite',
3838 );
3939
 40+# Configuration settings
 41+// Array of non-sysop user groups to be not effected by rights changes
 42+$wgProtectSiteExempt = array();
 43+
 44+/* Set the default timeout. */
 45+$wgProtectsiteDefaultTimeout = '1 hour';
 46+
 47+// Maximum time allowed for protection of the site
 48+$wgProtectSiteLimit = '1 week';
 49+
4050 /* Register the new user rights level */
4151 $wgAvailableRights[] = 'protectsite';
4252
@@ -43,16 +53,13 @@
4454 $wgGroupPermissions['bureaucrat']['protectsite'] = true;
4555 $wgGroupPermissions['staff']['protectsite'] = true;
4656
47 -/* Add this Special page to the Special page listing array */
 57+/* Add this special page to the special page listing array */
4858 $dir = dirname( __FILE__ ) . '/';
4959 $wgExtensionMessagesFiles['ProtectSite'] = $dir . 'ProtectSite.i18n.php';
5060 $wgExtensionAliasesFiles['ProtectSite'] = $dir . 'ProtectSite.alias.php';
5161 $wgAutoloadClasses['ProtectSite'] = $dir . 'ProtectSite.body.php';
5262 $wgSpecialPages['ProtectSite'] = 'ProtectSite';
5363
54 -/* Set the default timeout. */
55 -$wgProtectsiteDefaultTimeout = '1 hour';
56 -
5764 /* Register initialization function */
5865 $wgExtensionFunctions[] = 'wfSetupProtectsite';
5966
@@ -65,16 +72,13 @@
6673 */
6774 function wfSetupProtectsite() {
6875 /* Globals */
69 - global $wgGroupPermissions, $wgMemc, $wgProtectsiteExempt, $wgCommandLineMode;
 76+ global $wgGroupPermissions, $wgMemc, $wgProtectSiteExempt, $wgCommandLineMode;
7077
7178 // macbre: don't run code below when running in command line mode (memcache starts to act strange)
7279 if ( !empty( $wgCommandLineMode ) ) {
7380 return;
7481 }
7582
76 - /* Load i18n messages */
77 - wfLoadExtensionMessages( 'ProtectSite' );
78 -
7983 /* Initialize Object */
8084 $persist_data = new MediaWikiBagOStuff();
8185
@@ -95,28 +99,28 @@
96100 }
97101
98102 /* Protection-related code for MediaWiki 1.8+ */
99 - $wgGroupPermissions['*']['createaccount'] = !($prot['createaccount'] >= 1);
100 - $wgGroupPermissions['user']['createaccount'] = !($prot['createaccount'] == 2);
 103+ $wgGroupPermissions['*']['createaccount'] = !( $prot['createaccount'] >= 1 );
 104+ $wgGroupPermissions['user']['createaccount'] = !( $prot['createaccount'] == 2 );
101105
102 - $wgGroupPermissions['*']['createpage'] = !($prot['createpage'] >= 1);
103 - $wgGroupPermissions['*']['createtalk'] = !($prot['createpage'] >= 1);
104 - $wgGroupPermissions['user']['createpage'] = !($prot['createpage'] == 2);
105 - $wgGroupPermissions['user']['createtalk'] = !($prot['createpage'] == 2);
 106+ $wgGroupPermissions['*']['createpage'] = !( $prot['createpage'] >= 1 );
 107+ $wgGroupPermissions['*']['createtalk'] = !( $prot['createpage'] >= 1 );
 108+ $wgGroupPermissions['user']['createpage'] = !( $prot['createpage'] == 2 );
 109+ $wgGroupPermissions['user']['createtalk'] = !( $prot['createpage'] == 2 );
106110
107 - $wgGroupPermissions['*']['edit'] = !($prot['edit'] >= 1);
108 - $wgGroupPermissions['user']['edit'] = !($prot['edit'] == 2);
 111+ $wgGroupPermissions['*']['edit'] = !( $prot['edit'] >= 1 );
 112+ $wgGroupPermissions['user']['edit'] = !( $prot['edit'] == 2 );
109113 $wgGroupPermissions['sysop']['edit'] = true;
110114
111 - $wgGroupPermissions['user']['move'] = !($prot['move'] == 1);
112 - $wgGroupPermissions['user']['upload'] = !($prot['upload'] == 1);
113 - $wgGroupPermissions['user']['reupload'] = !($prot['upload'] == 1);
114 - $wgGroupPermissions['user']['reupload-shared'] = !($prot['upload'] == 1);
 115+ $wgGroupPermissions['user']['move'] = !( $prot['move'] == 1 );
 116+ $wgGroupPermissions['user']['upload'] = !( $prot['upload'] == 1 );
 117+ $wgGroupPermissions['user']['reupload'] = !( $prot['upload'] == 1 );
 118+ $wgGroupPermissions['user']['reupload-shared'] = !( $prot['upload'] == 1 );
115119
116120 // are there any groups that should not get affected by ProtectSite's lockdown?
117 - if( !empty( $wgProtectsiteExempt ) && is_array( $wgProtectsiteExempt ) ) {
 121+ if( !empty( $wgProtectSiteExempt ) && is_array( $wgProtectSiteExempt ) ) {
118122 // there are, so loop over them, and force these rights to be true
119123 // will resolve any problems from inheriting rights from 'user' or 'sysop'
120 - foreach( $wgProtectsiteExempt as $exemptGroup ) {
 124+ foreach( $wgProtectSiteExempt as $exemptGroup ) {
121125 $wgGroupPermissions[$exemptGroup]['edit'] = 1;
122126 $wgGroupPermissions[$exemptGroup]['createpage'] = 1;
123127 $wgGroupPermissions[$exemptGroup]['createtalk'] = 1;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r87407adding some new extensionsashley15:52, 4 May 2011

Status & tagging log