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