Restore ApiQueryUserInfo::getBlockInfo() as a stub.
[lhc/web/wiklou.git] / includes / api / ApiBase.php
index 9b3d116..b76a4ea 100644 (file)
@@ -20,8 +20,9 @@
  * @file
  */
 
-use Wikimedia\Rdbms\IDatabase;
+use MediaWiki\Block\AbstractBlock;
 use MediaWiki\MediaWikiServices;
+use Wikimedia\Rdbms\IDatabase;
 
 /**
  * This abstract class implements many basic API functions, and is the base of
@@ -37,6 +38,8 @@ use MediaWiki\MediaWikiServices;
  */
 abstract class ApiBase extends ContextSource {
 
+       use ApiBlockInfoTrait;
+
        /**
         * @name Constants for ::getAllowedParams() arrays
         * These constants are keys in the arrays returned by ::getAllowedParams()
@@ -800,6 +803,7 @@ abstract class ApiBase extends ContextSource {
                                        // $results if all are done.
                                        unset( $targets[$placeholder] );
                                        $placeholder = '{' . $placeholder . '}';
+                                       // @phan-suppress-next-line PhanTypeNoAccessiblePropertiesForeach
                                        foreach ( $results[$target] as $value ) {
                                                if ( !preg_match( '/^[^{}]*$/', $value ) ) {
                                                        // Skip values that make invalid parameter names.
@@ -1196,7 +1200,8 @@ abstract class ApiBase extends ContextSource {
                        $provided = $this->getMain()->getCheck( $encParamName );
 
                        if ( isset( $value ) && $type == 'namespace' ) {
-                               $type = MWNamespace::getValidNamespaces();
+                               $type = MediaWikiServices::getInstance()->getNamespaceInfo()->
+                                       getValidNamespaces();
                                if ( isset( $paramSettings[self::PARAM_EXTRA_NAMESPACES] ) &&
                                        is_array( $paramSettings[self::PARAM_EXTRA_NAMESPACES] )
                                ) {
@@ -1811,7 +1816,7 @@ abstract class ApiBase extends ContextSource {
                        if ( is_string( $error[0] ) && isset( self::$blockMsgMap[$error[0]] ) && $user->getBlock() ) {
                                list( $msg, $code ) = self::$blockMsgMap[$error[0]];
                                $status->fatal( ApiMessage::create( $msg, $code,
-                                       [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) ]
+                                       [ 'blockinfo' => $this->getBlockDetails( $user->getBlock() ) ]
                                ) );
                        } else {
                                $status->fatal( ...$error );
@@ -1834,7 +1839,7 @@ abstract class ApiBase extends ContextSource {
                foreach ( self::$blockMsgMap as $msg => list( $apiMsg, $code ) ) {
                        if ( $status->hasMessage( $msg ) && $user->getBlock() ) {
                                $status->replaceMessage( $msg, ApiMessage::create( $apiMsg, $code,
-                                       [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) ]
+                                       [ 'blockinfo' => $this->getBlockDetails( $user->getBlock() ) ]
                                ) );
                        }
                }
@@ -2027,25 +2032,25 @@ abstract class ApiBase extends ContextSource {
         * @param Block $block The block used to generate the ApiUsageException
         * @throws ApiUsageException always
         */
-       public function dieBlocked( Block $block ) {
+       public function dieBlocked( AbstractBlock $block ) {
                // Die using the appropriate message depending on block type
                if ( $block->getType() == Block::TYPE_AUTO ) {
                        $this->dieWithError(
                                'apierror-autoblocked',
                                'autoblocked',
-                               [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $block ) ]
+                               [ 'blockinfo' => $this->getBlockDetails( $block ) ]
                        );
                } elseif ( !$block->isSitewide() ) {
                        $this->dieWithError(
                                'apierror-blocked-partial',
                                'blocked',
-                               [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $block ) ]
+                               [ 'blockinfo' => $this->getBlockDetails( $block ) ]
                        );
                } else {
                        $this->dieWithError(
                                'apierror-blocked',
                                'blocked',
-                               [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $block ) ]
+                               [ 'blockinfo' => $this->getBlockDetails( $block ) ]
                        );
                }
        }
@@ -2137,11 +2142,6 @@ abstract class ApiBase extends ContextSource {
                }
 
                if ( $errors ) {
-                       // track block notices
-                       if ( $this->getConfig()->get( 'EnableBlockNoticeStats' ) ) {
-                               $this->trackBlockNotices( $errors );
-                       }
-
                        if ( !empty( $options['autoblock'] ) ) {
                                $user->spreadAnyEditBlock();
                        }
@@ -2150,30 +2150,6 @@ abstract class ApiBase extends ContextSource {
                }
        }
 
-       /**
-        * Keep track of errors messages resulting from a block
-        *
-        * @param array $errors
-        */
-       private function trackBlockNotices( array $errors ) {
-               $errorMessageKeys = [
-                       'blockedtext',
-                       'blockedtext-partial',
-                       'autoblockedtext',
-                       'systemblockedtext',
-               ];
-
-               $statsd = MediaWikiServices::getInstance()->getStatsdDataFactory();
-
-               foreach ( $errors as $error ) {
-                       if ( in_array( $error[0], $errorMessageKeys ) ) {
-                               $wiki = $this->getConfig()->get( 'DBname' );
-                               $statsd->increment( 'BlockNotices.' . $wiki . '.MediaWikiApi.returned' );
-                               break;
-                       }
-               }
-       }
-
        /**
         * Will only set a warning instead of failing if the global $wgDebugAPI
         * is set to true. Otherwise behaves exactly as self::dieWithError().