mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData
synced 2024-12-01 02:46:15 +00:00
Merge "Don't restrict format parameter in the API"
This commit is contained in:
commit
2b5546d6cb
|
@ -12,21 +12,21 @@
|
||||||
* @todo Support continuation (see I1a6e51cd)
|
* @todo Support continuation (see I1a6e51cd)
|
||||||
*/
|
*/
|
||||||
class ApiTemplateData extends ApiBase {
|
class ApiTemplateData extends ApiBase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override built-in handling of format parameter.
|
* For backwards compatibility, this module needs to output format=json when
|
||||||
* Only JSON is supported.
|
* no format is specified.
|
||||||
*
|
* @return ApiFormatBase|null
|
||||||
* @return ApiFormatBase
|
|
||||||
*/
|
*/
|
||||||
public function getCustomPrinter() {
|
public function getCustomPrinter() {
|
||||||
$params = $this->extractRequestParams();
|
if ( $this->getMain()->getVal( 'format' ) === null ) {
|
||||||
$format = $params['format'];
|
$this->setWarning(
|
||||||
$allowed = array( 'json', 'jsonfm' );
|
"The default output format will change to jsonfm in the future." .
|
||||||
if ( in_array( $format, $allowed ) ) {
|
" Please specify format=json explicitly."
|
||||||
return $this->getMain()->createPrinterByName( $format );
|
);
|
||||||
|
$this->logFeatureUsage( 'action=templatedata&!format' );
|
||||||
|
return $this->getMain()->createPrinterByName( 'json' );
|
||||||
}
|
}
|
||||||
return $this->getMain()->createPrinterByName( $allowed[0] );
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,6 +97,11 @@ class ApiTemplateData extends ApiBase {
|
||||||
$param->{ApiResult::META_BC_BOOLS} = array( 'required', 'suggested', 'deprecated' );
|
$param->{ApiResult::META_BC_BOOLS} = array( 'required', 'suggested', 'deprecated' );
|
||||||
}
|
}
|
||||||
unset( $param );
|
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] = array(
|
$resp[$row->pp_page] = array(
|
||||||
|
@ -104,6 +109,9 @@ class ApiTemplateData extends ApiBase {
|
||||||
) + (array) $data;
|
) + (array) $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ApiResult::setArrayType( $resp, 'kvp', 'id' );
|
||||||
|
ApiResult::setIndexedTagName( $resp, 'page' );
|
||||||
|
|
||||||
// Set top level element
|
// Set top level element
|
||||||
$result->addValue( null, 'pages', (object) $resp );
|
$result->addValue( null, 'pages', (object) $resp );
|
||||||
|
|
||||||
|
@ -119,10 +127,6 @@ class ApiTemplateData extends ApiBase {
|
||||||
|
|
||||||
public function getAllowedParams( $flags = 0 ) {
|
public function getAllowedParams( $flags = 0 ) {
|
||||||
return $this->getPageSet()->getFinalParams( $flags ) + array(
|
return $this->getPageSet()->getFinalParams( $flags ) + array(
|
||||||
'format' => array(
|
|
||||||
ApiBase::PARAM_DFLT => 'json',
|
|
||||||
ApiBase::PARAM_TYPE => array( 'json', 'jsonfm' ),
|
|
||||||
),
|
|
||||||
'lang' => null
|
'lang' => null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -132,7 +136,6 @@ class ApiTemplateData extends ApiBase {
|
||||||
*/
|
*/
|
||||||
public function getParamDescription() {
|
public function getParamDescription() {
|
||||||
return $this->getPageSet()->getParamDescription() + array(
|
return $this->getPageSet()->getParamDescription() + array(
|
||||||
'format' => 'The format of the output',
|
|
||||||
'lang' => 'Return localized values in this language (by default all available' .
|
'lang' => 'Return localized values in this language (by default all available' .
|
||||||
' translations are returned)',
|
' translations are returned)',
|
||||||
);
|
);
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
},
|
},
|
||||||
"apihelp-templatedata-description": "Fetch data stored by the TemplateData extension.",
|
"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 data for [[Template:Stub]] and [[Template:Example]]",
|
||||||
"apihelp-templatedata-param-format": "The format of the output.",
|
|
||||||
"apihelp-templatedata-param-lang": "Return localized values in this language. By default all available translations are returned.",
|
"apihelp-templatedata-param-lang": "Return localized values in this language. By default all available translations are returned.",
|
||||||
"templatedata-desc": "Implement data storage for template parameters (using JSON)",
|
"templatedata-desc": "Implement data storage for template parameters (using JSON)",
|
||||||
"templatedata-doc-desc-empty": "No description.",
|
"templatedata-doc-desc-empty": "No description.",
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
},
|
},
|
||||||
"apihelp-templatedata-description": "{{doc-apihelp-description|templatedata}}",
|
"apihelp-templatedata-description": "{{doc-apihelp-description|templatedata}}",
|
||||||
"apihelp-templatedata-example-1": "{{doc-apihelp-example|templatedata}}",
|
"apihelp-templatedata-example-1": "{{doc-apihelp-example|templatedata}}",
|
||||||
"apihelp-templatedata-param-format": "{{doc-apihelp-param|templatedata|format}}",
|
|
||||||
"apihelp-templatedata-param-lang": "{{doc-apihelp-param|templatedata|lang}}",
|
"apihelp-templatedata-param-lang": "{{doc-apihelp-param|templatedata|lang}}",
|
||||||
"templatedata-desc": "{{desc|name=Template Data|url=https://www.mediawiki.org/wiki/Extension:TemplateData}}",
|
"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-desc-empty": "Displayed when a template has no description (should be a valid sentence).\n{{Identical|No description}}",
|
||||||
|
|
Loading…
Reference in a new issue