r114408 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114407‎ | r114408 | r114409 >
Date:21:28, 21 March 2012
Author:catrope
Status:ok
Tags:historical 
Comment:
Revert r111465, unreviewed.

All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
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,19 +8,17 @@
99 }
1010
1111 function execute( $par ) {
12 - global $wgUser;
 12+ global $wgOut, $wgRequest, $wgUser;
1313 $this->setHeaders();
1414
1515 $this->loadParameters();
1616
17 - $out = $this->getOutput();
 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 );
1822
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 -
2523 if (!$this->userCanExecute( $wgUser )) {
2624 $this->displayRestrictionError();
2725 return;
@@ -28,8 +26,7 @@
2927
3028 $errors = '';
3129
32 - $request = $this->getRequest();
33 - if ( $request->wasPosted() && $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
 30+ if ($wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ))) {
3431 // They want to submit. Let's have a look.
3532 $errors = $this->trySubmit();
3633 if( !$errors ) {
@@ -37,12 +34,12 @@
3835 return;
3936 }
4037 }
 38+
 39+ $wgOut->addWikiMsg( 'globalblocking-unblock-intro' );
4140
42 - $out->addWikiMsg( 'globalblocking-unblock-intro' );
43 -
4441 if (is_array($errors) && count($errors)>0) {
4542 $errorstr = '';
46 -
 43+
4744 foreach ( $errors as $error ) {
4845 if (is_array($error)) {
4946 $msg = array_shift($error);
@@ -52,14 +49,15 @@
5350 }
5451 $errorstr .= Xml::tags( 'li', null, wfMsgExt( $msg, array( 'parseinline' ), $error ) );
5552 }
56 -
 53+
5754 $errorstr = Xml::tags( 'ul', array( 'class' => 'error' ), $errorstr );
5855 $errorstr = wfMsgExt( 'globalblocking-unblock-errors', array('parse'), array( count( $errors ) ) ) . $errorstr;
5956 $errorstr = Xml::tags( 'div', array( 'class' => 'error' ), $errorstr );
60 - $out->addHTML( $errorstr );
 57+ $wgOut->addHTML( $errorstr );
6158 }
 59+
 60+ $this->form( );
6261
63 - $this->form();
6462 }
6563
6664 function loadParameters() {
@@ -70,7 +68,7 @@
7169 }
7270
7371 function trySubmit() {
74 - global $wgOut;
 72+ global $wgOut,$wgUser;
7573 $errors = array();
7674 $ip = $this->mUnblockIP;
7775 if (!IP::isIPAddress($ip) && strlen($ip)) {
@@ -86,7 +84,6 @@
8785 return $errors;
8886 }
8987
90 - $out = $this->getOutput();
9188 $dbw = GlobalBlocking::getGlobalBlockingMaster();
9289 $dbw->delete( 'globalblocks', array( 'gb_id' => $id ), __METHOD__ );
9390
@@ -94,12 +91,12 @@
9592 $page->addEntry( 'gunblock', Title::makeTitleSafe( NS_USER, $ip ), $this->mReason );
9693
9794 $successmsg = wfMsgExt( 'globalblocking-unblock-unblocked', array( 'parse' ), $ip, $id );
98 - $out->addHTML( $successmsg );
 95+ $wgOut->addHTML( $successmsg );
9996
100 - $link = Linker::makeKnownLinkObj( SpecialPage::getTitleFor( 'GlobalBlockList' ), wfMsg( 'globalblocking-return' ) );
101 - $out->addHTML( $link );
 97+ $link = $wgUser->getSkin()->makeKnownLinkObj( SpecialPage::getTitleFor( 'GlobalBlockList' ), wfMsg( 'globalblocking-return' ) );
 98+ $wgOut->addHTML( $link );
10299
103 - $out->setSubtitle(wfMsg('globalblocking-unblock-successsub'));
 100+ $wgOut->setSubtitle(wfMsg('globalblocking-unblock-successsub'));
104101
105102 return array();
106103 }
Index: trunk/extensions/GlobalBlocking/SpecialGlobalBlock.php
@@ -10,17 +10,16 @@
1111 }
1212
1313 function execute( $par ) {
14 - global $wgUser;
 14+ global $wgOut, $wgRequest, $wgUser;
1515 $this->setHeaders();
1616
1717 $this->loadParameters( $par );
1818
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 );
 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 );
