From: Brion Vibber Date: Fri, 4 Jan 2008 17:35:09 +0000 (+0000) Subject: Revert r29261, r29271 for now -- some weird mixing up of functions and seemingly... X-Git-Tag: 1.31.0-rc.0~50129 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmes_infos.php?a=commitdiff_plain;h=c04db5771d5c2d498cb989605c7b0618a1bb1d59;p=lhc%2Fweb%2Fwiklou.git Revert r29261, r29271 for now -- some weird mixing up of functions and seemingly random array structures, and it puts back a restricted API module I'd rather not see there for now. --- diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 1b328d5692..0d1c751429 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -349,7 +349,6 @@ function __autoload($className) { # apiedit branch 'ApiBlock' => 'includes/api/ApiBlock.php', - 'ApiChangeRights' => 'includes/api/ApiChangeRights.php', 'ApiDelete' => 'includes/api/ApiDelete.php', 'ApiMove' => 'includes/api/ApiMove.php', 'ApiProtect' => 'includes/api/ApiProtect.php', diff --git a/includes/SpecialUserrights.php b/includes/SpecialUserrights.php index 9cc1e610ed..639ed3abc7 100644 --- a/includes/SpecialUserrights.php +++ b/includes/SpecialUserrights.php @@ -69,7 +69,7 @@ class UserrightsPage extends SpecialPage { $reason = $wgRequest->getVal( 'user-reason' ); if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $this->mTarget ) ) { $this->saveUserGroups( - $this->fetchUser($this->mTarget), + $this->mTarget, $wgRequest->getArray( 'removable' ), $wgRequest->getArray( 'available' ), $reason @@ -88,28 +88,25 @@ class UserrightsPage extends SpecialPage { * Save user groups changes in the database. * Data comes from the editUserGroupsForm() form function * - * @param object $user User or UserRightsProxy to apply changes to. + * @param string $username Username to apply changes to. * @param array $removegroup id of groups to be removed. * @param array $addgroup id of groups to be added. * @param string $reason Reason for group change * @return null */ - function saveUserGroups( $user, &$removegroup, &$addgroup, $reason = '') { + function saveUserGroups( $username, $removegroup, $addgroup, $reason = '') { + $user = $this->fetchUser( $username ); if( !$user ) { return; } - + // Validate input set... - $changeable = $this->splitGroups($user->getEffectiveGroups()); + $changeable = $this->changeableGroups(); $removegroup = array_unique( - array_intersect( (array)$removegroup, $changeable[1] ) ); + array_intersect( (array)$removegroup, $changeable['remove'] ) ); $addgroup = array_unique( - array_intersect( (array)$addgroup, $changeable[0] ) ); - - // If nothing is changed, no log entry should be created - if($removegroup == $addgroup) - return; - + array_intersect( (array)$addgroup, $changeable['add'] ) ); + $oldGroups = $user->getGroups(); $newGroups = $oldGroups; // remove then add groups @@ -142,7 +139,7 @@ class UserrightsPage extends SpecialPage { global $wgRequest; $log->addEntry( 'rights', $user->getUserPage(), - $reason, + $wgRequest->getText( 'user-reason' ), array( $this->makeGroupNameList( $oldGroups ), $this->makeGroupNameList( $newGroups ) @@ -179,44 +176,7 @@ class UserrightsPage extends SpecialPage { * @return mixed User, UserRightsProxy, or null */ function fetchUser( $username ) { - global $wgOut; - $retval = $this->fetchUser_real($username); - if(!is_array($retval)) - return $retval; - switch($retval[0]) - { - case self::FETCHUSER_NO_INTERWIKI: - $wgOut->addWikiText( wfMsg( 'userrights-no-interwiki' ) ); - break; - case self::FETCHUSER_NO_DATABASE: - $wgOut->addWikiText( wfMsg( 'userrights-nodatabase', $retval[1] ) ); - break; - case self::FETCHUSER_NO_USER: - $wgOut->addWikiText( wfMsg( 'nouserspecified' ) ); - break; - case self::FETCHUSER_NOSUCH_USERID: - $wgOut->addWikiText( wfMsg( 'noname' ) ); - break; - case self::FETCHUSER_NOSUCH_USERNAME: - $wgOut->addWikiText( wfMsg( 'nosuchusershort', wfEscapeWikiText( $retval[1] ) ) ); - break; - } - return null; - } - - /** - * Backend for fetchUser() - * - * @return mixed User, UserRightsProxy, or array(error code, argument) - */ - const FETCHUSER_NO_INTERWIKI = -1; // User is not allowed to change rights cross-wiki; no argument - const FETCHUSER_NO_DATABASE = -2; // Specified database doesn't exist or isn't local; argument=database - const FETCHUSER_NO_USER = -3; // No user name specified; no argument - const FETCHUSER_NOSUCH_USERID = -4; // Specified user ID doesn't exist; argument=userid - const FETCHUSER_NOSUCH_USERNAME = -5; // There is no user by this name; argument=username - - function fetchUser_real( $username ) { - global $wgUser; + global $wgOut, $wgUser; $parts = explode( '@', $username ); if( count( $parts ) < 2 ) { @@ -226,15 +186,18 @@ class UserrightsPage extends SpecialPage { list( $name, $database ) = array_map( 'trim', $parts ); if( !$wgUser->isAllowed( 'userrights-interwiki' ) ) { - return array(self::FETCHUSER_NO_INTERWIKI, null); + $wgOut->addWikiText( wfMsg( 'userrights-no-interwiki' ) ); + return null; } if( !UserRightsProxy::validDatabase( $database ) ) { - return array(self::FETCHUSER_NO_DATABASE, $database); + $wgOut->addWikiText( wfMsg( 'userrights-nodatabase', $database ) ); + return null; } } if( $name == '' ) { - return array(self::FETCHUSER_NO_USER, null); + $wgOut->addWikiText( wfMsg( 'nouserspecified' ) ); + return false; } if( $name{0} == '#' ) { @@ -249,7 +212,8 @@ class UserrightsPage extends SpecialPage { } if( !$name ) { - return array(self::FETCHUSER_NOSUCH_USERID, $id); + $wgOut->addWikiText( wfMsg( 'noname' ) ); + return null; } } @@ -260,7 +224,8 @@ class UserrightsPage extends SpecialPage { } if( !$user || $user->isAnon() ) { - return array(self::FETCHUSER_NOSUCH_USERNAME, $username); + $wgOut->addWikiText( wfMsg( 'nosuchusershort', wfEscapeWikiText( $username ) ) ); + return null; } return $user; @@ -276,7 +241,6 @@ class UserrightsPage extends SpecialPage { function switchForm() { global $wgOut; $form = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $this->getTitle()->escapeLocalURL(), 'name' => 'uluser' ) ); - $form .= Xml::hidden( 'title', 'Special:Userrights' ); $form .= '
' . wfMsgHtml( 'userrights-lookup-user' ) . ''; $form .= '

