36 private $namespaceInfo;
42 private $restrictionStore;
58 parent::__construct( $query, $moduleName,
'ap' );
59 $this->namespaceInfo = $namespaceInfo;
60 $this->genderCache = $genderCache;
61 $this->restrictionStore = $restrictionStore;
77 if ( $resultPageSet->isResolvingRedirects() ) {
78 $this->
dieWithError(
'apierror-allpages-generator-redirects',
'params' );
81 $this->run( $resultPageSet );
88 private function run( $resultPageSet =
null ) {
96 if ( $params[
'continue'] !==
null ) {
97 $cont = explode(
'|', $params[
'continue'] );
99 $op = $params[
'dir'] ==
'descending' ?
'<' :
'>';
100 $cont_from = $db->addQuotes( $cont[0] );
101 $this->
addWhere(
"page_title $op= $cont_from" );
104 $miserMode = $this->
getConfig()->get( MainConfigNames::MiserMode );
106 if ( $params[
'filterredir'] ==
'redirects' ) {
108 } elseif ( $params[
'filterredir'] ==
'nonredirects' ) {
113 $this->
addWhereFld(
'page_namespace', $params[
'namespace'] );
114 $dir = ( $params[
'dir'] ==
'descending' ?
'older' :
'newer' );
115 $from = ( $params[
'from'] ===
null
117 : $this->
titlePartToKey( $params[
'from'], $params[
'namespace'] ) );
118 $to = ( $params[
'to'] ===
null
123 if ( isset( $params[
'prefix'] ) ) {
124 $this->
addWhere(
'page_title' . $db->buildLike(
125 $this->titlePartToKey( $params[
'prefix'], $params[
'namespace'] ),
126 $db->anyString() ) );
129 if ( $resultPageSet ===
null ) {
136 $selectFields = $resultPageSet->getPageTableFields();
139 $miserModeFilterRedirValue =
null;
140 $miserModeFilterRedir = $miserMode && $params[
'filterredir'] !==
'all';
141 if ( $miserModeFilterRedir ) {
142 $selectFields[] =
'page_is_redirect';
144 if ( $params[
'filterredir'] ==
'redirects' ) {
145 $miserModeFilterRedirValue = 1;
146 } elseif ( $params[
'filterredir'] ==
'nonredirects' ) {
147 $miserModeFilterRedirValue = 0;
152 $forceNameTitleIndex =
true;
153 if ( isset( $params[
'minsize'] ) ) {
154 $this->
addWhere(
'page_len>=' . (
int)$params[
'minsize'] );
155 $forceNameTitleIndex =
false;
158 if ( isset( $params[
'maxsize'] ) ) {
159 $this->
addWhere(
'page_len<=' . (
int)$params[
'maxsize'] );
160 $forceNameTitleIndex =
false;
164 if ( $params[
'prtype'] || $params[
'prexpiry'] !=
'all' ) {
166 $this->
addWhere(
'page_id=pr_page' );
167 $this->
addWhere(
"pr_expiry > {$db->addQuotes( $db->timestamp() )} OR pr_expiry IS NULL" );
169 if ( $params[
'prtype'] ) {
170 $this->
addWhereFld(
'pr_type', $params[
'prtype'] );
172 if ( isset( $params[
'prlevel'] ) ) {
174 $prlevel = array_diff( $params[
'prlevel'], [
'',
'*' ] );
176 if ( count( $prlevel ) ) {
180 if ( $params[
'prfiltercascade'] ==
'cascading' ) {
182 } elseif ( $params[
'prfiltercascade'] ==
'noncascading' ) {
186 $forceNameTitleIndex =
false;
188 if ( $params[
'prexpiry'] ==
'indefinite' ) {
189 $this->
addWhere(
"pr_expiry = {$db->addQuotes( $db->getInfinity() )} OR pr_expiry IS NULL" );
190 } elseif ( $params[
'prexpiry'] ==
'definite' ) {
191 $this->
addWhere(
"pr_expiry != {$db->addQuotes( $db->getInfinity() )}" );
195 } elseif ( isset( $params[
'prlevel'] ) ) {
197 [
'apierror-invalidparammix-mustusewith',
'prlevel',
'prtype' ],
'invalidparammix'
201 if ( $params[
'filterlanglinks'] ==
'withoutlanglinks' ) {
203 $this->
addJoinConds( [
'langlinks' => [
'LEFT JOIN',
'page_id=ll_from' ] ] );
204 $this->
addWhere(
'll_from IS NULL' );
205 $forceNameTitleIndex =
false;
206 } elseif ( $params[
'filterlanglinks'] ==
'withlanglinks' ) {
208 $this->
addWhere(
'page_id=ll_from' );
216 $dbType = $db->getType();
217 if ( $dbType ===
'mysql' || $dbType ===
'sqlite' ) {
222 $this->
addOption(
'GROUP BY', [
'page_title' ] );
223 } elseif ( $dbType ===
'postgres' && $db->getServerVersion() >= 9.1 ) {
225 $this->
addOption(
'GROUP BY', [
'page_title',
'page_id' ] );
228 $this->
addOption(
'GROUP BY', $selectFields );
231 $forceNameTitleIndex =
false;
234 if ( $forceNameTitleIndex ) {
235 $this->
addOption(
'USE INDEX',
'page_name_title' );
238 $limit = $params[
'limit'];
243 if ( $this->namespaceInfo->hasGenderDistinction( $params[
'namespace'] ) ) {
245 foreach (
$res as $row ) {
246 $users[] = $row->page_title;
248 $this->genderCache->doQuery( $users, __METHOD__ );
254 foreach (
$res as $row ) {
255 if ( ++$count > $limit ) {
262 if ( $miserModeFilterRedir && (
int)$row->page_is_redirect !== $miserModeFilterRedirValue ) {
267 if ( $resultPageSet ===
null ) {
270 'pageid' => (int)$row->page_id,
271 'ns' =>
$title->getNamespace(),
272 'title' =>
$title->getPrefixedText()
274 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
280 $resultPageSet->processDbRow( $row );
284 if ( $resultPageSet ===
null ) {
285 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'p' );
298 ParamValidator::PARAM_DEFAULT =>
NS_MAIN,
299 ParamValidator::PARAM_TYPE =>
'namespace',
302 ParamValidator::PARAM_DEFAULT =>
'all',
303 ParamValidator::PARAM_TYPE => [
310 ParamValidator::PARAM_TYPE =>
'integer',
313 ParamValidator::PARAM_TYPE =>
'integer',
316 ParamValidator::PARAM_TYPE => $this->restrictionStore->listAllRestrictionTypes(
true ),
317 ParamValidator::PARAM_ISMULTI =>
true
320 ParamValidator::PARAM_TYPE =>
321 $this->
getConfig()->get( MainConfigNames::RestrictionLevels ),
322 ParamValidator::PARAM_ISMULTI =>
true
324 'prfiltercascade' => [
325 ParamValidator::PARAM_DEFAULT =>
'all',
326 ParamValidator::PARAM_TYPE => [
333 ParamValidator::PARAM_DEFAULT => 10,
334 ParamValidator::PARAM_TYPE =>
'limit',
335 IntegerDef::PARAM_MIN => 1,
340 ParamValidator::PARAM_DEFAULT =>
'ascending',
341 ParamValidator::PARAM_TYPE => [
346 'filterlanglinks' => [
347 ParamValidator::PARAM_TYPE => [
352 ParamValidator::PARAM_DEFAULT =>
'all'
355 ParamValidator::PARAM_TYPE => [
360 ParamValidator::PARAM_DEFAULT =>
'all',
365 if ( $this->
getConfig()->
get( MainConfigNames::MiserMode ) ) {
374 'action=query&list=allpages&apfrom=B'
375 =>
'apihelp-query+allpages-example-b',
376 'action=query&generator=allpages&gaplimit=4&gapfrom=T&prop=info'
377 =>
'apihelp-query+allpages-example-generator',
378 'action=query&generator=allpages&gaplimit=2&' .
379 'gapfilterredir=nonredirects&gapfrom=Re&prop=revisions&rvprop=content'
380 =>
'apihelp-query+allpages-example-generator-revisions',
385 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Allpages';
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
const PARAM_HELP_MSG_APPEND
((string|array|Message)[]) Specify additional i18n messages to append to the normal message for this ...
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,...
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 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)
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.
__construct(ApiQuery $query, $moduleName, NamespaceInfo $namespaceInfo, GenderCache $genderCache, RestrictionStore $restrictionStore)
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.
Caches user genders when needed to use correct namespace aliases.
A class containing constants representing the names of configuration variables.
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.