User: Avoid deprecated Linker::link()
[lhc/web/wiklou.git] / includes / api / ApiQueryPagePropNames.php
1 <?php
2 /**
3 * Created on January 21, 2013
4 *
5 * Copyright © 2013 Brad Jorsch <bjorsch@wikimedia.org>
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 * @author Brad Jorsch
25 */
26
27 /**
28 * A query module to list used page props
29 *
30 * @ingroup API
31 * @since 1.21
32 */
33 class ApiQueryPagePropNames extends ApiQueryBase {
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() {
44 $params = $this->extractRequestParams();
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 = explode( '|', $params['continue'] );
53 $this->dieContinueUsageIf( count( $cont ) != 1 );
54
55 // Add a WHERE clause
56 $this->addWhereRange( 'pp_propname', 'newer', $cont[0], null );
57 }
58
59 $limit = $params['limit'];
60
61 // mysql has issues with limit in loose index T115825
62 if ( $this->getDB()->getType() !== 'mysql' ) {
63 $this->addOption( 'LIMIT', $limit + 1 );
64 }
65
66 $result = $this->getResult();
67 $count = 0;
68 foreach ( $this->select( __METHOD__ ) as $row ) {
69 if ( ++$count > $limit ) {
70 // We've reached the one extra which shows that there are
71 // additional pages to be had. Stop here...
72 $this->setContinueEnumParameter( 'continue', $row->pp_propname );
73 break;
74 }
75
76 $vals = [];
77 $vals['propname'] = $row->pp_propname;
78 $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $vals );
79 if ( !$fit ) {
80 $this->setContinueEnumParameter( 'continue', $row->pp_propname );
81 break;
82 }
83 }
84
85 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'p' );
86 }
87
88 public function getAllowedParams() {
89 return [
90 'continue' => [
91 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
92 ],
93 'limit' => [
94 ApiBase::PARAM_TYPE => 'limit',
95 ApiBase::PARAM_DFLT => 10,
96 ApiBase::PARAM_MIN => 1,
97 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
98 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
99 ],
100 ];
101 }
102
103 protected function getExamplesMessages() {
104 return [
105 'action=query&list=pagepropnames'
106 => 'apihelp-query+pagepropnames-example-simple',
107 ];
108 }
109
110 public function getHelpUrls() {
111 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Pagepropnames';
112 }
113 }