40 switch ( $moduleName ) {
43 $this->table =
'pagelinks';
44 $this->tablePrefix =
'pl_';
45 $this->useIndex =
'pl_namespace';
46 $this->indexTag =
'l';
48 case 'alltransclusions':
50 $this->table =
'templatelinks';
51 $this->tablePrefix =
'tl_';
53 $this->useIndex =
'tl_namespace';
54 $this->indexTag =
't';
58 $this->table =
'imagelinks';
59 $this->tablePrefix =
'il_';
60 $this->fieldTitle =
'to';
62 $this->hasNamespace =
false;
63 $this->indexTag =
'f';
67 $this->table =
'redirect';
68 $this->tablePrefix =
'rd_';
69 $this->indexTag =
'r';
71 'fragment' =>
'rd_fragment',
72 'interwiki' =>
'rd_interwiki',
79 parent::__construct( $query, $moduleName, $prefix );
91 $this->
run( $resultPageSet );
98 private function run( $resultPageSet =
null ) {
104 $prop = array_flip( $params[
'prop'] );
105 $fld_ids = isset( $prop[
'ids'] );
106 $fld_title = isset( $prop[
'title'] );
107 if ( $this->hasNamespace ) {
108 $namespace = $params[
'namespace'];
113 if ( $params[
'unique'] ) {
114 $matches = array_intersect_key( $prop, $this->props + [
'ids' => 1 ] );
119 'apierror-invalidparammix-cannotusewith',
120 "{$p}prop=" . implode(
'|', array_keys(
$matches ) ),
130 if ( $this->hasNamespace ) {
131 $this->
addWhereFld( $pfx .
'namespace', $namespace );
134 $continue = $params[
'continue'] !==
null;
136 $continueArr = explode(
'|', $params[
'continue'] );
137 $op = $params[
'dir'] ==
'descending' ?
'<' :
'>';
138 if ( $params[
'unique'] ) {
140 $continueTitle = $db->addQuotes( $continueArr[0] );
141 $this->
addWhere(
"{$pfx}{$fieldTitle} $op= $continueTitle" );
144 $continueTitle = $db->addQuotes( $continueArr[0] );
145 $continueFrom = (int)$continueArr[1];
147 "{$pfx}{$fieldTitle} $op $continueTitle OR " .
148 "({$pfx}{$fieldTitle} = $continueTitle AND " .
149 "{$pfx}from $op= $continueFrom)"
155 $from = $continue || $params[
'from'] ===
null ? null :
157 $to = $params[
'to'] ===
null ? null :
161 if ( isset( $params[
'prefix'] ) ) {
163 $params[
'prefix'], $namespace ), $db->anyString() ) );
167 $this->
addFieldsIf( [
'pl_from' => $pfx .
'from' ], !$params[
'unique'] );
168 foreach ( $this->props as $name => $field ) {
169 $this->
addFieldsIf( $field, isset( $prop[$name] ) );
172 if ( $this->useIndex ) {
173 $this->
addOption(
'USE INDEX', $this->useIndex );
175 $limit = $params[
'limit'];
178 $sort = ( $params[
'dir'] ==
'descending' ?
' DESC' :
'' );
181 if ( !$params[
'unique'] ) {
182 $orderBy[] = $pfx .
'from' . $sort;
184 $this->
addOption(
'ORDER BY', $orderBy );
189 if (
$res->numRows() && $resultPageSet ===
null ) {
190 $services = MediaWikiServices::getInstance();
191 if ( $services->getNamespaceInfo()->hasGenderDistinction( $namespace ) ) {
193 foreach (
$res as $row ) {
194 $users[] = $row->pl_title;
196 if ( $users !== [] ) {
197 $services->getGenderCache()->doQuery( $users, __METHOD__ );
206 foreach (
$res as $row ) {
207 if ( ++$count > $limit ) {
210 if ( $params[
'unique'] ) {
218 if ( $resultPageSet ===
null ) {
220 ApiResult::META_TYPE =>
'assoc',
223 $vals[
'fromid'] = (int)$row->pl_from;
226 $title = Title::makeTitle( $namespace, $row->pl_title );
229 foreach ( $this->props as $name => $field ) {
230 if ( isset( $prop[$name] ) && $row->$field !==
null && $row->$field !==
'' ) {
231 $vals[$name] = $row->$field;
234 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
236 if ( $params[
'unique'] ) {
243 } elseif ( $params[
'unique'] ) {
244 $titles[] = Title::makeTitle( $namespace, $row->pl_title );
246 $pageids[] = $row->pl_from;
250 if ( $resultPageSet ===
null ) {
251 $result->addIndexedTagName( [
'query', $this->
getModuleName() ], $this->indexTag );
252 } elseif ( $params[
'unique'] ) {
253 $resultPageSet->populateFromTitles( $titles );
255 $resultPageSet->populateFromPageIDs( $pageids );
272 [
'ids',
'title' ], array_keys( $this->props )
296 if ( !$this->hasNamespace ) {
297 unset( $allowedParams[
'namespace'] );
300 return $allowedParams;
309 "action=query&list={$name}&{$p}from=B&{$p}prop=ids|title"
310 =>
"apihelp-$path-example-b",
311 "action=query&list={$name}&{$p}unique=&{$p}from=B"
312 =>
"apihelp-$path-example-unique",
313 "action=query&generator={$name}&g{$p}unique=&g{$p}from=B"
314 =>
"apihelp-$path-example-unique-generator",
315 "action=query&generator={$name}&g{$p}from=B"
316 =>
"apihelp-$path-example-generator",
323 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.
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.
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.
__construct(ApiQuery $query, $moduleName)
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) Stable to override.
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.