r111465 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111464‎ | r111465 | r111466 >
Date:16:19, 14 February 2012
Author:reedy
Status:reverted (Comments)
Tags:gerritmigration 
Comment:
Reduce global (ab)use

Various code updates

Trim trailing whitespace
Modified paths:
  • /trunk/extensions/GlobalBlocking/ApiQueryGlobalBlocks.php (modified) (history)
  • /trunk/extensions/GlobalBlocking/GlobalBlocking.class.php (modified) (history)
  • /trunk/extensions/GlobalBlocking/SpecialGlobalBlock.php (modified) (history)
  • /trunk/extensions/GlobalBlocking/SpecialGlobalBlockList.php (modified) (history)
  • /trunk/extensions/GlobalBlocking/SpecialGlobalBlockStatus.php (modified) (history)
  • /trunk/extensions/GlobalBlocking/SpecialRemoveGlobalBlock.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GlobalBlocking/SpecialRemoveGlobalBlock.php
@@ -8,17 +8,19 @@
99 }
1010
1111 function execute( $par ) {
12 - global $wgOut, $wgRequest, $wgUser;
 12+ global $wgUser;
1313 $this->setHeaders();
1414
1515 $this->loadParameters();
1616
17 - $wgOut->setPageTitle( wfMsg( 'globalblocking-unblock' ) );
18 - $wgOut->setSubtitle( GlobalBlocking::buildSubtitleLinks( 'RemoveGlobalBlock' ) );
19 - $wgOut->setRobotPolicy( "noindex,nofollow" );
20 - $wgOut->setArticleRelated( false );
21 - $wgOut->enableClientCache( false );
 17+ $out = $this->getOutput();
2218
 19+ $out->setPageTitle( wfMsg( 'globalblocking-unblock' ) );
 20+ $out->setSubtitle( GlobalBlocking::buildSubtitleLinks( 'RemoveGlobalBlock' ) );
 21+ $out->setRobotPolicy( "noindex,nofollow" );
 22+ $out->setArticleRelated( false );
 23+ $out->enableClientCache( false );
 24+
2325 if (!$this->userCanExecute( $wgUser )) {
2426 $this->displayRestrictionError();
2527 return;
@@ -26,7 +28,8 @@
2729
2830 $errors = '';
2931
30 - if ($wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ))) {
 32+ $request = $this->getRequest();
 33+ if ( $request->wasPosted() && $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
3134 // They want to submit. Let's have a look.
3235 $errors = $this->trySubmit();
3336 if( !$errors ) {
@@ -34,12 +37,12 @@
3538 return;
3639 }
3740 }
38 -
39 - $wgOut->addWikiMsg( 'globalblocking-unblock-intro' );
4041
 42+ $out->addWikiMsg( 'globalblocking-unblock-intro' );
 43+
4144 if (is_array($errors) && count($errors)>0) {
4245 $errorstr = '';
43 -
 46+
4447 foreach ( $errors as $error ) {
4548 if (is_array($error)) {
4649 $msg = array_shift($error);
@@ -49,15 +52,14 @@
5053 }
5154 $errorstr .= Xml::tags( 'li', null, wfMsgExt( $msg, array( 'parseinline' ), $error ) );
5255 }
53 -
 56+
5457 $errorstr = Xml::tags( 'ul', array( 'class' => 'error' ), $errorstr );
5558 $errorstr = wfMsgExt( 'globalblocking-unblock-errors', array('parse'), array( count( $errors ) ) ) . $errorstr;
5659 $errorstr = Xml::tags( 'div', array( 'class' => 'error' ), $errorstr );
57 - $wgOut->addHTML( $errorstr );
 60+ $out->addHTML( $errorstr );
5861 }
59 -
60 - $this->form( );
6162
 63+ $this->form();
6264 }
6365
6466 function loadParameters() {
@@ -68,7 +70,7 @@
6971 }
7072
7173 function trySubmit() {
72 - global $wgOut,$wgUser;
 74+ global $wgOut;
7375 $errors = array();
7476 $ip = $this->mUnblockIP;
7577 if (!IP::isIPAddress($ip) && strlen($ip)) {
@@ -84,6 +86,7 @@
8587 return $errors;
8688 }
8789
 90+ $out = $this->getOutput();
8891 $dbw = GlobalBlocking::getGlobalBlockingMaster();
8992 $dbw->delete( 'globalblocks', array( 'gb_id' => $id ), __METHOD__ );
9093
@@ -91,12 +94,12 @@
9295 $page->addEntry( 'gunblock', Title::makeTitleSafe( NS_USER, $ip ), $this->mReason );
9396
9497 $successmsg = wfMsgExt( 'globalblocking-unblock-unblocked', array( 'parse' ), $ip, $id );
95 - $wgOut->addHTML( $successmsg );
 98+ $out->addHTML( $successmsg );
9699
97 - $link = $wgUser->getSkin()->makeKnownLinkObj( SpecialPage::getTitleFor( 'GlobalBlockList' ), wfMsg( 'globalblocking-return' ) );
98 - $wgOut->addHTML( $link );
 100+ $link = Linker::makeKnownLinkObj( SpecialPage::getTitleFor( 'GlobalBlockList' ), wfMsg( 'globalblocking-return' ) );
 101+ $out->addHTML( $link );
99102
100 - $wgOut->setSubtitle(wfMsg('globalblocking-unblock-successsub'));
 103+ $out->setSubtitle(wfMsg('globalblocking-unblock-successsub'));
101104
102105 return array();
103106 }
Index: trunk/extensions/GlobalBlocking/SpecialGlobalBlock.php
@@ -10,16 +10,17 @@
1111 }
1212
1313 function execute( $par ) {
14 - global $wgOut, $wgRequest, $wgUser;
 14+ global $wgUser;
1515 $this->setHeaders();
1616
1717 $this->loadParameters( $par );
1818
19 - $wgOut->setPageTitle( wfMsg( 'globalblocking-block' ) );
20 - $wgOut->setSubtitle( GlobalBlocking::buildSubtitleLinks( 'GlobalBlock' ) );
21 - $wgOut->setRobotPolicy( "noindex,nofollow" );
22 - $wgOut->setArticleRelated( false );
23 - $wgOut->enableClientCache( false );
 19+ $out = $this->getOutput();
 20+ $out->setPageTitle( wfMsg( 'globalblocking-block' ) );
 21+ $out->setSubtitle( GlobalBlocking::buildSubtitleLinks( 'GlobalBlock' ) );
 22+ $out->setRobotPolicy( "noindex,nofollow" );
 23+ $out->setArticleRelated( false );
 24+ $out->enableClientCache( false );
2425
2526 if (!$this->userCanExecute( $wgUser )) {
2627 $this->displayRestrictionError();
@@ -28,7 +29,8 @@
2930
3031 $errors = '';
3132
32 - if ($wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ))) {
 33+ $request = $this->getRequest();
 34+ if ( $request->wasPosted() && $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
3335 // They want to submit. Let's have a look.
3436 $errors = $this->trySubmit();
3537 if( !$errors ) {
@@ -114,15 +116,14 @@
115117 }
116118
117119 function trySubmit() {
118 - global $wgOut, $wgUser;
119120 $options = array();
120 - $skin = $wgUser->getSkin();
121121
122122 if ($this->mAnonOnly)
123123 $options[] = 'anon-only';
124124 if ($this->mModify)
125125 $options[] = 'modify';
126126
 127+ $out = $this->getOutput();
127128 $reasonstr = $this->mReasonList;
128129 if( $reasonstr != 'other' && $this->mReason != '' ) {
129130 // Entry from drop down menu + additional comment
@@ -145,12 +146,12 @@
146147 $subMessage = 'globalblocking-block-successsub';
147148 }
148149
149 - $wgOut->addWikitext( wfMsg($textMessage, $this->mAddress ) );
150 - $wgOut->setSubtitle( wfMsg( $subMessage ) );
 150+ $out->addWikitext( wfMsg($textMessage, $this->mAddress ) );
 151+ $out->setSubtitle( wfMsg( $subMessage ) );
151152
152 - $link = $skin->link( SpecialPage::getTitleFor( 'GlobalBlockList' ),
 153+ $link = Linker::link( SpecialPage::getTitleFor( 'GlobalBlockList' ),
153154 wfMsg( 'globalblocking-return' ) );
154 - $wgOut->addHTML( $link );
 155+ $out->addHTML( $link );
155156
156157 return array();
157158 }
Index: trunk/extensions/GlobalBlocking/GlobalBlocking.class.php
@@ -42,7 +42,7 @@
4343 */
4444 static function getUserBlockErrors( $user, $ip ) {
4545 static $result = null;
46 -
 46+
4747 // Instance cache
4848 if ( !is_null( $result ) ) { return $result; }
4949
@@ -55,7 +55,7 @@
5656 // Block has been whitelisted.
5757 return $result = array();
5858 }
59 -
 59+
6060 if ( $user->isAllowed( 'ipblock-exempt' ) || $user->isAllowed( 'globalblock-exempt' ) ) {
6161 // User is exempt from IP blocks.
6262 return $result = array();
@@ -73,10 +73,10 @@
7474 $wgLang->time( $expiry )
7575 );
7676 }
77 -
 77+
7878 $display_wiki = self::getWikiName( $block->gb_by_wiki );
7979 $user_display = self::maybeLinkUserpage( $block->gb_by_wiki, $block->gb_by );
80 -
 80+
8181 return $result = array( 'globalblocking-blocked',
8282 $user_display, $display_wiki, $block->gb_reason, $expiry, $ip );
8383 }
@@ -95,7 +95,7 @@
9696 $hex_ip = IP::toHex( $ip );
9797 $ip_pattern = substr( $hex_ip, 0, 4 ) . '%'; // Don't bother checking blocks out of this /16.
9898
99 - $conds = array(
 99+ $conds = array(
100100 'gb_range_end>='.$dbr->addQuotes( $hex_ip ), // This block in the given range.
101101 'gb_range_start<='.$dbr->addQuotes( $hex_ip ),
102102 'gb_range_start like ' . $dbr->addQuotes( $ip_pattern ),
@@ -115,32 +115,32 @@
116116 global $wgGlobalBlockingDatabase;
117117 return wfGetDB( DB_MASTER, 'globalblocking', $wgGlobalBlockingDatabase );
118118 }
119 -
 119+
120120 static function getGlobalBlockingSlave() {
121121 global $wgGlobalBlockingDatabase;
122122 return wfGetDB( DB_SLAVE, 'globalblocking', $wgGlobalBlockingDatabase );
123123 }
124 -
 124+
125125 static function getGlobalBlockId( $ip ) {
126126 $dbr = GlobalBlocking::getGlobalBlockingSlave();
127 -
 127+
128128 if (!($row = $dbr->selectRow( 'globalblocks', 'gb_id', array( 'gb_address' => $ip ), __METHOD__ )))
129129 return 0;
130 -
 130+
131131 return $row->gb_id;
132132 }
133 -
 133+
134134 static function purgeExpired() {
135135 // This is expensive. It involves opening a connection to a new master,
136136 // and doing a write query. We should only do it when a connection to the master
137137 // is already open (currently, when a global block is made).
138138 $dbw = GlobalBlocking::getGlobalBlockingMaster();
139 -
 139+
140140 // Stand-alone transaction.
141141 $dbw->begin();
142142 $dbw->delete( 'globalblocks', array('gb_expiry<'.$dbw->addQuotes($dbw->timestamp())), __METHOD__ );
143143 $dbw->commit();
144 -
 144+
145145 // Purge the global_block_whitelist table.
146146 // We can't be perfect about this without an expensive check on the master
147147 // for every single global block. However, we can be clever about it and store
@@ -151,7 +151,7 @@
152152 $dbw->delete( 'global_block_whitelist', array( 'gbw_expiry<'.$dbw->addQuotes($dbw->timestamp())), __METHOD__ );
153153 $dbw->commit();
154154 }
155 -
 155+
156156 static function getWhitelistInfo( $id = null, $address = null ) {
157157 if ($id != null) {
158158 $conds = array( 'gbw_id' => $id );
@@ -161,10 +161,10 @@
162162 //WTF?
163163 throw new MWException( "Neither Block IP nor Block ID given for retrieving whitelist status" );
164164 }
165 -
 165+
166166 $dbr = wfGetDB( DB_SLAVE );
167167 $row = $dbr->selectRow( 'global_block_whitelist', array( 'gbw_by', 'gbw_reason' ), $conds, __METHOD__ );
168 -
 168+
169169 if ($row == false) {
170170 // Not whitelisted.
171171 return false;
@@ -173,45 +173,45 @@
174174 return array( 'user' => $row->gbw_by, 'reason' => $row->gbw_reason );
175175 }
176176 }
177 -
 177+
178178 static function getWhitelistInfoByIP( $block_ip ) {
179179 return self::getWhitelistInfo( null, $block_ip );
180180 }
181 -
 181+
182182 static function getWikiName( $wiki_id ) {
183183 if (class_exists('WikiMap')) {
184184 // We can give more info than just the wiki id!
185185 $wiki = WikiMap::getWiki( $wiki_id );
186 -
 186+
187187 if ($wiki) {
188188 return $wiki->getDisplayName();
189189 }
190190 }
191 -
 191+
192192 return $wiki_id;
193193 }
194 -
 194+
195195 static function maybeLinkUserpage( $wiki_id, $user ) {
196196 if (class_exists( 'WikiMap')) {
197197 $wiki = WikiMap::getWiki( $wiki_id );
198 -
 198+
199199 if ($wiki) {
200200 return "[".$wiki->getUrl( "User:$user" )." $user]";
201201 }
202202 }
203203 return $user;
204204 }
205 -
 205+
206206 static function insertBlock( $address, $reason, $expiry, $options = array() ) {
207207 global $wgUser;
208208 $errors = array();
209 -
 209+
210210 ## Purge expired blocks.
211211 GlobalBlocking::purgeExpired();
212212
213213 ## Validate input
214214 $ip = IP::sanitizeIP( $address );
215 -
 215+
216216 $anonOnly = in_array( 'anon-only', $options );
217217 $modify = in_array( 'modify', $options );
218218
@@ -219,37 +219,37 @@
220220 // Invalid IP address.
221221 $errors[] = array( 'globalblocking-block-ipinvalid', $ip );
222222 }
223 -
 223+
224224 if ( false === $expiry ) {
225225 $errors[] = array( 'globalblocking-block-expiryinvalid', $expiry );
226226 }
227 -
 227+
228228 $existingBlock = GlobalBlocking::getGlobalBlockId($ip);
229229 if ( !$modify && $existingBlock ) {
230230 $errors[] = array( 'globalblocking-block-alreadyblocked', $ip );
231231 }
232 -
 232+
233233 // Check for too-big ranges.
234234 list( $range_start, $range_end ) = IP::parseRange( $ip );
235 -
 235+
236236 if (substr( $range_start, 0, 4 ) != substr( $range_end, 0, 4 )) {
237237 // Range crosses a /16 boundary.
238238 $errors[] = array( 'globalblocking-block-bigrange', $ip );
239239 }
240 -
 240+
241241 // Normalise the range
242242 if ($range_start != $range_end) {
243243 $ip = Block::normaliseRange( $ip );
244244 }
245 -
 245+
246246 if (count($errors)>0)
247247 return $errors;
248248
249249 // We're a-ok.
250250 $dbw = GlobalBlocking::getGlobalBlockingMaster();
251 -
 251+
252252 // Delete the old block, if applicable
253 -
 253+
254254 if ($modify) {
255255 $dbw->delete( 'globalblocks', array( 'gb_id' => $existingBlock ), __METHOD__ );
256256 }
@@ -265,36 +265,36 @@
266266 list( $row['gb_range_start'], $row['gb_range_end'] ) = array( $range_start, $range_end );
267267
268268 $dbw->insert( 'globalblocks', $row, __METHOD__ );
269 -
 269+
270270 return array();
271271 }
272 -
 272+
273273 static function block( $address, $reason, $expiry, $options = array() ) {
274274 global $wgContLang;
275 -
 275+
276276 $expiry = SpecialBlock::parseExpiryInput( $expiry );
277277 $errors = self::insertBlock( $address, $reason, $expiry, $options );
278 -
 278+
279279 if ( count($errors) > 0 )
280280 return $errors;
281 -
 281+
282282 $anonOnly = in_array( 'anon-only', $options );
283283 $modify = in_array( 'modify', $options );
284284
285285 // Log it.
286286 $logAction = $modify ? 'modify' : 'gblock2';
287287 $flags = array();
288 -
 288+
289289 if ($anonOnly)
290290 $flags[] = wfMsgForContent( 'globalblocking-list-anononly' );
291 -
 291+
292292 if ( $expiry != 'infinity' ) {
293293 $displayExpiry = $wgContLang->timeanddate( $expiry );
294294 $flags[] = wfMsgForContent( 'globalblocking-logentry-expiry', $displayExpiry );
295295 } else {
296296 $flags[] = wfMsgForContent( 'globalblocking-logentry-noexpiry' );
297297 }
298 -
 298+
299299 $info = implode( ', ', $flags );
300300
301301 $page = new LogPage( 'gblblock' );
@@ -306,10 +306,10 @@
307307
308308 return array();
309309 }
310 -
 310+
311311 static function onSpecialPasswordResetOnSubmit( &$users, $data, &$error ) {
312312 global $wgUser;
313 -
 313+
314314 if ( GlobalBlocking::getUserBlockErrors( $wgUser, wfGetIp() ) ) {
315315 $error = wfMsg( 'globalblocking-blocked-nopassreset' );
316316 return false;
@@ -342,6 +342,7 @@
343343 );
344344 return true;
345345 }
 346+
346347 /**
347348 * Build links to other global blocking special pages, shown in the subtitle
348349 * @param string $pagetype The calling special page name
@@ -352,30 +353,29 @@
353354
354355 // Add a few useful links
355356 $links = array();
356 - $sk = $wgUser->getSkin();
357357
358358 // Don't show a link to a special page on the special page itself.
359359 // Show the links only if the user has sufficient rights
360360 if( $pagetype != 'GlobalBlockList' ) {
361361 $title = SpecialPage::getTitleFor( 'GlobalBlockList' );
362 - $links[] = $sk->linkKnown( $title, wfMsg( 'globalblocklist' ) );
 362+ $links[] = Linker::linkKnown( $title, wfMsg( 'globalblocklist' ) );
363363 }
364364
365365 if( $pagetype != 'GlobalBlock' && $wgUser->isAllowed( 'globalblock' ) ) {
366366 $title = SpecialPage::getTitleFor( 'GlobalBlock' );
367 - $links[] = $sk->linkKnown( $title, wfMsg( 'globalblocking-goto-block' ) );
 367+ $links[] = Linker::linkKnown( $title, wfMsg( 'globalblocking-goto-block' ) );
368368 }
369369 if( $pagetype != 'RemoveGlobalBlock' && $wgUser->isAllowed( 'globalunblock' ) ) {
370370 $title = SpecialPage::getTitleFor( 'RemoveGlobalBlock' );
371 - $links[] = $sk->linkKnown( $title, wfMsg( 'globalblocking-goto-unblock' ) );
 371+ $links[] = Linker::linkKnown( $title, wfMsg( 'globalblocking-goto-unblock' ) );
372372 }
373373 if( $pagetype != 'GlobalBlockStatus' && $wgUser->isAllowed( 'globalblock-whitelist' ) ) {
374374 $title = SpecialPage::getTitleFor( 'GlobalBlockStatus' );
375 - $links[] = $sk->linkKnown( $title, wfMsg( 'globalblocking-goto-status' ) );
 375+ $links[] = Linker::linkKnown( $title, wfMsg( 'globalblocking-goto-status' ) );
376376 }
377377 if( $pagetype == 'GlobalBlock' && $wgUser->isAllowed( 'editinterface' ) ) {
378378 $title = Title::makeTitle( NS_MEDIAWIKI, 'Globalblocking-block-reason-dropdown' );
379 - $links[] = $sk->linkKnown( $title, wfMsg( 'globalblocking-block-edit-dropdown' ), array(), array( 'action' => 'edit' ) );
 379+ $links[] = Linker::linkKnown( $title, wfMsg( 'globalblocking-block-edit-dropdown' ), array(), array( 'action' => 'edit' ) );
380380 }
381381 $linkItems = count( $links ) ? wfMsg( 'parentheses', $wgLang->pipeList( $links ) ) : '';
382382 return $linkItems;
Index: trunk/extensions/GlobalBlocking/ApiQueryGlobalBlocks.php
@@ -83,30 +83,29 @@
8484 }
8585 if(isset($params['ip'])) {
8686 list($ip, $range) = IP::parseCIDR($params['ip']);
87 - if($ip && $range)
88 - {
 87+ if($ip && $range) {
8988 # We got a CIDR range
9089 if($range < 16)
9190 $this->dieUsage('CIDR ranges broader than /16 are not accepted', 'cidrtoobroad');
9291 $lower = wfBaseConvert($ip, 10, 16, 8, false);
9392 $upper = wfBaseConvert($ip + pow(2, 32 - $range) - 1, 10, 16, 8, false);
94 - }
95 - else
 93+ } else {
9694 $lower = $upper = IP::toHex($params['ip']);
 95+ }
9796 $prefix = substr($lower, 0, 4);
98 - $this->addWhere(array(
99 - "gb_range_start LIKE '$prefix%'",
100 - "gb_range_start <= '$lower'",
101 - "gb_range_end >= '$upper'"
102 - ));
 97+ $this->addWhere( array(
 98+ "gb_range_start LIKE '$prefix%'",
 99+ "gb_range_start <= '$lower'",
 100+ "gb_range_end >= '$upper'"
 101+ )
 102+ );
103103 }
104104
105105 $res = $this->select(__METHOD__);
106106
107107 $count = 0;
108108 foreach ( $res as $row ) {
109 - if(++$count > $params['limit'])
110 - {
 109+ if(++$count > $params['limit']) {
111110 // We've had enough
112111 $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->gb_timestamp));
113112 break;
@@ -114,14 +113,12 @@
115114 $block = array();
116115 if($fld_id)
117116 $block['id'] = $row->gb_id;
118 - if($fld_address)
119 - {
 117+ if($fld_address) {
120118 $block['address'] = $row->gb_address;
121119 if($row->gb_anon_only)
122120 $block['anononly'] = '';
123121 }
124 - if($fld_by)
125 - {
 122+ if($fld_by) {
126123 $block['by'] = $row->gb_by;
127124 $block['bywiki'] = $row->gb_by_wiki;
128125 }
@@ -131,8 +128,7 @@
132129 $block['expiry'] = Block::decodeExpiry($row->gb_expiry, TS_ISO_8601);
133130 if($fld_reason)
134131 $block['reason'] = $row->gb_reason;
135 - if($fld_range)
136 - {
 132+ if($fld_range) {
137133 $block['rangestart'] = IP::hexToQuad($row->gb_range_start);
138134 $block['rangeend'] = IP::hexToQuad($row->gb_range_end);
139135 }
Index: trunk/extensions/GlobalBlocking/SpecialGlobalBlockStatus.php
@@ -8,31 +8,33 @@
99 }
1010
1111 function execute( $par ) {
12 - global $wgOut, $wgRequest, $wgUser;
 12+ global $wgUser;
1313 $this->setHeaders();
1414
1515 $this->loadParameters();
1616
17 - $wgOut->setPageTitle( wfMsg( 'globalblocking-whitelist' ) );
18 - $wgOut->setSubtitle( GlobalBlocking::buildSubtitleLinks( 'GlobalBlockStatus' ) );
19 - $wgOut->setRobotPolicy( "noindex,nofollow" );
20 - $wgOut->setArticleRelated( false );
21 - $wgOut->enableClientCache( false );
 17+ $out = $this->getOutput();
 18+ $out->setPageTitle( wfMsg( 'globalblocking-whitelist' ) );
 19+ $out->setSubtitle( GlobalBlocking::buildSubtitleLinks( 'GlobalBlockStatus' ) );
 20+ $out->setRobotPolicy( "noindex,nofollow" );
 21+ $out->setArticleRelated( false );
 22+ $out->enableClientCache( false );
2223
2324 if (!$this->userCanExecute( $wgUser )) {
2425 $this->displayRestrictionError();
2526 return;
2627 }
27 -
 28+
2829 global $wgApplyGlobalBlocks;
2930 if (!$wgApplyGlobalBlocks) {
30 - $wgOut->addWikiMsg( 'globalblocking-whitelist-notapplied' );
 31+ $out->addWikiMsg( 'globalblocking-whitelist-notapplied' );
3132 return;
3233 }
3334
3435 $errors = '';
3536
36 - if ($wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ))) {
 37+ $request = $this->getRequest();
 38+ if ( $request->wasPosted() && $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
3739 // They want to submit. Let's have a look.
3840 $errors = $this->trySubmit();
3941 if( !$errors ) {
@@ -40,11 +42,11 @@
4143 return;
4244 }
4345 }
44 -
 46+
4547 $errorstr = '';
4648
4749 if (is_array($errors) && count($errors)>0) {
48 -
 50+
4951 foreach ( $errors as $error ) {
5052 if (is_array($error)) {
5153 $msg = array_shift($error);
@@ -57,28 +59,27 @@
5860
5961 $errorstr = wfMsgExt( 'globalblocking-whitelist-errors', array( 'parse' ), array( count( $errors ) ) ) .
6062 Xml::tags( 'ul', array( 'class' => 'error' ), $errorstr );
61 -
 63+
6264 $errorstr = Xml::tags( 'div', array( 'class' => 'error' ), $errorstr );
6365 }
64 -
 66+
6567 $this->form( $errorstr );
66 -
6768 }
6869
6970 function loadParameters() {
70 - global $wgRequest;
71 - $ip = trim( $wgRequest->getText( 'address' ) );
72 - $this->mAddress = ( $ip !== '' || $wgRequest->wasPosted() )
 71+ $request = $this->getRequest();
 72+ $ip = trim( $request->getText( 'address' ) );
 73+ $this->mAddress = ( $ip !== '' || $request->wasPosted() )
7374 ? Block::normaliseRange( $ip )
7475 : '';
75 - $this->mReason = $wgRequest->getText( 'wpReason' );
76 - $this->mWhitelistStatus = $wgRequest->getCheck( 'wpWhitelistStatus' );
77 - $this->mEditToken = $wgRequest->getText( 'wpEditToken' );
78 -
 76+ $this->mReason = $request->getText( 'wpReason' );
 77+ $this->mWhitelistStatus = $request->getCheck( 'wpWhitelistStatus' );
 78+ $this->mEditToken = $request->getText( 'wpEditToken' );
 79+
7980 if ( $this->mAddress ) {
80 - $this->mCurrentStatus = (GlobalBlocking::getWhitelistInfoByIP( $this->mAddress ) !== false);
81 -
82 - if ( !$wgRequest->wasPosted() ) {
 81+ $this->mCurrentStatus = ( GlobalBlocking::getWhitelistInfoByIP( $this->mAddress ) !== false);
 82+
 83+ if ( !$request->wasPosted() ) {
8384 $this->mWhitelistStatus = $this->mCurrentStatus;
8485 }
8586 } else {
@@ -87,63 +88,65 @@
8889 }
8990
9091 function trySubmit() {
91 - global $wgOut,$wgUser;
92 -
 92+ global $wgUser;
 93+
9394 $ip = $this->mAddress;
94 -
 95+
9596 // Is it blocked?
9697 if ( !($id = GlobalBlocking::getGlobalBlockId( $ip ) ) ) {
9798 return array( array( 'globalblocking-notblocked', $ip ) );
9899 }
99 -
 100+
100101 $new_status = $this->mWhitelistStatus;
101102 $cur_status = $this->mCurrentStatus;
102 -
 103+
103104 // Already whitelisted.
104105 if ($cur_status == $new_status) {
105106 return array('globalblocking-whitelist-nochange');
106107 }
107108
108109 $dbw = wfGetDB( DB_MASTER );
109 -
 110+
 111+ $out = $this->getOutput();
110112 if ($new_status == true) {
111113 $gdbr = GlobalBlocking::getGlobalBlockingSlave();
112 -
 114+
113115 // Find the expiry of the block. This is important so that we can store it in the
114116 // global_block_whitelist table, which allows us to purge it when the block has expired.
115117 $expiry = $gdbr->selectField( 'globalblocks', 'gb_expiry', array( 'gb_id' => $id ), __METHOD__ );
116 -
 118+
117119 $row = array('gbw_by' => $wgUser->getId(), 'gbw_by_text' => $wgUser->getName(), 'gbw_reason' => $this->mReason, 'gbw_address' => $ip, 'gbw_expiry' => $expiry, 'gbw_id' => $id);
118120 $dbw->replace( 'global_block_whitelist', array( 'gbw_id' ), $row, __METHOD__ );
119121
120122 $page = new LogPage( 'gblblock' );
121123 $page->addEntry( 'whitelist', Title::makeTitleSafe( NS_USER, $ip ), $this->mReason );
122 -
123 - $wgOut->addWikiMsg( 'globalblocking-whitelist-whitelisted', $ip, $id );
 124+
 125+ $out->addWikiMsg( 'globalblocking-whitelist-whitelisted', $ip, $id );
124126 } else {
125127 // Delete the row from the database
126128 $dbw->delete( 'global_block_whitelist', array( 'gbw_id' => $id ), __METHOD__ );
127 -
 129+
128130 $page = new LogPage( 'gblblock' );
129131 $page->addEntry( 'dwhitelist', Title::makeTitleSafe( NS_USER, $ip ), $this->mReason );
130 - $wgOut->addWikiMsg( 'globalblocking-whitelist-dewhitelisted', $ip, $id );
 132+ $out->addWikiMsg( 'globalblocking-whitelist-dewhitelisted', $ip, $id );
131133 }
132 -
 134+
133135 $link = $wgUser->getSkin()->makeKnownLinkObj( SpecialPage::getTitleFor( 'GlobalBlockList' ), wfMsg( 'globalblocking-return' ) );
134 - $wgOut->addHTML( $link );
 136+ $out->addHTML( $link );
135137
136 - $wgOut->setSubtitle(wfMsg('globalblocking-whitelist-successsub'));
 138+ $out->setSubtitle(wfMsg('globalblocking-whitelist-successsub'));
137139
138140 return array();
139141 }
140142
141143 function form( $error ) {
142 - global $wgUser, $wgOut;
143 -
144 - $wgOut->addWikiMsg( 'globalblocking-whitelist-intro' );
145 -
146 - $wgOut->addHTML( $error );
 144+ global $wgUser;
147145
 146+ $out = $this->getOutput();
 147+ $out->addWikiMsg( 'globalblocking-whitelist-intro' );
 148+
 149+ $out->addHTML( $error );
 150+
148151 $form = '';
149152 $form .= Xml::openElement( 'fieldset' ) . Xml::element( 'legend', null, wfMsg( 'globalblocking-whitelist-legend' ) );
150153 $form .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getFullURL(), 'name' => 'globalblock-whitelist' ) );
@@ -165,6 +168,6 @@
166169 $form .= Xml::closeElement( 'form' );
167170 $form .= Xml::closeElement( 'fieldset' );
168171
169 - $wgOut->addHTML( $form );
 172+ $out->addHTML( $form );
170173 }
171174 }
Index: trunk/extensions/GlobalBlocking/SpecialGlobalBlockList.php
@@ -8,23 +8,22 @@
99 }
1010
1111 function execute( $par ) {
12 - global $wgOut, $wgRequest;
13 -
 12+ $out = $this->getOutput();
1413 $this->setHeaders();
15 - $ip = isset( $par ) ? $par : $wgRequest->getText( 'ip' );
 14+ $ip = isset( $par ) ? $par : $this->getRequest()->getText( 'ip' );
1615 $this->loadParameters( $ip );
1716
18 - $wgOut->setPageTitle( wfMsg( 'globalblocking-list' ) );
19 - $wgOut->setSubtitle( GlobalBlocking::buildSubtitleLinks( 'GlobalBlockList' ) );
20 - $wgOut->setRobotPolicy( "noindex,nofollow" );
21 - $wgOut->setArticleRelated( false );
22 - $wgOut->enableClientCache( false );
 17+ $out->setPageTitle( wfMsg( 'globalblocking-list' ) );
 18+ $out->setSubtitle( GlobalBlocking::buildSubtitleLinks( 'GlobalBlockList' ) );
 19+ $out->setRobotPolicy( "noindex,nofollow" );
 20+ $out->setArticleRelated( false );
 21+ $out->enableClientCache( false );
2322
2423 $this->showList();
2524 }
2625
2726 function showList( ) {
28 - global $wgOut, $wgScript;
 27+ global $wgScript;
2928 $errors = array();
3029
3130 // Validate search IP
@@ -34,8 +33,8 @@
3534 $ip = '';
3635 }
3736
38 - $wgOut->addWikiMsg( 'globalblocking-list-intro' );
39 -
 37+ $out = $this->getOutput();
 38+ $out->addWikiMsg( 'globalblocking-list-intro' );
4039
4140 // Build the search form
4241 $searchForm = '';
@@ -46,7 +45,7 @@
4746
4847 if (is_array($errors) && count($errors)>0) {
4948 $errorstr = '';
50 -
 49+
5150 foreach ( $errors as $error ) {
5251 if (is_array($error)) {
5352 $msg = array_shift($error);
@@ -54,12 +53,12 @@
5554 $msg = $error;
5655 $error = array();
5756 }
58 -
 57+
5958 $errorstr .= Xml::tags( 'li', null, wfMsgExt( $msg, array( 'parseinline' ), $error ) );
6059 }
6160
62 - $wgOut->addWikiMsg( 'globalblocking-unblock-errors', count($errors) );
63 - $wgOut->addHTML( Xml::tags( 'ul', array( 'class' => 'error' ), $errorstr ) );
 61+ $out->addWikiMsg( 'globalblocking-unblock-errors', count($errors) );
 62+ $out->addHTML( Xml::tags( 'ul', array( 'class' => 'error' ), $errorstr ) );
6463 }
6564
6665 $fields = array();
@@ -67,24 +66,24 @@
6867 $searchForm .= Xml::buildForm( $fields, 'globalblocking-search-submit' );
6968
7069 $searchForm .= Xml::closeElement( 'form' ) . Xml::closeElement( 'fieldset' );
71 - $wgOut->addHTML( $searchForm );
 70+ $out->addHTML( $searchForm );
7271
7372 // Build a list of blocks.
7473 $conds = array();
75 -
 74+
7675 if (strlen($ip)) {
7776 list ($range_start, $range_end) = IP::parseRange( $ip );
78 -
 77+
7978 if ($range_start != $range_end) {
8079 // They searched for a range. Match that exact range only
8180 $conds = array( 'gb_address' => $ip );
8281 } else {
83 - // They searched for an IP. Match any range covering that IP
 82+ // They searched for an IP. Match any range covering that IP
8483 $hex_ip = IP::toHex( $ip );
8584 $ip_pattern = substr( $hex_ip, 0, 4 ) . '%'; // Don't bother checking blocks out of this /16.
86 -
 85+
8786 $dbr = wfGetDB( DB_SLAVE );
88 -
 87+
8988 $conds = array( 'gb_range_end>='.$dbr->addQuotes($hex_ip), // This block in the given range.
9089 'gb_range_start<='.$dbr->addQuotes($hex_ip),
9190 'gb_range_start like ' . $dbr->addQuotes( $ip_pattern ),
@@ -95,11 +94,11 @@
9695 $pager = new GlobalBlockListPager( $this, $conds );
9796 $body = $pager->getBody();
9897 if( $body != '' ) {
99 - $wgOut->addHTML( $pager->getNavigationBar() .
 98+ $out->addHTML( $pager->getNavigationBar() .
10099 Html::rawElement( 'ul', array(), $body ) .
101100 $pager->getNavigationBar() );
102101 } else {
103 - $wgOut->wrapWikiMsg( "<div class='mw-globalblocking-noresults'>\n$1</div>\n",
 102+ $out->wrapWikiMsg( "<div class='mw-globalblocking-noresults'>\n$1</div>\n",
104103 array( 'globalblocking-list-noresults' ) );
105104 }
106105 }
@@ -125,19 +124,12 @@
126125
127126 function formatRow( $row ) {
128127 global $wgLang, $wgUser;
129 -
130 - ## One-time setup
131 - static $sk=null;
132 -
133 - if (is_null($sk)) {
134 - $sk = $wgUser->getSkin();
135 - }
136 -
 128+
137129 ## Setup
138130 $timestamp = $row->gb_timestamp;
139131 $expiry = $row->gb_expiry;
140132 $options = array();
141 -
 133+
142134 # Messy B/C until $wgLang->formatExpiry() is well embedded
143135 if( Block::decodeExpiry( $expiry ) == 'infinity' ){
144136 $options[] = wfMsgExt( 'infiniteblock', 'parseinline' );
@@ -150,24 +142,24 @@
151143 $wgLang->time( $expiry )
152144 );
153145 }
154 -
 146+
155147 # Check for whitelisting.
156148 $wlinfo = GlobalBlocking::getWhitelistInfo( $row->gb_id );
157149 if ($wlinfo) {
158150 $options[] = wfMsg( 'globalblocking-list-whitelisted', User::whois($wlinfo['user']), $wlinfo['reason'] );
159151 }
160 -
 152+
161153 $timestamp = $wgLang->timeanddate( wfTimestamp( TS_MW, $timestamp ), true );
162154
163155 if ($row->gb_anon_only)
164156 $options[] = wfMsg('globalblocking-list-anononly');
165 -
 157+
166158 ## Do afterthoughts (comment, links for admins)
167159 $info = array();
168160
169161 if( $wgUser->isAllowed( 'globalunblock' ) ) {
170162 $unblockTitle = SpecialPage::getTitleFor( "RemoveGlobalBlock" );
171 - $info[] = $sk->link( $unblockTitle,
 163+ $info[] = Linker::link( $unblockTitle,
172164 wfMsgExt( 'globalblocking-list-unblock', 'parseinline' ),
173165 array(),
174166 array( 'address' => $row->gb_address )
@@ -177,7 +169,7 @@
178170 global $wgApplyGlobalBlocks;
179171 if( $wgUser->isAllowed( 'globalblock-whitelist' ) && $wgApplyGlobalBlocks ) {
180172 $whitelistTitle = SpecialPage::getTitleFor( "GlobalBlockStatus" );
181 - $info[] = $sk->link( $whitelistTitle,
 173+ $info[] = Linker::link( $whitelistTitle,
182174 wfMsgExt( 'globalblocking-list-whitelist', 'parseinline' ),
183175 array(),
184176 array( 'address' => $row->gb_address )
@@ -187,7 +179,7 @@
188180 if ( $wgUser->isAllowed( 'globalblock' ) ) {
189181 $reblockTitle = SpecialPage::getTitleFor( 'GlobalBlock' );
190182 $msg = wfMsgExt( 'globalblocking-list-modify', 'parseinline' );
191 - $info[] = $sk->link(
 183+ $info[] = Linker::link(
192184 $reblockTitle,
193185 $msg,
194186 array(),
@@ -209,7 +201,7 @@
210202 $row->gb_address,
211203 $wgLang->commaList( $options )
212204 ) . ' ' .
213 - $sk->commentBlock( $row->gb_reason ) . ' ' .
 205+ Linker::commentBlock( $row->gb_reason ) . ' ' .
214206 $infoItems
215207 );
216208 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r114408Revert r111465, unreviewed....catrope21:28, 21 March 2012

Comments

#Comment by Awjrichards (talk | contribs)   22:40, 17 February 2012

function trySubmit() { 72 - global $wgOut,$wgUser;

	74	+		global $wgOut;

Why did you leave $wgOut here?

This otherwise looks ok to me.

#Comment by Reedy (talk | contribs)   21:53, 20 February 2012

No idea. Looks like someone (maybe me) has dealt with it in a subsequent commit

Status & tagging log