diff options
Diffstat (limited to 'includes/api')
-rw-r--r-- | includes/api/ApiChangeRights.php | 155 | ||||
-rw-r--r-- | includes/api/ApiFormatBase.php | 11 | ||||
-rw-r--r-- | includes/api/ApiMain.php | 4 |
3 files changed, 11 insertions, 159 deletions
diff --git a/includes/api/ApiChangeRights.php b/includes/api/ApiChangeRights.php deleted file mode 100644 index 647a5194..00000000 --- a/includes/api/ApiChangeRights.php +++ /dev/null @@ -1,155 +0,0 @@ -<?php - -/* - * Created on Sep 11, 2007 - * API for MediaWiki 1.8+ - * - * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * http://www.gnu.org/copyleft/gpl.html - */ - -if (!defined('MEDIAWIKI')) { - // Eclipse helper - will be ignored in production - require_once ("ApiBase.php"); -} - -/** - * API module that facilitates the changing of user rights. The API eqivalent of - * Special:Userrights. Requires API write mode to be enabled. - * - * @addtogroup API - */ -class ApiChangeRights extends ApiBase { - - public function __construct($main, $action) { - parent :: __construct($main, $action); - } - - public function execute() { - global $wgUser, $wgRequest; - $this->getMain()->requestWriteMode(); - - if(wfReadOnly()) - $this->dieUsage('The wiki is in read-only mode', 'readonly'); - $params = $this->extractRequestParams(); - - $ur = new UserrightsPage($wgRequest); - $allowed = $ur->changeableGroups(); - $res = array(); - - $u = $ur->fetchUser_real($params['user']); - if(is_array($u)) - switch($u[0]) - { - case UserrightsPage::FETCHUSER_NO_INTERWIKI: - $this->dieUsage("You don't have permission to change users' rights on other wikis", 'nointerwiki'); - case UserrightsPage::FETCHUSER_NO_DATABASE: - $this->dieUsage("Database ``{$u[1]}'' does not exist or is not local", 'nosuchdatabase'); - case UserrightsPage::FETCHUSER_NO_USER: - $this->dieUsage("You specified an empty username, or none at all", 'emptyuser'); - case UserrightsPage::FETCHUSER_NOSUCH_USERID: - $this->dieUsage("There is no user with ID ``{$u[1]}''", 'nosuchuserid'); - case UserrightsPage::FETCHUSER_NOSUCH_USERNAME: - $this->dieUsage("There is no user with username ``{$u[1]}''", 'nosuchusername'); - default: - $this->dieDebug(__METHOD__, "UserrightsPage::fetchUser_real() returned an unknown error ({$u[0]})"); - } - - $curgroups = $u->getGroups(); - if($params['listgroups']) - { - $res['user'] = $u->getName(); - $res['allowedgroups'] = $allowed; - $res['ingroups'] = $curgroups; - $this->getResult()->setIndexedTagName($res['ingroups'], 'group'); - $this->getResult()->setIndexedTagName($res['allowedgroups']['add'], 'group'); - $this->getResult()->setIndexedTagName($res['allowedgroups']['remove'], 'group'); - } -; - if($params['gettoken']) - { - $res['changerightstoken'] = $wgUser->editToken($u->getName()); - $this->getResult()->addValue(null, $this->getModuleName(), $res); - return; - } - - if(empty($params['addto']) && empty($params['rmfrom'])) - $this->dieUsage('At least one of the addto and rmfrom parameters must be set', 'noaddrm'); - if(is_null($params['token'])) - $this->dieUsage('The token parameter must be set', 'notoken'); - if(!$wgUser->matchEditToken($params['token'], $u->getName())) - $this->dieUsage('Invalid token', 'badtoken'); - - $dbw = wfGetDb(DB_MASTER); - $dbw->begin(); - $ur->saveUserGroups($u, $params['rmfrom'], $params['addto'], $params['reason']); - $dbw->commit(); - $res['user'] = $u->getName(); - $res['addedto'] = (array)$params['addto']; - $res['removedfrom'] = (array)$params['rmfrom']; - $res['reason'] = $params['reason']; - - $this->getResult()->setIndexedTagName($res['addedto'], 'group'); - $this->getResult()->setIndexedTagName($res['removedfrom'], 'group'); - $this->getResult()->addValue(null, $this->getModuleName(), $res); - } - - public function getAllowedParams() { - return array ( - 'user' => null, - 'token' => null, - 'gettoken' => false, - 'listgroups' => false, - 'addto' => array( - ApiBase :: PARAM_ISMULTI => true, - ), - 'rmfrom' => array( - ApiBase :: PARAM_ISMULTI => true, - ), - 'reason' => '' - ); - } - - public function getParamDescription() { - return array ( - 'user' => 'The user you want to add to or remove from groups.', - 'token' => 'A changerights token previously obtained through the gettoken parameter.', - 'gettoken' => 'Output a token. Note that the user parameter still has to be set.', - 'listgroups' => 'List the groups the user is in, and the ones you can add them to and remove them from.', - 'addto' => 'Pipe-separated list of groups to add this user to', - 'rmfrom' => 'Pipe-separated list of groups to remove this user from', - 'reason' => 'Reason for change (optional)' - ); - } - - public function getDescription() { - return array( - 'Add or remove a user from certain groups.' - ); - } - - protected function getExamples() { - return array ( - 'api.php?action=changerights&user=Bob&gettoken&listgroups', - 'api.php?action=changerights&user=Bob&token=123ABC&addto=sysop&reason=Promoting%20per%20RFA' - ); - } - - public function getVersion() { - return __CLASS__ . ': $Id: ApiChangeRights.php 28216 2007-12-06 18:33:18Z vasilievvv $'; - } -} diff --git a/includes/api/ApiFormatBase.php b/includes/api/ApiFormatBase.php index db58fe52..8f08f4db 100644 --- a/includes/api/ApiFormatBase.php +++ b/includes/api/ApiFormatBase.php @@ -70,6 +70,13 @@ abstract class ApiFormatBase extends ApiBase { } /** + * Get the internal format name + */ + public function getFormat() { + return $this->mFormat; + } + + /** * Specify whether or not ampersands should be escaped to '&' when rendering. This * should only be set to true for the help message when rendered in the default (xmlfm) * format. This is a temporary special-case fix that should be removed once the help @@ -232,7 +239,7 @@ See <a href='http://www.mediawiki.org/wiki/API'>complete documentation</a>, or } public static function getBaseVersion() { - return __CLASS__ . ': $Id: ApiFormatBase.php 36153 2008-06-10 15:20:22Z tstarling $'; + return __CLASS__ . ': $Id: ApiFormatBase.php 44569 2008-12-14 08:31:04Z tstarling $'; } } @@ -293,6 +300,6 @@ class ApiFormatFeedWrapper extends ApiFormatBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiFormatBase.php 36153 2008-06-10 15:20:22Z tstarling $'; + return __CLASS__ . ': $Id: ApiFormatBase.php 44569 2008-12-14 08:31:04Z tstarling $'; } } diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index cce4c3e7..2d0e278c 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -403,7 +403,7 @@ class ApiMain extends ApiBase { * tell the printer not to escape ampersands so that our links do * not break. */ $printer->setUnescapeAmps ( ( $this->mAction == 'help' || $isError ) - && $this->getParameter('format') == ApiMain::API_DEFAULT_FORMAT ); + && $printer->getFormat() == 'XML' && $printer->getIsHtml() ); $printer->initPrinter($isError); @@ -603,7 +603,7 @@ class ApiMain extends ApiBase { public function getVersion() { $vers = array (); $vers[] = 'MediaWiki ' . SpecialVersion::getVersion(); - $vers[] = __CLASS__ . ': $Id: ApiMain.php 37349 2008-07-08 20:53:41Z catrope $'; + $vers[] = __CLASS__ . ': $Id: ApiMain.php 44569 2008-12-14 08:31:04Z tstarling $'; $vers[] = ApiBase :: getBaseVersion(); $vers[] = ApiFormatBase :: getBaseVersion(); $vers[] = ApiQueryBase :: getBaseVersion(); |