mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData
synced 2024-11-14 11:15:39 +00:00
Merge "API: Identify missing and no-TemplateData pages in the response"
This commit is contained in:
commit
069e9997be
|
@ -52,12 +52,32 @@ class ApiTemplateData extends ApiBase {
|
|||
$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;
|
||||
}
|
||||
|
||||
$resp = [];
|
||||
|
||||
if ( $legacyMode ) {
|
||||
$this->addDeprecation(
|
||||
'apiwarn-templatedata-deprecation-legacyMode', 'action=templatedata&!doNotIgnoreMissingTitles'
|
||||
);
|
||||
} else {
|
||||
foreach ( $missingTitles as $missingTitleId => $missingTitle ) {
|
||||
$resp[ $missingTitleId ] = [ 'title' => $missingTitle, 'missing' => true ];
|
||||
}
|
||||
|
||||
foreach ( $titles as $titleId => $title ) {
|
||||
$resp[ $titleId ] = [ 'title' => $title, 'notemplatedata' => true ];
|
||||
}
|
||||
}
|
||||
|
||||
if ( count( $titles ) ) {
|
||||
$db = $this->getDB();
|
||||
$res = $db->select( 'page_props',
|
||||
[ 'pp_page', 'pp_value' ], [
|
||||
|
@ -68,8 +88,6 @@ class ApiTemplateData extends ApiBase {
|
|||
[ 'ORDER BY', 'pp_page' ]
|
||||
);
|
||||
|
||||
$resp = [];
|
||||
|
||||
foreach ( $res as $row ) {
|
||||
$rawData = $row->pp_value;
|
||||
$tdb = TemplateDataBlob::newFromDatabase( $rawData );
|
||||
|
@ -99,9 +117,15 @@ class ApiTemplateData extends ApiBase {
|
|||
$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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ApiResult::setArrayType( $resp, 'kvp', 'id' );
|
||||
|
@ -122,6 +146,7 @@ class ApiTemplateData extends ApiBase {
|
|||
|
||||
public function getAllowedParams( $flags = 0 ) {
|
||||
return $this->getPageSet()->getFinalParams( $flags ) + [
|
||||
'doNotIgnoreMissingTitles' => false,
|
||||
'lang' => null
|
||||
];
|
||||
}
|
||||
|
@ -131,8 +156,10 @@ class ApiTemplateData extends ApiBase {
|
|||
*/
|
||||
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',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -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.",
|
||||
|
|
|
@ -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\")",
|
||||
|
|
Loading…
Reference in a new issue