Index: trunk/phase3/includes/api/ApiUserrights.php |
— | — | @@ -0,0 +1,117 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/* |
| 5 | + * Created on Mar 24, 2009 |
| 6 | + * API for MediaWiki 1.8+ |
| 7 | + * |
| 8 | + * Copyright (C) 2009 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 | +/** |
| 33 | + * @ingroup API |
| 34 | + */ |
| 35 | +class ApiUserrights extends ApiBase { |
| 36 | + |
| 37 | + public function __construct($main, $action) { |
| 38 | + parent :: __construct($main, $action); |
| 39 | + } |
| 40 | + |
| 41 | + public function execute() { |
| 42 | + global $wgUser; |
| 43 | + $params = $this->extractRequestParams(); |
| 44 | + if(is_null($params['user'])) |
| 45 | + $this->dieUsageMsg(array('missingparam', 'user')); |
| 46 | + $user = User::newFromName($params['user']); |
| 47 | + if($user->isAnon()) |
| 48 | + $this->dieUsageMsg(array('nosuchuser', $params['user'])); |
| 49 | + if(is_null($params['token'])) |
| 50 | + $this->dieUsageMsg(array('missingparam', 'token')); |
| 51 | + if(!$wgUser->matchEditToken($params['token'], $user->getName())) |
| 52 | + $this->dieUsageMsg(array('sessionfailure')); |
| 53 | + |
| 54 | + $r['user'] = $user->getName(); |
| 55 | + list($r['added'], $r['removed']) = |
| 56 | + UserrightsPage::doSaveUserGroups( |
| 57 | + $user, (array)$params['add'], |
| 58 | + (array)$params['remove'], $params['reason']); |
| 59 | + |
| 60 | + $this->getResult()->setIndexedTagName($r['added'], 'group'); |
| 61 | + $this->getResult()->setIndexedTagName($r['removed'], 'group'); |
| 62 | + $this->getResult()->addValue(null, $this->getModuleName(), $r); |
| 63 | + } |
| 64 | + |
| 65 | + public function mustBePosted() { |
| 66 | + return true; |
| 67 | + } |
| 68 | + |
| 69 | + public function isWriteMode() { |
| 70 | + return true; |
| 71 | + } |
| 72 | + |
| 73 | + public function getAllowedParams() { |
| 74 | + return array ( |
| 75 | + 'user' => array( |
| 76 | + ApiBase :: PARAM_TYPE => 'user' |
| 77 | + ), |
| 78 | + 'add' => array( |
| 79 | + ApiBase :: PARAM_TYPE => User::getAllGroups(), |
| 80 | + ApiBase :: PARAM_ISMULTI => true |
| 81 | + ), |
| 82 | + 'remove' => array( |
| 83 | + ApiBase :: PARAM_TYPE => User::getAllGroups(), |
| 84 | + ApiBase :: PARAM_ISMULTI => true |
| 85 | + ), |
| 86 | + 'token' => null, |
| 87 | + 'reason' => array( |
| 88 | + ApiBase :: PARAM_DFLT => '' |
| 89 | + ) |
| 90 | + ); |
| 91 | + } |
| 92 | + |
| 93 | + public function getParamDescription() { |
| 94 | + return array ( |
| 95 | + 'user' => 'User name', |
| 96 | + 'add' => 'Add the user to these groups', |
| 97 | + 'remove' => 'Remove the user from these groups', |
| 98 | + 'token' => 'A userrights token previously retrieved through list=users', |
| 99 | + 'reason' => 'Reason for the change', |
| 100 | + ); |
| 101 | + } |
| 102 | + |
| 103 | + public function getDescription() { |
| 104 | + return array( |
| 105 | + 'Add/remove a user to/from groups', |
| 106 | + ); |
| 107 | + } |
| 108 | + |
| 109 | + protected function getExamples() { |
| 110 | + return array ( |
| 111 | + 'api.php?action=userrights&user=FooBot&add=bot&remove=sysop|bureaucrat&token=123ABC' |
| 112 | + ); |
| 113 | + } |
| 114 | + |
| 115 | + public function getVersion() { |
| 116 | + return __CLASS__ . ': $Id: ApiMove.php 48091 2009-03-06 13:49:44Z catrope $'; |
| 117 | + } |
| 118 | +} |
Property changes on: trunk/phase3/includes/api/ApiUserrights.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 119 | + native |