X-Git-Url: http://git.cyclocoop.org/%22.%24image2.%22?a=blobdiff_plain;f=includes%2Fapi%2FApiExpandTemplates.php;h=6611a09d0b0e0d22f5501a8aaea63fb880b113bb;hb=6e9b4f0e9ce4ccd6089c18b205065ef7fa077484;hp=be1a695f8b048478c57c68bd18ad65177e4cdac0;hpb=7f1df682b62457e267831ec6527ca4728723caef;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiExpandTemplates.php b/includes/api/ApiExpandTemplates.php index be1a695f8b..6611a09d0b 100644 --- a/includes/api/ApiExpandTemplates.php +++ b/includes/api/ApiExpandTemplates.php @@ -47,7 +47,7 @@ class ApiExpandTemplates extends ApiBase { '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(); + $prop = []; } else { $prop = array_flip( $params['prop'] ); } @@ -63,7 +63,7 @@ class ApiExpandTemplates extends ApiBase { } else { $title_obj = Title::newFromText( $params['title'] ); if ( !$title_obj || $title_obj->isExternal() ) { - $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); + $this->dieUsageMsg( [ 'invalidtitle', $params['title'] ] ); } } @@ -77,16 +77,12 @@ class ApiExpandTemplates extends ApiBase { $options->setRemoveComments( false ); } - $retval = array(); + $retval = []; if ( isset( $prop['parsetree'] ) || $params['generatexml'] ) { - if ( !isset( $prop['parsetree'] ) ) { - $this->logFeatureUsage( 'action=expandtemplates&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(); @@ -97,7 +93,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,14 +107,15 @@ class ApiExpandTemplates extends ApiBase { // the old way ApiResult::setContentValue( $retval, 'wikitext', $wikitext ); } else { + $p_output = $wgParser->getOutput(); if ( isset( $prop['categories'] ) ) { - $categories = $wgParser->getOutput()->getCategories(); + $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' ); @@ -126,7 +123,7 @@ class ApiExpandTemplates extends ApiBase { } } if ( isset( $prop['properties'] ) ) { - $properties = $wgParser->getOutput()->getProperties(); + $properties = $p_output->getProperties(); if ( $properties ) { ApiResult::setArrayType( $properties, 'BCkvp', 'name' ); ApiResult::setIndexedTagName( $properties, 'property' ); @@ -142,48 +139,73 @@ class ApiExpandTemplates extends ApiBase { if ( isset( $prop['wikitext'] ) ) { $retval['wikitext'] = $wikitext; } + if ( isset( $prop['modules'] ) ) { + $retval['modules'] = array_values( array_unique( $p_output->getModules() ) ); + $retval['modulescripts'] = array_values( array_unique( $p_output->getModuleScripts() ) ); + $retval['modulestyles'] = array_values( array_unique( $p_output->getModuleStyles() ) ); + } + if ( isset( $prop['jsconfigvars'] ) ) { + $retval['jsconfigvars'] = + ApiResult::addMetadataToResultVars( $p_output->getJsConfigVars() ); + } + if ( isset( $prop['encodedjsconfigvars'] ) ) { + $retval['encodedjsconfigvars'] = FormatJson::encode( + $p_output->getJsConfigVars(), false, FormatJson::ALL_OK + ); + $retval[ApiResult::META_SUBELEMENTS][] = 'encodedjsconfigvars'; + } + 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." ); + } } } - 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', 'volatile', 'ttl', + 'modules', + 'jsconfigvars', + 'encodedjsconfigvars', 'parsetree', - ), + ], ApiBase::PARAM_ISMULTI => true, - ), + 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() {