Export ParserOutput strategy keys for jsConfigVars
This allows Parsoid to properly merge jsconfigvars via the external API (ie, when Parsoid is run in 'standalone mode') when an extension uses the new-in-1.38 ParserOutput::appendJsConfigVar() method. Change-Id: I974d9ecfb4ca8b22361d25c4c70fc5e55c39d5ed
This commit is contained in:
parent
65b95dfa1e
commit
a3000c2972
5 changed files with 15 additions and 4 deletions
|
|
@ -186,8 +186,9 @@ class ApiExpandTemplates extends ApiBase {
|
|||
$retval['modulestyles'] = array_values( array_unique( $p_output->getModuleStyles() ) );
|
||||
}
|
||||
if ( isset( $prop['jsconfigvars'] ) ) {
|
||||
$showStrategyKeys = (bool)( $params['showstrategykeys'] );
|
||||
$retval['jsconfigvars'] =
|
||||
ApiResult::addMetadataToResultVars( $p_output->getJsConfigVars() );
|
||||
ApiResult::addMetadataToResultVars( $p_output->getJsConfigVars( $showStrategyKeys ) );
|
||||
}
|
||||
if ( isset( $prop['encodedjsconfigvars'] ) ) {
|
||||
$retval['encodedjsconfigvars'] = FormatJson::encode(
|
||||
|
|
@ -231,6 +232,7 @@ class ApiExpandTemplates extends ApiBase {
|
|||
ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
|
||||
],
|
||||
'includecomments' => false,
|
||||
'showstrategykeys' => false,
|
||||
'generatexml' => [
|
||||
ApiBase::PARAM_TYPE => 'boolean',
|
||||
ApiBase::PARAM_DEPRECATED => true,
|
||||
|
|
|
|||
|
|
@ -604,7 +604,8 @@ class ApiParse extends ApiBase {
|
|||
}
|
||||
|
||||
if ( isset( $prop['jsconfigvars'] ) ) {
|
||||
$jsconfigvars = $skin ? $outputPage->getJsConfigVars() : $p_result->getJsConfigVars();
|
||||
$showStrategyKeys = (bool)( $params['showstrategykeys'] );
|
||||
$jsconfigvars = $skin ? $outputPage->getJsConfigVars() : $p_result->getJsConfigVars( $showStrategyKeys );
|
||||
$result_array['jsconfigvars'] = ApiResult::addMetadataToResultVars( $jsconfigvars );
|
||||
}
|
||||
|
||||
|
|
@ -1059,6 +1060,7 @@ class ApiParse extends ApiBase {
|
|||
'disablelimitreport' => false,
|
||||
'disableeditsection' => false,
|
||||
'disablestylededuplication' => false,
|
||||
'showstrategykeys' => false,
|
||||
'generatexml' => [
|
||||
ApiBase::PARAM_DFLT => false,
|
||||
ApiBase::PARAM_HELP_MSG => [
|
||||
|
|
|
|||
|
|
@ -202,6 +202,7 @@
|
|||
"apihelp-expandtemplates-paramvalue-prop-parsetree": "The XML parse tree of the input.",
|
||||
"apihelp-expandtemplates-param-includecomments": "Whether to include HTML comments in the output.",
|
||||
"apihelp-expandtemplates-param-generatexml": "Generate XML parse tree (replaced by $1prop=parsetree).",
|
||||
"apihelp-expandtemplates-param-showstrategykeys": "Whether to include internal merge strategy information in jsconfigvars.",
|
||||
"apihelp-expandtemplates-example-simple": "Expand the wikitext <kbd><nowiki>{{Project:Sandbox}}</nowiki></kbd>.",
|
||||
|
||||
"apihelp-feedcontributions-summary": "Returns a user's contributions feed.",
|
||||
|
|
@ -416,6 +417,7 @@
|
|||
"apihelp-parse-param-disablepp": "Use <var>$1disablelimitreport</var> instead.",
|
||||
"apihelp-parse-param-disableeditsection": "Omit edit section links from the parser output.",
|
||||
"apihelp-parse-param-disablestylededuplication": "Do not deduplicate inline stylesheets in the parser output.",
|
||||
"apihelp-parse-param-showstrategykeys": "Whether to include internal merge strategy information in jsconfigvars.",
|
||||
"apihelp-parse-param-generatexml": "Generate XML parse tree (requires content model <code>$1</code>; replaced by <kbd>$2prop=parsetree</kbd>).",
|
||||
"apihelp-parse-param-preview": "Parse in preview mode.",
|
||||
"apihelp-parse-param-sectionpreview": "Parse in section preview mode (enables preview mode too).",
|
||||
|
|
|
|||
|
|
@ -204,6 +204,7 @@
|
|||
"apihelp-expandtemplates-paramvalue-prop-parsetree": "{{doc-apihelp-paramvalue|expandtemplates|prop|parsetree}}",
|
||||
"apihelp-expandtemplates-param-includecomments": "{{doc-apihelp-param|expandtemplates|includecomments}}",
|
||||
"apihelp-expandtemplates-param-generatexml": "{{doc-apihelp-param|expandtemplates|generatexml}}",
|
||||
"apihelp-expandtemplates-param-showstrategykeys": "{{doc-apihelp-param|expandtemplates|showstrategykeys}}",
|
||||
"apihelp-expandtemplates-example-simple": "{{doc-apihelp-example|expandtemplates}}",
|
||||
"apihelp-feedcontributions-summary": "{{doc-apihelp-summary|feedcontributions}}",
|
||||
"apihelp-feedcontributions-param-feedformat": "{{doc-apihelp-param|feedcontributions|feedformat}}",
|
||||
|
|
@ -401,6 +402,7 @@
|
|||
"apihelp-parse-param-disablepp": "{{doc-apihelp-param|parse|disablepp}}",
|
||||
"apihelp-parse-param-disableeditsection": "{{doc-apihelp-param|parse|disableeditsection}}",
|
||||
"apihelp-parse-param-disablestylededuplication": "{{doc-apihelp-param|parse|disablestylededuplication}}",
|
||||
"apihelp-parse-param-showstrategykeys": "{{doc-apihelp-param|parse|showstrategykeys}}",
|
||||
"apihelp-parse-param-generatexml": "{{doc-apihelp-param|parse|generatexml|params=* $1 - Value of the constant CONTENT_MODEL_WIKITEXT|paramstart=2}}",
|
||||
"apihelp-parse-param-preview": "{{doc-apihelp-param|parse|preview}}",
|
||||
"apihelp-parse-param-sectionpreview": "{{doc-apihelp-param|parse|sectionpreview}}",
|
||||
|
|
|
|||
|
|
@ -777,14 +777,17 @@ class ParserOutput extends CacheTime implements ContentMetadataCollector {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param bool $showStrategyKeys Defaults to false; if set to true will
|
||||
* expose the internal `MW_MERGE_STRATEGY_KEY` in the result. This
|
||||
* should only be used internally to allow safe merge of config vars.
|
||||
* @return array
|
||||
* @since 1.23
|
||||
*/
|
||||
public function getJsConfigVars() {
|
||||
public function getJsConfigVars( bool $showStrategyKeys = false ) {
|
||||
$result = $this->mJsConfigVars;
|
||||
// Don't expose the internal strategy key
|
||||
foreach ( $result as $key => &$value ) {
|
||||
if ( is_array( $value ) ) {
|
||||
if ( is_array( $value ) && !$showStrategyKeys ) {
|
||||
unset( $value[self::MW_MERGE_STRATEGY_KEY] );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue