Remove Revision::getRevisionText from ApiQueryDeletedrevs
[lhc/web/wiklou.git] / includes / api / ApiBlock.php
index 336943d..30a9242 100644 (file)
@@ -20,6 +20,8 @@
  * @file
  */
 
+use MediaWiki\Block\DatabaseBlock;
+
 /**
  * API module that facilitates the blocking of users. Requires API write mode
  * to be enabled.
@@ -52,7 +54,7 @@ class ApiBlock extends ApiBase {
                                $this->dieWithError(
                                        $status,
                                        null,
-                                       [ 'blockinfo' => $this->getBlockInfo( $block ) ]
+                                       [ 'blockinfo' => $this->getBlockDetails( $block ) ]
                                );
                        }
                }
@@ -82,7 +84,7 @@ class ApiBlock extends ApiBase {
 
                        // T40633 - if the target is a user (not an IP address), but it
                        // doesn't exist or is unusable, error.
-                       if ( $type === Block::TYPE_USER &&
+                       if ( $type === DatabaseBlock::TYPE_USER &&
                                ( $target->isAnon() /* doesn't exist */ || !User::isUsableName( $params['user'] ) )
                        ) {
                                $this->dieWithError( [ 'nosuchusershort', $params['user'] ], 'nosuchuser' );
@@ -96,7 +98,8 @@ class ApiBlock extends ApiBase {
                        }
                }
 
-               if ( $params['hidename'] && !$user->isAllowed( 'hideuser' ) ) {
+               if ( $params['hidename'] &&
+                        !$this->getPermissionManager()->userHasRight( $user, 'hideuser' ) ) {
                        $this->dieWithError( 'apierror-canthide' );
                }
                if ( $params['noemail'] && !SpecialBlock::canBlockEmail( $user ) ) {
@@ -127,17 +130,24 @@ class ApiBlock extends ApiBase {
                        'NamespaceRestrictions' => $namespaceRestrictions,
                ];
 
+               $status = SpecialBlock::validateTarget( $params['user'], $user );
+               if ( !$status->isOK() ) {
+                       $this->dieStatus( $status );
+               }
+
                $retval = SpecialBlock::processForm( $data, $this->getContext() );
                if ( $retval !== true ) {
                        $this->dieStatus( $this->errorArrayToStatus( $retval ) );
                }
 
-               list( $target, /*...*/ ) = SpecialBlock::getTargetAndType( $params['user'] );
+               $res = [];
+
                $res['user'] = $params['user'];
+               list( $target, /*...*/ ) = SpecialBlock::getTargetAndType( $params['user'] );
                $res['userID'] = $target instanceof User ? $target->getId() : 0;
 
-               $block = Block::newFromTarget( $target, null, true );
-               if ( $block instanceof Block ) {
+               $block = DatabaseBlock::newFromTarget( $target, null, true );
+               if ( $block instanceof DatabaseBlock ) {
                        $res['expiry'] = ApiResult::formatExpiry( $block->getExpiry(), 'infinite' );
                        $res['id'] = $block->getId();
                } else {