Index: trunk/phase3/includes/HTMLForm.php |
— | — | @@ -891,7 +891,7 @@ |
892 | 892 | } |
893 | 893 | |
894 | 894 | if ( isset( $this->mValidationCallback ) ) { |
895 | | - return call_user_func( $this->mValidationCallback, $value, $alldata ); |
| 895 | + return call_user_func( $this->mValidationCallback, $value, $alldata, $this->mParent ); |
896 | 896 | } |
897 | 897 | |
898 | 898 | return true; |
— | — | @@ -899,7 +899,7 @@ |
900 | 900 | |
901 | 901 | function filter( $value, $alldata ) { |
902 | 902 | if ( isset( $this->mFilterCallback ) ) { |
903 | | - $value = call_user_func( $this->mFilterCallback, $value, $alldata ); |
| 903 | + $value = call_user_func( $this->mFilterCallback, $value, $alldata, $this->mParent ); |
904 | 904 | } |
905 | 905 | |
906 | 906 | return $value; |
Index: trunk/phase3/includes/api/ApiUnblock.php |
— | — | @@ -66,7 +66,7 @@ |
67 | 67 | } |
68 | 68 | # bug 15810: blocked admins should have limited access here |
69 | 69 | if ( $user->isBlocked() ) { |
70 | | - $status = SpecialBlock::checkUnblockSelf( $params['user'] ); |
| 70 | + $status = SpecialBlock::checkUnblockSelf( $params['user'], $user ); |
71 | 71 | if ( $status !== true ) { |
72 | 72 | $this->dieUsageMsg( $status ); |
73 | 73 | } |
— | — | @@ -77,7 +77,7 @@ |
78 | 78 | 'Reason' => is_null( $params['reason'] ) ? '' : $params['reason'] |
79 | 79 | ); |
80 | 80 | $block = Block::newFromTarget( $data['Target'] ); |
81 | | - $retval = SpecialUnblock::processUnblock( $data ); |
| 81 | + $retval = SpecialUnblock::processUnblock( $data, $this->getContext() ); |
82 | 82 | if ( $retval !== true ) { |
83 | 83 | $this->dieUsageMsg( $retval[0] ); |
84 | 84 | } |
Index: trunk/phase3/includes/api/ApiBlock.php |
— | — | @@ -62,7 +62,7 @@ |
63 | 63 | } |
64 | 64 | # bug 15810: blocked admins should have limited access here |
65 | 65 | if ( $user->isBlocked() ) { |
66 | | - $status = SpecialBlock::checkUnblockSelf( $params['user'] ); |
| 66 | + $status = SpecialBlock::checkUnblockSelf( $params['user'], $user ); |
67 | 67 | if ( $status !== true ) { |
68 | 68 | $this->dieUsageMsg( array( $status ) ); |
69 | 69 | } |
— | — | @@ -93,7 +93,7 @@ |
94 | 94 | 'Confirm' => true, |
95 | 95 | ); |
96 | 96 | |
97 | | - $retval = SpecialBlock::processForm( $data ); |
| 97 | + $retval = SpecialBlock::processForm( $data, $this->getContext() ); |
98 | 98 | if ( $retval !== true ) { |
99 | 99 | // We don't care about multiple errors, just report one of them |
100 | 100 | $this->dieUsageMsg( $retval ); |
Index: trunk/phase3/includes/specials/SpecialUnblock.php |
— | — | @@ -58,7 +58,7 @@ |
59 | 59 | |
60 | 60 | $form = new HTMLForm( $this->getFields(), $this->getContext() ); |
61 | 61 | $form->setWrapperLegend( wfMsg( 'unblockip' ) ); |
62 | | - $form->setSubmitCallback( array( __CLASS__, 'processUnblock' ) ); |
| 62 | + $form->setSubmitCallback( array( __CLASS__, 'processUIUnblock' ) ); |
63 | 63 | $form->setSubmitText( wfMsg( 'ipusubmit' ) ); |
64 | 64 | $form->addPreText( wfMsgExt( 'unblockiptext', 'parse' ) ); |
65 | 65 | |
— | — | @@ -143,12 +143,21 @@ |
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
| 147 | + * Submit callback for an HTMLForm object |
| 148 | + */ |
| 149 | + public static function processUIUnblock( array $data, HTMLForm $form ) { |
| 150 | + return self::processUnblock( $data, $form->getContext() ); |
| 151 | + } |
| 152 | + |
| 153 | + /** |
147 | 154 | * Process the form |
| 155 | + * |
| 156 | + * @param $data Array |
| 157 | + * @param $context IContextSource |
148 | 158 | * @return Array( Array(message key, parameters) ) on failure, True on success |
149 | 159 | */ |
150 | | - public static function processUnblock( array $data ){ |
151 | | - global $wgUser; |
152 | | - |
| 160 | + public static function processUnblock( array $data, IContextSource $context ){ |
| 161 | + $performer = $context->getUser(); |
153 | 162 | $target = $data['Target']; |
154 | 163 | $block = Block::newFromTarget( $data['Target'] ); |
155 | 164 | |
— | — | @@ -159,7 +168,7 @@ |
160 | 169 | # bug 15810: blocked admins should have limited access here. This |
161 | 170 | # won't allow sysops to remove autoblocks on themselves, but they |
162 | 171 | # should have ipblock-exempt anyway |
163 | | - $status = SpecialBlock::checkUnblockSelf( $target ); |
| 172 | + $status = SpecialBlock::checkUnblockSelf( $target, $performer ); |
164 | 173 | if ( $status !== true ) { |
165 | 174 | throw new ErrorPageError( 'badaccess', $status ); |
166 | 175 | } |
— | — | @@ -174,7 +183,7 @@ |
175 | 184 | |
176 | 185 | # If the name was hidden and the blocking user cannot hide |
177 | 186 | # names, then don't allow any block removals... |
178 | | - if( !$wgUser->isAllowed( 'hideuser' ) && $block->mHideName ) { |
| 187 | + if( !$performer->isAllowed( 'hideuser' ) && $block->mHideName ) { |
179 | 188 | return array( 'unblock-hideuser' ); |
180 | 189 | } |
181 | 190 | |
Index: trunk/phase3/includes/specials/SpecialBlock.php |
— | — | @@ -57,7 +57,8 @@ |
58 | 58 | |
59 | 59 | public function execute( $par ) { |
60 | 60 | # Permission check |
61 | | - if( !$this->userCanExecute( $this->getUser() ) ) { |
| 61 | + $user = $this->getUser(); |
| 62 | + if( !$this->userCanExecute( $user ) ) { |
62 | 63 | $this->displayRestrictionError(); |
63 | 64 | return; |
64 | 65 | } |
— | — | @@ -82,7 +83,7 @@ |
83 | 84 | $this->requestedHideUser = $request->getBool( 'wpHideUser' ); |
84 | 85 | |
85 | 86 | # bug 15810: blocked admins should have limited access here |
86 | | - $status = self::checkUnblockSelf( $this->target ); |
| 87 | + $status = self::checkUnblockSelf( $this->target, $user ); |
87 | 88 | if ( $status !== true ) { |
88 | 89 | throw new ErrorPageError( 'badaccess', $status ); |
89 | 90 | } |
— | — | @@ -99,7 +100,7 @@ |
100 | 101 | |
101 | 102 | $form = new HTMLForm( $fields, $this->getContext() ); |
102 | 103 | $form->setWrapperLegend( wfMsg( 'blockip-legend' ) ); |
103 | | - $form->setSubmitCallback( array( __CLASS__, 'processForm' ) ); |
| 104 | + $form->setSubmitCallback( array( __CLASS__, 'processUIForm' ) ); |
104 | 105 | |
105 | 106 | $t = $this->alreadyBlocked |
106 | 107 | ? wfMsg( 'ipb-change-block' ) |
— | — | @@ -492,7 +493,7 @@ |
493 | 494 | * @param $alldata Array |
494 | 495 | * @return Message |
495 | 496 | */ |
496 | | - public static function validateTargetField( $value, $alldata = null ) { |
| 497 | + public static function validateTargetField( $value, $alldata, $form ) { |
497 | 498 | global $wgBlockCIDRLimit; |
498 | 499 | |
499 | 500 | list( $target, $type ) = self::getTargetAndType( $value ); |
— | — | @@ -500,13 +501,13 @@ |
501 | 502 | if( $type == Block::TYPE_USER ){ |
502 | 503 | # TODO: why do we not have a User->exists() method? |
503 | 504 | if( !$target->getId() ){ |
504 | | - return wfMessage( 'nosuchusershort', |
| 505 | + return $form->msg( 'nosuchusershort', |
505 | 506 | wfEscapeWikiText( $target->getName() ) ); |
506 | 507 | } |
507 | 508 | |
508 | | - $status = self::checkUnblockSelf( $target ); |
| 509 | + $status = self::checkUnblockSelf( $target, $form->getUser() ); |
509 | 510 | if ( $status !== true ) { |
510 | | - return wfMessage( 'badaccess', $status ); |
| 511 | + return $form->msg( 'badaccess', $status ); |
511 | 512 | } |
512 | 513 | |
513 | 514 | } elseif( $type == Block::TYPE_RANGE ){ |
— | — | @@ -516,40 +517,49 @@ |
517 | 518 | || ( IP::isIPv6( $ip ) && $wgBlockCIDRLimit['IPv6'] == 128 ) ) |
518 | 519 | { |
519 | 520 | # Range block effectively disabled |
520 | | - return wfMessage( 'range_block_disabled' ); |
| 521 | + return $form->msg( 'range_block_disabled' ); |
521 | 522 | } |
522 | 523 | |
523 | 524 | if( ( IP::isIPv4( $ip ) && $range > 32 ) |
524 | 525 | || ( IP::isIPv6( $ip ) && $range > 128 ) ) |
525 | 526 | { |
526 | 527 | # Dodgy range |
527 | | - return wfMessage( 'ip_range_invalid' ); |
| 528 | + return $form->msg( 'ip_range_invalid' ); |
528 | 529 | } |
529 | 530 | |
530 | 531 | if( IP::isIPv4( $ip ) && $range < $wgBlockCIDRLimit['IPv4'] ) { |
531 | | - return wfMessage( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] ); |
| 532 | + return $form->msg( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] ); |
532 | 533 | } |
533 | 534 | |
534 | 535 | if( IP::isIPv6( $ip ) && $range < $wgBlockCIDRLimit['IPv6'] ) { |
535 | | - return wfMessage( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] ); |
| 536 | + return $form->msg( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] ); |
536 | 537 | } |
537 | 538 | } elseif( $type == Block::TYPE_IP ){ |
538 | 539 | # All is well |
539 | 540 | } else { |
540 | | - return wfMessage( 'badipaddress' ); |
| 541 | + return $form->msg( 'badipaddress' ); |
541 | 542 | } |
542 | 543 | |
543 | 544 | return true; |
544 | 545 | } |
545 | 546 | |
546 | 547 | /** |
| 548 | + * Submit callback for an HTMLForm object, will simply pass |
| 549 | + */ |
| 550 | + public static function processUIForm( array $data, HTMLForm $form ) { |
| 551 | + return self::processForm( $data, $form->getContext() ); |
| 552 | + } |
| 553 | + |
| 554 | + /** |
547 | 555 | * Given the form data, actually implement a block |
548 | 556 | * @param $data Array |
549 | 557 | * @return Bool|String |
550 | 558 | */ |
551 | | - public static function processForm( array $data ){ |
552 | | - global $wgUser, $wgBlockAllowsUTEdit; |
| 559 | + public static function processForm( array $data, IContextSource $context ){ |
| 560 | + global $wgBlockAllowsUTEdit; |
553 | 561 | |
| 562 | + $performer = $context->getUser(); |
| 563 | + |
554 | 564 | // Handled by field validator callback |
555 | 565 | // self::validateTargetField( $data['Target'] ); |
556 | 566 | |
— | — | @@ -566,7 +576,7 @@ |
567 | 577 | # Give admins a heads-up before they go and block themselves. Much messier |
568 | 578 | # to do this for IPs, but it's pretty unlikely they'd ever get the 'block' |
569 | 579 | # permission anyway, although the code does allow for it |
570 | | - if( $target === $wgUser->getName() && |
| 580 | + if( $target === $performer->getName() && |
571 | 581 | ( $data['PreviousTarget'] !== $data['Target'] || !$data['Confirm'] ) ) |
572 | 582 | { |
573 | 583 | return array( 'ipb-blockingself' ); |
— | — | @@ -598,7 +608,7 @@ |
599 | 609 | } |
600 | 610 | |
601 | 611 | if( $data['HideUser'] ) { |
602 | | - if( !$wgUser->isAllowed('hideuser') ){ |
| 612 | + if( !$performer->isAllowed('hideuser') ){ |
603 | 613 | # this codepath is unreachable except by a malicious user spoofing forms, |
604 | 614 | # or by race conditions (user has oversight and sysop, loads block form, |
605 | 615 | # and is de-oversighted before submission); so need to fail completely |
— | — | @@ -624,7 +634,7 @@ |
625 | 635 | # Create block object. |
626 | 636 | $block = new Block(); |
627 | 637 | $block->setTarget( $target ); |
628 | | - $block->setBlocker( $wgUser ); |
| 638 | + $block->setBlocker( $performer ); |
629 | 639 | $block->mReason = $data['Reason'][0]; |
630 | 640 | $block->mExpiry = self::parseExpiryInput( $data['Expiry'] ); |
631 | 641 | $block->prevents( 'createaccount', $data['CreateAccount'] ); |
— | — | @@ -634,7 +644,7 @@ |
635 | 645 | $block->isAutoblocking( $data['AutoBlock'] ); |
636 | 646 | $block->mHideName = $data['HideUser']; |
637 | 647 | |
638 | | - if( !wfRunHooks( 'BlockIp', array( &$block, &$wgUser ) ) ) { |
| 648 | + if( !wfRunHooks( 'BlockIp', array( &$block, &$performer ) ) ) { |
639 | 649 | return array( 'hookaborted' ); |
640 | 650 | } |
641 | 651 | |
— | — | @@ -658,7 +668,7 @@ |
659 | 669 | |
660 | 670 | # If the name was hidden and the blocking user cannot hide |
661 | 671 | # names, then don't allow any block changes... |
662 | | - if( $currentBlock->mHideName && !$wgUser->isAllowed( 'hideuser' ) ) { |
| 672 | + if( $currentBlock->mHideName && !$performer->isAllowed( 'hideuser' ) ) { |
663 | 673 | return array( 'cant-see-hidden-user' ); |
664 | 674 | } |
665 | 675 | |
— | — | @@ -680,7 +690,7 @@ |
681 | 691 | $logaction = 'block'; |
682 | 692 | } |
683 | 693 | |
684 | | - wfRunHooks( 'BlockIpComplete', array( $block, $wgUser ) ); |
| 694 | + wfRunHooks( 'BlockIpComplete', array( $block, $performer ) ); |
685 | 695 | |
686 | 696 | # Set *_deleted fields if requested |
687 | 697 | if( $data['HideUser'] ) { |
— | — | @@ -689,7 +699,7 @@ |
690 | 700 | |
691 | 701 | # Can't watch a rangeblock |
692 | 702 | if( $type != Block::TYPE_RANGE && $data['Watch'] ) { |
693 | | - $wgUser->addWatch( Title::makeTitle( NS_USER, $target ) ); |
| 703 | + $performer->addWatch( Title::makeTitle( NS_USER, $target ) ); |
694 | 704 | } |
695 | 705 | |
696 | 706 | # Block constructor sanitizes certain block options on insert |
— | — | @@ -791,24 +801,23 @@ |
792 | 802 | * others, and probably shouldn't be able to unblock themselves |
793 | 803 | * either. |
794 | 804 | * @param $user User|Int|String |
| 805 | + * @param $performer User user doing the request |
795 | 806 | * @return Bool|String true or error message key |
796 | 807 | */ |
797 | | - public static function checkUnblockSelf( $user ) { |
798 | | - global $wgUser; |
799 | | - |
| 808 | + public static function checkUnblockSelf( $user, User $performer ) { |
800 | 809 | if ( is_int( $user ) ) { |
801 | 810 | $user = User::newFromId( $user ); |
802 | 811 | } elseif ( is_string( $user ) ) { |
803 | 812 | $user = User::newFromName( $user ); |
804 | 813 | } |
805 | 814 | |
806 | | - if( $wgUser->isBlocked() ){ |
807 | | - if( $user instanceof User && $user->getId() == $wgUser->getId() ) { |
| 815 | + if( $performer->isBlocked() ){ |
| 816 | + if( $user instanceof User && $user->getId() == $performer->getId() ) { |
808 | 817 | # User is trying to unblock themselves |
809 | | - if ( $wgUser->isAllowed( 'unblockself' ) ) { |
| 818 | + if ( $performer->isAllowed( 'unblockself' ) ) { |
810 | 819 | return true; |
811 | 820 | # User blocked themselves and is now trying to reverse it |
812 | | - } elseif ( $wgUser->blockedBy() === $wgUser->getName() ) { |
| 821 | + } elseif ( $performer->blockedBy() === $performer->getName() ) { |
813 | 822 | return true; |
814 | 823 | } else { |
815 | 824 | return 'ipbnounblockself'; |