40 'linktable' =>
'redirect',
44 'showredirects' =>
false,
53 'linktable' =>
'pagelinks',
54 'indexes' => [
'pl_namespace',
'pl_backlinks_namespace' ],
55 'from_namespace' =>
true,
56 'showredirects' =>
true,
61 'linktable' =>
'templatelinks',
62 'indexes' => [
'tl_namespace',
'tl_backlinks_namespace' ],
63 'from_namespace' =>
true,
64 'showredirects' =>
true,
69 'linktable' =>
'imagelinks',
70 'indexes' => [
'il_to',
'il_backlinks_namespace' ],
71 'from_namespace' =>
true,
73 'exampletitle' =>
'File:Example.jpg',
74 'showredirects' =>
true,
83 parent::__construct( $query, $moduleName, self::$settings[$moduleName][
'code'] );
91 $this->
run( $resultPageSet );
100 $db = $this->
getDB();
102 $prop = array_fill_keys( $params[
'prop'],
true );
103 $emptyString = $db->addQuotes(
'' );
106 $titles = $pageSet->getGoodAndMissingPages();
107 $map = $pageSet->getGoodAndMissingTitlesByNamespace();
111 foreach ( $pageSet->getSpecialPages() as $id =>
$title ) {
118 $hasNS = !isset(
$settings[
'to_namespace'] );
120 $bl_namespace =
"{$p}_namespace";
121 $bl_title =
"{$p}_title";
123 $bl_namespace =
$settings[
'to_namespace'];
124 $bl_title =
"{$p}_to";
126 $titles = array_filter( $titles,
static function (
$t ) use ( $bl_namespace ) {
127 return $t->getNamespace() === $bl_namespace;
129 $map = array_intersect_key( $map, [ $bl_namespace =>
true ] );
131 $bl_from =
"{$p}_from";
136 if ( $params[
'namespace'] !==
null && count( $params[
'namespace'] ) === 0 ) {
144 if ( $hasNS && count( $map ) > 1 ) {
145 $sortby[$bl_namespace] =
'ns';
148 foreach ( $map as $nsTitles ) {
150 $key = key( $nsTitles );
151 if ( $theTitle ===
null ) {
154 if ( count( $nsTitles ) > 1 || $key !== $theTitle ) {
155 $sortby[$bl_title] =
'title';
160 if ( $params[
'namespace'] !==
null ) {
161 if ( empty(
$settings[
'from_namespace'] ) ) {
162 if ( $this->
getConfig()->
get(
'MiserMode' ) ) {
163 $miser_ns = $params[
'namespace'];
165 $this->
addWhereFld(
'page_namespace', $params[
'namespace'] );
168 $this->
addWhereFld(
"{$p}_from_namespace", $params[
'namespace'] );
169 if ( !empty(
$settings[
'from_namespace'] )
170 && $params[
'namespace'] !==
null && count( $params[
'namespace'] ) > 1
172 $sortby[
"{$p}_from_namespace"] =
'int';
176 $sortby[$bl_from] =
'int';
179 if ( $params[
'continue'] !==
null ) {
180 $cont = explode(
'|', $params[
'continue'] );
183 $i = count( $sortby ) - 1;
184 foreach ( array_reverse( $sortby,
true ) as $field =>
$type ) {
193 $v = $db->addQuotes( $v );
197 if ( $where ===
'' ) {
198 $where =
"$field >= $v";
200 $where =
"$field > $v OR ($field = $v AND ($where))";
210 $this->
addWhere(
"$bl_from = page_id" );
213 $this->
addWhere(
"rd_interwiki = $emptyString OR rd_interwiki IS NULL" );
216 $this->
addFields( array_keys( $sortby ) );
217 $this->
addFields( [
'bl_namespace' => $bl_namespace,
'bl_title' => $bl_title ] );
218 if ( $resultPageSet ===
null ) {
219 $fld_pageid = isset( $prop[
'pageid'] );
220 $fld_title = isset( $prop[
'title'] );
221 $fld_redirect = isset( $prop[
'redirect'] );
224 $this->
addFieldsIf( [
'page_title',
'page_namespace' ], $fld_title );
225 $this->
addFieldsIf(
'page_is_redirect', $fld_redirect );
228 $fld_fragment = isset( $prop[
'fragment'] );
229 $this->
addFieldsIf(
'rd_fragment', $fld_fragment );
231 $this->
addFields( $resultPageSet->getPageTableFields() );
234 $this->
addFieldsIf(
'page_namespace', $miser_ns !==
null );
239 $this->
addWhere( $db->makeWhereFrom2d( $map, $bl_namespace, $bl_title ) );
242 foreach ( $titles as
$t ) {
243 if (
$t->getNamespace() == $bl_namespace ) {
244 $where[] =
"$bl_title = " . $db->addQuotes(
$t->getDBkey() );
250 if ( $params[
'show'] !==
null ) {
252 $show = array_fill_keys( $params[
'show'],
true );
253 if ( isset( $show[
'fragment'] ) && isset( $show[
'!fragment'] ) ||
254 isset( $show[
'redirect'] ) && isset( $show[
'!redirect'] )
258 $this->
addWhereIf(
"rd_fragment != $emptyString", isset( $show[
'fragment'] ) );
260 "rd_fragment = $emptyString OR rd_fragment IS NULL",
261 isset( $show[
'!fragment'] )
263 $this->
addWhereIf( [
'page_is_redirect' => 1 ], isset( $show[
'redirect'] ) );
264 $this->
addWhereIf( [
'page_is_redirect' => 0 ], isset( $show[
'!redirect'] ) );
268 $this->
addOption(
'ORDER BY', array_keys( $sortby ) );
274 list( $idxNoFromNS, $idxWithFromNS ) =
$settings[
'indexes'];
275 if ( $params[
'namespace'] !==
null && !empty(
$settings[
'from_namespace'] ) ) {
288 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
292 if ( $resultPageSet ===
null ) {
298 foreach (
$res as $row ) {
299 if ( ++$count > $params[
'limit'] ) {
306 if ( $miser_ns !==
null && !in_array( $row->page_namespace, $miser_ns ) ) {
312 $id = $map[$row->bl_namespace][$row->bl_title];
316 $vals[
'pageid'] = (int)$row->page_id;
320 Title::makeTitle( $row->page_namespace, $row->page_title )
323 if ( $fld_fragment && $row->rd_fragment !==
null && $row->rd_fragment !==
'' ) {
324 $vals[
'fragment'] = $row->rd_fragment;
326 if ( $fld_redirect ) {
327 $vals[
'redirect'] = (bool)$row->page_is_redirect;
338 foreach (
$res as $row ) {
339 if ( ++$count > $params[
'limit'] ) {
346 if ( $miser_ns !==
null && !in_array( $row->page_namespace, $miser_ns ) ) {
351 $titles[] = Title::makeTitle( $row->page_namespace, $row->page_title );
353 $resultPageSet->populateFromTitles( $titles );
359 foreach ( $sortby as $field => $v ) {
360 $cont[] = $row->$field;
399 if ( empty(
$settings[
'from_namespace'] ) && $this->
getConfig()->
get(
'MiserMode' ) ) {
401 'api-help-param-limited-in-miser-mode',
405 if ( !empty(
$settings[
'showredirects'] ) ) {
416 if ( !empty(
$settings[
'showredirects'] ) ) {
417 $show[] =
'redirect';
418 $show[] =
'!redirect';
421 $show = array_merge( $show,
$settings[
'show'] );
429 unset( $ret[
'show'] );
440 $etitle = rawurlencode(
$title );
443 "action=query&prop={$name}&titles={$etitle}"
444 =>
"apihelp-$path-example-simple",
445 "action=query&generator={$name}&titles={$etitle}&prop=info"
446 =>
"apihelp-$path-example-generator",
452 return "https://www.mediawiki.org/wiki/Special:MyLanguage/API:{$name}";
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
const PARAM_HELP_MSG_APPEND
((string|array|Message)[]) Specify additional i18n messages to append to the normal message for this ...
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
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,...
setContinue( $row, $sortby)
executeGenerator( $resultPageSet)
Execute this module as a generator.
static array $settings
Data for the various modules implemented by this class.
getHelpUrls()
Return links to more detailed help pages about the module.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
run(ApiPageSet $resultPageSet=null)
getExamplesMessages()
Returns usage examples for this module.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
__construct(ApiQuery $query, $moduleName)
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.
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.