MediaWiki master
ApiQueryPagePropNames.php
Go to the documentation of this file.
1<?php
26
34
35 public function __construct( ApiQuery $query, $moduleName ) {
36 parent::__construct( $query, $moduleName, 'ppn' );
37 }
38
39 public function getCacheMode( $params ) {
40 return 'public';
41 }
42
43 public function execute() {
45
46 $this->addTables( 'page_props' );
47 $this->addFields( 'pp_propname' );
48 $this->addOption( 'DISTINCT' );
49 $this->addOption( 'ORDER BY', 'pp_propname' );
50
51 if ( $params['continue'] ) {
52 $cont = $this->parseContinueParamOrDie( $params['continue'], [ 'string' ] );
53 // Add a WHERE clause
54 $this->addWhereRange( 'pp_propname', 'newer', $cont[0], null );
55 }
56
57 $limit = $params['limit'];
58
59 // mysql has issues with limit in loose index T115825
60 if ( $this->getDB()->getType() !== 'mysql' ) {
61 $this->addOption( 'LIMIT', $limit + 1 );
62 }
63
64 $result = $this->getResult();
65 $count = 0;
66 foreach ( $this->select( __METHOD__ ) as $row ) {
67 if ( ++$count > $limit ) {
68 // We've reached the one extra which shows that there are
69 // additional pages to be had. Stop here...
70 $this->setContinueEnumParameter( 'continue', $row->pp_propname );
71 break;
72 }
73
74 $vals = [];
75 $vals['propname'] = $row->pp_propname;
76 $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $vals );
77 if ( !$fit ) {
78 $this->setContinueEnumParameter( 'continue', $row->pp_propname );
79 break;
80 }
81 }
82
83 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'p' );
84 }
85
86 public function getAllowedParams() {
87 return [
88 'continue' => [
89 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
90 ],
91 'limit' => [
92 ParamValidator::PARAM_TYPE => 'limit',
93 ParamValidator::PARAM_DEFAULT => 10,
94 IntegerDef::PARAM_MIN => 1,
95 IntegerDef::PARAM_MAX => ApiBase::LIMIT_BIG1,
96 IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_BIG2
97 ],
98 ];
99 }
100
101 protected function getExamplesMessages() {
102 return [
103 'action=query&list=pagepropnames'
104 => 'apihelp-query+pagepropnames-example-simple',
105 ];
106 }
107
108 public function getHelpUrls() {
109 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Pagepropnames';
110 }
111}
array $params
The job parameters.
parseContinueParamOrDie(string $continue, array $types)
Parse the 'continue' parameter in the usual format and validate the types of each part,...
Definition ApiBase.php:1734
const LIMIT_BIG1
Fast query, standard limit.
Definition ApiBase.php:236
getResult()
Get the result object.
Definition ApiBase.php:680
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:820
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:171
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition ApiBase.php:238
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:541
This is a base class for all Query modules.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
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.
A query module to list used page props.
__construct(ApiQuery $query, $moduleName)
getExamplesMessages()
Returns usage examples for this module.
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.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
This is the main query class.
Definition ApiQuery.php:43
Service for formatting and validating API parameters.
Type definition for integer types.