38 private $fieldTitle =
'title';
39 private $dfltNamespace =
NS_MAIN;
40 private $hasNamespace =
true;
41 private $useIndex =
null;
62 switch ( $moduleName ) {
65 $this->table =
'pagelinks';
66 $this->tablePrefix =
'pl_';
67 $this->useIndex =
'pl_namespace';
68 $this->indexTag =
'l';
70 case 'alltransclusions':
72 $this->table =
'templatelinks';
73 $this->tablePrefix =
'tl_';
75 $this->useIndex =
'tl_namespace';
76 $this->indexTag =
't';
80 $this->table =
'imagelinks';
81 $this->tablePrefix =
'il_';
82 $this->fieldTitle =
'to';
84 $this->hasNamespace =
false;
85 $this->indexTag =
'f';
89 $this->table =
'redirect';
90 $this->tablePrefix =
'rd_';
91 $this->indexTag =
'r';
93 'fragment' =>
'rd_fragment',
94 'interwiki' =>
'rd_interwiki',
101 parent::__construct( $query, $moduleName, $prefix );
102 $this->namespaceInfo = $namespaceInfo;
103 $this->genderCache = $genderCache;
104 $this->linksMigration = $linksMigration;
116 $this->run( $resultPageSet );
123 private function run( $resultPageSet =
null ) {
124 $db = $this->
getDB();
129 $nsField = $pfx .
'namespace';
130 $titleField = $pfx . $this->fieldTitle;
131 if ( isset( $this->linksMigration::$mapping[$this->table] ) ) {
132 [ $nsField, $titleField ] = $this->linksMigration->getTitleFields( $this->table );
133 $queryInfo = $this->linksMigration->getQueryInfo( $this->table );
134 $this->
addTables( $queryInfo[
'tables'] );
137 if ( $this->useIndex ) {
138 $this->
addOption(
'USE INDEX', $this->useIndex );
143 $prop = array_fill_keys( $params[
'prop'],
true );
144 $fld_ids = isset( $prop[
'ids'] );
145 $fld_title = isset( $prop[
'title'] );
146 if ( $this->hasNamespace ) {
147 $namespace = $params[
'namespace'];
149 $namespace = $this->dfltNamespace;
152 if ( $params[
'unique'] ) {
153 $matches = array_intersect_key( $prop, $this->props + [
'ids' => 1 ] );
158 'apierror-invalidparammix-cannotusewith',
159 "{$p}prop=" . implode(
'|', array_keys(
$matches ) ),
168 if ( $this->hasNamespace ) {
172 $continue = $params[
'continue'] !==
null;
174 $op = $params[
'dir'] ==
'descending' ?
'<=' :
'>=';
175 if ( $params[
'unique'] ) {
177 $this->
addWhere( $db->buildComparison( $op, [ $titleField => $cont[0] ] ) );
180 $this->
addWhere( $db->buildComparison( $op, [
181 $titleField => $cont[0],
182 "{$pfx}from" => $cont[1],
188 $from = $continue || $params[
'from'] ===
null ? null :
190 $to = $params[
'to'] ===
null ? null :
194 if ( isset( $params[
'prefix'] ) ) {
195 $this->
addWhere( $titleField . $db->buildLike( $this->titlePartToKey(
196 $params[
'prefix'], $namespace ), $db->anyString() ) );
199 $this->
addFields( [
'pl_title' => $titleField ] );
200 $this->
addFieldsIf( [
'pl_from' => $pfx .
'from' ], !$params[
'unique'] );
201 foreach ( $this->props as $name => $field ) {
202 $this->
addFieldsIf( $field, isset( $prop[$name] ) );
205 $limit = $params[
'limit'];
208 $sort = ( $params[
'dir'] ==
'descending' ?
' DESC' :
'' );
210 $orderBy[] = $titleField . $sort;
211 if ( !$params[
'unique'] ) {
212 $orderBy[] = $pfx .
'from' . $sort;
214 $this->
addOption(
'ORDER BY', $orderBy );
216 $res = $this->
select( __METHOD__ );
219 if ( $resultPageSet ===
null && $res->numRows() && $this->namespaceInfo->hasGenderDistinction( $namespace ) ) {
221 foreach ( $res as $row ) {
222 $users[] = $row->pl_title;
224 if ( $users !== [] ) {
225 $this->genderCache->doQuery( $users, __METHOD__ );
233 foreach ( $res as $row ) {
234 if ( ++$count > $limit ) {
237 if ( $params[
'unique'] ) {
245 if ( $resultPageSet ===
null ) {
250 $vals[
'fromid'] = (int)$row->pl_from;
253 $title = Title::makeTitle( $namespace, $row->pl_title );
256 foreach ( $this->props as $name => $field ) {
257 if ( isset( $prop[$name] ) && $row->$field !==
null && $row->$field !==
'' ) {
258 $vals[$name] = $row->$field;
261 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
263 if ( $params[
'unique'] ) {
270 } elseif ( $params[
'unique'] ) {
271 $titles[] = Title::makeTitle( $namespace, $row->pl_title );
273 $pageids[] = $row->pl_from;
277 if ( $resultPageSet ===
null ) {
278 $result->addIndexedTagName( [
'query', $this->
getModuleName() ], $this->indexTag );
279 } elseif ( $params[
'unique'] ) {
280 $resultPageSet->populateFromTitles( $titles );
282 $resultPageSet->populateFromPageIDs( $pageids );
296 ParamValidator::PARAM_ISMULTI =>
true,
297 ParamValidator::PARAM_DEFAULT =>
'title',
298 ParamValidator::PARAM_TYPE => array_merge(
299 [
'ids',
'title' ], array_keys( $this->props )
304 ParamValidator::PARAM_DEFAULT => $this->dfltNamespace,
305 ParamValidator::PARAM_TYPE =>
'namespace',
309 ParamValidator::PARAM_DEFAULT => 10,
310 ParamValidator::PARAM_TYPE =>
'limit',
311 IntegerDef::PARAM_MIN => 1,
316 ParamValidator::PARAM_DEFAULT =>
'ascending',
317 ParamValidator::PARAM_TYPE => [
323 if ( !$this->hasNamespace ) {
324 unset( $allowedParams[
'namespace'] );
327 return $allowedParams;
336 "action=query&list={$name}&{$p}from=B&{$p}prop=ids|title"
337 =>
"apihelp-$path-example-b",
338 "action=query&list={$name}&{$p}unique=&{$p}from=B"
339 =>
"apihelp-$path-example-unique",
340 "action=query&generator={$name}&g{$p}unique=&g{$p}from=B"
341 =>
"apihelp-$path-example-unique-generator",
342 "action=query&generator={$name}&g{$p}from=B"
343 =>
"apihelp-$path-example-generator",
350 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).
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
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.
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_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.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
__construct(ApiQuery $query, $moduleName, NamespaceInfo $namespaceInfo, GenderCache $genderCache, LinksMigration $linksMigration)
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.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
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.
const META_TYPE
Key for the 'type' metadata item.
Look up "gender" user preference.