32 parent::__construct( $query, $moduleName,
'ap' );
48 if ( $resultPageSet->isResolvingRedirects() ) {
49 $this->
dieWithError(
'apierror-allpages-generator-redirects',
'params' );
52 $this->
run( $resultPageSet );
59 private function run( $resultPageSet =
null ) {
67 if ( !is_null( $params[
'continue'] ) ) {
68 $cont = explode(
'|', $params[
'continue'] );
70 $op = $params[
'dir'] ==
'descending' ?
'<' :
'>';
71 $cont_from = $db->addQuotes( $cont[0] );
72 $this->
addWhere(
"page_title $op= $cont_from" );
75 $miserMode = $this->
getConfig()->get(
'MiserMode' );
77 if ( $params[
'filterredir'] ==
'redirects' ) {
79 } elseif ( $params[
'filterredir'] ==
'nonredirects' ) {
84 $this->
addWhereFld(
'page_namespace', $params[
'namespace'] );
85 $dir = ( $params[
'dir'] ==
'descending' ?
'older' :
'newer' );
86 $from = ( $params[
'from'] ===
null
88 : $this->
titlePartToKey( $params[
'from'], $params[
'namespace'] ) );
89 $to = ( $params[
'to'] ===
null
94 if ( isset( $params[
'prefix'] ) ) {
95 $this->
addWhere(
'page_title' . $db->buildLike(
96 $this->titlePartToKey( $params[
'prefix'], $params[
'namespace'] ),
100 if ( is_null( $resultPageSet ) ) {
107 $selectFields = $resultPageSet->getPageTableFields();
110 $miserModeFilterRedirValue =
null;
111 $miserModeFilterRedir = $miserMode && $params[
'filterredir'] !==
'all';
112 if ( $miserModeFilterRedir ) {
113 $selectFields[] =
'page_is_redirect';
115 if ( $params[
'filterredir'] ==
'redirects' ) {
116 $miserModeFilterRedirValue = 1;
117 } elseif ( $params[
'filterredir'] ==
'nonredirects' ) {
118 $miserModeFilterRedirValue = 0;
123 $forceNameTitleIndex =
true;
124 if ( isset( $params[
'minsize'] ) ) {
125 $this->
addWhere(
'page_len>=' . (
int)$params[
'minsize'] );
126 $forceNameTitleIndex =
false;
129 if ( isset( $params[
'maxsize'] ) ) {
130 $this->
addWhere(
'page_len<=' . (
int)$params[
'maxsize'] );
131 $forceNameTitleIndex =
false;
135 if ( $params[
'prtype'] || $params[
'prexpiry'] !=
'all' ) {
137 $this->
addWhere(
'page_id=pr_page' );
138 $this->
addWhere(
"pr_expiry > {$db->addQuotes( $db->timestamp() )} OR pr_expiry IS NULL" );
140 if ( $params[
'prtype'] ) {
141 $this->
addWhereFld(
'pr_type', $params[
'prtype'] );
143 if ( isset( $params[
'prlevel'] ) ) {
145 $prlevel = array_diff( $params[
'prlevel'], [
'',
'*' ] );
147 if ( count( $prlevel ) ) {
151 if ( $params[
'prfiltercascade'] ==
'cascading' ) {
153 } elseif ( $params[
'prfiltercascade'] ==
'noncascading' ) {
157 $forceNameTitleIndex =
false;
159 if ( $params[
'prexpiry'] ==
'indefinite' ) {
160 $this->
addWhere(
"pr_expiry = {$db->addQuotes( $db->getInfinity() )} OR pr_expiry IS NULL" );
161 } elseif ( $params[
'prexpiry'] ==
'definite' ) {
162 $this->
addWhere(
"pr_expiry != {$db->addQuotes( $db->getInfinity() )}" );
166 } elseif ( isset( $params[
'prlevel'] ) ) {
168 [
'apierror-invalidparammix-mustusewith',
'prlevel',
'prtype' ],
'invalidparammix'
172 if ( $params[
'filterlanglinks'] ==
'withoutlanglinks' ) {
174 $this->
addJoinConds( [
'langlinks' => [
'LEFT JOIN',
'page_id=ll_from' ] ] );
175 $this->
addWhere(
'll_from IS NULL' );
176 $forceNameTitleIndex =
false;
177 } elseif ( $params[
'filterlanglinks'] ==
'withlanglinks' ) {
179 $this->
addWhere(
'page_id=ll_from' );
187 $dbType = $db->getType();
188 if ( $dbType ===
'mysql' || $dbType ===
'sqlite' ) {
193 $this->
addOption(
'GROUP BY', [
'page_title' ] );
194 } elseif ( $dbType ===
'postgres' && $db->getServerVersion() >= 9.1 ) {
196 $this->
addOption(
'GROUP BY', [
'page_title',
'page_id' ] );
199 $this->
addOption(
'GROUP BY', $selectFields );
202 $forceNameTitleIndex =
false;
205 if ( $forceNameTitleIndex ) {
206 $this->
addOption(
'USE INDEX',
'name_title' );
209 $limit = $params[
'limit'];
214 $services = MediaWikiServices::getInstance();
215 if ( $services->getNamespaceInfo()->hasGenderDistinction( $params[
'namespace'] ) ) {
217 foreach (
$res as $row ) {
218 $users[] = $row->page_title;
220 $services->getGenderCache()->doQuery( $users, __METHOD__ );
226 foreach (
$res as $row ) {
227 if ( ++$count > $limit ) {
234 if ( $miserModeFilterRedir && (
int)$row->page_is_redirect !== $miserModeFilterRedirValue ) {
239 if ( is_null( $resultPageSet ) ) {
240 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
242 'pageid' => (int)$row->page_id,
243 'ns' => (
int)
$title->getNamespace(),
244 'title' =>
$title->getPrefixedText()
246 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
252 $resultPageSet->processDbRow( $row );
256 if ( is_null( $resultPageSet ) ) {
257 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'p' );
295 'prfiltercascade' => [
297 ApiBase::PARAM_TYPE => [
317 'filterlanglinks' => [
335 if ( $this->
getConfig()->
get(
'MiserMode' ) ) {
344 'action=query&list=allpages&apfrom=B'
345 =>
'apihelp-query+allpages-example-b',
346 'action=query&generator=allpages&gaplimit=4&gapfrom=T&prop=info'
347 =>
'apihelp-query+allpages-example-generator',
348 'action=query&generator=allpages&gaplimit=2&' .
349 'gapfilterredir=nonredirects&gapfrom=Re&prop=revisions&rvprop=content'
350 =>
'apihelp-query+allpages-example-generator-revisions',
355 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Allpages';
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
const PARAM_HELP_MSG_APPEND
((string|array|Message)[]) Specify additional i18n messages to append to the normal message for this ...
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
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,...
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.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Query module to enumerate all available pages.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getCacheMode( $params)
Get the cache mode for the data generated by this module.
executeGenerator( $resultPageSet)
run( $resultPageSet=null)
__construct(ApiQuery $query, $moduleName)
getHelpUrls()
Return links to more detailed help pages about the module.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getExamplesMessages()
Returns usage examples for this module.
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.
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.