48 parent::__construct( $query, $moduleName,
'll' );
49 $this->languageNameUtils = $languageNameUtils;
50 $this->contentLanguage = $contentLanguage;
51 $this->urlUtils = $urlUtils;
56 if ( $pages === [] ) {
61 $prop = array_fill_keys( (array)$params[
'prop'],
true );
63 if ( isset( $params[
'title'] ) && !isset( $params[
'lang'] ) ) {
66 'apierror-invalidparammix-mustusewith',
76 if ( $params[
'url'] ) {
77 $prop = [
'url' => 1 ];
87 $this->
addWhereFld(
'll_from', array_keys( $pages ) );
88 if ( $params[
'continue'] !==
null ) {
91 $op = $params[
'dir'] ==
'descending' ?
'<=' :
'>=';
92 $this->
addWhere( $db->buildComparison( $op, [
93 'll_from' => $cont[0],
94 'll_lang' => $cont[1],
104 $sort = ( $params[
'dir'] ==
'descending' ?
' DESC' :
'' );
105 if ( isset( $params[
'lang'] ) ) {
107 if ( isset( $params[
'title'] ) ) {
108 $this->
addWhereFld(
'll_title', $params[
'title'] );
110 $this->
addOption(
'ORDER BY',
'll_from' . $sort );
113 if ( count( $pages ) === 1 ) {
114 $this->
addOption(
'ORDER BY',
'll_lang' . $sort );
123 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
124 $res = $this->
select( __METHOD__ );
127 foreach ( $res as $row ) {
128 if ( ++$count > $params[
'limit'] ) {
135 $languageNameMap = $this->
getConfig()->get( MainConfigNames::InterlanguageLinkCodeMap );
136 $displayLanguageCode = $languageNameMap[ $row->ll_lang ] ?? $row->ll_lang;
139 $entry = [
'lang' => $displayLanguageCode ];
140 if ( isset( $prop[
'url'] ) ) {
141 $title = Title::newFromText(
"{$row->ll_lang}:{$row->ll_title}" );
143 $entry[
'url'] = (string)$this->urlUtils->expand( $title->getFullURL(),
PROTO_CURRENT );
147 if ( isset( $prop[
'langname'] ) ) {
148 $entry[
'langname'] = $this->languageNameUtils
149 ->getLanguageName( $displayLanguageCode, $params[
'inlanguagecode'] );
151 if ( isset( $prop[
'autonym'] ) ) {
152 $entry[
'autonym'] = $this->languageNameUtils->getLanguageName( $displayLanguageCode );
154 ApiResult::setContentValue( $entry,
'title', $row->ll_title );
170 ParamValidator::PARAM_ISMULTI =>
true,
171 ParamValidator::PARAM_TYPE => [
181 ParamValidator::PARAM_DEFAULT =>
'ascending',
182 ParamValidator::PARAM_TYPE => [
187 'inlanguagecode' => $this->contentLanguage->getCode(),
189 ParamValidator::PARAM_DEFAULT => 10,
190 ParamValidator::PARAM_TYPE =>
'limit',
191 IntegerDef::PARAM_MIN => 1,
199 ParamValidator::PARAM_DEFAULT =>
false,
200 ParamValidator::PARAM_DEPRECATED =>
true,
206 $title = Title::newMainPage()->getPrefixedText();
207 $mp = rawurlencode( $title );
210 "action=query&prop=langlinks&titles={$mp}&redirects="
211 =>
'apihelp-query+langlinks-example-simple',
216 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Langlinks';
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
encodeParamName( $paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
parseContinueParamOrDie(string $continue, array $types)
Parse the 'continue' parameter in the usual format and validate the types of each part,...
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI,...
const LIMIT_BIG1
Fast query, standard limit.
requireMaxOneParameter( $params,... $required)
Dies if more than one parameter from a certain set of parameters are set and not false.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
const LIMIT_BIG2
Fast query, apihighlimits limit.
This is a base class for all Query modules.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
addFields( $value)
Add a set of fields to select to the internal array.
addPageSubItem( $pageId, $item, $elemname=null)
Same as addPageSubItems(), but one element of $data at a time.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
getDB()
Get the Query database connection (read-only)
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
getPageSet()
Get the PageSet object to work on.
addWhere( $value)
Add a set of WHERE clauses to the internal array.
A query module to list all langlinks (links to corresponding foreign language pages).
getExamplesMessages()
Returns usage examples for this module.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
__construct(ApiQuery $query, $moduleName, LanguageNameUtils $languageNameUtils, Language $contentLanguage, UrlUtils $urlUtils)
getCacheMode( $params)
Get the cache mode for the data generated by this module.
getHelpUrls()
Return links to more detailed help pages about the module.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
This is the main query class.
Base class for language-specific code.
A class containing constants representing the names of configuration variables.