' . Xml::inputLabel( wfMsg( 'userrights-user-editname' ), 'user', 'username', 30, $this->mTarget ) . '

'; $form .= '

' . Xml::submitButton( wfMsg( 'editusergroup' ) ) . '

'; @@ -324,7 +288,6 @@ class UserrightsPage extends SpecialPage { $wgOut->addHTML( Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->escapeLocalURL(), 'name' => 'editGroup' ) ) . Xml::hidden( 'user', $user->getName() ) . - Xml::hidden( 'title', 'Special:Userrights' ) . Xml::hidden( 'wpEditToken', $wgUser->editToken( $user->getName() ) ) . Xml::openElement( 'fieldset' ) . Xml::element( 'legend', array(), wfMsg( 'userrights-editusergroup' ) ) . diff --git a/includes/api/ApiChangeRights.php b/includes/api/ApiChangeRights.php deleted file mode 100644 index 2bfcbf1e1f..0000000000 --- a/includes/api/ApiChangeRights.php +++ /dev/null @@ -1,152 +0,0 @@ -.@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"); -} - -/** - * @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); - } - - protected 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' => '' - ); - } - - protected 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)' - ); - } - - protected 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/ApiMain.php b/includes/api/ApiMain.php index 9c9ce5c68d..5509c31e6d 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -69,8 +69,7 @@ class ApiMain extends ApiBase { 'protect' => 'ApiProtect', 'block' => 'ApiBlock', 'unblock' => 'ApiUnblock', - 'move' => 'ApiMove', - 'changerights' => 'ApiChangeRights' + 'move' => 'ApiMove' ); /**