2524
2625 if (!$this->userCanExecute( $wgUser )) {
2726 $this->displayRestrictionError();
@@ -29,8 +28,7 @@
3029
3130 $errors = '';
3231
33 - $request = $this->getRequest();
34 - if ( $request->wasPosted() && $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
 32+ if ($wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ))) {
3533 // They want to submit. Let's have a look.
3634 $errors = $this->trySubmit();
3735 if( !$errors ) {
@@ -116,14 +114,15 @@
117115 }
118116
119117 function trySubmit() {
 118+ global $wgOut, $wgUser;
120119 $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();
128127 $reasonstr = $this->mReasonList;
129128 if( $reasonstr != 'other' && $this->mReason != '' ) {
130129 // Entry from drop down menu + additional comment
@@ -146,12 +145,12 @@
147146 $subMessage = 'globalblocking-block-successsub';
148147 }
149148
150 - $out->addWikitext( wfMsg($textMessage, $this->mAddress ) );
151 - $out->setSubtitle( wfMsg( $subMessage ) );
 149+ $wgOut->addWikitext( wfMsg($textMessage, $this->mAddress ) );
 150+ $wgOut->setSubtitle( wfMsg( $subMessage ) );
152151
153 - $link = Linker::link( SpecialPage::getTitleFor( 'GlobalBlockList' ),
 152+ $link = $skin->link( SpecialPage::getTitleFor( 'GlobalBlockList' ),
154153 wfMsg( 'globalblocking-return' ) );
155 - $out->addHTML( $link );
 154+ $wgOut->addHTML( $link );
156155
157156 return array();
158157 }
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 ) ) {
4949 return $result;
@@ -57,7 +57,7 @@
5858 // Block has been whitelisted.
5959 return $result = array();
6060 }
61 -
 61+
6262 if ( $user->isAllowed( 'ipblock-exempt' ) || $user->isAllowed( 'globalblock-exempt' ) ) {
6363 // User is exempt from IP blocks.
6464 return $result = array();
@@ -72,10 +72,10 @@
7373 } else {
7474 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW, $blockExpiry ), true );
7575 }
76 -
 76+
7777 $display_wiki = self::getWikiName( $block->gb_by_wiki );
7878 $blockingUser = self::maybeLinkUserpage( $block->gb_by_wiki, $block->gb_by );
79 -
 79+
