Go to the documentation of this file.
38 switch ( $moduleName ) {
41 $this->table =
'pagelinks';
42 $this->tablePrefix =
'pl_';
43 $this->useIndex =
'pl_namespace';
44 $this->indexTag =
'l';
46 case 'alltransclusions':
48 $this->table =
'templatelinks';
49 $this->tablePrefix =
'tl_';
51 $this->useIndex =
'tl_namespace';
52 $this->indexTag =
't';
56 $this->table =
'imagelinks';
57 $this->tablePrefix =
'il_';
58 $this->fieldTitle =
'to';
60 $this->hasNamespace =
false;
61 $this->indexTag =
'f';
65 $this->table =
'redirect';
66 $this->tablePrefix =
'rd_';
67 $this->indexTag =
'r';
69 'fragment' =>
'rd_fragment',
70 'interwiki' =>
'rd_interwiki',
77 parent::__construct( $query, $moduleName, $prefix );
89 $this->
run( $resultPageSet );
96 private function run( $resultPageSet =
null ) {
102 $prop = array_flip( $params[
'prop'] );
103 $fld_ids = isset( $prop[
'ids'] );
104 $fld_title = isset( $prop[
'title'] );
105 if ( $this->hasNamespace ) {
106 $namespace = $params[
'namespace'];
111 if ( $params[
'unique'] ) {
112 $matches = array_intersect_key( $prop, $this->props + [
'ids' => 1 ] );
117 'apierror-invalidparammix-cannotusewith',
118 "{$p}prop=" . implode(
'|', array_keys(
$matches ) ),
128 if ( $this->hasNamespace ) {
129 $this->
addWhereFld( $pfx .
'namespace', $namespace );
132 $continue = !is_null( $params[
'continue'] );
134 $continueArr = explode(
'|', $params[
'continue'] );
135 $op = $params[
'dir'] ==
'descending' ?
'<' :
'>';
136 if ( $params[
'unique'] ) {
138 $continueTitle = $db->addQuotes( $continueArr[0] );
139 $this->
addWhere(
"{$pfx}{$fieldTitle} $op= $continueTitle" );
142 $continueTitle = $db->addQuotes( $continueArr[0] );
143 $continueFrom = (int)$continueArr[1];
145 "{$pfx}{$fieldTitle} $op $continueTitle OR " .
146 "({$pfx}{$fieldTitle} = $continueTitle AND " .
147 "{$pfx}from $op= $continueFrom)"
153 $from = $continue || $params[
'from'] ===
null ? null :
155 $to = $params[
'to'] ===
null ? null :
159 if ( isset( $params[
'prefix'] ) ) {
161 $params[
'prefix'], $namespace ), $db->anyString() ) );
165 $this->
addFieldsIf( [
'pl_from' => $pfx .
'from' ], !$params[
'unique'] );
166 foreach ( $this->props as $name => $field ) {
167 $this->
addFieldsIf( $field, isset( $prop[$name] ) );
170 if ( $this->useIndex ) {
171 $this->
addOption(
'USE INDEX', $this->useIndex );
173 $limit = $params[
'limit'];
176 $sort = ( $params[
'dir'] ==
'descending' ?
' DESC' :
'' );
179 if ( !$params[
'unique'] ) {
180 $orderBy[] = $pfx .
'from' .
$sort;
182 $this->
addOption(
'ORDER BY', $orderBy );
190 foreach (
$res as $row ) {
191 if ( ++$count > $limit ) {
194 if ( $params[
'unique'] ) {
202 if ( is_null( $resultPageSet ) ) {
207 $vals[
'fromid'] = (int)$row->pl_from;
213 foreach ( $this->props as $name => $field ) {
214 if ( isset( $prop[$name] ) && $row->$field !==
null && $row->$field !==
'' ) {
215 $vals[$name] = $row->$field;
218 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
220 if ( $params[
'unique'] ) {
227 } elseif ( $params[
'unique'] ) {
230 $pageids[] = $row->pl_from;
234 if ( is_null( $resultPageSet ) ) {
235 $result->addIndexedTagName( [
'query', $this->
getModuleName() ], $this->indexTag );
236 } elseif ( $params[
'unique'] ) {
237 $resultPageSet->populateFromTitles( $titles );
239 $resultPageSet->populateFromPageIDs( $pageids );
256 [
'ids',
'title' ], array_keys( $this->props )
280 if ( !$this->hasNamespace ) {
281 unset( $allowedParams[
'namespace'] );
284 return $allowedParams;
293 "action=query&list={$name}&{$p}from=B&{$p}prop=ids|title"
294 =>
"apihelp-$path-example-b",
295 "action=query&list={$name}&{$p}unique=&{$p}from=B"
296 =>
"apihelp-$path-example-unique",
297 "action=query&generator={$name}&g{$p}unique=&g{$p}from=B"
298 =>
"apihelp-$path-example-unique-generator",
299 "action=query&generator={$name}&g{$p}from=B"
300 =>
"apihelp-$path-example-generator",
307 return "https://www.mediawiki.org/wiki/Special:MyLanguage/API:{$name}";
addFields( $value)
Add a set of fields to select to the internal array.
This is the main query class.
const META_TYPE
Key for the 'type' metadata item.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
getResult()
Get the result object.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
run( $resultPageSet=null)
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
setContinueEnumParameter( $paramName, $paramValue)
Overridden to set the generator param if in generator mode.
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
getModulePath()
Get the path to this module.
const LIMIT_BIG1
Fast query, standard limit.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getDB()
Get the Query database connection (read-only)
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
const PARAM_EXTRA_NAMESPACES
(int[]) When PARAM_TYPE is 'namespace', include these as additional possible values.
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
addWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, and an ORDER BY clause to sort in the right direction.
getHelpUrls()
Return links to more detailed help pages about the module.
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
executeGenerator( $resultPageSet)
Execute this module as a generator.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
getExamplesMessages()
Returns usage examples for this module.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
__construct(ApiQuery $query, $moduleName)
const LIMIT_BIG2
Fast query, apihighlimits limit.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
getModuleName()
Get the name of the module being executed by this instance.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
addWhere( $value)
Add a set of WHERE clauses to the internal array.
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
titlePartToKey( $titlePart, $namespace=NS_MAIN)
Convert an input title or title prefix into a dbkey.
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
Query module to enumerate links from all pages together.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.