Index: trunk/phase3/includes/api/ApiChangeRights.php |
— | — | @@ -1,155 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -/* |
5 | | - * Created on Sep 11, 2007 |
6 | | - * API for MediaWiki 1.8+ |
7 | | - * |
8 | | - * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl |
9 | | - * |
10 | | - * This program is free software; you can redistribute it and/or modify |
11 | | - * it under the terms of the GNU General Public License as published by |
12 | | - * the Free Software Foundation; either version 2 of the License, or |
13 | | - * (at your option) any later version. |
14 | | - * |
15 | | - * This program is distributed in the hope that it will be useful, |
16 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | | - * GNU General Public License for more details. |
19 | | - * |
20 | | - * You should have received a copy of the GNU General Public License along |
21 | | - * with this program; if not, write to the Free Software Foundation, Inc., |
22 | | - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 | | - * http://www.gnu.org/copyleft/gpl.html |
24 | | - */ |
25 | | - |
26 | | -if (!defined('MEDIAWIKI')) { |
27 | | - // Eclipse helper - will be ignored in production |
28 | | - require_once ("ApiBase.php"); |
29 | | -} |
30 | | - |
31 | | -/** |
32 | | - * API module that facilitates the changing of user rights. The API eqivalent of |
33 | | - * Special:Userrights. Requires API write mode to be enabled. |
34 | | - * |
35 | | - * @addtogroup API |
36 | | - */ |
37 | | -class ApiChangeRights extends ApiBase { |
38 | | - |
39 | | - public function __construct($main, $action) { |
40 | | - parent :: __construct($main, $action); |
41 | | - } |
42 | | - |
43 | | - public function execute() { |
44 | | - global $wgUser, $wgRequest; |
45 | | - $this->getMain()->requestWriteMode(); |
46 | | - |
47 | | - if(wfReadOnly()) |
48 | | - $this->dieUsage('The wiki is in read-only mode', 'readonly'); |
49 | | - $params = $this->extractRequestParams(); |
50 | | - |
51 | | - $ur = new UserrightsPage($wgRequest); |
52 | | - $allowed = $ur->changeableGroups(); |
53 | | - $res = array(); |
54 | | - |
55 | | - $u = $ur->fetchUser_real($params['user']); |
56 | | - if(is_array($u)) |
57 | | - switch($u[0]) |
58 | | - { |
59 | | - case UserrightsPage::FETCHUSER_NO_INTERWIKI: |
60 | | - $this->dieUsage("You don't have permission to change users' rights on other wikis", 'nointerwiki'); |
61 | | - case UserrightsPage::FETCHUSER_NO_DATABASE: |
62 | | - $this->dieUsage("Database ``{$u[1]}'' does not exist or is not local", 'nosuchdatabase'); |
63 | | - case UserrightsPage::FETCHUSER_NO_USER: |
64 | | - $this->dieUsage("You specified an empty username, or none at all", 'emptyuser'); |
65 | | - case UserrightsPage::FETCHUSER_NOSUCH_USERID: |
66 | | - $this->dieUsage("There is no user with ID ``{$u[1]}''", 'nosuchuserid'); |
67 | | - case UserrightsPage::FETCHUSER_NOSUCH_USERNAME: |
68 | | - $this->dieUsage("There is no user with username ``{$u[1]}''", 'nosuchusername'); |
69 | | - default: |
70 | | - $this->dieDebug(__METHOD__, "UserrightsPage::fetchUser_real() returned an unknown error ({$u[0]})"); |
71 | | - } |
72 | | - |
73 | | - $curgroups = $u->getGroups(); |
74 | | - if($params['listgroups']) |
75 | | - { |
76 | | - $res['user'] = $u->getName(); |
77 | | - $res['allowedgroups'] = $allowed; |
78 | | - $res['ingroups'] = $curgroups; |
79 | | - $this->getResult()->setIndexedTagName($res['ingroups'], 'group'); |
80 | | - $this->getResult()->setIndexedTagName($res['allowedgroups']['add'], 'group'); |
81 | | - $this->getResult()->setIndexedTagName($res['allowedgroups']['remove'], 'group'); |
82 | | - } |
83 | | -; |
84 | | - if($params['gettoken']) |
85 | | - { |
86 | | - $res['changerightstoken'] = $wgUser->editToken($u->getName()); |
87 | | - $this->getResult()->addValue(null, $this->getModuleName(), $res); |
88 | | - return; |
89 | | - } |
90 | | - |
91 | | - if(empty($params['addto']) && empty($params['rmfrom'])) |
92 | | - $this->dieUsage('At least one of the addto and rmfrom parameters must be set', 'noaddrm'); |
93 | | - if(is_null($params['token'])) |
94 | | - $this->dieUsage('The token parameter must be set', 'notoken'); |
95 | | - if(!$wgUser->matchEditToken($params['token'], $u->getName())) |
96 | | - $this->dieUsage('Invalid token', 'badtoken'); |
97 | | - |
98 | | - $dbw = wfGetDb(DB_MASTER); |
99 | | - $dbw->begin(); |
100 | | - $ur->saveUserGroups($u, $params['rmfrom'], $params['addto'], $params['reason']); |
101 | | - $dbw->commit(); |
102 | | - $res['user'] = $u->getName(); |
103 | | - $res['addedto'] = (array)$params['addto']; |
104 | | - $res['removedfrom'] = (array)$params['rmfrom']; |
105 | | - $res['reason'] = $params['reason']; |
106 | | - |
107 | | - $this->getResult()->setIndexedTagName($res['addedto'], 'group'); |
108 | | - $this->getResult()->setIndexedTagName($res['removedfrom'], 'group'); |
109 | | - $this->getResult()->addValue(null, $this->getModuleName(), $res); |
110 | | - } |
111 | | - |
112 | | - public function getAllowedParams() { |
113 | | - return array ( |
114 | | - 'user' => null, |
115 | | - 'token' => null, |
116 | | - 'gettoken' => false, |
117 | | - 'listgroups' => false, |
118 | | - 'addto' => array( |
119 | | - ApiBase :: PARAM_ISMULTI => true, |
120 | | - ), |
121 | | - 'rmfrom' => array( |
122 | | - ApiBase :: PARAM_ISMULTI => true, |
123 | | - ), |
124 | | - 'reason' => '' |
125 | | - ); |
126 | | - } |
127 | | - |
128 | | - public function getParamDescription() { |
129 | | - return array ( |
130 | | - 'user' => 'The user you want to add to or remove from groups.', |
131 | | - 'token' => 'A changerights token previously obtained through the gettoken parameter.', |
132 | | - 'gettoken' => 'Output a token. Note that the user parameter still has to be set.', |
133 | | - 'listgroups' => 'List the groups the user is in, and the ones you can add them to and remove them from.', |
134 | | - 'addto' => 'Pipe-separated list of groups to add this user to', |
135 | | - 'rmfrom' => 'Pipe-separated list of groups to remove this user from', |
136 | | - 'reason' => 'Reason for change (optional)' |
137 | | - ); |
138 | | - } |
139 | | - |
140 | | - public function getDescription() { |
141 | | - return array( |
142 | | - 'Add or remove a user from certain groups.' |
143 | | - ); |
144 | | - } |
145 | | - |
146 | | - protected function getExamples() { |
147 | | - return array ( |
148 | | - 'api.php?action=changerights&user=Bob&gettoken&listgroups', |
149 | | - 'api.php?action=changerights&user=Bob&token=123ABC&addto=sysop&reason=Promoting%20per%20RFA' |
150 | | - ); |
151 | | - } |
152 | | - |
153 | | - public function getVersion() { |
154 | | - return __CLASS__ . ': $Id$'; |
155 | | - } |
156 | | -} |
Index: trunk/phase3/includes/api/ApiMain.php |
— | — | @@ -72,8 +72,6 @@ |
73 | 73 | 'unblock' => 'ApiUnblock', |
74 | 74 | 'move' => 'ApiMove', |
75 | 75 | 'edit' => 'ApiEditPage', |
76 | | - #'changerights' => 'ApiChangeRights' |
77 | | - # Disabled for now |
78 | 76 | ); |
79 | 77 | |
80 | 78 | /** |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -373,8 +373,6 @@ |
374 | 374 | |
375 | 375 | # apiedit branch |
376 | 376 | 'ApiBlock' => 'includes/api/ApiBlock.php', |
377 | | - # Disabled for now |
378 | | - #'ApiChangeRights' => 'includes/api/ApiChangeRights.php', |
379 | 377 | 'ApiDelete' => 'includes/api/ApiDelete.php', |
380 | 378 | 'ApiEditPage' => 'includes/api/ApiEditPage.php', |
381 | 379 | 'ApiMove' => 'includes/api/ApiMove.php', |