r95987 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95986‎ | r95987 | r95988 >
Date:13:59, 1 September 2011
Author:siebrand
Status:ok
Tags:
Comment:
w/s
Modified paths:
  • /trunk/phase3/includes/specials/SpecialBlock.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialBlock.php
@@ -28,7 +28,6 @@
2929 * @ingroup SpecialPage
3030 */
3131 class SpecialBlock extends SpecialPage {
32 -
3332 /** The maximum number of edits a user can have and still be hidden
3433 * TODO: config setting? */
3534 const HIDEUSER_CONTRIBLIMIT = 1000;
@@ -238,15 +237,19 @@
239238 $fields['HardBlock']['default'] = $block->isHardblock();
240239 $fields['CreateAccount']['default'] = $block->prevents( 'createaccount' );
241240 $fields['AutoBlock']['default'] = $block->isAutoblocking();
 241+
242242 if( isset( $fields['DisableEmail'] ) ){
243243 $fields['DisableEmail']['default'] = $block->prevents( 'sendemail' );
244244 }
 245+
245246 if( isset( $fields['HideUser'] ) ){
246247 $fields['HideUser']['default'] = $block->mHideName;
247248 }
 249+
248250 if( isset( $fields['DisableUTEdit'] ) ){
249251 $fields['DisableUTEdit']['default'] = $block->prevents( 'editownusertalk' );
250252 }
 253+
251254 $fields['Reason']['default'] = $block->mReason;
252255
253256 if( $wgRequest->wasPosted() ){
@@ -304,15 +307,19 @@
305308 array(),
306309 wfMsgExt( 'ipb-otherblocks-header', 'parseinline', count( $otherBlockMessages ) )
307310 ) . "\n";
 311+
308312 $list = '';
 313+
309314 foreach( $otherBlockMessages as $link ) {
310315 $list .= Html::rawElement( 'li', array(), $link ) . "\n";
311316 }
 317+
312318 $s .= Html::rawElement(
313319 'ul',
314320 array( 'class' => 'mw-blockip-alreadyblocked' ),
315321 $list
316322 ) . "\n";
 323+
317324 $form->addPreText( $s );
318325 }
319326 }
@@ -325,6 +332,7 @@
326333 */
327334 protected function doHeaderText( HTMLForm &$form ){
328335 global $wgRequest;
 336+
329337 # Don't need to do anything if the form has been posted
330338 if( !$wgRequest->wasPosted() && $this->preErrors ){
331339 $s = HTMLForm::formatErrors( $this->preErrors );
@@ -419,6 +427,7 @@
420428 'showIfEmpty' => false
421429 )
422430 );
 431+
423432 $form->addPostText( $out );
424433 }
425434 }
@@ -435,6 +444,7 @@
436445 public static function getTargetAndType( $par, WebRequest $request = null ){
437446 $i = 0;
438447 $target = null;
 448+
439449 while( true ){
440450 switch( $i++ ){
441451 case 0:
@@ -463,11 +473,14 @@
464474 case 4:
465475 break 2;
466476 }
 477+
467478 list( $target, $type ) = Block::parseTarget( $target );
 479+
468480 if( $type !== null ){
469481 return array( $target, $type );
470482 }
471483 }
 484+
472485 return array( null, null );
473486 }
474487
@@ -519,10 +532,8 @@
520533 if( IP::isIPv6( $ip ) && $range < $wgBlockCIDRLimit['IPv6'] ) {
521534 return wfMessage( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] );
522535 }
523 -
524536 } elseif( $type == Block::TYPE_IP ){
525537 # All is well
526 -
527538 } else {
528539 return wfMessage( 'badipaddress' );
529540 }
@@ -559,14 +570,11 @@
560571 {
561572 return array( 'ipb-blockingself' );
562573 }
563 -
564574 } elseif( $type == Block::TYPE_RANGE ){
565575 $userId = 0;
566 -
567576 } elseif( $type == Block::TYPE_IP ){
568577 $target = $target->getName();
569578 $userId = 0;
570 -
571579 } else {
572580 # This should have been caught in the form field validation
573581 return array( 'badipaddress' );
@@ -587,6 +595,7 @@
588596 if( !isset( $data['HideUser'] ) ){
589597 $data['HideUser'] = false;
590598 }
 599+
591600 if( $data['HideUser'] ) {
592601 if( !$wgUser->isAllowed('hideuser') ){
593602 # this codepath is unreachable except by a malicious user spoofing forms,
@@ -599,16 +608,13 @@
600609 # Recheck params here...
601610 if( $type != Block::TYPE_USER ) {
602611 $data['HideUser'] = false; # IP users should not be hidden
603 -
604612 } elseif( !in_array( $data['Expiry'], array( 'infinite', 'infinity', 'indefinite' ) ) ) {
605613 # Bad expiry.
606614 return array( 'ipb_expiry_temp' );
607 -
608615 } elseif( $user->getEditCount() > self::HIDEUSER_CONTRIBLIMIT ) {
609616 # Typically, the user should have a handful of edits.
610617 # Disallow hiding users with many edits for performance.
611618 return array( 'ipb_hide_invalid' );
612 -
613619 } elseif( !$data['Confirm'] ){
614620 return array( 'ipb-confirmhideuser' );
615621 }
@@ -733,9 +739,11 @@
734740 if( strpos( $option, ':' ) === false ){
735741 $option = "$option:$option";
736742 }
 743+
737744 list( $show, $value ) = explode( ':', $option );
738745 $a[htmlspecialchars( $show )] = htmlspecialchars( $value );
739746 }
 747+
740748 return $a;
741749 }
742750
@@ -750,15 +758,19 @@
751759 if( $infinity == null ){
752760 $infinity = wfGetDB( DB_SLAVE )->getInfinity();
753761 }
 762+
754763 if ( $expiry == 'infinite' || $expiry == 'indefinite' ) {
755764 $expiry = $infinity;
756765 } else {
757766 $expiry = strtotime( $expiry );
 767+
758768 if ( $expiry < 0 || $expiry === false ) {
759769 return false;
760770 }
 771+
761772 $expiry = wfTimestamp( TS_MW, $expiry );
762773 }
 774+
763775 return $expiry;
764776 }
765777
@@ -769,6 +781,7 @@
770782 */
771783 public static function canBlockEmail( $user ) {
772784 global $wgEnableUserEmail, $wgSysopEmailBans;
 785+
773786 return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) );
774787 }
775788
@@ -781,11 +794,13 @@
782795 */
783796 public static function checkUnblockSelf( $user ) {
784797 global $wgUser;
 798+
785799 if ( is_int( $user ) ) {
786800 $user = User::newFromId( $user );
787801 } elseif ( is_string( $user ) ) {
788802 $user = User::newFromName( $user );
789803 }
 804+
790805 if( $wgUser->isBlocked() ){
791806 if( $user instanceof User && $user->getId() == $wgUser->getId() ) {
792807 # User is trying to unblock themselves

Status & tagging log