37 private $fieldTitle =
'title';
38 private $dfltNamespace =
NS_MAIN;
39 private $hasNamespace =
true;
40 private $useIndex =
null;
44 private $namespaceInfo;
50 private $linksMigration;
66 switch ( $moduleName ) {
69 $this->table =
'pagelinks';
70 $this->tablePrefix =
'pl_';
71 $this->useIndex =
'pl_namespace';
72 $this->indexTag =
'l';
74 case 'alltransclusions':
76 $this->table =
'templatelinks';
77 $this->tablePrefix =
'tl_';
79 $this->useIndex =
'tl_namespace';
80 $this->indexTag =
't';
84 $this->table =
'imagelinks';
85 $this->tablePrefix =
'il_';
86 $this->fieldTitle =
'to';
88 $this->hasNamespace =
false;
89 $this->indexTag =
'f';
93 $this->table =
'redirect';
94 $this->tablePrefix =
'rd_';
95 $this->indexTag =
'r';
97 'fragment' =>
'rd_fragment',
98 'interwiki' =>
'rd_interwiki',
105 parent::__construct( $query, $moduleName, $prefix );
106 $this->namespaceInfo = $namespaceInfo;
107 $this->genderCache = $genderCache;
108 $this->linksMigration = $linksMigration;
120 $this->run( $resultPageSet );
127 private function run( $resultPageSet =
null ) {
128 $db = $this->
getDB();
133 $nsField = $pfx .
'namespace';
134 $titleField = $pfx . $this->fieldTitle;
135 if ( isset( $this->linksMigration::$mapping[$this->table] ) ) {
136 [ $nsField, $titleField ] = $this->linksMigration->getTitleFields( $this->table );
137 $queryInfo = $this->linksMigration->getQueryInfo( $this->table );
138 $this->
addTables( $queryInfo[
'tables'] );
141 if ( $this->useIndex ) {
142 $this->
addOption(
'USE INDEX', $this->useIndex );
147 $prop = array_fill_keys( $params[
'prop'],
true );
148 $fld_ids = isset( $prop[
'ids'] );
149 $fld_title = isset( $prop[
'title'] );
150 if ( $this->hasNamespace ) {
151 $namespace = $params[
'namespace'];
153 $namespace = $this->dfltNamespace;
156 if ( $params[
'unique'] ) {
157 $matches = array_intersect_key( $prop, $this->props + [
'ids' => 1 ] );
162 'apierror-invalidparammix-cannotusewith',
163 "{$p}prop=" . implode(
'|', array_keys(
$matches ) ),
172 if ( $this->hasNamespace ) {
176 $continue = $params[
'continue'] !==
null;
178 $op = $params[
'dir'] ==
'descending' ?
'<=' :
'>=';
179 if ( $params[
'unique'] ) {
181 $this->
addWhere( $db->buildComparison( $op, [ $titleField => $cont[0] ] ) );
184 $this->
addWhere( $db->buildComparison( $op, [
185 $titleField => $cont[0],
186 "{$pfx}from" => $cont[1],
192 $from = $continue || $params[
'from'] ===
null ? null :
194 $to = $params[
'to'] ===
null ? null :
198 if ( isset( $params[
'prefix'] ) ) {
199 $this->
addWhere( $titleField . $db->buildLike( $this->titlePartToKey(
200 $params[
'prefix'], $namespace ), $db->anyString() ) );
203 $this->
addFields( [
'pl_title' => $titleField ] );
204 $this->
addFieldsIf( [
'pl_from' => $pfx .
'from' ], !$params[
'unique'] );
205 foreach ( $this->props as $name => $field ) {
206 $this->
addFieldsIf( $field, isset( $prop[$name] ) );
209 $limit = $params[
'limit'];
212 $sort = ( $params[
'dir'] ==
'descending' ?
' DESC' :
'' );
214 $orderBy[] = $titleField . $sort;
215 if ( !$params[
'unique'] ) {
216 $orderBy[] = $pfx .
'from' . $sort;
218 $this->
addOption(
'ORDER BY', $orderBy );
223 if ( $resultPageSet ===
null &&
$res->numRows() && $this->namespaceInfo->hasGenderDistinction( $namespace ) ) {
225 foreach (
$res as $row ) {
226 $users[] = $row->pl_title;
228 if ( $users !== [] ) {
229 $this->genderCache->doQuery( $users, __METHOD__ );
237 foreach (
$res as $row ) {
238 if ( ++$count > $limit ) {
241 if ( $params[
'unique'] ) {
249 if ( $resultPageSet ===
null ) {
254 $vals[
'fromid'] = (int)$row->pl_from;
257 $title = Title::makeTitle( $namespace, $row->pl_title );
260 foreach ( $this->props as $name => $field ) {
261 if ( isset( $prop[$name] ) && $row->$field !==
null && $row->$field !==
'' ) {
262 $vals[$name] = $row->$field;
265 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
267 if ( $params[
'unique'] ) {
274 } elseif ( $params[
'unique'] ) {
275 $titles[] = Title::makeTitle( $namespace, $row->pl_title );
277 $pageids[] = $row->pl_from;
281 if ( $resultPageSet ===
null ) {
282 $result->addIndexedTagName( [
'query', $this->
getModuleName() ], $this->indexTag );
283 } elseif ( $params[
'unique'] ) {
284 $resultPageSet->populateFromTitles( $titles );
286 $resultPageSet->populateFromPageIDs( $pageids );
300 ParamValidator::PARAM_ISMULTI =>
true,
301 ParamValidator::PARAM_DEFAULT =>
'title',
302 ParamValidator::PARAM_TYPE => array_merge(
303 [
'ids',
'title' ], array_keys( $this->props )
308 ParamValidator::PARAM_DEFAULT => $this->dfltNamespace,
309 ParamValidator::PARAM_TYPE =>
'namespace',
313 ParamValidator::PARAM_DEFAULT => 10,
314 ParamValidator::PARAM_TYPE =>
'limit',
315 IntegerDef::PARAM_MIN => 1,
320 ParamValidator::PARAM_DEFAULT =>
'ascending',
321 ParamValidator::PARAM_TYPE => [
327 if ( !$this->hasNamespace ) {
328 unset( $allowedParams[
'namespace'] );
331 return $allowedParams;
340 "action=query&list={$name}&{$p}from=B&{$p}prop=ids|title"
341 =>
"apihelp-$path-example-b",
342 "action=query&list={$name}&{$p}unique=&{$p}from=B"
343 =>
"apihelp-$path-example-unique",
344 "action=query&generator={$name}&g{$p}unique=&g{$p}from=B"
345 =>
"apihelp-$path-example-unique-generator",
346 "action=query&generator={$name}&g{$p}from=B"
347 =>
"apihelp-$path-example-generator",
354 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.
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...