8080 return $result = array( 'globalblocking-ipblocked',
8181 $blockingUser, $display_wiki, $block->gb_reason, $blockTimestamp, $blockExpiry, $ip );
8282 }
@@ -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,7 +342,6 @@
343343 );
344344 return true;
345345 }
346 -
347346 /**
348347 * Build links to other global blocking special pages, shown in the subtitle
349348 * @param string $pagetype The calling special page name
@@ -353,29 +352,30 @@
354353
355354 // Add a few useful links
356355 $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[] = Linker::linkKnown( $title, wfMsg( 'globalblocklist' ) );
 362+ $links[] = $sk->linkKnown( $title, wfMsg( 'globalblocklist' ) );
363363 }
364364
365365 if( $pagetype != 'GlobalBlock' && $wgUser->isAllowed( 'globalblock' ) ) {
366366 $title = SpecialPage::getTitleFor( 'GlobalBlock' );
367 - $links[] = Linker::linkKnown( $title, wfMsg( 'globalblocking-goto-block' ) );
 367+ $links[] = $sk->linkKnown( $title, wfMsg( 'globalblocking-goto-block' ) );
368368 }
369369 if( $pagetype != 'RemoveGlobalBlock' && $wgUser->isAllowed( 'globalunblock' ) ) {
370370 $title = SpecialPage::getTitleFor( 'RemoveGlobalBlock' );
371 - $links[] = Linker::linkKnown( $title, wfMsg( 'globalblocking-goto-unblock' ) );
 371+ $links[] = $sk->linkKnown( $title, wfMsg( 'globalblocking-goto-unblock' ) );
372372 }
373373 if( $pagetype != 'GlobalBlockStatus' && $wgUser->isAllowed( 'globalblock-whitelist' ) ) {
374374 $title = SpecialPage::getTitleFor( 'GlobalBlockStatus' );
375 - $links[] = Linker::linkKnown( $title, wfMsg( 'globalblocking-goto-status' ) );
 375+ $links[] = $sk->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[] = Linker::linkKnown( $title, wfMsg( 'globalblocking-block-edit-dropdown' ), array(), array( 'action' => 'edit' ) );
 379+ $links[] = $sk->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,29 +83,30 @@
8484 }
8585 if(isset($params['ip'])) {
8686 list($ip, $range) = IP::parseCIDR($params['ip']);
87 - if($ip && $range) {
 87+ if($ip && $range)
 88+ {
8889 # We got a CIDR range
8990 if($range < 16)
9091 $this->dieUsage('CIDR ranges broader than /16 are not accepted', 'cidrtoobroad');
9192 $lower = wfBaseConvert($ip, 10, 16, 8, false);
9293 $upper = wfBaseConvert($ip + pow(2, 32 - $range) - 1, 10, 16, 8, false);
93 - } else {
 94+ }
 95+ else
9496 $lower = $upper = IP::toHex($params['ip']);
95 - }
9697 $prefix = substr($lower, 0, 4);
97 - $this->addWhere( array(
98 - "gb_range_start LIKE '$prefix%'",
99 - "gb_range_start <= '$lower'",
100 - "gb_range_end >= '$upper'"
101 - )
102 - );
 98+ $this->addWhere(array(
 99+ "gb_range_start LIKE '$prefix%'",
 100+ "gb_range_start <= '$lower'",
 101+ "gb_range_end >= '$upper'"
 102+ ));
103103 }
104104
105105 $res = $this->select(__METHOD__);
106106
107107 $count = 0;
108108 foreach ( $res as $row ) {
109 - if(++$count > $params['limit']) {
 109+ if(++$count > $params['limit'])
 110+ {
110111 // We've had enough
111112 $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->gb_timestamp));
112113 break;
@@ -113,12 +114,14 @@
114115 $block = array();
115116 if($fld_id)
116117 $block['id'] = $row->gb_id;
117 - if($fld_address) {
 118+ if($fld_address)
 119+ {
118120 $block['address'] = $row->gb_address;
119121 if($row->gb_anon_only)
120122 $block['anononly'] = '';
121123 }
122 - if($fld_by) {
 124+ if($fld_by)
 125+ {
123126 $block['by'] = $row->gb_by;
124127 $block['bywiki'] = $row->gb_by_wiki;
125128 }
@@ -128,7 +131,8 @@
129132 $block['expiry'] = Block::decodeExpiry($row->gb_expiry, TS_ISO_8601);
130133 if($fld_reason)
131134 $block['reason'] = $row->gb_reason;
132 - if($fld_range) {
 135+ if($fld_range)
 136+ {
133137 $block['rangestart'] = IP::hexToQuad($row->gb_range_start);
134138 $block['rangeend'] = IP::hexToQuad($row->gb_range_end);
135139 }
Index: trunk/extensions/GlobalBlocking/SpecialGlobalBlockStatus.php
@@ -8,33 +8,31 @@
99 }
1010
1111 function execute( $par ) {
12 - global $wgUser;
 12+ global $wgOut, $wgRequest, $wgUser;
1313 $this->setHeaders();
1414
1515 $this->loadParameters();
1616
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 );
 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 );
2322
2423 if (!$this->userCanExecute( $wgUser )) {
2524 $this->displayRestrictionError();
2625 return;
2726 }
28 -
 27+
2928 global $wgApplyGlobalBlocks;
3029 if (!$wgApplyGlobalBlocks) {
31 - $out->addWikiMsg( 'globalblocking-whitelist-notapplied' );
 30+ $wgOut->addWikiMsg( 'globalblocking-whitelist-notapplied' );
3231 return;
3332 }
3433
3534 $errors = '';
3635
37 - $request = $this->getRequest();
38 - if ( $request->wasPosted() && $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
 36+ if ($wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ))) {
3937 // They want to submit. Let's have a look.
4038 $errors = $this->trySubmit();
4139 if( !$errors ) {
@@ -42,11 +40,11 @@
4341 return;
4442 }
4543 }
46 -
 44+
4745 $errorstr = '';
4846
4947 if (is_array($errors) && count($errors)>0) {
50 -
 48+
5149 foreach ( $errors as $error ) {
5250 if (is_array($error)) {
5351 $msg = array_shift($error);
@@ -59,27 +57,28 @@
6058
6159 $errorstr = wfMsgExt( 'globalblocking-whitelist-errors', array( 'parse' ), array( count( $errors ) ) ) .
6260 Xml::tags( 'ul', array( 'class' => 'error' ), $errorstr );
63 -
 61+
6462 $errorstr = Xml::tags( 'div', array( 'class' => 'error' ), $errorstr );
6563 }
66 -
 64+
6765 $this->form( $errorstr );
 66+
6867 }
6968
7069 function loadParameters() {
71 - $request = $this->getRequest();
72 - $ip = trim( $request->getText( 'address' ) );
73 - $this->mAddress = ( $ip !== '' || $request->wasPosted() )
 70+ global $wgRequest;
 71+ $ip = trim( $wgRequest->getText( 'address' ) );
 72+ $this->mAddress = ( $ip !== '' || $wgRequest->wasPosted() )
7473 ? Block::normaliseRange( $ip )
7574 : '';
76 - $this->mReason = $request->getText( 'wpReason' );
77 - $this->mWhitelistStatus = $request->getCheck( 'wpWhitelistStatus' );
78 - $this->mEditToken = $request->getText( 'wpEditToken' );
79 -
 75+ $this->mReason = $wgRequest->getText( 'wpReason' );
 76+ $this->mWhitelistStatus = $wgRequest->getCheck( 'wpWhitelistStatus' );
 77+ $this->mEditToken = $wgRequest->getText( 'wpEditToken' );
 78+
8079 if ( $this->mAddress ) {
81 - $this->mCurrentStatus = ( GlobalBlocking::getWhitelistInfoByIP( $this->mAddress ) !== false);
82 -
83 - if ( !$request->wasPosted() ) {
 80+ $this->mCurrentStatus = (GlobalBlocking::getWhitelistInfoByIP( $this->mAddress ) !== false);
 81+
 82+ if ( !$wgRequest->wasPosted() ) {
8483 $this->mWhitelistStatus = $this->mCurrentStatus;
8584 }
8685 } else {
@@ -88,65 +87,63 @@
8988 }
9089
9190 function trySubmit() {
92 - global $wgUser;
93 -
 91+ global $wgOut,$wgUser;
 92+
9493 $ip = $this->mAddress;
95 -
 94+
9695 // Is it blocked?
9796 if ( !($id = GlobalBlocking::getGlobalBlockId( $ip ) ) ) {
9897 return array( array( 'globalblocking-notblocked', $ip ) );
9998 }
100 -
 99+
101100 $new_status = $this->mWhitelistStatus;
102101 $cur_status = $this->mCurrentStatus;
103 -
 102+
104103 // Already whitelisted.
105104 if ($cur_status == $new_status) {
106105 return array('globalblocking-whitelist-nochange');
107106 }
108107
109108 $dbw = wfGetDB( DB_MASTER );
110 -
111 - $out = $this->getOutput();
 109+
112110 if ($new_status == true) {
113111 $gdbr = GlobalBlocking::getGlobalBlockingSlave();
114 -
 112+
115113 // Find the expiry of the block. This is important so that we can store it in the
116114 // global_block_whitelist table, which allows us to purge it when the block has expired.
117115 $expiry = $gdbr->selectField( 'globalblocks', 'gb_expiry', array( 'gb_id' => $id ), __METHOD__ );
118 -
 116+
119117 $row = array('gbw_by' => $wgUser->getId(), 'gbw_by_text' => $wgUser->getName(), 'gbw_reason' => $this->mReason, 'gbw_address' => $ip, 'gbw_expiry' => $expiry, 'gbw_id' => $id);
120118 $dbw->replace( 'global_block_whitelist', array( 'gbw_id' ), $row, __METHOD__ );
121119
122120 $page = new LogPage( 'gblblock' );
123121 $page->addEntry( 'whitelist', Title::makeTitleSafe( NS_USER, $ip ), $this->mReason );
124 -
125 - $out->addWikiMsg( 'globalblocking-whitelist-whitelisted', $ip, $id );
 122+
 123+ $wgOut->addWikiMsg( 'globalblocking-whitelist-whitelisted', $ip, $id );
126124 } else {
127125 // Delete the row from the database
128126 $dbw->delete( 'global_block_whitelist', array( 'gbw_id' => $id ), __METHOD__ );
129 -
 127+
130128 $page = new LogPage( 'gblblock' );
131129 $page->addEntry( 'dwhitelist', Title::makeTitleSafe( NS_USER, $ip ), $this->mReason );
132 - $out->addWikiMsg( 'globalblocking-whitelist-dewhitelisted', $ip, $id );
 130+ $wgOut->addWikiMsg( 'globalblocking-whitelist-dewhitelisted', $ip, $id );
133131 }
134 -
 132+
135133 $link = Linker::makeKnownLinkObj( SpecialPage::getTitleFor( 'GlobalBlockList' ), wfMsg( 'globalblocking-return' ) );
136 - $out->addHTML( $link );
 134+ $wgOut->addHTML( $link );
137135
138 - $out->setSubtitle(wfMsg('globalblocking-whitelist-successsub'));
 136+ $wgOut->setSubtitle(wfMsg('globalblocking-whitelist-successsub'));
139137
140138 return array();
141139 }
142140
143141 function form( $error ) {
144 - global $wgUser;
 142+ global $wgUser, $wgOut;
 143+
 144+ $wgOut->addWikiMsg( 'globalblocking-whitelist-intro' );
 145+
 146+ $wgOut->addHTML( $error );
145147
146 - $out = $this->getOutput();
147 - $out->addWikiMsg( 'globalblocking-whitelist-intro' );
148 -
149 - $out->addHTML( $error );
150 -
151148 $form = '';
152149 $form .= Xml::openElement( 'fieldset' ) . Xml::element( 'legend', null, wfMsg( 'globalblocking-whitelist-legend' ) );
153150 $form .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getFullURL(), 'name' => 'globalblock-whitelist' ) );
@@ -168,6 +165,6 @@
169166 $form .= Xml::closeElement( 'form' );
170167 $form .= Xml::closeElement( 'fieldset' );
171168
172 - $out->addHTML( $form );
 169+ $wgOut->addHTML( $form );
173170 }
174171 }
Index: trunk/extensions/GlobalBlocking/SpecialGlobalBlockList.php
@@ -8,22 +8,23 @@
99 }
1010
1111 function execute( $par ) {
12 - $out = $this->getOutput();
 12+ global $wgOut, $wgRequest;
 13+
1314 $this->setHeaders();
14 - $ip = isset( $par ) ? $par : $this->getRequest()->getText( 'ip' );
 15+ $ip = isset( $par ) ? $par : $wgRequest->getText( 'ip' );
1516 $this->loadParameters( $ip );
1617
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 );
 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 );
2223
2324 $this->showList();
2425 }
2526
2627 function showList( ) {
27 - global $wgScript;
 28+ global $wgOut, $wgScript;
2829 $errors = array();
2930
3031 // Validate search IP
@@ -33,8 +34,8 @@
3435 $ip = '';
3536 }
3637
37 - $out = $this->getOutput();
38 - $out->addWikiMsg( 'globalblocking-list-intro' );
 38+ $wgOut->addWikiMsg( 'globalblocking-list-intro' );
 39+
3940
4041 // Build the search form
4142 $searchForm = '';
@@ -45,7 +46,7 @@
4647
4748 if (is_array($errors) && count($errors)>0) {
4849 $errorstr = '';
49 -
 50+
5051 foreach ( $errors as $error ) {
5152 if (is_array($error)) {
5253 $msg = array_shift($error);
@@ -53,12 +54,12 @@
5455 $msg = $error;
5556 $error = array();
5657 }
57 -
 58+
5859 $errorstr .= Xml::tags( 'li', null, wfMsgExt( $msg, array( 'parseinline' ), $error ) );
5960 }
6061
61 - $out->addWikiMsg( 'globalblocking-unblock-errors', count($errors) );
62 - $out->addHTML( Xml::tags( 'ul', array( 'class' => 'error' ), $errorstr ) );
 62+ $wgOut->addWikiMsg( 'globalblocking-unblock-errors', count($errors) );
 63+ $wgOut->addHTML( Xml::tags( 'ul', array( 'class' => 'error' ), $errorstr ) );
6364 }
6465
6566 $fields = array();
@@ -66,24 +67,24 @@
6768 $searchForm .= Xml::buildForm( $fields, 'globalblocking-search-submit' );
6869
6970 $searchForm .= Xml::closeElement( 'form' ) . Xml::closeElement( 'fieldset' );
70 - $out->addHTML( $searchForm );
 71+ $wgOut->addHTML( $searchForm );
7172
7273 // Build a list of blocks.
7374 $conds = array();
74 -
 75+
7576 if (strlen($ip)) {
7677 list ($range_start, $range_end) = IP::parseRange( $ip );
77 -
 78+
7879 if ($range_start != $range_end) {
7980 // They searched for a range. Match that exact range only
8081 $conds = array( 'gb_address' => $ip );
8182 } else {
82 - // They searched for an IP. Match any range covering that IP
 83+ // They searched for an IP. Match any range covering that IP
8384 $hex_ip = IP::toHex( $ip );
8485 $ip_pattern = substr( $hex_ip, 0, 4 ) . '%'; // Don't bother checking blocks out of this /16.
85 -
 86+
8687 $dbr = wfGetDB( DB_SLAVE );
87 -
 88+
8889 $conds = array( 'gb_range_end>='.$dbr->addQuotes($hex_ip), // This block in the given range.
8990 'gb_range_start<='.$dbr->addQuotes($hex_ip),
9091 'gb_range_start like ' . $dbr->addQuotes( $ip_pattern ),
@@ -94,11 +95,11 @@
9596 $pager = new GlobalBlockListPager( $this, $conds );
9697 $body = $pager->getBody();
9798 if( $body != '' ) {
98 - $out->addHTML( $pager->getNavigationBar() .
 99+ $wgOut->addHTML( $pager->getNavigationBar() .
99100 Html::rawElement( 'ul', array(), $body ) .
100101 $pager->getNavigationBar() );
101102 } else {
102 - $out->wrapWikiMsg( "<div class='mw-globalblocking-noresults'>\n$1</div>\n",
 103+ $wgOut->wrapWikiMsg( "<div class='mw-globalblocking-noresults'>\n$1</div>\n",
103104 array( 'globalblocking-list-noresults' ) );
104105 }
105106 }
@@ -124,12 +125,19 @@
125126
126127 function formatRow( $row ) {
127128 global $wgLang, $wgUser;
128 -
 129+
 130+ ## One-time setup
 131+ static $sk=null;
 132+
 133+ if (is_null($sk)) {
 134+ $sk = $wgUser->getSkin();
 135+ }
 136+
129137 ## Setup
130138 $timestamp = $row->gb_timestamp;
131139 $expiry = $row->gb_expiry;
132140 $options = array();
133 -
 141+
134142 # Messy B/C until $wgLang->formatExpiry() is well embedded
135143 if( Block::decodeExpiry( $expiry ) == 'infinity' ){
136144 $options[] = wfMsgExt( 'infiniteblock', 'parseinline' );
@@ -142,24 +150,24 @@
143151 $wgLang->time( $expiry )
144152 );
145153 }
146 -
 154+
147155 # Check for whitelisting.
148156 $wlinfo = GlobalBlocking::getWhitelistInfo( $row->gb_id );
149157 if ($wlinfo) {
150158 $options[] = wfMsg( 'globalblocking-list-whitelisted', User::whois($wlinfo['user']), $wlinfo['reason'] );
151159 }
152 -
 160+
153161 $timestamp = $wgLang->timeanddate( wfTimestamp( TS_MW, $timestamp ), true );
154162
155163 if ($row->gb_anon_only)
156164 $options[] = wfMsg('globalblocking-list-anononly');
157 -
 165+
158166 ## Do afterthoughts (comment, links for admins)
159167 $info = array();
160168
161169 if( $wgUser->isAllowed( 'globalunblock' ) ) {
162170 $unblockTitle = SpecialPage::getTitleFor( "RemoveGlobalBlock" );
163 - $info[] = Linker::link( $unblockTitle,
 171+ $info[] = $sk->link( $unblockTitle,
164172 wfMsgExt( 'globalblocking-list-unblock', 'parseinline' ),
165173 array(),
166174 array( 'address' => $row->gb_address )
@@ -169,7 +177,7 @@
170178 global $wgApplyGlobalBlocks;
171179 if( $wgUser->isAllowed( 'globalblock-whitelist' ) && $wgApplyGlobalBlocks ) {
172180 $whitelistTitle = SpecialPage::getTitleFor( "GlobalBlockStatus" );
173 - $info[] = Linker::link( $whitelistTitle,
 181+ $info[] = $sk->link( $whitelistTitle,
174182 wfMsgExt( 'globalblocking-list-whitelist', 'parseinline' ),
175183 array(),
176184 array( 'address' => $row->gb_address )
@@ -179,7 +187,7 @@
180188 if ( $wgUser->isAllowed( 'globalblock' ) ) {
181189 $reblockTitle = SpecialPage::getTitleFor( 'GlobalBlock' );
182190 $msg = wfMsgExt( 'globalblocking-list-modify', 'parseinline' );
183 - $info[] = Linker::link(
 191+ $info[] = $sk->link(
184192 $reblockTitle,
185193 $msg,
186194 array(),
@@ -201,7 +209,7 @@
202210 $row->gb_address,
203211 $wgLang->commaList( $options )
204212 ) . ' ' .
205 - Linker::commentBlock( $row->gb_reason ) . ' ' .
 213+ $sk->commentBlock( $row->gb_reason ) . ' ' .
206214 $infoItems
207215 );
208216 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r111465Reduce global (ab)use...reedy16:19, 14 February 2012

Status & tagging log