Followup r71831, it's not mutually exclusive!
[lhc/web/wiklou.git] / includes / api / ApiBlock.php
index 6af2a21..ecfc45f 100644 (file)
@@ -1,9 +1,9 @@
 <?php
-
 /**
- * Created on Sep 4, 2007
  * API for MediaWiki 1.8+
  *
+ * Created on Sep 4, 2007
+ *
  * Copyright © 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
  *
  * This program is free software; you can redistribute it and/or modify
  *
  * You should have received a copy of the GNU General Public License along
  * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
  */
 
 if ( !defined( 'MEDIAWIKI' ) ) {
@@ -58,25 +60,14 @@ class ApiBlock extends ApiBase {
                        return;
                }
 
-               if ( is_null( $params['user'] ) ) {
-                       $this->dieUsageMsg( array( 'missingparam', 'user' ) );
-               }
                if ( !$wgUser->isAllowed( 'block' ) ) {
                        $this->dieUsageMsg( array( 'cantblock' ) );
                }
                # bug 15810: blocked admins should have limited access here
-               if( $wgUser->isBlocked() ){
-                       $user = User::newFromName( $params['user'] );
-                       if( $user instanceof User
-                               && $user->getId() == $wgUser->getId() )
-                       {
-                               # User is trying to unblock themselves
-                               if( !$wgUser->isAllowed( 'unblockself' ) ){
-                                       $this->dieUsageMsg( array( 'ipbnounblockself' ) );
-                               }
-                       } else {
-                               # User is trying to block/unblock someone else
-                               $this->dieUsageMsg( array( 'ipbblocked' ) );
+               if ( $wgUser->isBlocked() ) {
+                       $status = IPBlockForm::checkUnblockSelf( $params['user'] );
+                       if ( $status !== true ) {
+                               $this->dieUsageMsg( array( $status ) );
                        }
                }
                if ( $params['hidename'] && !$wgUser->isAllowed( 'hideuser' ) ) {
@@ -143,7 +134,10 @@ class ApiBlock extends ApiBase {
 
        public function getAllowedParams() {
                return array(
-                       'user' => null,
+                       'user' => array(
+                               ApiBase::PARAM_TYPE => 'string',
+                               ApiBase::PARAM_REQUIRED => true
+                       ),
                        'token' => null,
                        'gettoken' => false,
                        'expiry' => 'never',
@@ -176,14 +170,11 @@ class ApiBlock extends ApiBase {
        }
 
        public function getDescription() {
-               return array(
-                       'Block a user.'
-               );
+               return 'Block a user';
        }
-       
+
        public function getPossibleErrors() {
                return array_merge( parent::getPossibleErrors(), array(
-                       array( 'missingparam', 'user' ),
                        array( 'cantblock' ),
                        array( 'canthide' ),
                        array( 'cantblock-email' ),
@@ -191,7 +182,7 @@ class ApiBlock extends ApiBase {
                        array( 'ipbnounblockself' ),
                ) );
        }
-       
+
        public function getTokenSalt() {
                return '';
        }