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 MediaWiki\Api\ApiBase; |
28 | use MediaWiki\Api\ApiQuery; |
29 | use MediaWiki\Api\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 | |
43 | private CentralAuthWikiListService $wikiListService; |
44 | |
45 | public function __construct( |
46 | ApiQuery $query, |
47 | string $moduleName, |
48 | CentralAuthWikiListService $wikiListService |
49 | ) { |
50 | parent::__construct( $query, $moduleName, 'ws' ); |
51 | $this->wikiListService = $wikiListService; |
52 | } |
53 | |
54 | public function execute() { |
55 | $params = $this->extractRequestParams(); |
56 | |
57 | $prop = array_flip( (array)$params['prop'] ); |
58 | $from = $params['from'] ?? null; |
59 | |
60 | $APIResult = $this->getResult(); |
61 | $data = []; |
62 | |
63 | $wikiList = $this->wikiListService->getWikiList(); |
64 | |
65 | foreach ( |
66 | WikiSet::getAllWikiSets( $from, $params['limit'], $params['orderbyname'] ) as $wikiSet |
67 | ) { |
68 | $entry = []; |
69 | $entry['id'] = $wikiSet->getId(); |
70 | $entry['name'] = $wikiSet->getName(); |
71 | |
72 | if ( isset( $prop['type'] ) ) { |
73 | $entry['type'] = $wikiSet->getType(); |
74 | } |
75 | |
76 | if ( isset( $prop['wikisincluded'] ) ) { |
77 | $entry['wikisincluded'] = $wikiSet->getWikis(); |
78 | if ( count( $entry['wikisincluded'] ) ) { |
79 | $APIResult->setIndexedTagName( $entry['wikisincluded'], 'wiki' ); |
80 | } |
81 | } |
82 | |
83 | if ( isset( $prop['wikisnotincluded'] ) ) { |
84 | $entry['wikisnotincluded'] = array_diff( |
85 | $wikiList, $wikiSet->getWikis() ); |
86 | if ( count( $entry['wikisnotincluded'] ) ) { |
87 | $APIResult->setIndexedTagName( $entry['wikisnotincluded'], 'wiki' ); |
88 | } |
89 | } |
90 | |
91 | $data[] = $entry; |
92 | } |
93 | |
94 | $APIResult->setIndexedTagName( $data, 'wikiset' ); |
95 | |
96 | $APIResult->addValue( 'query', $this->getModuleName(), $data ); |
97 | } |
98 | |
99 | /** @inheritDoc */ |
100 | public function getCacheMode( $params ) { |
101 | return 'public'; |
102 | } |
103 | |
104 | /** @inheritDoc */ |
105 | public function getAllowedParams() { |
106 | return [ |
107 | 'from' => null, |
108 | 'prop' => [ |
109 | ParamValidator::PARAM_ISMULTI => true, |
110 | ParamValidator::PARAM_TYPE => [ |
111 | 'type', |
112 | 'wikisincluded', |
113 | 'wikisnotincluded' |
114 | ], |
115 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [], |
116 | ], |
117 | 'limit' => [ |
118 | ParamValidator::PARAM_DEFAULT => 10, |
119 | ParamValidator::PARAM_TYPE => 'limit', |
120 | IntegerDef::PARAM_MIN => 1, |
121 | IntegerDef::PARAM_MAX => ApiBase::LIMIT_BIG1, |
122 | IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
123 | ], |
124 | 'orderbyname' => [ |
125 | ParamValidator::PARAM_DEFAULT => false, |
126 | ParamValidator::PARAM_TYPE => 'boolean' |
127 | ] |
128 | ]; |
129 | } |
130 | |
131 | /** @inheritDoc */ |
132 | protected function getExamplesMessages() { |
133 | return [ |
134 | 'action=query&list=wikisets' |
135 | => 'apihelp-query+wikisets-example-1', |
136 | 'action=query&list=wikisets&wsprop=type&wslimit=200' |
137 | => 'apihelp-query+wikisets-example-2', |
138 | ]; |
139 | } |
140 | } |