55 switch ( $moduleName ) {
58 $this->table =
'pagelinks';
59 $this->tablePrefix =
'pl_';
60 $this->useIndex =
'pl_namespace';
61 $this->indexTag =
'l';
63 case 'alltransclusions':
65 $this->table =
'templatelinks';
66 $this->tablePrefix =
'tl_';
68 $this->useIndex =
'tl_namespace';
69 $this->indexTag =
't';
73 $this->table =
'imagelinks';
74 $this->tablePrefix =
'il_';
75 $this->fieldTitle =
'to';
77 $this->hasNamespace =
false;
78 $this->indexTag =
'f';
82 $this->table =
'redirect';
83 $this->tablePrefix =
'rd_';
84 $this->indexTag =
'r';
86 'fragment' =>
'rd_fragment',
87 'interwiki' =>
'rd_interwiki',
94 parent::__construct( $query, $moduleName, $prefix );
108 $this->
run( $resultPageSet );
115 private function run( $resultPageSet =
null ) {
116 $db = $this->
getDB();
121 $prop = array_fill_keys( $params[
'prop'],
true );
122 $fld_ids = isset( $prop[
'ids'] );
123 $fld_title = isset( $prop[
'title'] );
124 if ( $this->hasNamespace ) {
125 $namespace = $params[
'namespace'];
130 if ( $params[
'unique'] ) {
131 $matches = array_intersect_key( $prop, $this->props + [
'ids' => 1 ] );
136 'apierror-invalidparammix-cannotusewith',
137 "{$p}prop=" . implode(
'|', array_keys(
$matches ) ),
147 if ( $this->hasNamespace ) {
148 $this->
addWhereFld( $pfx .
'namespace', $namespace );
151 $continue = $params[
'continue'] !==
null;
153 $continueArr = explode(
'|', $params[
'continue'] );
154 $op = $params[
'dir'] ==
'descending' ?
'<' :
'>';
155 if ( $params[
'unique'] ) {
157 $continueTitle = $db->addQuotes( $continueArr[0] );
158 $this->
addWhere(
"{$pfx}{$fieldTitle} $op= $continueTitle" );
161 $continueTitle = $db->addQuotes( $continueArr[0] );
162 $continueFrom = (int)$continueArr[1];
164 "{$pfx}{$fieldTitle} $op $continueTitle OR " .
165 "({$pfx}{$fieldTitle} = $continueTitle AND " .
166 "{$pfx}from $op= $continueFrom)"
172 $from = $continue || $params[
'from'] ===
null ? null :
174 $to = $params[
'to'] ===
null ? null :
178 if ( isset( $params[
'prefix'] ) ) {
180 $params[
'prefix'], $namespace ), $db->anyString() ) );
184 $this->
addFieldsIf( [
'pl_from' => $pfx .
'from' ], !$params[
'unique'] );
185 foreach ( $this->props as $name => $field ) {
186 $this->
addFieldsIf( $field, isset( $prop[$name] ) );
189 if ( $this->useIndex ) {
190 $this->
addOption(
'USE INDEX', $this->useIndex );
192 $limit = $params[
'limit'];
195 $sort = ( $params[
'dir'] ==
'descending' ?
' DESC' :
'' );
198 if ( !$params[
'unique'] ) {
199 $orderBy[] = $pfx .
'from' . $sort;
201 $this->
addOption(
'ORDER BY', $orderBy );
206 if (
$res->numRows() && $resultPageSet ===
null ) {
207 if ( $this->namespaceInfo->hasGenderDistinction( $namespace ) ) {
209 foreach (
$res as $row ) {
210 $users[] = $row->pl_title;
212 if ( $users !== [] ) {
213 $this->genderCache->doQuery( $users, __METHOD__ );
222 foreach (
$res as $row ) {
223 if ( ++$count > $limit ) {
226 if ( $params[
'unique'] ) {
234 if ( $resultPageSet ===
null ) {
236 ApiResult::META_TYPE =>
'assoc',
239 $vals[
'fromid'] = (int)$row->pl_from;
242 $title = Title::makeTitle( $namespace, $row->pl_title );
245 foreach ( $this->props as $name => $field ) {
246 if ( isset( $prop[$name] ) && $row->$field !==
null && $row->$field !==
'' ) {
247 $vals[$name] = $row->$field;
250 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
252 if ( $params[
'unique'] ) {
259 } elseif ( $params[
'unique'] ) {
260 $titles[] = Title::makeTitle( $namespace, $row->pl_title );
262 $pageids[] = $row->pl_from;
266 if ( $resultPageSet ===
null ) {
267 $result->addIndexedTagName( [
'query', $this->
getModuleName() ], $this->indexTag );
268 } elseif ( $params[
'unique'] ) {
269 $resultPageSet->populateFromTitles( $titles );
271 $resultPageSet->populateFromPageIDs( $pageids );
288 [
'ids',
'title' ], array_keys( $this->props )
312 if ( !$this->hasNamespace ) {
313 unset( $allowedParams[
'namespace'] );
316 return $allowedParams;
325 "action=query&list={$name}&{$p}from=B&{$p}prop=ids|title"
326 =>
"apihelp-$path-example-b",
327 "action=query&list={$name}&{$p}unique=&{$p}from=B"
328 =>
"apihelp-$path-example-unique",
329 "action=query&generator={$name}&g{$p}unique=&g{$p}from=B"
330 =>
"apihelp-$path-example-unique-generator",
331 "action=query&generator={$name}&g{$p}from=B"
332 =>
"apihelp-$path-example-generator",
339 return "https://www.mediawiki.org/wiki/Special:MyLanguage/API:{$name}";
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
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.
getResult()
Get the result object.
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_EXTRA_NAMESPACES
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.
Query module to enumerate links from all pages together.
NamespaceInfo $namespaceInfo
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getHelpUrls()
Return links to more detailed help pages about the module.
__construct(ApiQuery $query, $moduleName, NamespaceInfo $namespaceInfo, GenderCache $genderCache)
executeGenerator( $resultPageSet)
Execute this module as a generator.
run( $resultPageSet=null)
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getExamplesMessages()
Returns usage examples for this module.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
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.
addFields( $value)
Add a set of fields to select to the internal array.
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.
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
titlePartToKey( $titlePart, $namespace=NS_MAIN)
Convert an input title or title prefix into a dbkey.
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.
This is the main query class.
Caches user genders when needed to use correct namespace aliases.
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...