Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 56 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
ApiQueryWikiSets | |
0.00% |
0 / 56 |
|
0.00% |
0 / 5 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
56 | |||
getCacheMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAllowedParams | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Created on Sep 06, 2012 |
4 | * |
5 | * CentralAuth extension |
6 | * |
7 | * Copyright (C) 2012 Jan Luca Naumann jan AT toolserver DOT org |
8 | * |
9 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or |
12 | * (at your option) any later version. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License along |
20 | * with this program; if not, write to the Free Software Foundation, Inc., |
21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
22 | * http://www.gnu.org/copyleft/gpl.html |
23 | */ |
24 | |
25 | namespace MediaWiki\Extension\CentralAuth\Api; |
26 | |
27 | use ApiBase; |
28 | use ApiQuery; |
29 | use ApiQueryBase; |
30 | use MediaWiki\Extension\CentralAuth\CentralAuthWikiListService; |
31 | use MediaWiki\Extension\CentralAuth\WikiSet; |
32 | use Wikimedia\ParamValidator\ParamValidator; |
33 | use Wikimedia\ParamValidator\TypeDef\IntegerDef; |
34 | |
35 | /** |
36 | * Query module to list the wiki sets |
37 | * |
38 | * @ingroup API |
39 | * @ingroup Extensions |
40 | */ |
41 | class ApiQueryWikiSets extends ApiQueryBase { |
42 | /** @var CentralAuthWikiListService */ |
43 | private $wikiListService; |
44 | |
45 | /** |
46 | * @param ApiQuery $query |
47 | * @param string $moduleName |
48 | * @param CentralAuthWikiListService $wikiListService |
49 | */ |
50 | public function __construct( ApiQuery $query, $moduleName, CentralAuthWikiListService $wikiListService ) { |
51 | parent::__construct( $query, $moduleName, 'ws' ); |
52 | |
53 | $this->wikiListService = $wikiListService; |
54 | } |
55 | |
56 | public function execute() { |
57 | $params = $this->extractRequestParams(); |
58 | |
59 | $prop = array_flip( (array)$params['prop'] ); |
60 | $from = $params['from'] ?? null; |
61 | |
62 | $APIResult = $this->getResult(); |
63 | $data = []; |
64 | |
65 | $wikiList = $this->wikiListService->getWikiList(); |
66 | |
67 | /** |
68 | * @var $wikiSet WikiSet |
69 | */ |
70 | foreach ( |
71 | WikiSet::getAllWikiSets( $from, $params['limit'], $params['orderbyname'] ) as $wikiSet |
72 | ) { |
73 | $entry = []; |
74 | $entry['id'] = $wikiSet->getId(); |
75 | $entry['name'] = $wikiSet->getName(); |
76 | |
77 | if ( isset( $prop['type'] ) ) { |
78 | $entry['type'] = $wikiSet->getType(); |
79 | } |
80 | |
81 | if ( isset( $prop['wikisincluded'] ) ) { |
82 | $entry['wikisincluded'] = $wikiSet->getWikis(); |
83 | if ( count( $entry['wikisincluded'] ) ) { |
84 | $APIResult->setIndexedTagName( $entry['wikisincluded'], 'wiki' ); |
85 | } |
86 | } |
87 | |
88 | if ( isset( $prop['wikisnotincluded'] ) ) { |
89 | $entry['wikisnotincluded'] = array_diff( |
90 | $wikiList, $wikiSet->getWikis() ); |
91 | if ( count( $entry['wikisnotincluded'] ) ) { |
92 | $APIResult->setIndexedTagName( $entry['wikisnotincluded'], 'wiki' ); |
93 | } |
94 | } |
95 | |
96 | $data[] = $entry; |
97 | } |
98 | |
99 | $APIResult->setIndexedTagName( $data, 'wikiset' ); |
100 | |
101 | $APIResult->addValue( 'query', $this->getModuleName(), $data ); |
102 | } |
103 | |
104 | /** @inheritDoc */ |
105 | public function getCacheMode( $params ) { |
106 | return 'public'; |
107 | } |
108 | |
109 | /** @inheritDoc */ |
110 | public function getAllowedParams() { |
111 | return [ |
112 | 'from' => null, |
113 | 'prop' => [ |
114 | ParamValidator::PARAM_ISMULTI => true, |
115 | ParamValidator::PARAM_TYPE => [ |
116 | 'type', |
117 | 'wikisincluded', |
118 | 'wikisnotincluded' |
119 | ], |
120 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [], |
121 | ], |
122 | 'limit' => [ |
123 | ParamValidator::PARAM_DEFAULT => 10, |
124 | ParamValidator::PARAM_TYPE => 'limit', |
125 | IntegerDef::PARAM_MIN => 1, |
126 | IntegerDef::PARAM_MAX => ApiBase::LIMIT_BIG1, |
127 | IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
128 | ], |
129 | 'orderbyname' => [ |
130 | ParamValidator::PARAM_DEFAULT => false, |
131 | ParamValidator::PARAM_TYPE => 'boolean' |
132 | ] |
133 | ]; |
134 | } |
135 | |
136 | /** @inheritDoc */ |
137 | protected function getExamplesMessages() { |
138 | return [ |
139 | 'action=query&list=wikisets' |
140 | => 'apihelp-query+wikisets-example-1', |
141 | 'action=query&list=wikisets&wsprop=type&wslimit=200' |
142 | => 'apihelp-query+wikisets-example-2', |
143 | ]; |
144 | } |
145 | } |