r83810 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83809‎ | r83810 | r83811 >
Date:09:57, 13 March 2011
Author:nikerabbit
Status:resolved (Comments)
Tags:
Comment:
* Moved Target field validation into a field validation callback to show erros next to the field
* Some changes to comments and one addHtml -> addWikiMsg
Modified paths:
  • /trunk/phase3/includes/specials/SpecialBlock.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialBlock.php
@@ -29,18 +29,18 @@
3030 */
3131 class SpecialBlock extends SpecialPage {
3232
33 - # The maximum number of edits a user can have and still be hidden
34 - # TODO: config setting?
 33+ /** The maximum number of edits a user can have and still be hidden
 34+ * TODO: config setting? */
3535 const HIDEUSER_CONTRIBLIMIT = 1000;
3636
37 - # @var User user to be blocked, as passed either by parameter (url?wpTarget=Foo)
38 - # or as subpage (Special:Block/Foo)
 37+ /** @var User user to be blocked, as passed either by parameter (url?wpTarget=Foo)
 38+ * or as subpage (Special:Block/Foo) */
3939 protected $target;
4040
41 - # @var Block::TYPE_ constant
 41+ /// @var Block::TYPE_ constant
4242 protected $type;
4343
44 - # @var Bool
 44+ /// @var Bool
4545 protected $alreadyBlocked;
4646
4747 public function __construct() {
@@ -98,7 +98,7 @@
9999
100100 if( $form->show() ){
101101 $wgOut->setPageTitle( wfMsg( 'blockipsuccesssub' ) );
102 - $wgOut->addHTML( wfMsgExt( 'blockipsuccesstext', array( 'parse' ), $this->target ) );
 102+ $wgOut->addWikiMsg( 'blockipsuccesstext', $this->target );
103103 }
104104 }
105105
@@ -117,6 +117,7 @@
118118 'id' => 'mw-bi-target',
119119 'size' => '45',
120120 'required' => true,
 121+ 'validation-callback' => array( __CLASS__, 'validateTargetField' ),
121122 ),
122123 'Expiry' => array(
123124 'type' => 'selectorother',
@@ -448,25 +449,20 @@
449450 }
450451 }
451452
452 - /**
453 - * Given the form data, actually implement a block
454 - * @param $data Array
455 - * @return Bool|String
456 - */
457 - public static function processForm( array $data ){
458 - global $wgUser, $wgBlockAllowsUTEdit, $wgBlockCIDRLimit;
 453+ public static function validateTargetField( $data, $alldata = null ) {
 454+ global $wgBlockCIDRLimit;
459455
460 - list( $target, $type ) = self::getTargetAndType( $data['Target'] );
 456+ list( $target, $type ) = self::getTargetAndType( $data );
461457
462458 if( $type == Block::TYPE_USER ){
463459 # TODO: why do we not have a User->exists() method?
464460 if( !$target->getId() ){
465 - return array( array( 'nosuchusershort', $target->getName() ) );
 461+ return wfMessage( 'nosuchusershort', $target->getName() );
466462 }
467463
468464 $status = self::checkUnblockSelf( $target );
469465 if ( $status !== true ) {
470 - return array( array( 'badaccess', $status ) );
 466+ return wfMessage( 'badaccess', $status );
471467 }
472468
473469 $user = $target;
@@ -480,22 +476,22 @@
481477 || ( IP::isIPv6( $ip ) && $wgBlockCIDRLimit['IPV6'] == 128 ) )
482478 {
483479 # Range block effectively disabled
484 - return array( 'range_block_disabled' );
 480+ return wfMessage( 'range_block_disabled' );
485481 }
486482
487483 if( ( IP::isIPv4( $ip ) && $range > 32 )
488484 || ( IP::isIPv6( $ip ) && $range > 128 ) )
489485 {
490486 # Dodgy range
491 - return array( 'ip_range_invalid' );
 487+ return wfMessage( 'ip_range_invalid' );
492488 }
493489
494490 if( IP::isIPv4( $ip ) && $range < $wgBlockCIDRLimit['IPv4'] ) {
495 - return array( array( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] ) );
 491+ return wfMessage( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] );
496492 }
497493
498494 if( IP::isIPv6( $ip ) && $range < $wgBlockCIDRLimit['IPv6'] ) {
499 - return array( array( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] ) );
 495+ return wfMessage( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] );
500496 }
501497
502498 $userId = 0;
@@ -506,9 +502,21 @@
507503 $userId = 0;
508504
509505 } else {
510 - return array( 'badipaddress' );
 506+ return wfMessage( 'badipaddress' );
511507 }
 508+ }
512509
 510+ /**
 511+ * Given the form data, actually implement a block
 512+ * @param $data Array
 513+ * @return Bool|String
 514+ */
 515+ public static function processForm( array $data ){
 516+ global $wgUser, $wgBlockAllowsUTEdit;
 517+
 518+ // Handled by field validator callback
 519+ // self::validateTargetField( $data['Target'] );
 520+
513521 if( ( strlen( $data['Expiry'] ) == 0) || ( strlen( $data['Expiry'] ) > 50 )
514522 || !Block::parseExpiryInput( $data['Expiry'] ) )
515523 {

Follow-up revisions

RevisionCommit summaryAuthorDate
r83811Follow-up r83809 r83810: improved documentationnikerabbit10:02, 13 March 2011
r83824Fix totally-broken r83810.happy-melon14:41, 13 March 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r83786Divert a river through the Augean Stables that is SpecialBlockip.php....happy-melon21:54, 12 March 2011

Comments

#Comment by Happy-melon (talk | contribs)   14:28, 13 March 2011

This is completely broken; now $type, $user and $target are not defined in SpecialBlock::processForm(). Plus you need to return true from the validation function or form submission fails with an unexplained "problems with your input... but we're not going to tell you what they are" error.

#Comment by Nikerabbit (talk | contribs)   14:51, 13 March 2011

What went wrong: I only tested that it works with invalid input.

#Comment by Happy-melon (talk | contribs)   17:03, 13 March 2011

Fixed in r83824.

#Comment by Tim Starling (talk | contribs)   05:52, 30 March 2012

Apparently this caused bug 35578.

Status & tagging log