r49731 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49730‎ | r49731 | r49732 >
Date:06:37, 22 April 2009
Author:aaron
Status:ok
Tags:
Comment:
* Added visibility to some functions
* Whitespace/style/comment tweaks
Modified paths:
  • /trunk/phase3/includes/specials/SpecialBlockip.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialBlockip.php
@@ -11,13 +11,11 @@
1212 */
1313 function wfSpecialBlockip( $par ) {
1414 global $wgUser, $wgOut, $wgRequest;
15 -
1615 # Can't block when the database is locked
1716 if( wfReadOnly() ) {
1817 $wgOut->readOnlyPage();
1918 return;
2019 }
21 -
2220 # Permission check
2321 if( !$wgUser->isAllowed( 'block' ) ) {
2422 $wgOut->permissionRequired( 'block' );
@@ -27,9 +25,9 @@
2826 $ipb = new IPBlockForm( $par );
2927
3028 $action = $wgRequest->getVal( 'action' );
31 - if ( 'success' == $action ) {
 29+ if( 'success' == $action ) {
3230 $ipb->showSuccess();
33 - } else if ( $wgRequest->wasPosted() && 'submit' == $action &&
 31+ } else if( $wgRequest->wasPosted() && 'submit' == $action &&
3432 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
3533 $ipb->doSubmit();
3634 } else {
@@ -44,9 +42,8 @@
4543 */
4644 class IPBlockForm {
4745 var $BlockAddress, $BlockExpiry, $BlockReason;
48 -# var $BlockEmail;
4946
50 - function IPBlockForm( $par ) {
 47+ public function __construct( $par ) {
5148 global $wgRequest, $wgUser, $wgBlockAllowsUTEdit;
5249
5350 $this->BlockAddress = $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip', $par ) );
@@ -70,7 +67,7 @@
7168 $this->BlockReblock = $wgRequest->getBool( 'wpChangeBlock', false );
7269 }
7370
74 - function showForm( $err ) {
 71+ public function showForm( $err ) {
7572 global $wgOut, $wgUser, $wgSysopUserBans;
7673
7774 $wgOut->setPagetitle( wfMsg( 'blockip' ) );
@@ -90,17 +87,17 @@
9188 $user = User::newFromName( $this->BlockAddress );
9289
9390 $alreadyBlocked = false;
94 - if ( $err && $err[0] != 'ipb_already_blocked' ) {
 91+ if( $err && $err[0] != 'ipb_already_blocked' ) {
9592 $key = array_shift($err);
9693 $msg = wfMsgReal($key, $err);
9794 $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
9895 $wgOut->addHTML( Xml::tags( 'p', array( 'class' => 'error' ), $msg ) );
99 - } elseif ( $this->BlockAddress ) {
 96+ } elseif( $this->BlockAddress ) {
10097 $userId = 0;
101 - if ( is_object( $user ) )
 98+ if( is_object( $user ) )
10299 $userId = $user->getId();
103100 $currentBlock = Block::newFromDB( $this->BlockAddress, $userId );
104 - if ( !is_null($currentBlock) && !$currentBlock->mAuto && # The block exists and isn't an autoblock
 101+ if( !is_null($currentBlock) && !$currentBlock->mAuto && # The block exists and isn't an autoblock
105102 ( $currentBlock->mRangeStart == $currentBlock->mRangeEnd || # The block isn't a rangeblock
106103 # or if it is, the range is what we're about to block
107104 ( $currentBlock->mAddress == $this->BlockAddress ) ) ) {
@@ -125,12 +122,11 @@
126123 $scBlockExpiryOptions = wfMsgForContent( 'ipboptions' );
127124
128125 $showblockoptions = $scBlockExpiryOptions != '-';
129 - if (!$showblockoptions)
130 - $mIpbother = $mIpbexpiry;
 126+ if( !$showblockoptions ) $mIpbother = $mIpbexpiry;
131127
132128 $blockExpiryFormOptions = Xml::option( wfMsg( 'ipbotheroption' ), 'other' );
133129 foreach (explode(',', $scBlockExpiryOptions) as $option) {
134 - if ( strpos($option, ":") === false ) $option = "$option:$option";
 130+ if( strpos($option, ":") === false ) $option = "$option:$option";
135131 list($show, $value) = explode(":", $option);
136132 $show = htmlspecialchars($show);
137133 $value = htmlspecialchars($value);
@@ -162,7 +158,7 @@
163159 </tr>
164160 <tr>"
165161 );
166 - if ( $showblockoptions ) {
 162+ if( $showblockoptions ) {
167163 $wgOut->addHTML("
168164 <td class='mw-label'>
169165 {$mIpbexpiry}
@@ -233,7 +229,7 @@
234230 );
235231
236232 global $wgSysopEmailBans, $wgBlockAllowsUTEdit;
237 - if ( $wgSysopEmailBans && $wgUser->isAllowed( 'blockemail' ) ) {
 233+ if( $wgSysopEmailBans && $wgUser->isAllowed( 'blockemail' ) ) {
238234 $wgOut->addHTML("
239235 <tr id='wpEnableEmailBan'>
240236 <td>&nbsp;</td>
@@ -247,7 +243,7 @@
248244 }
249245
250246 // Allow some users to hide name from block log, blocklist and listusers
251 - if ( $wgUser->isAllowed( 'hideuser' ) ) {
 247+ if( $wgUser->isAllowed( 'hideuser' ) ) {
252248 $wgOut->addHTML("
253249 <tr id='wpEnableHideUser'>
254250 <td>&nbsp;</td>
@@ -328,12 +324,12 @@
329325 $rxIP = "($rxIP4|$rxIP6)";
330326
331327 # Check for invalid specifications
332 - if ( !preg_match( "/^$rxIP$/", $this->BlockAddress ) ) {
 328+ if( !preg_match( "/^$rxIP$/", $this->BlockAddress ) ) {
333329 $matches = array();
334 - if ( preg_match( "/^($rxIP4)\\/(\\d{1,2})$/", $this->BlockAddress, $matches ) ) {
 330+ if( preg_match( "/^($rxIP4)\\/(\\d{1,2})$/", $this->BlockAddress, $matches ) ) {
335331 # IPv4
336 - if ( $wgSysopRangeBans ) {
337 - if ( !IP::isIPv4( $this->BlockAddress ) || $matches[2] < 16 || $matches[2] > 32 ) {
 332+ if( $wgSysopRangeBans ) {
 333+ if( !IP::isIPv4( $this->BlockAddress ) || $matches[2] < 16 || $matches[2] > 32 ) {
338334 return array('ip_range_invalid');
339335 }
340336 $this->BlockAddress = Block::normaliseRange( $this->BlockAddress );
@@ -341,10 +337,10 @@
342338 # Range block illegal
343339 return array('range_block_disabled');
344340 }
345 - } else if ( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress, $matches ) ) {
 341+ } else if( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress, $matches ) ) {
346342 # IPv6
347 - if ( $wgSysopRangeBans ) {
348 - if ( !IP::isIPv6( $this->BlockAddress ) || $matches[2] < 64 || $matches[2] > 128 ) {
 343+ if( $wgSysopRangeBans ) {
 344+ if( !IP::isIPv6( $this->BlockAddress ) || $matches[2] < 64 || $matches[2] > 128 ) {
349345 return array('ip_range_invalid');
350346 }
351347 $this->BlockAddress = Block::normaliseRange( $this->BlockAddress );
@@ -354,7 +350,7 @@
355351 }
356352 } else {
357353 # Username block
358 - if ( $wgSysopUserBans ) {
 354+ if( $wgSysopUserBans ) {
359355 $user = User::newFromName( $this->BlockAddress );
360356 if( !is_null( $user ) && $user->getId() ) {
361357 # Use canonical name
@@ -369,15 +365,15 @@
370366 }
371367 }
372368
373 - if ( $wgUser->isBlocked() && ( $wgUser->getId() !== $userId ) ) {
 369+ if( $wgUser->isBlocked() && ( $wgUser->getId() !== $userId ) ) {
374370 return array( 'cant-block-while-blocked' );
375371 }
376372
377373 $reasonstr = $this->BlockReasonList;
378 - if ( $reasonstr != 'other' && $this->BlockReason != '' ) {
 374+ if( $reasonstr != 'other' && $this->BlockReason != '' ) {
379375 // Entry from drop down menu + additional comment
380376 $reasonstr .= wfMsgForContent( 'colon-separator' ) . $this->BlockReason;
381 - } elseif ( $reasonstr == 'other' ) {
 377+ } elseif( $reasonstr == 'other' ) {
382378 $reasonstr = $this->BlockReason;
383379 }
384380
@@ -385,11 +381,11 @@
386382 if( $expirestr == 'other' )
387383 $expirestr = $this->BlockOther;
388384
389 - if ( ( strlen( $expirestr ) == 0) || ( strlen( $expirestr ) > 50) ) {
 385+ if( ( strlen( $expirestr ) == 0) || ( strlen( $expirestr ) > 50) ) {
390386 return array('ipb_expiry_invalid');
391387 }
392388
393 - if ( false === ($expiry = Block::parseExpiryInput( $expirestr )) ) {
 389+ if( false === ($expiry = Block::parseExpiryInput( $expirestr )) ) {
394390 // Bad expiry.
395391 return array('ipb_expiry_invalid');
396392 }
@@ -397,8 +393,7 @@
398394 if( $this->BlockHideName ) {
399395 // Recheck params here...
400396 if( !$userId || !$wgUser->isAllowed('hideuser') ) {
401 - // IP users should not be hidden
402 - $this->BlockHideName = false;
 397+ $this->BlockHideName = false; // IP users should not be hidden
403398 } else if( $expiry !== 'infinity' ) {
404399 // Bad expiry.
405400 return array('ipb_expiry_temp');
@@ -409,7 +404,7 @@
410405 }
411406 }
412407
413 - # Create block
 408+ # Create block object
414409 # Note: for a user block, ipb_address is only for display purposes
415410 $block = new Block( $this->BlockAddress, $userId, $wgUser->getId(),
416411 $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly,
@@ -419,11 +414,11 @@
420415
421416 # Should this be privately logged?
422417 $suppressLog = (bool)$this->BlockHideName;
423 - if ( wfRunHooks('BlockIp', array(&$block, &$wgUser)) ) {
 418+ if( wfRunHooks('BlockIp', array(&$block, &$wgUser)) ) {
424419 # Try to insert block. Is there a conflicting block?
425 - if ( !$block->insert() ) {
 420+ if( !$block->insert() ) {
426421 # Show form unless the user is already aware of this...
427 - if ( !$this->BlockReblock ) {
 422+ if( !$this->BlockReblock ) {
428423 return array( 'ipb_already_blocked' );
429424 # Otherwise, try to update the block...
430425 } else {
@@ -458,7 +453,7 @@
459454 self::suppressUserName( $this->BlockAddress, $userId );
460455 }
461456
462 - if ( $this->BlockWatchUser &&
 457+ if( $this->BlockWatchUser &&
463458 # Only show watch link when this is no range block
464459 $block->mRangeStart == $block->mRangeEnd) {
465460 $wgUser->addWatch ( Title::makeTitle( NS_USER, $this->BlockAddress ) );
@@ -477,7 +472,7 @@
478473 $log_type = $suppressLog ? 'suppress' : 'block';
479474 $log = new LogPage( $log_type );
480475 $log->addEntry( $log_action, Title::makeTitle( NS_USER, $this->BlockAddress ),
481 - $reasonstr, $logParams );
 476+ $reasonstr, $logParams );
482477
483478 # Report to the user
484479 return array();
@@ -545,11 +540,10 @@
546541 * UI entry point for blocking
547542 * Wraps around doBlock()
548543 */
549 - function doSubmit()
550 - {
 544+ public function doSubmit() {
551545 global $wgOut;
552546 $retval = $this->doBlock();
553 - if(empty($retval)) {
 547+ if( empty($retval) ) {
554548 $titleObj = SpecialPage::getTitleFor( 'Blockip' );
555549 $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
556550 urlencode( $this->BlockAddress ) ) );
@@ -558,7 +552,7 @@
559553 $this->showForm( $retval );
560554 }
561555
562 - function showSuccess() {
 556+ public function showSuccess() {
563557 global $wgOut;
564558
565559 $wgOut->setPagetitle( wfMsg( 'blockip' ) );
@@ -567,7 +561,7 @@
568562 $wgOut->addHTML( $text );
569563 }
570564
571 - function showLogFragment( $out, $title ) {
 565+ private function showLogFragment( $out, $title ) {
572566 global $wgUser;
573567 $out->addHTML( Xml::element( 'h2', NULL, LogPage::logName( 'block' ) ) );
574568 $count = LogEventsList::showLogExtract( $out, 'block', $title->getPrefixedText(), '', 10 );
@@ -605,11 +599,11 @@
606600 if( !$this->BlockEnableAutoblock && !IP::isIPAddress( $this->BlockAddress ) )
607601 // Same as anononly, this is not displayed when blocking an IP address
608602 $flags[] = 'noautoblock';
609 - if ( $this->BlockEmail )
 603+ if( $this->BlockEmail )
610604 $flags[] = 'noemail';
611 - if ( !$this->BlockAllowUsertalk && $wgBlockAllowsUTEdit )
 605+ if( !$this->BlockAllowUsertalk && $wgBlockAllowsUTEdit )
612606 $flags[] = 'nousertalk';
613 - if ( $this->BlockHideName )
 607+ if( $this->BlockHideName )
614608 $flags[] = 'hiddenname';
615609 return implode( ',', $flags );
616610 }

Status & tagging log