MediaWiki  master
ApiQueryPagePropNames.php
Go to the documentation of this file.
1 <?php
31 
32  public function __construct( ApiQuery $query, $moduleName ) {
33  parent::__construct( $query, $moduleName, 'ppn' );
34  }
35 
36  public function getCacheMode( $params ) {
37  return 'public';
38  }
39 
40  public function execute() {
41  $params = $this->extractRequestParams();
42 
43  $this->addTables( 'page_props' );
44  $this->addFields( 'pp_propname' );
45  $this->addOption( 'DISTINCT' );
46  $this->addOption( 'ORDER BY', 'pp_propname' );
47 
48  if ( $params['continue'] ) {
49  $cont = explode( '|', $params['continue'] );
50  $this->dieContinueUsageIf( count( $cont ) != 1 );
51 
52  // Add a WHERE clause
53  $this->addWhereRange( 'pp_propname', 'newer', $cont[0], null );
54  }
55 
56  $limit = $params['limit'];
57 
58  // mysql has issues with limit in loose index T115825
59  if ( $this->getDB()->getType() !== 'mysql' ) {
60  $this->addOption( 'LIMIT', $limit + 1 );
61  }
62 
63  $result = $this->getResult();
64  $count = 0;
65  foreach ( $this->select( __METHOD__ ) as $row ) {
66  if ( ++$count > $limit ) {
67  // We've reached the one extra which shows that there are
68  // additional pages to be had. Stop here...
69  $this->setContinueEnumParameter( 'continue', $row->pp_propname );
70  break;
71  }
72 
73  $vals = [];
74  $vals['propname'] = $row->pp_propname;
75  $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $vals );
76  if ( !$fit ) {
77  $this->setContinueEnumParameter( 'continue', $row->pp_propname );
78  break;
79  }
80  }
81 
82  $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'p' );
83  }
84 
85  public function getAllowedParams() {
86  return [
87  'continue' => [
88  ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
89  ],
90  'limit' => [
91  ApiBase::PARAM_TYPE => 'limit',
92  ApiBase::PARAM_DFLT => 10,
93  ApiBase::PARAM_MIN => 1,
96  ],
97  ];
98  }
99 
100  protected function getExamplesMessages() {
101  return [
102  'action=query&list=pagepropnames'
103  => 'apihelp-query+pagepropnames-example-simple',
104  ];
105  }
106 
107  public function getHelpUrls() {
108  return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Pagepropnames';
109  }
110 }
ApiQueryBase\addFields
addFields( $value)
Add a set of fields to select to the internal array.
Definition: ApiQueryBase.php:215
ApiQuery
This is the main query class.
Definition: ApiQuery.php:37
ApiBase\PARAM_HELP_MSG
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition: ApiBase.php:107
ApiBase\PARAM_TYPE
const PARAM_TYPE
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:71
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:565
ApiQueryBase\addOption
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
Definition: ApiQueryBase.php:381
ApiBase\PARAM_MIN
const PARAM_MIN
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:74
ApiQueryPagePropNames\__construct
__construct(ApiQuery $query, $moduleName)
Definition: ApiQueryPagePropNames.php:32
ApiQueryPagePropNames\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiQueryPagePropNames.php:107
ApiQueryBase
This is a base class for all Query modules.
Definition: ApiQueryBase.php:37
ApiBase\LIMIT_BIG1
const LIMIT_BIG1
Fast query, standard limit.
Definition: ApiBase.php:165
ApiQueryBase\getDB
getDB()
Get the Query database connection (read-only) Stable to override.
Definition: ApiQueryBase.php:119
ApiBase\PARAM_MAX
const PARAM_MAX
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:72
ApiQueryBase\addTables
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
Definition: ApiQueryBase.php:185
ApiQueryPagePropNames
A query module to list used page props.
Definition: ApiQueryPagePropNames.php:30
ApiQueryBase\select
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
Definition: ApiQueryBase.php:402
ApiBase\extractRequestParams
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:717
ApiQueryBase\addWhereRange
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.
Definition: ApiQueryBase.php:340
ApiBase\dieContinueUsageIf
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
Definition: ApiBase.php:1562
ApiQueryPagePropNames\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiQueryPagePropNames.php:100
ApiBase\LIMIT_BIG2
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition: ApiBase.php:167
ApiBase\PARAM_DFLT
const PARAM_DFLT
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:69
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:444
ApiBase\PARAM_MAX2
const PARAM_MAX2
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:73
ApiQueryPagePropNames\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryPagePropNames.php:85
ApiQueryBase\setContinueEnumParameter
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
Definition: ApiQueryBase.php:519
ApiQueryPagePropNames\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryPagePropNames.php:40
ApiQueryPagePropNames\getCacheMode
getCacheMode( $params)
Get the cache mode for the data generated by this module.
Definition: ApiQueryPagePropNames.php:36