X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryLangLinks.php;h=8e155f281672cf2ac66bd22315744a5d34deb464;hb=ca895b7072b9d98a5b3abf8f2a46474095c16210;hp=a20b8553d7de1bdaf4e8066ec3241fa86cd59ebe;hpb=7d0aec16f7b4947e278562f4601b4816fc1ed8a6;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryLangLinks.php b/includes/api/ApiQueryLangLinks.php index a20b8553d7..8e155f2816 100644 --- a/includes/api/ApiQueryLangLinks.php +++ b/includes/api/ApiQueryLangLinks.php @@ -41,11 +41,18 @@ 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'] ) { + $prop = array( 'url' => 1 ); + } + $this->addFields( array( 'll_from', 'll_lang', @@ -104,12 +111,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 +137,7 @@ class ApiQueryLangLinks extends ApiQueryBase { } public function getAllowedParams() { + global $wgContLang; return array( 'limit' => array( ApiBase::PARAM_DFLT => 10, @@ -133,7 +147,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 +168,7 @@ class ApiQueryLangLinks extends ApiQueryBase { 'descending' ) ), + 'inlanguagecode' => $wgContLang->getCode(), ); } @@ -150,10 +176,18 @@ 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', + 'inlanguagecode' => 'Language code for localised language names', ); } @@ -165,19 +199,32 @@ class ApiQueryLangLinks extends ApiQueryBase { ApiBase::PROP_TYPE => 'string', ApiBase::PROP_NULLABLE => true ), + 'langname' => array( + ApiBase::PROP_TYPE => 'string', + ApiBase::PROP_NULLABLE => true + ), + 'autonym' => array( + ApiBase::PROP_TYPE => 'string', + ApiBase::PROP_NULLABLE => true + ), '*' => 'string' ) ); } public function getDescription() { - return 'Returns all interlanguage links from the given page(s)'; + return 'Returns all interlanguage links from the given page(s).'; } public function getPossibleErrors() { - return array_merge( parent::getPossibleErrors(), array( - array( 'missingparam', 'lang' ), - ) ); + return array_merge( parent::getPossibleErrors(), + $this->getRequireMaxOneParameterErrorMessages( + array( 'url', 'prop' ) + ), + array( + array( 'missingparam', 'lang' ), + ) + ); } public function getExamples() {