Merge "Http::getProxy() method to get proxy configuration"
[lhc/web/wiklou.git] / includes / api / ApiHelp.php
index 092e3e6..f2d6329 100644 (file)
@@ -33,7 +33,7 @@
 class ApiHelp extends ApiBase {
        public function execute() {
                $params = $this->extractRequestParams();
-               $modules = array();
+               $modules = [];
 
                foreach ( $params['modules'] as $path ) {
                        $modules[] = $this->getModuleFromPath( $path );
@@ -57,10 +57,10 @@ class ApiHelp extends ApiBase {
 
                $result = $this->getResult();
                if ( $params['wrap'] ) {
-                       $data = array(
+                       $data = [
                                'mime' => 'text/html',
                                'help' => $html,
-                       );
+                       ];
                        ApiResult::setSubelementsList( $data, 'help' );
                        $result->addValue( null, $this->getModuleName(), $data );
                } else {
@@ -94,7 +94,7 @@ class ApiHelp extends ApiBase {
                global $wgContLang;
 
                if ( !is_array( $modules ) ) {
-                       $modules = array( $modules );
+                       $modules = [ $modules ];
                }
 
                $out = $context->getOutput();
@@ -140,7 +140,7 @@ class ApiHelp extends ApiBase {
                        }
                }
 
-               $haveModules = array();
+               $haveModules = [];
                $html = self::getHelpInternal( $context, $modules, $options, $haveModules );
                if ( !empty( $options['toc'] ) && $haveModules ) {
                        $out->addHTML( Linker::generateTOC( $haveModules, $context->getLanguage() ) );
@@ -165,7 +165,7 @@ class ApiHelp extends ApiBase {
         * @param array $localModules Keys are modules to link within the current page, values are ignored
         * @return string
         */
-       public static function fixHelpLinks( $html, $helptitle = null, $localModules = array() ) {
+       public static function fixHelpLinks( $html, $helptitle = null, $localModules = [] ) {
                $formatter = new HtmlFormatter( $html );
                $doc = $formatter->getDoc();
                $xpath = new DOMXPath( $doc );
@@ -183,10 +183,10 @@ class ApiHelp extends ApiBase {
                                        $href = Title::newFromText( str_replace( '$1', $m[1], $helptitle ) . $m[2] )
                                                ->getFullURL();
                                } else {
-                                       $href = wfAppendQuery( wfScript( 'api' ), array(
+                                       $href = wfAppendQuery( wfScript( 'api' ), [
                                                'action' => 'help',
                                                'modules' => $m[1],
-                                       ) ) . $m[2];
+                                       ] ) . $m[2];
                                }
                                $node->setAttribute( 'href', $href );
                                $node->removeAttribute( 'title' );
@@ -205,7 +205,7 @@ class ApiHelp extends ApiBase {
         * @return string
         */
        private static function wrap( Message $msg, $class, $tag = 'span' ) {
-               return Html::rawElement( $tag, array( 'class' => $class ),
+               return Html::rawElement( $tag, [ 'class' => $class ],
                        $msg->parse()
                );
        }
@@ -226,7 +226,7 @@ class ApiHelp extends ApiBase {
 
                $level = empty( $options['headerlevel'] ) ? 2 : $options['headerlevel'];
                if ( empty( $options['tocnumber'] ) ) {
-                       $tocnumber = array( 2 => 0 );
+                       $tocnumber = [ 2 => 0 ];
                } else {
                        $tocnumber = &$options['tocnumber'];
                }
@@ -235,7 +235,7 @@ class ApiHelp extends ApiBase {
                        $tocnumber[$level]++;
                        $path = $module->getModulePath();
                        $module->setContext( $context );
-                       $help = array(
+                       $help = [
                                'header' => '',
                                'flags' => '',
                                'description' => '',
@@ -243,7 +243,7 @@ class ApiHelp extends ApiBase {
                                'parameters' => '',
                                'examples' => '',
                                'submodules' => '',
-                       );
+                       ];
 
                        if ( empty( $options['noheader'] ) || !empty( $options['toc'] ) ) {
                                $anchor = $path;
@@ -263,17 +263,17 @@ class ApiHelp extends ApiBase {
                                                        $context->msg( 'parentheses', $module->getModulePrefix() )->parse();
                                        }
                                }
-                               $haveModules[$anchor] = array(
+                               $haveModules[$anchor] = [
                                        'toclevel' => count( $tocnumber ),
                                        'level' => $level,
                                        'anchor' => $anchor,
                                        'line' => $header,
-                                       'number' => join( '.', $tocnumber ),
+                                       'number' => implode( '.', $tocnumber ),
                                        'index' => false,
-                               );
+                               ];
                                if ( empty( $options['noheader'] ) ) {
                                        $help['header'] .= Html::element( 'h' . min( 6, $level ),
-                                               array( 'id' => $anchor, 'class' => 'apihelp-header' ),
+                                               [ 'id' => $anchor, 'class' => 'apihelp-header' ],
                                                $header
                                        );
                                }
@@ -281,7 +281,7 @@ class ApiHelp extends ApiBase {
                                $haveModules[$path] = true;
                        }
 
-                       $links = array();
+                       $links = [];
                        $any = false;
                        for ( $m = $module; $m !== null; $m = $m->getParent() ) {
                                $name = $m->getModuleName();
@@ -296,7 +296,7 @@ class ApiHelp extends ApiBase {
                                } else {
                                        $link = SpecialPage::getTitleFor( 'ApiHelp', $m->getModulePath() )->getLocalURL();
                                        $link = Html::element( 'a',
-                                               array( 'href' => $link, 'class' => 'apihelp-linktrail' ),
+                                               [ 'href' => $link, 'class' => 'apihelp-linktrail' ],
                                                $name
                                        );
                                        $any = true;
@@ -313,7 +313,7 @@ class ApiHelp extends ApiBase {
 
                        $flags = $module->getHelpFlags();
                        $help['flags'] .= Html::openElement( 'div',
-                               array( 'class' => 'apihelp-block apihelp-flags' ) );
+                               [ 'class' => 'apihelp-block apihelp-flags' ] );
                        $msg = $context->msg( 'api-help-flags' );
                        if ( !$msg->isDisabled() ) {
                                $help['flags'] .= self::wrap(
@@ -370,7 +370,7 @@ class ApiHelp extends ApiBase {
                        $urls = $module->getHelpUrls();
                        if ( $urls ) {
                                $help['help-urls'] .= Html::openElement( 'div',
-                                       array( 'class' => 'apihelp-block apihelp-help-urls' )
+                                       [ 'class' => 'apihelp-block apihelp-help-urls' ]
                                );
                                $msg = $context->msg( 'api-help-help-urls' );
                                if ( !$msg->isDisabled() ) {
@@ -379,12 +379,12 @@ class ApiHelp extends ApiBase {
                                        );
                                }
                                if ( !is_array( $urls ) ) {
-                                       $urls = array( $urls );
+                                       $urls = [ $urls ];
                                }
                                $help['help-urls'] .= Html::openElement( 'ul' );
                                foreach ( $urls as $url ) {
                                        $help['help-urls'] .= Html::rawElement( 'li', null,
-                                               Html::element( 'a', array( 'href' => $url ), $url )
+                                               Html::element( 'a', [ 'href' => $url ], $url )
                                        );
                                }
                                $help['help-urls'] .= Html::closeElement( 'ul' );
@@ -393,10 +393,10 @@ class ApiHelp extends ApiBase {
 
                        $params = $module->getFinalParams( ApiBase::GET_VALUES_FOR_HELP );
                        $dynamicParams = $module->dynamicParameterDocumentation();
-                       $groups = array();
+                       $groups = [];
                        if ( $params || $dynamicParams !== null ) {
                                $help['parameters'] .= Html::openElement( 'div',
-                                       array( 'class' => 'apihelp-block apihelp-parameters' )
+                                       [ 'class' => 'apihelp-block apihelp-parameters' ]
                                );
                                $msg = $context->msg( 'api-help-parameters' );
                                if ( !$msg->isDisabled() ) {
@@ -410,14 +410,14 @@ class ApiHelp extends ApiBase {
 
                                foreach ( $params as $name => $settings ) {
                                        if ( !is_array( $settings ) ) {
-                                               $settings = array( ApiBase::PARAM_DFLT => $settings );
+                                               $settings = [ ApiBase::PARAM_DFLT => $settings ];
                                        }
 
                                        $help['parameters'] .= Html::element( 'dt', null,
                                                $module->encodeParamName( $name ) );
 
                                        // Add description
-                                       $description = array();
+                                       $description = [];
                                        if ( isset( $descriptions[$name] ) ) {
                                                foreach ( $descriptions[$name] as $msg ) {
                                                        $msg->setContext( $context );
@@ -426,7 +426,7 @@ class ApiHelp extends ApiBase {
                                        }
 
                                        // Add usage info
-                                       $info = array();
+                                       $info = [];
 
                                        // Required?
                                        if ( !empty( $settings[ApiBase::PARAM_REQUIRED] ) ) {
@@ -468,7 +468,7 @@ class ApiHelp extends ApiBase {
                                                        $count = count( $type );
                                                        $links = isset( $settings[ApiBase::PARAM_VALUE_LINKS] )
                                                                ? $settings[ApiBase::PARAM_VALUE_LINKS]
-                                                               : array();
+                                                               : [];
                                                        $type = array_map( function ( $v ) use ( $links ) {
                                                                $ret = wfEscapeWikiText( $v );
                                                                if ( isset( $links[$v] ) ) {
@@ -498,7 +498,7 @@ class ApiHelp extends ApiBase {
                                                                        if ( isset( $settings[ApiBase::PARAM_SUBMODULE_MAP] ) ) {
                                                                                $map = $settings[ApiBase::PARAM_SUBMODULE_MAP];
                                                                                ksort( $map );
-                                                                               $submodules = array();
+                                                                               $submodules = [];
                                                                                foreach ( $map as $v => $m ) {
                                                                                        $submodules[] = "[[Special:ApiHelp/{$m}|{$v}]]";
                                                                                }
@@ -608,7 +608,7 @@ class ApiHelp extends ApiBase {
                                                }
 
                                                if ( $multi ) {
-                                                       $extra = array();
+                                                       $extra = [];
                                                        if ( $hintPipeSeparated ) {
                                                                $extra[] = $context->msg( 'api-help-param-multi-separate' )->parse();
                                                        }
@@ -618,7 +618,7 @@ class ApiHelp extends ApiBase {
                                                                        ->parse();
                                                        }
                                                        if ( $extra ) {
-                                                               $info[] = join( ' ', $extra );
+                                                               $info[] = implode( ' ', $extra );
                                                        }
                                                }
                                        }
@@ -637,16 +637,16 @@ class ApiHelp extends ApiBase {
                                        }
 
                                        if ( !array_filter( $description ) ) {
-                                               $description = array( self::wrap(
+                                               $description = [ self::wrap(
                                                        $context->msg( 'api-help-param-no-description' ),
                                                        'apihelp-empty'
-                                               ) );
+                                               ) ];
                                        }
 
                                        // Add "deprecated" flag
                                        if ( !empty( $settings[ApiBase::PARAM_DEPRECATED] ) ) {
                                                $help['parameters'] .= Html::openElement( 'dd',
-                                                       array( 'class' => 'info' ) );
+                                                       [ 'class' => 'info' ] );
                                                $help['parameters'] .= self::wrap(
                                                        $context->msg( 'api-help-param-deprecated' ),
                                                        'apihelp-deprecated', 'strong'
@@ -655,26 +655,26 @@ class ApiHelp extends ApiBase {
                                        }
 
                                        if ( $description ) {
-                                               $description = join( '', $description );
+                                               $description = implode( '', $description );
                                                $description = preg_replace( '!\s*</([oud]l)>\s*<\1>\s*!', "\n", $description );
                                                $help['parameters'] .= Html::rawElement( 'dd',
-                                                       array( 'class' => 'description' ), $description );
+                                                       [ 'class' => 'description' ], $description );
                                        }
 
                                        foreach ( $info as $i ) {
-                                               $help['parameters'] .= Html::rawElement( 'dd', array( 'class' => 'info' ), $i );
+                                               $help['parameters'] .= Html::rawElement( 'dd', [ 'class' => 'info' ], $i );
                                        }
                                }
 
                                if ( $dynamicParams !== null ) {
-                                       $dynamicParams = ApiBase::makeMessage( $dynamicParams, $context, array(
+                                       $dynamicParams = ApiBase::makeMessage( $dynamicParams, $context, [
                                                $module->getModulePrefix(),
                                                $module->getModuleName(),
                                                $module->getModulePath()
-                                       ) );
+                                       ] );
                                        $help['parameters'] .= Html::element( 'dt', null, '*' );
                                        $help['parameters'] .= Html::rawElement( 'dd',
-                                               array( 'class' => 'description' ), $dynamicParams->parse() );
+                                               [ 'class' => 'description' ], $dynamicParams->parse() );
                                }
 
                                $help['parameters'] .= Html::closeElement( 'dl' );
@@ -684,7 +684,7 @@ class ApiHelp extends ApiBase {
                        $examples = $module->getExamplesMessages();
                        if ( $examples ) {
                                $help['examples'] .= Html::openElement( 'div',
-                                       array( 'class' => 'apihelp-block apihelp-examples' ) );
+                                       [ 'class' => 'apihelp-block apihelp-examples' ] );
                                $msg = $context->msg( 'api-help-examples' );
                                if ( !$msg->isDisabled() ) {
                                        $help['examples'] .= self::wrap(
@@ -694,18 +694,18 @@ class ApiHelp extends ApiBase {
 
                                $help['examples'] .= Html::openElement( 'dl' );
                                foreach ( $examples as $qs => $msg ) {
-                                       $msg = ApiBase::makeMessage( $msg, $context, array(
+                                       $msg = ApiBase::makeMessage( $msg, $context, [
                                                $module->getModulePrefix(),
                                                $module->getModuleName(),
                                                $module->getModulePath()
-                                       ) );
+                                       ] );
 
                                        $link = wfAppendQuery( wfScript( 'api' ), $qs );
                                        $sandbox = SpecialPage::getTitleFor( 'ApiSandbox' )->getLocalURL() . '#' . $qs;
                                        $help['examples'] .= Html::rawElement( 'dt', null, $msg->parse() );
                                        $help['examples'] .= Html::rawElement( 'dd', null,
-                                               Html::element( 'a', array( 'href' => $link ), "api.php?$qs" ) . ' ' .
-                                               Html::rawElement( 'a', array( 'href' => $sandbox ),
+                                               Html::element( 'a', [ 'href' => $link ], "api.php?$qs" ) . ' ' .
+                                               Html::rawElement( 'a', [ 'href' => $sandbox ],
                                                        $context->msg( 'api-help-open-in-apisandbox' )->parse() )
                                        );
                                }
@@ -715,16 +715,16 @@ class ApiHelp extends ApiBase {
 
                        $subtocnumber = $tocnumber;
                        $subtocnumber[$level + 1] = 0;
-                       $suboptions = array(
+                       $suboptions = [
                                'submodules' => $options['recursivesubmodules'],
                                'headerlevel' => $level + 1,
                                'tocnumber' => &$subtocnumber,
                                'noheader' => false,
-                       ) + $options;
+                       ] + $options;
 
                        if ( $options['submodules'] && $module->getModuleManager() ) {
                                $manager = $module->getModuleManager();
-                               $submodules = array();
+                               $submodules = [];
                                foreach ( $groups as $group ) {
                                        $names = $manager->getNames( $group );
                                        sort( $names );
@@ -742,9 +742,9 @@ class ApiHelp extends ApiBase {
 
                        $module->modifyHelp( $help, $suboptions, $haveModules );
 
-                       Hooks::run( 'APIHelpModifyOutput', array( $module, &$help, $suboptions, &$haveModules ) );
+                       Hooks::run( 'APIHelpModifyOutput', [ $module, &$help, $suboptions, &$haveModules ] );
 
-                       $out .= join( "\n", $help );
+                       $out .= implode( "\n", $help );
                }
 
                return $out;
@@ -770,20 +770,20 @@ class ApiHelp extends ApiBase {
        }
 
        public function getAllowedParams() {
-               return array(
-                       'modules' => array(
+               return [
+                       'modules' => [
                                ApiBase::PARAM_DFLT => 'main',
                                ApiBase::PARAM_ISMULTI => true,
-                       ),
+                       ],
                        'submodules' => false,
                        'recursivesubmodules' => false,
                        'wrap' => false,
                        'toc' => false,
-               );
+               ];
        }
 
        protected function getExamplesMessages() {
-               return array(
+               return [
                        'action=help'
                                => 'apihelp-help-example-main',
                        'action=help&modules=query&submodules=1'
@@ -794,14 +794,14 @@ class ApiHelp extends ApiBase {
                                => 'apihelp-help-example-help',
                        'action=help&modules=query+info|query+categorymembers'
                                => 'apihelp-help-example-query',
-               );
+               ];
        }
 
        public function getHelpUrls() {
-               return array(
+               return [
                        'https://www.mediawiki.org/wiki/API:Main_page',
                        'https://www.mediawiki.org/wiki/API:FAQ',
                        'https://www.mediawiki.org/wiki/API:Quick_start_guide',
-               );
+               ];
        }
 }