42 private static $settings = [
46 'linktable' =>
'redirect',
50 'showredirects' =>
false,
59 'linktable' =>
'pagelinks',
60 'indexes' => [
'pl_namespace',
'pl_backlinks_namespace' ],
61 'from_namespace' =>
true,
62 'showredirects' =>
true,
67 'linktable' =>
'templatelinks',
68 'from_namespace' =>
true,
69 'showredirects' =>
true,
74 'linktable' =>
'imagelinks',
75 'indexes' => [
'il_to',
'il_backlinks_namespace' ],
76 'from_namespace' =>
true,
78 'exampletitle' =>
'File:Example.jpg',
79 'showredirects' =>
true,
95 parent::__construct( $query, $moduleName, self::$settings[$moduleName][
'code'] );
96 $this->linksMigration = $linksMigration;
104 $this->
run( $resultPageSet );
113 $db = $this->
getDB();
115 $prop = array_fill_keys(
$params[
'prop'],
true );
118 $titles = $pageSet->getGoodAndMissingPages();
119 $map = $pageSet->getGoodAndMissingTitlesByNamespace();
123 foreach ( $pageSet->getSpecialPages() as $id => $title ) {
125 $map[$title->getNamespace()][$title->getDBkey()] = $id;
129 $p = $settings[
'prefix'];
130 $hasNS = !isset( $settings[
'to_namespace'] );
132 if ( isset( $this->linksMigration::$mapping[$settings[
'linktable']] ) ) {
133 [ $bl_namespace, $bl_title ] = $this->linksMigration->getTitleFields( $settings[
'linktable'] );
135 $bl_namespace =
"{$p}_namespace";
136 $bl_title =
"{$p}_title";
140 $bl_namespace = $settings[
'to_namespace'];
141 $bl_title =
"{$p}_to";
143 $titles = array_filter( $titles,
static function ( $t ) use ( $bl_namespace ) {
144 return $t->getNamespace() === $bl_namespace;
146 $map = array_intersect_key( $map, [ $bl_namespace =>
true ] );
148 $bl_from =
"{$p}_from";
153 if (
$params[
'namespace'] !==
null && count(
$params[
'namespace'] ) === 0 ) {
161 if ( $hasNS && count( $map ) > 1 ) {
162 $sortby[$bl_namespace] =
'int';
165 foreach ( $map as $nsTitles ) {
166 $key = array_key_first( $nsTitles );
168 if ( count( $nsTitles ) > 1 || $key !== $theTitle ) {
169 $sortby[$bl_title] =
'string';
174 if (
$params[
'namespace'] !==
null ) {
175 if ( empty( $settings[
'from_namespace'] ) ) {
176 if ( $this->
getConfig()->
get( MainConfigNames::MiserMode ) ) {
177 $miser_ns =
$params[
'namespace'];
183 if ( !empty( $settings[
'from_namespace'] )
184 &&
$params[
'namespace'] !==
null && count(
$params[
'namespace'] ) > 1
186 $sortby[
"{$p}_from_namespace"] =
'int';
190 $sortby[$bl_from] =
'int';
193 $continueFields = array_keys( $sortby );
194 $continueTypes = array_values( $sortby );
195 if (
$params[
'continue'] !==
null ) {
197 $conds = array_combine( $continueFields, $continueValues );
198 $this->
addWhere( $db->buildComparison(
'>=', $conds ) );
202 [ $idxNoFromNS, $idxWithFromNS ] = $settings[
'indexes'] ?? [
'',
'' ];
204 if ( isset( $this->linksMigration::$mapping[$settings[
'linktable']] ) ) {
206 $queryInfo = $this->linksMigration->getQueryInfo( $settings[
'linktable'] );
207 $this->
addTables( array_merge( [
'page' ], $queryInfo[
'tables'] ) );
210 if ( in_array(
'linktarget', $queryInfo[
'tables'] ) ) {
211 $idxWithFromNS .=
'_target_id';
215 $this->
addTables( [ $settings[
'linktable'],
'page' ] );
217 $this->
addWhere(
"$bl_from = page_id" );
223 $this->
addFields( array_keys( $sortby ) );
224 $this->
addFields( [
'bl_namespace' => $bl_namespace,
'bl_title' => $bl_title ] );
225 if ( $resultPageSet ===
null ) {
226 $fld_pageid = isset( $prop[
'pageid'] );
227 $fld_title = isset( $prop[
'title'] );
228 $fld_redirect = isset( $prop[
'redirect'] );
231 $this->
addFieldsIf( [
'page_title',
'page_namespace' ], $fld_title );
232 $this->
addFieldsIf(
'page_is_redirect', $fld_redirect );
235 $fld_fragment = isset( $prop[
'fragment'] );
236 $this->
addFieldsIf(
'rd_fragment', $fld_fragment );
238 $this->
addFields( $resultPageSet->getPageTableFields() );
241 $this->
addFieldsIf(
'page_namespace', $miser_ns !==
null );
243 if ( $hasNS && $map ) {
246 $this->
addWhere( $db->makeWhereFrom2d( $map, $bl_namespace, $bl_title ) );
249 foreach ( $titles as $t ) {
250 if (
$t->getNamespace() == $bl_namespace ) {
251 $where[] = $db->expr( $bl_title,
'=',
$t->getDBkey() );
254 $this->
addWhere( $db->orExpr( $where ) );
257 if (
$params[
'show'] !==
null ) {
259 $show = array_fill_keys(
$params[
'show'],
true );
260 if ( ( isset( $show[
'fragment'] ) && isset( $show[
'!fragment'] ) ) ||
261 ( isset( $show[
'redirect'] ) && isset( $show[
'!redirect'] ) )
265 $this->
addWhereIf( $db->expr(
'rd_fragment',
'!=',
'' ), isset( $show[
'fragment'] ) );
266 $this->
addWhereIf( [
'rd_fragment' =>
'' ], isset( $show[
'!fragment'] ) );
267 $this->
addWhereIf( [
'page_is_redirect' => 1 ], isset( $show[
'redirect'] ) );
268 $this->
addWhereIf( [
'page_is_redirect' => 0 ], isset( $show[
'!redirect'] ) );
272 $this->
addOption(
'ORDER BY', array_keys( $sortby ) );
277 if ( !empty( $settings[
'indexes'] ) ) {
279 $params[
'namespace'] !==
null &&
280 count(
$params[
'namespace'] ) == 1 &&
281 !empty( $settings[
'from_namespace'] )
284 $this->
addOption(
'USE INDEX', [ $settings[
'linktable'] => $idxWithFromNS ] );
286 } elseif ( !isset( $this->linksMigration::$mapping[$settings[
'linktable']] ) ) {
288 $this->
addOption(
'USE INDEX', [ $settings[
'linktable'] => $idxNoFromNS ] );
294 $res = $this->
select( __METHOD__ );
296 if ( $resultPageSet ===
null ) {
303 foreach ( $res as $row ) {
304 if ( ++$count >
$params[
'limit'] ) {
307 $this->setContinue( $row, $sortby );
311 if ( $miser_ns !==
null && !in_array( $row->page_namespace, $miser_ns ) ) {
317 $id = $map[$row->bl_namespace][$row->bl_title];
322 $vals[
'pageid'] = (int)$row->page_id;
326 Title::makeTitle( $row->page_namespace, $row->page_title )
330 if ( $fld_fragment && $row->rd_fragment !==
'' ) {
331 $vals[
'fragment'] = $row->rd_fragment;
334 if ( $fld_redirect ) {
335 $vals[
'redirect'] = (bool)$row->page_is_redirect;
339 $this->setContinue( $row, $sortby );
346 foreach ( $res as $row ) {
347 if ( ++$count >
$params[
'limit'] ) {
350 $this->setContinue( $row, $sortby );
354 if ( $miser_ns !==
null && !in_array( $row->page_namespace, $miser_ns ) ) {
359 $titles[] = Title::makeTitle( $row->page_namespace, $row->page_title );
361 $resultPageSet->populateFromTitles( $titles );
365 private function setContinue( $row, $sortby ) {
367 foreach ( $sortby as $field => $v ) {
368 $cont[] = $row->$field;
382 ParamValidator::PARAM_TYPE => [
386 ParamValidator::PARAM_ISMULTI =>
true,
387 ParamValidator::PARAM_DEFAULT =>
'pageid|title',
391 ParamValidator::PARAM_ISMULTI =>
true,
392 ParamValidator::PARAM_TYPE =>
'namespace',
396 ParamValidator::PARAM_DEFAULT => 10,
397 ParamValidator::PARAM_TYPE =>
'limit',
398 IntegerDef::PARAM_MIN => 1,
407 if ( empty( $settings[
'from_namespace'] ) &&
408 $this->
getConfig()->
get( MainConfigNames::MiserMode ) ) {
410 'api-help-param-limited-in-miser-mode',
414 if ( !empty( $settings[
'showredirects'] ) ) {
415 $ret[
'prop'][ParamValidator::PARAM_TYPE][] =
'redirect';
416 $ret[
'prop'][ParamValidator::PARAM_DEFAULT] .=
'|redirect';
418 if ( isset( $settings[
'props'] ) ) {
419 $ret[
'prop'][ParamValidator::PARAM_TYPE] = array_merge(
420 $ret[
'prop'][ParamValidator::PARAM_TYPE], $settings[
'props']
425 if ( !empty( $settings[
'showredirects'] ) ) {
426 $show[] =
'redirect';
427 $show[] =
'!redirect';
429 if ( isset( $settings[
'show'] ) ) {
430 $show = array_merge( $show, $settings[
'show'] );
434 ParamValidator::PARAM_TYPE => $show,
435 ParamValidator::PARAM_ISMULTI =>
true,
439 unset( $ret[
'show'] );
449 $title = $settings[
'exampletitle'] ?? Title::newMainPage()->getPrefixedText();
450 $etitle = rawurlencode( $title );
453 "action=query&prop={$name}&titles={$etitle}"
454 =>
"apihelp-$path-example-simple",
455 "action=query&generator={$name}&titles={$etitle}&prop=info"
456 =>
"apihelp-$path-example-generator",
462 return "https://www.mediawiki.org/wiki/Special:MyLanguage/API:{$name}";
array $params
The job parameters.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
const PARAM_HELP_MSG_APPEND
((string|array|Message)[]) Specify additional i18n messages to append to the normal message for this ...
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.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
getModulePath()
Get the path to this module.
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
const LIMIT_BIG2
Fast query, apihighlimits limit.
getModuleName()
Get the name of the module being executed by this instance.
This class contains a list of pages that the client has requested.
This implements prop=redirects, prop=linkshere, prop=catmembers, prop=transcludedin,...
executeGenerator( $resultPageSet)
Execute this module as a generator.
getHelpUrls()
Return links to more detailed help pages about the module.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getExamplesMessages()
Returns usage examples for this module.
__construct(ApiQuery $query, $moduleName, LinksMigration $linksMigration)
getCacheMode( $params)
Get the cache mode for the data generated by this module.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
addWhereIf( $value, $condition)
Same as addWhere(), but add the WHERE clauses only if a condition is met.
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)
executeGenderCacheFromResultWrapper(IResultWrapper $res, $fname=__METHOD__, $fieldPrefix='page')
Preprocess the result set to fill the GenderCache with the necessary information before using self::a...
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
addWhere( $value)
Add a set of WHERE clauses to the internal array.
setContinueEnumParameter( $paramName, $paramValue)
Overridden to set the generator param if in generator mode.
getPageSet()
Get the PageSet object to work on.
This is the main query class.
A class containing constants representing the names of configuration variables.