12use MediaWiki\Languages\LanguageNameUtils;
37 parent::__construct( $query, $moduleName,
'll' );
38 $this->languageNameUtils = $languageNameUtils;
39 $this->contentLanguage = $contentLanguage;
40 $this->urlUtils = $urlUtils;
45 if ( $pages === [] ) {
50 $prop = array_fill_keys( (array)$params[
'prop'],
true );
52 if ( isset( $params[
'title'] ) && !isset( $params[
'lang'] ) ) {
55 'apierror-invalidparammix-mustusewith',
65 if ( $params[
'url'] ) {
66 $prop = [
'url' => 1 ];
76 $this->
addWhereFld(
'll_from', array_keys( $pages ) );
77 if ( $params[
'continue'] !==
null ) {
80 $op = $params[
'dir'] ==
'descending' ?
'<=' :
'>=';
81 $this->
addWhere( $db->buildComparison( $op, [
82 'll_from' => $cont[0],
83 'll_lang' => $cont[1],
93 $sort = ( $params[
'dir'] ==
'descending' ?
' DESC' :
'' );
94 if ( isset( $params[
'lang'] ) ) {
96 if ( isset( $params[
'title'] ) ) {
99 $this->
addOption(
'ORDER BY',
'll_from' . $sort );
102 if ( count( $pages ) === 1 ) {
103 $this->
addOption(
'ORDER BY',
'll_lang' . $sort );
112 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
113 $res = $this->
select( __METHOD__ );
116 foreach ( $res as $row ) {
117 if ( ++$count > $params[
'limit'] ) {
125 $displayLanguageCode = $languageNameMap[ $row->ll_lang ] ?? $row->ll_lang;
128 $entry = [
'lang' => $displayLanguageCode ];
129 if ( isset( $prop[
'url'] ) ) {
130 $title = Title::newFromText(
"{$row->ll_lang}:{$row->ll_title}" );
132 $entry[
'url'] = (string)$this->urlUtils->expand( $title->getFullURL(),
PROTO_CURRENT );
136 if ( isset( $prop[
'langname'] ) ) {
137 $entry[
'langname'] = $this->languageNameUtils
138 ->getLanguageName( $displayLanguageCode, $params[
'inlanguagecode'] );
140 if ( isset( $prop[
'autonym'] ) ) {
141 $entry[
'autonym'] = $this->languageNameUtils->getLanguageName( $displayLanguageCode );
161 ParamValidator::PARAM_ISMULTI =>
true,
162 ParamValidator::PARAM_TYPE => [
172 ParamValidator::PARAM_DEFAULT =>
'ascending',
173 ParamValidator::PARAM_TYPE => [
178 'inlanguagecode' => $this->contentLanguage->getCode(),
180 ParamValidator::PARAM_DEFAULT => 10,
181 ParamValidator::PARAM_TYPE =>
'limit',
182 IntegerDef::PARAM_MIN => 1,
190 ParamValidator::PARAM_DEFAULT =>
false,
191 ParamValidator::PARAM_DEPRECATED =>
true,
198 $title = Title::newMainPage()->getPrefixedText();
199 $mp = rawurlencode( $title );
202 "action=query&prop=langlinks&titles={$mp}&redirects="
203 =>
'apihelp-query+langlinks-example-simple',
209 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Langlinks';
214class_alias( ApiQueryLangLinks::class,
'ApiQueryLangLinks' );
A class containing constants representing the names of configuration variables.
const InterlanguageLinkCodeMap
Name constant for the InterlanguageLinkCodeMap setting, for use with Config::get()