jenkins-bot has submitted this change and it was merged.
Change subject: API: Add output of JS config vars to action=parse
......................................................................
API: Add output of JS config vars to action=parse
Modules will sometimes depend on these.
Bug: T67015
Change-Id: Ida3fd5f8808202892001f66c4a534c1725e769a6
(cherry picked from commit 47eab0bacba49f83600baff88cb7c41a56357edb)
---
M includes/api/ApiParse.php
M includes/api/i18n/en.json
M includes/api/i18n/qqq.json
3 files changed, 108 insertions(+), 3 deletions(-)
Approvals:
Manybubbles: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php
index a917c54..4bb99d5 100644
--- a/includes/api/ApiParse.php
+++ b/includes/api/ApiParse.php
@@ -353,6 +353,17 @@
$result_array['modulemessages'] = array_values(
array_unique( $p_result->getModuleMessages() ) );
}
+ if ( isset( $prop['jsconfigvars'] ) ) {
+ $result_array['jsconfigvars'] =
$this->formatJsConfigVars( $p_result->getJsConfigVars() );
+ }
+
+ if ( isset( $prop['encodedjsconfigvars'] ) ) {
+ $result_array['encodedjsconfigvars'] =
FormatJson::encode(
+ $p_result->getJsConfigVars(), false,
FormatJson::ALL_OK
+ );
+ $result_array[ApiResult::META_SUBELEMENTS][] =
'encodedjsconfigvars';
+ }
+
if ( isset( $prop['indicators'] ) ) {
$result_array['indicators'] =
(array)$p_result->getIndicators();
ApiResult::setArrayType( $result_array['indicators'],
'BCkvp', 'name' );
@@ -668,6 +679,53 @@
return $result;
}
+ private function formatJsConfigVars( $vars, $forceHash = true ) {
+ // Process subarrays and determine if this is a JS [] or {}
+ $hash = $forceHash;
+ $maxKey = -1;
+ $bools = array();
+ foreach ( $vars as $k => $v ) {
+ if ( is_array( $v ) || is_object( $v ) ) {
+ $vars[$k] = $this->formatJsConfigVars(
(array)$v, false );
+ } elseif ( is_bool( $v ) ) {
+ // Better here to use real bools even in BC
formats
+ $bools[] = $k;
+ }
+ if ( is_string( $k ) ) {
+ $hash = true;
+ } elseif ( $k > $maxKey ) {
+ $maxKey = $k;
+ }
+ }
+ if ( !$hash && $maxKey !== count( $vars ) - 1 ) {
+ $hash = true;
+ }
+
+ // Get the list of keys we actually care about. Unfortunately,
we can't support
+ // certain keys that conflict with ApiResult metadata.
+ $keys = array_diff( array_keys( $vars ), array(
+ ApiResult::META_TYPE, ApiResult::META_PRESERVE_KEYS,
ApiResult::META_KVP_KEY_NAME,
+ ApiResult::META_INDEXED_TAG_NAME,
ApiResult::META_BC_BOOLS
+ ) );
+
+ // Set metadata appropriately
+ if ( $hash ) {
+ return array(
+ ApiResult::META_TYPE => 'kvp',
+ ApiResult::META_KVP_KEY_NAME => 'key',
+ ApiResult::META_PRESERVE_KEYS => $keys,
+ ApiResult::META_BC_BOOLS => $bools,
+ ApiResult::META_INDEXED_TAG_NAME => 'var',
+ ) + $vars;
+ } else {
+ return array(
+ ApiResult::META_TYPE => 'array',
+ ApiResult::META_BC_BOOLS => $bools,
+ ApiResult::META_INDEXED_TAG_NAME => 'value',
+ ) + $vars;
+ }
+ }
+
private function setIndexedTagNames( &$array, $mapping ) {
foreach ( $mapping as $key => $name ) {
if ( isset( $array[$key] ) ) {
@@ -708,13 +766,16 @@
'headitems',
'headhtml',
'modules',
+ 'jsconfigvars',
+ 'encodedjsconfigvars',
'indicators',
'iwlinks',
'wikitext',
'properties',
'limitreportdata',
'limitreporthtml',
- )
+ ),
+ ApiBase::PARAM_HELP_MSG_PER_VALUE => array(),
),
'pst' => false,
'onlypst' => false,
diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json
index 1e88909..359994a 100644
--- a/includes/api/i18n/en.json
+++ b/includes/api/i18n/en.json
@@ -271,7 +271,29 @@
"apihelp-parse-param-pageid": "Parse the content of this page.
Overrides <var>$1page</var>.",
"apihelp-parse-param-redirects": "If <var>$1page</var> or
<var>$1pageid</var> is set to a redirect, resolve it.",
"apihelp-parse-param-oldid": "Parse the content of this revision.
Overrides <var>$1page</var> and <var>$1pageid</var>.",
- "apihelp-parse-param-prop": "Which pieces of information to
get:\n;text:Gives the parsed text of the wikitext.\n;langlinks:Gives the
language links in the parsed wikitext.\n;categories:Gives the categories in the
parsed wikitext.\n;categorieshtml:Gives the HTML version of the
categories.\n;links:Gives the internal links in the parsed
wikitext.\n;templates:Gives the templates in the parsed
wikitext.\n;images:Gives the images in the parsed
wikitext.\n;externallinks:Gives the external links in the parsed
wikitext.\n;sections:Gives the sections in the parsed wikitext.\n;revid:Adds
the revision ID of the parsed page.\n;displaytitle:Adds the title of the parsed
wikitext.\n;headitems:Gives items to put in the <head> of the
page.\n;headhtml:Gives parsed <head> of the page.\n;modules:Gives the
ResourceLoader modules used on the page.\n;indicators:Gives the HTML of page
status indicators used on the page.\n;iwlinks:Gives interwiki links in the
parsed wikitext.\n;wikitext:Gives the original wikitext that was
parsed.\n;properties:Gives various properties defined in the parsed
wikitext.\n;limitreportdata:Gives the limit report in a structured way. Gives
no data, when $1disablepp is set.\n;limitreporthtml:Gives the HTML version of
the limit report. Gives no data, when $1disablepp is set.",
+ "apihelp-parse-param-prop": "Which pieces of information to get:",
+ "apihelp-parse-paramvalue-prop-text": "Gives the parsed text of the
wikitext.",
+ "apihelp-parse-paramvalue-prop-langlinks": "Gives the language links in
the parsed wikitext.",
+ "apihelp-parse-paramvalue-prop-categories": "Gives the categories in
the parsed wikitext.",
+ "apihelp-parse-paramvalue-prop-categorieshtml": "Gives the HTML version
of the categories.",
+ "apihelp-parse-paramvalue-prop-links": "Gives the internal links in the
parsed wikitext.",
+ "apihelp-parse-paramvalue-prop-templates": "Gives the templates in the
parsed wikitext.",
+ "apihelp-parse-paramvalue-prop-images": "Gives the images in the parsed
wikitext.",
+ "apihelp-parse-paramvalue-prop-externallinks": "Gives the external
links in the parsed wikitext.",
+ "apihelp-parse-paramvalue-prop-sections": "Gives the sections in the
parsed wikitext.",
+ "apihelp-parse-paramvalue-prop-revid": "Adds the revision ID of the
parsed page.",
+ "apihelp-parse-paramvalue-prop-displaytitle": "Adds the title of the
parsed wikitext.",
+ "apihelp-parse-paramvalue-prop-headitems": "Gives items to put in the
<code><head></code> of the page.",
+ "apihelp-parse-paramvalue-prop-headhtml": "Gives parsed
<code><head></code> of the page.",
+ "apihelp-parse-paramvalue-prop-modules": "Gives the ResourceLoader
modules used on the page.",
+ "apihelp-parse-paramvalue-prop-jsconfigvars": "Gives the JavaScript
configuration variables specific to the page.",
+ "apihelp-parse-paramvalue-prop-encodedjsconfigvars": "Gives the
JavaScript configuration variables specific to the page as a JSON string.",
+ "apihelp-parse-paramvalue-prop-indicators": "Gives the HTML of page
status indicators used on the page.",
+ "apihelp-parse-paramvalue-prop-iwlinks": "Gives interwiki links in the
parsed wikitext.",
+ "apihelp-parse-paramvalue-prop-wikitext": "Gives the original wikitext
that was parsed.",
+ "apihelp-parse-paramvalue-prop-properties": "Gives various properties
defined in the parsed wikitext.",
+ "apihelp-parse-paramvalue-prop-limitreportdata": "Gives the limit
report in a structured way. Gives no data, when <var>$1disablepp</var> is set.",
+ "apihelp-parse-paramvalue-prop-limitreporthtml": "Gives the HTML
version of the limit report. Gives no data, when <var>$1disablepp</var> is
set.",
"apihelp-parse-param-pst": "Do a pre-save transform on the input before
parsing it. Only valid when used with text.",
"apihelp-parse-param-onlypst": "Do a pre-save transform (PST) on the
input, but don't parse it. Returns the same wikitext, after a PST has been
applied. Only valid when used with <var>$1text</var>.",
"apihelp-parse-param-effectivelanglinks": "Includes language links
supplied by extensions (for use with <kbd>$1prop=langlinks</kbd>).",
diff --git a/includes/api/i18n/qqq.json b/includes/api/i18n/qqq.json
index 876f598..24b63e0 100644
--- a/includes/api/i18n/qqq.json
+++ b/includes/api/i18n/qqq.json
@@ -250,7 +250,29 @@
"apihelp-parse-param-pageid": "{{doc-apihelp-param|parse|pageid}}",
"apihelp-parse-param-redirects":
"{{doc-apihelp-param|parse|redirects}}",
"apihelp-parse-param-oldid": "{{doc-apihelp-param|parse|oldid}}",
- "apihelp-parse-param-prop": "{{doc-apihelp-param|parse|prop}}",
+ "apihelp-parse-param-prop":
"{{doc-apihelp-param|parse|prop|paramvalues=1}}",
+ "apihelp-parse-paramvalue-prop-text":
"{{doc-apihelp-paramvalue|parse|prop|text}}",
+ "apihelp-parse-paramvalue-prop-langlinks":
"{{doc-apihelp-paramvalue|parse|prop|langlinks}}",
+ "apihelp-parse-paramvalue-prop-categories":
"{{doc-apihelp-paramvalue|parse|prop|categories}}",
+ "apihelp-parse-paramvalue-prop-categorieshtml":
"{{doc-apihelp-paramvalue|parse|prop|categorieshtml}}",
+ "apihelp-parse-paramvalue-prop-links":
"{{doc-apihelp-paramvalue|parse|prop|links}}",
+ "apihelp-parse-paramvalue-prop-templates":
"{{doc-apihelp-paramvalue|parse|prop|templates}}",
+ "apihelp-parse-paramvalue-prop-images":
"{{doc-apihelp-paramvalue|parse|prop|images}}",
+ "apihelp-parse-paramvalue-prop-externallinks":
"{{doc-apihelp-paramvalue|parse|prop|externallinks}}",
+ "apihelp-parse-paramvalue-prop-sections":
"{{doc-apihelp-paramvalue|parse|prop|sections}}",
+ "apihelp-parse-paramvalue-prop-revid":
"{{doc-apihelp-paramvalue|parse|prop|revid}}",
+ "apihelp-parse-paramvalue-prop-displaytitle":
"{{doc-apihelp-paramvalue|parse|prop|displaytitle}}",
+ "apihelp-parse-paramvalue-prop-headitems":
"{{doc-apihelp-paramvalue|parse|prop|headitems}}",
+ "apihelp-parse-paramvalue-prop-headhtml":
"{{doc-apihelp-paramvalue|parse|prop|headhtml}}",
+ "apihelp-parse-paramvalue-prop-modules":
"{{doc-apihelp-paramvalue|parse|prop|modules}}",
+ "apihelp-parse-paramvalue-prop-jsconfigvars":
"{{doc-apihelp-paramvalue|parse|prop|jsconfigvars}}",
+ "apihelp-parse-paramvalue-prop-encodedjsconfigvars":
"{{doc-apihelp-paramvalue|parse|prop|encodedjsconfigvars}}",
+ "apihelp-parse-paramvalue-prop-indicators":
"{{doc-apihelp-paramvalue|parse|prop|indicators}}",
+ "apihelp-parse-paramvalue-prop-iwlinks":
"{{doc-apihelp-paramvalue|parse|prop|iwlinks}}",
+ "apihelp-parse-paramvalue-prop-wikitext":
"{{doc-apihelp-paramvalue|parse|prop|wikitext}}",
+ "apihelp-parse-paramvalue-prop-properties":
"{{doc-apihelp-paramvalue|parse|prop|properties}}",
+ "apihelp-parse-paramvalue-prop-limitreportdata":
"{{doc-apihelp-paramvalue|parse|prop|limitreportdata}}",
+ "apihelp-parse-paramvalue-prop-limitreporthtml":
"{{doc-apihelp-paramvalue|parse|prop|limitreporthtml}}",
"apihelp-parse-param-pst": "{{doc-apihelp-param|parse|pst}}",
"apihelp-parse-param-onlypst": "{{doc-apihelp-param|parse|onlypst}}",
"apihelp-parse-param-effectivelanglinks":
"{{doc-apihelp-param|parse|effectivelanglinks}}",
--
To view, visit https://gerrit.wikimedia.org/r/210065
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ida3fd5f8808202892001f66c4a534c1725e769a6
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: wmf/1.26wmf5
Gerrit-Owner: Manybubbles <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: Manybubbles <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits