jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/349368 )
Change subject: API: Identify missing and no-TemplateData pages in the response
......................................................................
API: Identify missing and no-TemplateData pages in the response
Change-Id: I7905502d0c419a04e4487095214634f1513b461c
---
M api/ApiTemplateData.php
M i18n/en.json
M i18n/qqq.json
3 files changed, 73 insertions(+), 40 deletions(-)
Approvals:
Bartosz Dziewoński: Looks good to me, approved
jenkins-bot: Verified
diff --git a/api/ApiTemplateData.php b/api/ApiTemplateData.php
index d66ae1f..d614263 100644
--- a/api/ApiTemplateData.php
+++ b/api/ApiTemplateData.php
@@ -52,56 +52,80 @@
$pageSet = $this->getPageSet();
$pageSet->execute();
$titles = $pageSet->getGoodTitles(); // page_id => Title object
+ $missingTitles = $pageSet->getMissingTitles(); // page_id =>
Title object
- if ( !count( $titles ) ) {
+ $legacyMode = !$this->getParameter( 'doNotIgnoreMissingTitles'
);
+
+ if ( !count( $titles ) && ( $legacyMode || !count(
$missingTitles ) ) ) {
$result->addValue( null, 'pages', (object) [] );
return;
}
- $db = $this->getDB();
- $res = $db->select( 'page_props',
- [ 'pp_page', 'pp_value' ], [
- 'pp_page' => array_keys( $titles ),
- 'pp_propname' => 'templatedata'
- ],
- __METHOD__,
- [ 'ORDER BY', 'pp_page' ]
- );
-
$resp = [];
- foreach ( $res as $row ) {
- $rawData = $row->pp_value;
- $tdb = TemplateDataBlob::newFromDatabase( $rawData );
- $status = $tdb->getStatus();
-
- if ( !$status->isOK() ) {
- $this->dieWithError(
- [ 'apierror-templatedata-corrupt',
intval( $row->pp_page ), $status->getMessage() ]
- );
+ if ( $legacyMode ) {
+ $this->addDeprecation(
+ 'apiwarn-templatedata-deprecation-legacyMode',
'action=templatedata&!doNotIgnoreMissingTitles'
+ );
+ } else {
+ foreach ( $missingTitles as $missingTitleId =>
$missingTitle ) {
+ $resp[ $missingTitleId ] = [ 'title' =>
$missingTitle, 'missing' => true ];
}
- if ( $langCode ) {
- $data = $tdb->getDataInLanguage( $langCode );
- } else {
- $data = $tdb->getData();
+ foreach ( $titles as $titleId => $title ) {
+ $resp[ $titleId ] = [ 'title' => $title,
'notemplatedata' => true ];
}
+ }
- // HACK: don't let ApiResult's formatversion=1
compatibility layer mangle our booleans
- // to empty strings / absent properties
- foreach ( $data->params as &$param ) {
- $param->{ApiResult::META_BC_BOOLS} = [
'required', 'suggested', 'deprecated' ];
+ if ( count( $titles ) ) {
+ $db = $this->getDB();
+ $res = $db->select( 'page_props',
+ [ 'pp_page', 'pp_value' ], [
+ 'pp_page' => array_keys( $titles ),
+ 'pp_propname' => 'templatedata'
+ ],
+ __METHOD__,
+ [ 'ORDER BY', 'pp_page' ]
+ );
+
+ foreach ( $res as $row ) {
+ $rawData = $row->pp_value;
+ $tdb = TemplateDataBlob::newFromDatabase(
$rawData );
+ $status = $tdb->getStatus();
+
+ if ( !$status->isOK() ) {
+ $this->dieWithError(
+ [
'apierror-templatedata-corrupt', intval( $row->pp_page ), $status->getMessage()
]
+ );
+ }
+
+ if ( $langCode ) {
+ $data = $tdb->getDataInLanguage(
$langCode );
+ } else {
+ $data = $tdb->getData();
+ }
+
+ // HACK: don't let ApiResult's formatversion=1
compatibility layer mangle our booleans
+ // to empty strings / absent properties
+ foreach ( $data->params as &$param ) {
+ $param->{ApiResult::META_BC_BOOLS} = [
'required', 'suggested', 'deprecated' ];
+ }
+ unset( $param );
+
+ $data->params->{ApiResult::META_TYPE} = 'kvp';
+ $data->params->{ApiResult::META_KVP_KEY_NAME} =
'key';
+
$data->params->{ApiResult::META_INDEXED_TAG_NAME} = 'param';
+ ApiResult::setIndexedTagName(
$data->paramOrder, 'p' );
+
+ if ( count( $data ) ) {
+ if ( !$legacyMode ) {
+ unset(
$resp[$row->pp_page]['notemplatedata'] );
+ } else {
+ $resp[ $row->pp_page ] = [
'title' => $titles[ $row->pp_page ] ];
+ }
+ $resp[$row->pp_page] += (array) $data;
+ }
}
- unset( $param );
-
- $data->params->{ApiResult::META_TYPE} = 'kvp';
- $data->params->{ApiResult::META_KVP_KEY_NAME} = 'key';
- $data->params->{ApiResult::META_INDEXED_TAG_NAME} =
'param';
- ApiResult::setIndexedTagName( $data->paramOrder, 'p' );
-
- $resp[$row->pp_page] = [
- 'title' => strval( $titles[$row->pp_page] ),
- ] + (array) $data;
}
ApiResult::setArrayType( $resp, 'kvp', 'id' );
@@ -122,6 +146,7 @@
public function getAllowedParams( $flags = 0 ) {
return $this->getPageSet()->getFinalParams( $flags ) + [
+ 'doNotIgnoreMissingTitles' => false,
'lang' => null
];
}
@@ -131,8 +156,10 @@
*/
protected function getExamplesMessages() {
return [
-
'action=templatedata&titles=Template:Stub|Template:Example'
+
'action=templatedata&titles=Template:Stub|Template:Example&doNotIgnoreMissingTitles=1'
=> 'apihelp-templatedata-example-1',
+
'action=templatedata&titles=Template:Stub|Template:Example&doNotIgnoreMissingTitles=0'
+ => 'apihelp-templatedata-example-2',
];
}
diff --git a/i18n/en.json b/i18n/en.json
index 84dd7eb..f546de3 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -8,9 +8,12 @@
]
},
"apihelp-templatedata-description": "Fetch data stored by the
TemplateData extension.",
- "apihelp-templatedata-example-1": "Return data for [[Template:Stub]]
and [[Template:Example]]",
+ "apihelp-templatedata-example-1": "Return TemplateData for
[[Template:Stub]] and [[Template:Example]], with results if the templates do
not exist or do exist but have no TemplateData",
+ "apihelp-templatedata-example-2": "Return TemplateData for
[[Template:Stub]] and [[Template:Example]], with no results if the templates do
not exist or do exist but have no TemplateData",
+ "apihelp-templatedata-param-doNotIgnoreMissingTitles": "Return data
about titles even if they are missing or lack TemplateData. By default (for
backwards compatibility) titles are only returned if they exist and have
TemplateData.",
"apihelp-templatedata-param-lang": "Return localized values in this
language. By default all available translations are returned.",
"apierror-templatedata-corrupt": "Page #$1 templatedata contains
invalid data: $2",
+ "apiwarn-templatedata-deprecation-legacyMode": "The default output will
change to include missing titles in the future. Please specify
<kbd>doNotIgnoreMissingTitles=1</kbd> explicitly.",
"apiwarn-templatedata-deprecation-format": "The default output format
will change to <kbd>jsonfm</kbd> in the future. Please specify
<kbd>format=json</kbd> explicitly.",
"templatedata-desc": "Implement data storage for template parameters
(using JSON)",
"templatedata-doc-desc-empty": "No description.",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 574cbc2..19ddcd5 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -20,9 +20,12 @@
},
"apihelp-templatedata-description":
"{{doc-apihelp-description|templatedata}}",
"apihelp-templatedata-example-1":
"{{doc-apihelp-example|templatedata}}",
+ "apihelp-templatedata-example-2":
"{{doc-apihelp-example|templatedata}}",
+ "apihelp-templatedata-param-doNotIgnoreMissingTitles":
"{{doc-apihelp-param|templatedata|doNotIgnoreMissingTitles}}",
"apihelp-templatedata-param-lang":
"{{doc-apihelp-param|templatedata|lang}}",
"apierror-templatedata-corrupt": "{{doc-apierror}}\n\nParameters:\n* $1
- Page ID number\n* $2 - Localized message with further information.",
"apiwarn-templatedata-deprecation-format": "{{doc-apierror}}",
+ "apiwarn-templatedata-deprecation-legacyMode": "{{doc-apierror}}",
"templatedata-desc": "{{desc|name=Template
Data|url=https://www.mediawiki.org/wiki/Extension:TemplateData}}",
"templatedata-doc-desc-empty": "Displayed when a template has no
description (should be a valid sentence).\n{{Identical|No description}}",
"templatedata-doc-format-block": "Use block formatting of the template
parameters in wikitext, i.e.\n\n<pre><nowiki>{{Template name\n| p1 = v1\n| p2 =
v2\n}}</nowiki></pre>\n\nas opposed to <nowiki>{{Template
name|p1=v1|p2=v2}}</nowiki> (\"inline\")",
--
To view, visit https://gerrit.wikimedia.org/r/349368
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I7905502d0c419a04e4487095214634f1513b461c
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/TemplateData
Gerrit-Branch: master
Gerrit-Owner: Jforrester <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: DLynch <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits