Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 44 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
ApiQueryGlobalGroups | |
0.00% |
0 / 44 |
|
0.00% |
0 / 5 |
156 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
72 | |||
getCacheMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAllowedParams | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Created on Sep 20, 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 ApiQuery; |
28 | use ApiQueryBase; |
29 | use MediaWiki\Extension\CentralAuth\CentralAuthDatabaseManager; |
30 | use Wikimedia\ParamValidator\ParamValidator; |
31 | |
32 | /** |
33 | * Query module to list all global groups |
34 | * |
35 | * @ingroup API |
36 | * @ingroup Extensions |
37 | */ |
38 | class ApiQueryGlobalGroups extends ApiQueryBase { |
39 | |
40 | /** @var CentralAuthDatabaseManager */ |
41 | private $databaseManager; |
42 | |
43 | /** |
44 | * @param ApiQuery $query |
45 | * @param string $moduleName |
46 | * @param CentralAuthDatabaseManager $databaseManager |
47 | */ |
48 | public function __construct( |
49 | $query, |
50 | $moduleName, |
51 | CentralAuthDatabaseManager $databaseManager |
52 | ) { |
53 | parent::__construct( $query, $moduleName, 'ggp' ); |
54 | $this->databaseManager = $databaseManager; |
55 | } |
56 | |
57 | public function execute() { |
58 | $params = $this->extractRequestParams(); |
59 | |
60 | $prop = array_flip( (array)$params['prop'] ); |
61 | |
62 | $APIResult = $this->getResult(); |
63 | $data = []; |
64 | |
65 | $dbr = $this->databaseManager->getCentralReplicaDB(); |
66 | |
67 | $qb = $dbr->newSelectQueryBuilder() |
68 | ->select( 'ggp_group' ) |
69 | ->distinct() |
70 | ->from( 'global_group_permissions' ) |
71 | ->caller( __METHOD__ ); |
72 | |
73 | if ( isset( $prop['rights'] ) ) { |
74 | $qb->select( 'ggp_permission' ); |
75 | } |
76 | |
77 | $result = $qb->fetchResultSet(); |
78 | |
79 | $globalGroups = []; |
80 | |
81 | foreach ( $result as $row ) { |
82 | if ( !isset( $globalGroups[$row->ggp_group] ) ) { |
83 | $globalGroups[$row->ggp_group] = [ 'rights' => [] ]; |
84 | } |
85 | |
86 | if ( isset( $prop['rights'] ) ) { |
87 | $globalGroups[$row->ggp_group]['rights'][] = $row->ggp_permission; |
88 | } |
89 | } |
90 | |
91 | foreach ( $globalGroups as $name => $value ) { |
92 | $entry = [ 'name' => $name ]; |
93 | |
94 | if ( isset( $prop['rights'] ) && count( $value['rights'] ) ) { |
95 | $entry['rights'] = $value['rights']; |
96 | $APIResult->setIndexedTagName( $entry['rights'], 'right' ); |
97 | } |
98 | |
99 | $data[] = $entry; |
100 | } |
101 | |
102 | $APIResult->setIndexedTagName( $data, 'globalgroup' ); |
103 | |
104 | $APIResult->addValue( 'query', $this->getModuleName(), $data ); |
105 | } |
106 | |
107 | /** @inheritDoc */ |
108 | public function getCacheMode( $params ) { |
109 | return 'public'; |
110 | } |
111 | |
112 | /** @inheritDoc */ |
113 | public function getAllowedParams() { |
114 | return [ |
115 | 'prop' => [ |
116 | ParamValidator::PARAM_ISMULTI => true, |
117 | ParamValidator::PARAM_TYPE => [ |
118 | 'rights', |
119 | ] |
120 | ] |
121 | ]; |
122 | } |
123 | |
124 | /** @inheritDoc */ |
125 | protected function getExamplesMessages() { |
126 | return [ |
127 | 'action=query&list=globalgroups' |
128 | => 'apihelp-query+globalgroups-example-1', |
129 | 'action=query&list=globalgroups&ggpprop=rights' |
130 | => 'apihelp-query+globalgroups-example-2', |
131 | ]; |
132 | } |
133 | } |