Remove Revision::getRevisionText from ApiQueryDeletedrevs
[lhc/web/wiklou.git] / includes / api / ApiQueryPagePropNames.php
1 <?php
2 /**
3 * Copyright © 2013 Wikimedia Foundation and contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @since 1.21
22 */
23
24 /**
25 * A query module to list used page props
26 *
27 * @ingroup API
28 * @since 1.21
29 */
30 class ApiQueryPagePropNames extends ApiQueryBase {
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,
94 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
95 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
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 }