48 parent::__construct( $query, $moduleName,
'ap' );
66 if ( $resultPageSet->isResolvingRedirects() ) {
67 $this->
dieWithError(
'apierror-allpages-generator-redirects',
'params' );
70 $this->
run( $resultPageSet );
77 private function run( $resultPageSet =
null ) {
85 if ( $params[
'continue'] !==
null ) {
86 $cont = explode(
'|', $params[
'continue'] );
88 $op = $params[
'dir'] ==
'descending' ?
'<' :
'>';
89 $cont_from = $db->addQuotes( $cont[0] );
90 $this->
addWhere(
"page_title $op= $cont_from" );
93 $miserMode = $this->
getConfig()->get(
'MiserMode' );
95 if ( $params[
'filterredir'] ==
'redirects' ) {
97 } elseif ( $params[
'filterredir'] ==
'nonredirects' ) {
102 $this->
addWhereFld(
'page_namespace', $params[
'namespace'] );
103 $dir = ( $params[
'dir'] ==
'descending' ?
'older' :
'newer' );
104 $from = ( $params[
'from'] ===
null
106 : $this->
titlePartToKey( $params[
'from'], $params[
'namespace'] ) );
107 $to = ( $params[
'to'] ===
null
112 if ( isset( $params[
'prefix'] ) ) {
113 $this->
addWhere(
'page_title' . $db->buildLike(
114 $this->titlePartToKey( $params[
'prefix'], $params[
'namespace'] ),
115 $db->anyString() ) );
118 if ( $resultPageSet ===
null ) {
125 $selectFields = $resultPageSet->getPageTableFields();
128 $miserModeFilterRedirValue =
null;
129 $miserModeFilterRedir = $miserMode && $params[
'filterredir'] !==
'all';
130 if ( $miserModeFilterRedir ) {
131 $selectFields[] =
'page_is_redirect';
133 if ( $params[
'filterredir'] ==
'redirects' ) {
134 $miserModeFilterRedirValue = 1;
135 } elseif ( $params[
'filterredir'] ==
'nonredirects' ) {
136 $miserModeFilterRedirValue = 0;
141 $forceNameTitleIndex =
true;
142 if ( isset( $params[
'minsize'] ) ) {
143 $this->
addWhere(
'page_len>=' . (
int)$params[
'minsize'] );
144 $forceNameTitleIndex =
false;
147 if ( isset( $params[
'maxsize'] ) ) {
148 $this->
addWhere(
'page_len<=' . (
int)$params[
'maxsize'] );
149 $forceNameTitleIndex =
false;
153 if ( $params[
'prtype'] || $params[
'prexpiry'] !=
'all' ) {
155 $this->
addWhere(
'page_id=pr_page' );
156 $this->
addWhere(
"pr_expiry > {$db->addQuotes( $db->timestamp() )} OR pr_expiry IS NULL" );
158 if ( $params[
'prtype'] ) {
159 $this->
addWhereFld(
'pr_type', $params[
'prtype'] );
161 if ( isset( $params[
'prlevel'] ) ) {
163 $prlevel = array_diff( $params[
'prlevel'], [
'',
'*' ] );
165 if ( count( $prlevel ) ) {
169 if ( $params[
'prfiltercascade'] ==
'cascading' ) {
171 } elseif ( $params[
'prfiltercascade'] ==
'noncascading' ) {
175 $forceNameTitleIndex =
false;
177 if ( $params[
'prexpiry'] ==
'indefinite' ) {
178 $this->
addWhere(
"pr_expiry = {$db->addQuotes( $db->getInfinity() )} OR pr_expiry IS NULL" );
179 } elseif ( $params[
'prexpiry'] ==
'definite' ) {
180 $this->
addWhere(
"pr_expiry != {$db->addQuotes( $db->getInfinity() )}" );
184 } elseif ( isset( $params[
'prlevel'] ) ) {
186 [
'apierror-invalidparammix-mustusewith',
'prlevel',
'prtype' ],
'invalidparammix'
190 if ( $params[
'filterlanglinks'] ==
'withoutlanglinks' ) {
192 $this->
addJoinConds( [
'langlinks' => [
'LEFT JOIN',
'page_id=ll_from' ] ] );
193 $this->
addWhere(
'll_from IS NULL' );
194 $forceNameTitleIndex =
false;
195 } elseif ( $params[
'filterlanglinks'] ==
'withlanglinks' ) {
197 $this->
addWhere(
'page_id=ll_from' );
205 $dbType = $db->getType();
206 if ( $dbType ===
'mysql' || $dbType ===
'sqlite' ) {
211 $this->
addOption(
'GROUP BY', [
'page_title' ] );
212 } elseif ( $dbType ===
'postgres' && $db->getServerVersion() >= 9.1 ) {
214 $this->
addOption(
'GROUP BY', [
'page_title',
'page_id' ] );
217 $this->
addOption(
'GROUP BY', $selectFields );
220 $forceNameTitleIndex =
false;
223 if ( $forceNameTitleIndex ) {
224 $this->
addOption(
'USE INDEX',
'page_name_title' );
227 $limit = $params[
'limit'];
232 if ( $this->namespaceInfo->hasGenderDistinction( $params[
'namespace'] ) ) {
234 foreach (
$res as $row ) {
235 $users[] = $row->page_title;
237 $this->genderCache->doQuery( $users, __METHOD__ );
243 foreach (
$res as $row ) {
244 if ( ++$count > $limit ) {
251 if ( $miserModeFilterRedir && (
int)$row->page_is_redirect !== $miserModeFilterRedirValue ) {
256 if ( $resultPageSet ===
null ) {
257 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
259 'pageid' => (int)$row->page_id,
260 'ns' =>
$title->getNamespace(),
261 'title' =>
$title->getPrefixedText()
263 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
269 $resultPageSet->processDbRow( $row );
273 if ( $resultPageSet ===
null ) {
274 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'p' );
312 'prfiltercascade' => [
334 'filterlanglinks' => [
352 if ( $this->
getConfig()->
get(
'MiserMode' ) ) {
361 'action=query&list=allpages&apfrom=B'
362 =>
'apihelp-query+allpages-example-b',
363 'action=query&generator=allpages&gaplimit=4&gapfrom=T&prop=info'
364 =>
'apihelp-query+allpages-example-generator',
365 'action=query&generator=allpages&gaplimit=2&' .
366 'gapfilterredir=nonredirects&gapfrom=Re&prop=revisions&rvprop=content'
367 =>
'apihelp-query+allpages-example-generator-revisions',
372 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 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.
NamespaceInfo $namespaceInfo
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)
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)
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.
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...