Convert all array() syntax to []
[lhc/web/wiklou.git] / includes / api / ApiMain.php
index 3b62541..ed5c1bc 100644 (file)
@@ -47,7 +47,7 @@ class ApiMain extends ApiBase {
        /**
         * List of available modules: action name => module class
         */
-       private static $Modules = array(
+       private static $Modules = [
                'login' => 'ApiLogin',
                'logout' => 'ApiLogout',
                'createaccount' => 'ApiCreateAccount',
@@ -91,12 +91,12 @@ class ApiMain extends ApiBase {
                'managetags' => 'ApiManageTags',
                'tag' => 'ApiTag',
                'mergehistory' => 'ApiMergeHistory',
-       );
+       ];
 
        /**
         * List of available formats: format name => format class
         */
-       private static $Formats = array(
+       private static $Formats = [
                'json' => 'ApiFormatJson',
                'jsonfm' => 'ApiFormatJson',
                'php' => 'ApiFormatPhp',
@@ -105,7 +105,7 @@ class ApiMain extends ApiBase {
                'xmlfm' => 'ApiFormatXml',
                'rawfm' => 'ApiFormatJson',
                'none' => 'ApiFormatNone',
-       );
+       ];
 
        // @codingStandardsIgnoreStart String contenation on "msg" not allowed to break long line
        /**
@@ -137,8 +137,8 @@ class ApiMain extends ApiBase {
        private $mInternalMode, $mSquidMaxage, $mModule;
 
        private $mCacheMode = 'private';
-       private $mCacheControl = array();
-       private $mParamsUsed = array();
+       private $mCacheControl = [];
+       private $mParamsUsed = [];
 
        /**
         * Constructs an instance of ApiMain that utilizes the module and format specified by $request.
@@ -207,7 +207,7 @@ class ApiMain extends ApiBase {
                $this->mModuleMgr->addModules( self::$Formats, 'format' );
                $this->mModuleMgr->addModules( $config->get( 'APIFormatModules' ), 'format' );
 
-               Hooks::run( 'ApiMain::moduleManager', array( $this->mModuleMgr ) );
+               Hooks::run( 'ApiMain::moduleManager', [ $this->mModuleMgr ] );
 
                $this->mResult = new ApiResult( $this->getConfig()->get( 'APIMaxResultSize' ) );
                $this->mErrorFormatter = new ApiErrorFormatter_BackCompat( $this->mResult );
@@ -298,10 +298,10 @@ class ApiMain extends ApiBase {
         * @param int $maxage
         */
        public function setCacheMaxAge( $maxage ) {
-               $this->setCacheControl( array(
+               $this->setCacheControl( [
                        'max-age' => $maxage,
                        's-maxage' => $maxage
-               ) );
+               ] );
        }
 
        /**
@@ -330,7 +330,7 @@ class ApiMain extends ApiBase {
         *  If this function is never called, then the default will be the private mode.
         */
        public function setCacheMode( $mode ) {
-               if ( !in_array( $mode, array( 'private', 'public', 'anon-public-user-private' ) ) ) {
+               if ( !in_array( $mode, [ 'private', 'public', 'anon-public-user-private' ] ) ) {
                        wfDebug( __METHOD__ . ": unrecognised cache mode \"$mode\"\n" );
 
                        // Ignore for forwards-compatibility
@@ -469,7 +469,7 @@ class ApiMain extends ApiBase {
                }
 
                // Allow extra cleanup and logging
-               Hooks::run( 'ApiMain::onException', array( $this, $e ) );
+               Hooks::run( 'ApiMain::onException', [ $this, $e ] );
 
                // Log it
                if ( !( $e instanceof UsageException ) ) {
@@ -569,7 +569,7 @@ class ApiMain extends ApiBase {
                // Origin: header is a space-separated list of origins, check all of them
                $originHeader = $request->getHeader( 'Origin' );
                if ( $originHeader === false ) {
-                       $origins = array();
+                       $origins = [];
                } else {
                        $originHeader = trim( $originHeader );
                        $origins = preg_split( '/\s+/', $originHeader );
@@ -667,7 +667,7 @@ class ApiMain extends ApiBase {
                        return true;
                }
                $requestedHeaders = explode( ',', $requestedHeaders );
-               $allowedAuthorHeaders = array_flip( array(
+               $allowedAuthorHeaders = array_flip( [
                        /* simple headers (see spec) */
                        'accept',
                        'accept-language',
@@ -679,7 +679,7 @@ class ApiMain extends ApiBase {
                        'origin',
                        /* MediaWiki whitelist */
                        'api-user-agent',
-               ) );
+               ] );
                foreach ( $requestedHeaders as $rHeader ) {
                        $rHeader = strtolower( trim( $rHeader ) );
                        if ( !isset( $allowedAuthorHeaders[$rHeader] ) ) {
@@ -701,8 +701,8 @@ class ApiMain extends ApiBase {
        protected static function wildcardToRegex( $wildcard ) {
                $wildcard = preg_quote( $wildcard, '/' );
                $wildcard = str_replace(
-                       array( '\*', '\?' ),
-                       array( '.*?', '.' ),
+                       [ '\*', '\?' ],
+                       [ '.*?', '.' ],
                        $wildcard
                );
 
@@ -869,10 +869,10 @@ class ApiMain extends ApiBase {
                                $info = "Exception Caught: {$e->getMessage()}";
                        }
 
-                       $errMessage = array(
+                       $errMessage = [
                                'code' => 'internal_api_error_' . get_class( $e ),
                                'info' => '[' . MWExceptionHandler::getLogId( $e ) . '] ' . $info,
-                       );
+                       ];
                        if ( $config->get( 'ShowExceptionDetails' ) ) {
                                ApiResult::setContentValue(
                                        $errMessage,
@@ -883,7 +883,7 @@ class ApiMain extends ApiBase {
                }
 
                // Remember all the warnings to re-add them later
-               $warnings = $result->getResultData( array( 'warnings' ) );
+               $warnings = $result->getResultData( [ 'warnings' ] );
 
                $result->reset();
                // Re-add the id
@@ -968,7 +968,7 @@ class ApiMain extends ApiBase {
                        }
 
                        if ( !isset( $moduleParams['token'] ) ) {
-                               $this->dieUsageMsg( array( 'missingparam', 'token' ) );
+                               $this->dieUsageMsg( [ 'missingparam', 'token' ] );
                        }
 
                        if ( !$this->getConfig()->get( 'DebugAPI' ) &&
@@ -1054,11 +1054,11 @@ class ApiMain extends ApiBase {
                $return304 = false;
 
                $ifNoneMatch = array_diff(
-                       $this->getRequest()->getHeader( 'If-None-Match', WebRequest::GETHEADER_LIST ) ?: array(),
-                       array( '' )
+                       $this->getRequest()->getHeader( 'If-None-Match', WebRequest::GETHEADER_LIST ) ?: [],
+                       [ '' ]
                );
                if ( $ifNoneMatch ) {
-                       if ( $ifNoneMatch === array( '*' ) ) {
+                       if ( $ifNoneMatch === [ '*' ] ) {
                                // API responses always "exist"
                                $etag = '*';
                        } else {
@@ -1097,18 +1097,18 @@ class ApiMain extends ApiBase {
                                                $lastMod = $module->getConditionalRequestData( 'last-modified' );
                                                if ( $lastMod !== null ) {
                                                        // Mix in some MediaWiki modification times
-                                                       $modifiedTimes = array(
+                                                       $modifiedTimes = [
                                                                'page' => $lastMod,
                                                                'user' => $this->getUser()->getTouched(),
                                                                'epoch' => $this->getConfig()->get( 'CacheEpoch' ),
-                                                       );
+                                                       ];
                                                        if ( $this->getConfig()->get( 'UseSquid' ) ) {
                                                                // T46570: the core page itself may not change, but resources might
                                                                $modifiedTimes['sepoch'] = wfTimestamp(
                                                                        TS_MW, time() - $this->getConfig()->get( 'SquidMaxage' )
                                                                );
                                                        }
-                                                       Hooks::run( 'OutputPageCheckLastModified', array( &$modifiedTimes ) );
+                                                       Hooks::run( 'OutputPageCheckLastModified', [ &$modifiedTimes ] );
                                                        $lastMod = max( $modifiedTimes );
                                                        $return304 = wfTimestamp( TS_MW, $lastMod ) <= $ts->getTimestamp( TS_MW );
                                                }
@@ -1163,7 +1163,7 @@ class ApiMain extends ApiBase {
 
                // Allow extensions to stop execution for arbitrary reasons.
                $message = false;
-               if ( !Hooks::run( 'ApiCheckCanExecute', array( $module, $user, &$message ) ) ) {
+               if ( !Hooks::run( 'ApiCheckCanExecute', [ $module, $user, &$message ] ) ) {
                        $this->dieUsageMsg( $message );
                }
        }
@@ -1192,7 +1192,7 @@ class ApiMain extends ApiBase {
                // Figure out how many servers have passed the lag threshold
                $numLagged = 0;
                $lagLimit = $this->getConfig()->get( 'APIMaxLagThreshold' );
-               $laggedServers = array();
+               $laggedServers = [];
                $loadBalancer = wfGetLB();
                foreach ( $loadBalancer->getLagTimes() as $serverIndex => $lag ) {
                        if ( $lag > $lagLimit ) {
@@ -1210,13 +1210,13 @@ class ApiMain extends ApiBase {
                                "Api request failed as read only because the following DBs are lagged: $laggedServers"
                        );
 
-                       $parsed = $this->parseMsg( array( 'readonlytext' ) );
+                       $parsed = $this->parseMsg( [ 'readonlytext' ] );
                        $this->dieUsage(
                                $parsed['info'],
                                $parsed['code'],
                                /* http error */
                                0,
-                               array( 'readonlyreason' => "Waiting for $numLagged lagged database(s)" )
+                               [ 'readonlyreason' => "Waiting for $numLagged lagged database(s)" ]
                        );
                }
        }
@@ -1253,7 +1253,7 @@ class ApiMain extends ApiBase {
                if ( !$request->wasPosted() && $module->mustBePosted() ) {
                        // Module requires POST. GET request might still be allowed
                        // if $wgDebugApi is true, otherwise fail.
-                       $this->dieUsageMsgOrDebug( array( 'mustbeposted', $this->mAction ) );
+                       $this->dieUsageMsgOrDebug( [ 'mustbeposted', $this->mAction ] );
                }
 
                // See if custom printer is used
@@ -1303,7 +1303,7 @@ class ApiMain extends ApiBase {
 
                // Execute
                $module->execute();
-               Hooks::run( 'APIAfterExecute', array( &$module ) );
+               Hooks::run( 'APIAfterExecute', [ &$module ] );
 
                $this->reportUnusedParams();
 
@@ -1340,14 +1340,14 @@ class ApiMain extends ApiBase {
         */
        protected function logRequest( $time ) {
                $request = $this->getRequest();
-               $logCtx = array(
+               $logCtx = [
                        'dt' => date( 'c' ),
                        'client_ip' => $request->getIP(),
                        'user_agent' => $this->getUserAgent(),
                        'wiki' => wfWikiID(),
                        'time_backend_ms' => round( $time * 1000 ),
-                       'params' => array(),
-               );
+                       'params' => [],
+               ];
 
                // Construct space separated message for 'api' log channel
                $msg = "API {$request->getMethod()} " .
@@ -1460,8 +1460,8 @@ class ApiMain extends ApiBase {
                if ( !$this->mInternalMode ) {
                        // Printer has not yet executed; don't warn that its parameters are unused
                        $printerParams = array_map(
-                               array( $this->mPrinter, 'encodeParamName' ),
-                               array_keys( $this->mPrinter->getFinalParams() ?: array() )
+                               [ $this->mPrinter, 'encodeParamName' ],
+                               array_keys( $this->mPrinter->getFinalParams() ?: [] )
                        );
                        $unusedParams = array_diff( $allParams, $paramsUsed, $printerParams );
                } else {
@@ -1503,54 +1503,54 @@ class ApiMain extends ApiBase {
         * @return array
         */
        public function getAllowedParams() {
-               return array(
-                       'action' => array(
+               return [
+                       'action' => [
                                ApiBase::PARAM_DFLT => 'help',
                                ApiBase::PARAM_TYPE => 'submodule',
-                       ),
-                       'format' => array(
+                       ],
+                       'format' => [
                                ApiBase::PARAM_DFLT => ApiMain::API_DEFAULT_FORMAT,
                                ApiBase::PARAM_TYPE => 'submodule',
-                       ),
-                       'maxlag' => array(
+                       ],
+                       'maxlag' => [
                                ApiBase::PARAM_TYPE => 'integer'
-                       ),
-                       'smaxage' => array(
+                       ],
+                       'smaxage' => [
                                ApiBase::PARAM_TYPE => 'integer',
                                ApiBase::PARAM_DFLT => 0
-                       ),
-                       'maxage' => array(
+                       ],
+                       'maxage' => [
                                ApiBase::PARAM_TYPE => 'integer',
                                ApiBase::PARAM_DFLT => 0
-                       ),
-                       'assert' => array(
-                               ApiBase::PARAM_TYPE => array( 'user', 'bot' )
-                       ),
+                       ],
+                       'assert' => [
+                               ApiBase::PARAM_TYPE => [ 'user', 'bot' ]
+                       ],
                        'requestid' => null,
                        'servedby' => false,
                        'curtimestamp' => false,
                        'origin' => null,
-                       'uselang' => array(
+                       'uselang' => [
                                ApiBase::PARAM_DFLT => 'user',
-                       ),
-               );
+                       ],
+               ];
        }
 
        /** @see ApiBase::getExamplesMessages() */
        protected function getExamplesMessages() {
-               return array(
+               return [
                        'action=help'
                                => 'apihelp-help-example-main',
                        'action=help&recursivesubmodules=1'
                                => 'apihelp-help-example-recursive',
-               );
+               ];
        }
 
        public function modifyHelp( array &$help, array $options, array &$tocData ) {
                // Wish PHP had an "array_insert_before". Instead, we have to manually
                // reindex the array to get 'permissions' in the right place.
                $oldHelp = $help;
-               $help = array();
+               $help = [];
                foreach ( $oldHelp as $k => $v ) {
                        if ( $k === 'submodules' ) {
                                $help['permissions'] = '';
@@ -1562,10 +1562,10 @@ class ApiMain extends ApiBase {
 
                // Fill 'permissions'
                $help['permissions'] .= Html::openElement( 'div',
-                       array( 'class' => 'apihelp-block apihelp-permissions' ) );
+                       [ 'class' => 'apihelp-block apihelp-permissions' ] );
                $m = $this->msg( 'api-help-permissions' );
                if ( !$m->isDisabled() ) {
-                       $help['permissions'] .= Html::rawElement( 'div', array( 'class' => 'apihelp-block-head' ),
+                       $help['permissions'] .= Html::rawElement( 'div', [ 'class' => 'apihelp-block-head' ],
                                $m->numParams( count( self::$mRights ) )->parse()
                        );
                }
@@ -1597,40 +1597,40 @@ class ApiMain extends ApiBase {
 
                        $header = $this->msg( 'api-help-datatypes-header' )->parse();
                        $help['datatypes'] .= Html::rawElement( 'h' . min( 6, $level ),
-                               array( 'id' => 'main/datatypes', 'class' => 'apihelp-header' ),
-                               Html::element( 'span', array( 'id' => Sanitizer::escapeId( 'main/datatypes' ) ) ) .
+                               [ 'id' => 'main/datatypes', 'class' => 'apihelp-header' ],
+                               Html::element( 'span', [ 'id' => Sanitizer::escapeId( 'main/datatypes' ) ] ) .
                                $header
                        );
                        $help['datatypes'] .= $this->msg( 'api-help-datatypes' )->parseAsBlock();
                        if ( !isset( $tocData['main/datatypes'] ) ) {
                                $tocnumber[$level]++;
-                               $tocData['main/datatypes'] = array(
+                               $tocData['main/datatypes'] = [
                                        'toclevel' => count( $tocnumber ),
                                        'level' => $level,
                                        'anchor' => 'main/datatypes',
                                        'line' => $header,
                                        'number' => join( '.', $tocnumber ),
                                        'index' => false,
-                               );
+                               ];
                        }
 
                        $header = $this->msg( 'api-credits-header' )->parse();
                        $help['credits'] .= Html::rawElement( 'h' . min( 6, $level ),
-                               array( 'id' => 'main/credits', 'class' => 'apihelp-header' ),
-                               Html::element( 'span', array( 'id' => Sanitizer::escapeId( 'main/credits' ) ) ) .
+                               [ 'id' => 'main/credits', 'class' => 'apihelp-header' ],
+                               Html::element( 'span', [ 'id' => Sanitizer::escapeId( 'main/credits' ) ] ) .
                                $header
                        );
                        $help['credits'] .= $this->msg( 'api-credits' )->useDatabase( false )->parseAsBlock();
                        if ( !isset( $tocData['main/credits'] ) ) {
                                $tocnumber[$level]++;
-                               $tocData['main/credits'] = array(
+                               $tocData['main/credits'] = [
                                        'toclevel' => count( $tocnumber ),
                                        'level' => $level,
                                        'anchor' => 'main/credits',
                                        'line' => $header,
                                        'number' => join( '.', $tocnumber ),
                                        'index' => false,
-                               );
+                               ];
                        }
                }
        }
@@ -1707,7 +1707,7 @@ class ApiMain extends ApiBase {
                                str_replace( ' ', '_', SpecialVersion::getVersion( 'nodb' ) )
                        ),
                        $cacheHelpTimeout > 0 ? $cacheHelpTimeout : WANObjectCache::TTL_UNCACHEABLE,
-                       array( $this, 'reallyMakeHelpMsg' )
+                       [ $this, 'reallyMakeHelpMsg' ]
                );
        }
 
@@ -1870,10 +1870,10 @@ class UsageException extends MWException {
         * @return array
         */
        public function getMessageArray() {
-               $result = array(
+               $result = [
                        'code' => $this->mCodestr,
                        'info' => $this->getMessage()
-               );
+               ];
                if ( is_array( $this->mExtraData ) ) {
                        $result = array_merge( $result, $this->mExtraData );
                }