summaryrefslogtreecommitdiff
path: root/includes/api/ApiQueryLangLinks.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/api/ApiQueryLangLinks.php')
-rw-r--r--includes/api/ApiQueryLangLinks.php73
1 files changed, 45 insertions, 28 deletions
diff --git a/includes/api/ApiQueryLangLinks.php b/includes/api/ApiQueryLangLinks.php
index aa796e31..da05f273 100644
--- a/includes/api/ApiQueryLangLinks.php
+++ b/includes/api/ApiQueryLangLinks.php
@@ -31,7 +31,7 @@
*/
class ApiQueryLangLinks extends ApiQueryBase {
- public function __construct( $query, $moduleName ) {
+ public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'll' );
}
@@ -41,11 +41,19 @@ class ApiQueryLangLinks extends ApiQueryBase {
}
$params = $this->extractRequestParams();
+ $prop = array_flip( (array)$params['prop'] );
if ( isset( $params['title'] ) && !isset( $params['lang'] ) ) {
$this->dieUsageMsg( array( 'missingparam', 'lang' ) );
}
+ // Handle deprecated param
+ $this->requireMaxOneParameter( $params, 'url', 'prop' );
+ if ( $params['url'] ) {
+ $this->logFeatureUsage( 'prop=langlinks&llurl' );
+ $prop = array( 'url' => 1 );
+ }
+
$this->addFields( array(
'll_from',
'll_lang',
@@ -86,9 +94,9 @@ class ApiQueryLangLinks extends ApiQueryBase {
$this->addOption( 'ORDER BY', 'll_lang' . $sort );
} else {
$this->addOption( 'ORDER BY', array(
- 'll_from' . $sort,
- 'll_lang' . $sort
- ));
+ 'll_from' . $sort,
+ 'll_lang' . $sort
+ ) );
}
}
@@ -104,12 +112,18 @@ class ApiQueryLangLinks extends ApiQueryBase {
break;
}
$entry = array( 'lang' => $row->ll_lang );
- if ( $params['url'] ) {
+ if ( isset( $prop['url'] ) ) {
$title = Title::newFromText( "{$row->ll_lang}:{$row->ll_title}" );
if ( $title ) {
$entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
}
}
+ if ( isset( $prop['langname'] ) ) {
+ $entry['langname'] = Language::fetchLanguageName( $row->ll_lang, $params['inlanguagecode'] );
+ }
+ if ( isset( $prop['autonym'] ) ) {
+ $entry['autonym'] = Language::fetchLanguageName( $row->ll_lang );
+ }
ApiResult::setContent( $entry, $row->ll_title );
$fit = $this->addPageSubItem( $row->ll_from, $entry );
if ( !$fit ) {
@@ -124,6 +138,7 @@ class ApiQueryLangLinks extends ApiQueryBase {
}
public function getAllowedParams() {
+ global $wgContLang;
return array(
'limit' => array(
ApiBase::PARAM_DFLT => 10,
@@ -133,7 +148,18 @@ class ApiQueryLangLinks extends ApiQueryBase {
ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
'continue' => null,
- 'url' => false,
+ 'url' => array(
+ ApiBase::PARAM_DFLT => false,
+ ApiBase::PARAM_DEPRECATED => true,
+ ),
+ 'prop' => array(
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_TYPE => array(
+ 'url',
+ 'langname',
+ 'autonym',
+ )
+ ),
'lang' => null,
'title' => null,
'dir' => array(
@@ -143,6 +169,7 @@ class ApiQueryLangLinks extends ApiQueryBase {
'descending'
)
),
+ 'inlanguagecode' => $wgContLang->getCode(),
);
}
@@ -150,39 +177,29 @@ class ApiQueryLangLinks extends ApiQueryBase {
return array(
'limit' => 'How many langlinks to return',
'continue' => 'When more results are available, use this to continue',
- 'url' => 'Whether to get the full URL',
+ 'url' => "Whether to get the full URL (Cannot be used with {$this->getModulePrefix()}prop)",
+ 'prop' => array(
+ 'Which additional properties to get for each interlanguage link',
+ ' url - Adds the full URL',
+ ' langname - Adds the localised language name (best effort, use CLDR extension)',
+ " Use {$this->getModulePrefix()}inlanguagecode to control the language",
+ ' autonym - Adds the native language name',
+ ),
'lang' => 'Language code',
'title' => "Link to search for. Must be used with {$this->getModulePrefix()}lang",
'dir' => 'The direction in which to list',
- );
- }
-
- public function getResultProperties() {
- return array(
- '' => array(
- 'lang' => 'string',
- 'url' => array(
- ApiBase::PROP_TYPE => 'string',
- ApiBase::PROP_NULLABLE => true
- ),
- '*' => 'string'
- )
+ 'inlanguagecode' => 'Language code for localised language names',
);
}
public function getDescription() {
- return 'Returns all interlanguage links from the given page(s)';
- }
-
- public function getPossibleErrors() {
- return array_merge( parent::getPossibleErrors(), array(
- array( 'missingparam', 'lang' ),
- ) );
+ return 'Returns all interlanguage links from the given page(s).';
}
public function getExamples() {
return array(
- 'api.php?action=query&prop=langlinks&titles=Main%20Page&redirects=' => 'Get interlanguage links from the [[Main Page]]',
+ 'api.php?action=query&prop=langlinks&titles=Main%20Page&redirects='
+ => 'Get interlanguage links from the [[Main Page]]',
);
}