Merge "Add CollationFa"
[lhc/web/wiklou.git] / includes / api / ApiExpandTemplates.php
index 8a63070..6f7cf65 100644 (file)
@@ -34,7 +34,7 @@
 class ApiExpandTemplates extends ApiBase {
 
        public function execute() {
-               // Cache may vary on $wgUser because ParserOptions gets data from it
+               // Cache may vary on the user because ParserOptions gets data from it
                $this->getMain()->setCacheMode( 'anon-public-user-private' );
 
                // Get parameters
@@ -42,12 +42,10 @@ class ApiExpandTemplates extends ApiBase {
                $this->requireMaxOneParameter( $params, 'prop', 'generatexml' );
 
                if ( $params['prop'] === null ) {
-                       $this->logFeatureUsage( 'action=expandtemplates&!prop' );
-                       $this->setWarning( 'Because no values have been specified for the prop parameter, a ' .
-                               'legacy format has been used for the output. This format is deprecated, and in ' .
-                               'the future, a default value will be set for the prop parameter, causing the new' .
-                               'format to always be used.' );
-                       $prop = array();
+                       $this->addDeprecation(
+                               'apiwarn-deprecation-expandtemplates-prop', 'action=expandtemplates&!prop'
+                       );
+                       $prop = [];
                } else {
                        $prop = array_flip( $params['prop'] );
                }
@@ -57,13 +55,13 @@ class ApiExpandTemplates extends ApiBase {
                if ( $revid !== null ) {
                        $rev = Revision::newFromId( $revid );
                        if ( !$rev ) {
-                               $this->dieUsage( "There is no revision ID $revid", 'missingrev' );
+                               $this->dieWithError( [ 'apierror-nosuchrevid', $revid ] );
                        }
                        $title_obj = $rev->getTitle();
                } else {
                        $title_obj = Title::newFromText( $params['title'] );
                        if ( !$title_obj || $title_obj->isExternal() ) {
-                               $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
+                               $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['title'] ) ] );
                        }
                }
 
@@ -77,12 +75,17 @@ class ApiExpandTemplates extends ApiBase {
                        $options->setRemoveComments( false );
                }
 
-               $retval = array();
+               $reset = null;
+               $suppressCache = false;
+               Hooks::run( 'ApiMakeParserOptions',
+                       [ $options, $title_obj, $params, $this, &$reset, &$suppressCache ] );
+
+               $retval = [];
 
                if ( isset( $prop['parsetree'] ) || $params['generatexml'] ) {
                        $wgParser->startExternalParse( $title_obj, $options, Parser::OT_PREPROCESS );
                        $dom = $wgParser->preprocessToDom( $params['text'] );
-                       if ( is_callable( array( $dom, 'saveXML' ) ) ) {
+                       if ( is_callable( [ $dom, 'saveXML' ] ) ) {
                                $xml = $dom->saveXML();
                        } else {
                                $xml = $dom->__toString();
@@ -93,7 +96,7 @@ class ApiExpandTemplates extends ApiBase {
                        } else {
                                // the old way
                                $result->addValue( null, 'parsetree', $xml );
-                               $result->addValue( null, ApiResult::META_BC_SUBELEMENTS, array( 'parsetree' ) );
+                               $result->addValue( null, ApiResult::META_BC_SUBELEMENTS, [ 'parsetree' ] );
                        }
                }
 
@@ -111,11 +114,11 @@ class ApiExpandTemplates extends ApiBase {
                                if ( isset( $prop['categories'] ) ) {
                                        $categories = $p_output->getCategories();
                                        if ( $categories ) {
-                                               $categories_result = array();
+                                               $categories_result = [];
                                                foreach ( $categories as $category => $sortkey ) {
-                                                       $entry = array();
+                                                       $entry = [];
                                                        $entry['sortkey'] = $sortkey;
-                                                       ApiResult::setContentValue( $entry, 'category', $category );
+                                                       ApiResult::setContentValue( $entry, 'category', (string)$category );
                                                        $categories_result[] = $entry;
                                                }
                                                ApiResult::setIndexedTagName( $categories_result, 'category' );
@@ -156,30 +159,28 @@ class ApiExpandTemplates extends ApiBase {
                                }
                                if ( isset( $prop['modules'] ) &&
                                        !isset( $prop['jsconfigvars'] ) && !isset( $prop['encodedjsconfigvars'] ) ) {
-                                       $this->setWarning( "Property 'modules' was set but not 'jsconfigvars' " .
-                                               "or 'encodedjsconfigvars'. Configuration variables are necessary " .
-                                               "for proper module usage." );
+                                       $this->addWarning( 'apiwarn-moduleswithoutvars' );
                                }
                        }
                }
-               ApiResult::setSubelementsList( $retval, array( 'wikitext', 'parsetree' ) );
+               ApiResult::setSubelementsList( $retval, [ 'wikitext', 'parsetree' ] );
                $result->addValue( null, $this->getModuleName(), $retval );
        }
 
        public function getAllowedParams() {
-               return array(
-                       'title' => array(
+               return [
+                       'title' => [
                                ApiBase::PARAM_DFLT => 'API',
-                       ),
-                       'text' => array(
+                       ],
+                       'text' => [
                                ApiBase::PARAM_TYPE => 'text',
                                ApiBase::PARAM_REQUIRED => true,
-                       ),
-                       'revid' => array(
+                       ],
+                       'revid' => [
                                ApiBase::PARAM_TYPE => 'integer',
-                       ),
-                       'prop' => array(
-                               ApiBase::PARAM_TYPE => array(
+                       ],
+                       'prop' => [
+                               ApiBase::PARAM_TYPE => [
                                        'wikitext',
                                        'categories',
                                        'properties',
@@ -189,23 +190,23 @@ class ApiExpandTemplates extends ApiBase {
                                        'jsconfigvars',
                                        'encodedjsconfigvars',
                                        'parsetree',
-                               ),
+                               ],
                                ApiBase::PARAM_ISMULTI => true,
-                               ApiBase::PARAM_HELP_MSG_PER_VALUE => array(),
-                       ),
+                               ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
+                       ],
                        'includecomments' => false,
-                       'generatexml' => array(
+                       'generatexml' => [
                                ApiBase::PARAM_TYPE => 'boolean',
                                ApiBase::PARAM_DEPRECATED => true,
-                       ),
-               );
+                       ],
+               ];
        }
 
        protected function getExamplesMessages() {
-               return array(
+               return [
                        'action=expandtemplates&text={{Project:Sandbox}}'
                                => 'apihelp-expandtemplates-example-simple',
-               );
+               ];
        }
 
        public function getHelpUrls() {