]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/api/ApiQueryPagePropNames.php
MediaWiki 1.30.2
[autoinstalls/mediawiki.git] / includes / api / ApiQueryPagePropNames.php
1 <?php
2 /**
3  * Created on January 21, 2013
4  *
5  * Copyright © 2013 Wikimedia Foundation and contributors
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  * http://www.gnu.org/copyleft/gpl.html
21  *
22  * @file
23  * @since 1.21
24  */
25
26 /**
27  * A query module to list used page props
28  *
29  * @ingroup API
30  * @since 1.21
31  */
32 class ApiQueryPagePropNames extends ApiQueryBase {
33
34         public function __construct( ApiQuery $query, $moduleName ) {
35                 parent::__construct( $query, $moduleName, 'ppn' );
36         }
37
38         public function getCacheMode( $params ) {
39                 return 'public';
40         }
41
42         public function execute() {
43                 $params = $this->extractRequestParams();
44
45                 $this->addTables( 'page_props' );
46                 $this->addFields( 'pp_propname' );
47                 $this->addOption( 'DISTINCT' );
48                 $this->addOption( 'ORDER BY', 'pp_propname' );
49
50                 if ( $params['continue'] ) {
51                         $cont = explode( '|', $params['continue'] );
52                         $this->dieContinueUsageIf( count( $cont ) != 1 );
53
54                         // Add a WHERE clause
55                         $this->addWhereRange( 'pp_propname', 'newer', $cont[0], null );
56                 }
57
58                 $limit = $params['limit'];
59
60                 // mysql has issues with limit in loose index T115825
61                 if ( $this->getDB()->getType() !== 'mysql' ) {
62                         $this->addOption( 'LIMIT', $limit + 1 );
63                 }
64
65                 $result = $this->getResult();
66                 $count = 0;
67                 foreach ( $this->select( __METHOD__ ) as $row ) {
68                         if ( ++$count > $limit ) {
69                                 // We've reached the one extra which shows that there are
70                                 // additional pages to be had. Stop here...
71                                 $this->setContinueEnumParameter( 'continue', $row->pp_propname );
72                                 break;
73                         }
74
75                         $vals = [];
76                         $vals['propname'] = $row->pp_propname;
77                         $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $vals );
78                         if ( !$fit ) {
79                                 $this->setContinueEnumParameter( 'continue', $row->pp_propname );
80                                 break;
81                         }
82                 }
83
84                 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'p' );
85         }
86
87         public function getAllowedParams() {
88                 return [
89                         'continue' => [
90                                 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
91                         ],
92                         'limit' => [
93                                 ApiBase::PARAM_TYPE => 'limit',
94                                 ApiBase::PARAM_DFLT => 10,
95                                 ApiBase::PARAM_MIN => 1,
96                                 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
97                                 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
98                         ],
99                 ];
100         }
101
102         protected function getExamplesMessages() {
103                 return [
104                         'action=query&list=pagepropnames'
105                                 => 'apihelp-query+pagepropnames-example-simple',
106                 ];
107         }
108
109         public function getHelpUrls() {
110                 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Pagepropnames';
111         }
112 }