r64256 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64255‎ | r64256 | r64257 >
Date:15:05, 27 March 2010
Author:happy-melon
Status:ok
Tags:
Comment:
Per r64228 CR: make the check a static method in IPBlockForm to reduce duplication.
Modified paths:
  • /trunk/phase3/includes/api/ApiBlock.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUnblock.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialBlockip.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialIpblocklist.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiUnblock.php
@@ -64,18 +64,10 @@
6565 }
6666 # bug 15810: blocked admins should have limited access here
6767 if( $wgUser->isBlocked() ){
68 - $user = User::newFromName( $params['user'] );
69 - if( $user instanceof User
70 - && $user->getId() == $wgUser->getId() )
71 - {
72 - # User is trying to unblock themselves
73 - if( !$wgUser->isAllowed( 'unblockself' ) ){
74 - $this->dieUsageMsg( array( 'ipbnounblockself' ) );
75 - }
76 - } else {
77 - # User is trying to block/unblock someone else
78 - $this->dieUsageMsg( array( 'ipbblocked' ) );
79 - }
 68+ $status = IPBlockForm::checkUnblockSelf( $params['user'] );
 69+ if( $status !== true ){
 70+ $this->dieUsageMsg( array( $status ) );
 71+ }
8072 }
8173
8274 $id = $params['id'];
Index: trunk/phase3/includes/api/ApiBlock.php
@@ -66,18 +66,10 @@
6767 }
6868 # bug 15810: blocked admins should have limited access here
6969 if( $wgUser->isBlocked() ){
70 - $user = User::newFromName( $params['user'] );
71 - if( $user instanceof User
72 - && $user->getId() == $wgUser->getId() )
73 - {
74 - # User is trying to unblock themselves
75 - if( !$wgUser->isAllowed( 'unblockself' ) ){
76 - $this->dieUsageMsg( array( 'ipbnounblockself' ) );
77 - }
78 - } else {
79 - # User is trying to block/unblock someone else
80 - $this->dieUsageMsg( array( 'ipbblocked' ) );
81 - }
 70+ $status = IPBlockForm::checkUnblockSelf( $params['user'] );
 71+ if( $status !== true ){
 72+ $this->dieUsageMsg( array( $status ) );
 73+ }
8274 }
8375 if ( $params['hidename'] && !$wgUser->isAllowed( 'hideuser' ) ) {
8476 $this->dieUsageMsg( array( 'canthide' ) );
Index: trunk/phase3/includes/specials/SpecialIpblocklist.php
@@ -41,18 +41,12 @@
4242 } else {
4343 $user = User::newFromName( $ip );
4444 }
45 - if( $user instanceof User
46 - && $user->getId() == $wgUser->getId() )
47 - {
48 - # User is trying to unblock themselves
49 - if( !$wgUser->isAllowed( 'unblockself' ) ){
50 - throw new ErrorPageError( 'badaccess', 'ipbnounblockself' );
51 - }
52 - } else {
53 - # User is trying to block/unblock someone else
54 - throw new ErrorPageError( 'badaccess', 'ipbblocked' );
55 - }
 45+ $status = IPBlockForm::checkUnblockSelf( $user );
 46+ if( $status !== true ){
 47+ throw new ErrorPageError( 'badaccess', $status );
 48+ }
5649 }
 50+
5751 if( $action == 'unblock' ){
5852 # Show unblock form
5953 $ipu->showForm( '' );
Index: trunk/phase3/includes/specials/SpecialBlockip.php
@@ -27,18 +27,10 @@
2828
2929 # bug 15810: blocked admins should have limited access here
3030 if( $wgUser->isBlocked() ){
31 - $user = User::newFromName( $ipb->BlockAddress );
32 - if( $user instanceof User
33 - && $user->getId() == $wgUser->getId() )
34 - {
35 - # User is trying to unblock themselves
36 - if( !$wgUser->isAllowed( 'unblockself' ) ){
37 - throw new ErrorPageError( 'badaccess', 'ipbnounblockself' );
38 - }
39 - } else {
40 - # User is trying to block/unblock someone else
41 - throw new ErrorPageError( 'badaccess', 'ipbblocked' );
42 - }
 31+ $status = IPBlockForm::checkUnblockSelf( $ipb->BlockAddress );
 32+ if( $status !== true ){
 33+ throw new ErrorPageError( 'badaccess', $status );
 34+ }
4335 }
4436
4537 $action = $wgRequest->getVal( 'action' );
@@ -376,6 +368,34 @@
377369 global $wgEnableUserEmail, $wgSysopEmailBans;
378370 return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) );
379371 }
 372+
 373+ /**
 374+ * bug 15810: blocked admins should not be able to block/unblock
 375+ * others, and probably shouldn't be able to unblock themselves
 376+ * either.
 377+ * @param $user User, Int or String
 378+ */
 379+ public static function checkUnblockSelf( $user ){
 380+ global $wgUser;
 381+ if( is_int( $user ) ){
 382+ $user = User::newFromId( $user );
 383+ } elseif ( is_string( $user ) ){
 384+ $user = User::newFromName( $user );
 385+ }
 386+ if( $user instanceof User
 387+ && $user->getId() == $wgUser->getId() )
 388+ {
 389+ # User is trying to unblock themselves
 390+ if( $wgUser->isAllowed( 'unblockself' ) ){
 391+ return true;
 392+ } else {
 393+ return 'ipbnounblockself';
 394+ }
 395+ } else {
 396+ # User is trying to block/unblock someone else
 397+ return 'ipbblocked';
 398+ }
 399+ }
380400
381401 /**
382402 * Backend block code.

Follow-up revisions

RevisionCommit summaryAuthorDate
r64274Fix coding style in r64230, r64256catrope21:31, 27 March 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r64228(bug 15810) stop blocked admins from unblocking themselves or others.happy-melon22:02, 26 March 2010

Status & tagging log