Revert r29261, r29271 for now -- some weird mixing up of functions and seemingly...
authorBrion Vibber <brion@users.mediawiki.org>
Fri, 4 Jan 2008 17:35:09 +0000 (17:35 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Fri, 4 Jan 2008 17:35:09 +0000 (17:35 +0000)
includes/AutoLoader.php
includes/SpecialUserrights.php
includes/api/ApiChangeRights.php [deleted file]
includes/api/ApiMain.php

index 1b328d5..0d1c751 100644 (file)
@@ -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',
index 9cc1e61..639ed3a 100644 (file)
@@ -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 .= '<fieldset><legend>' . wfMsgHtml( 'userrights-lookup-user' ) . '</legend>';
                $form .= '<p>' . Xml::inputLabel( wfMsg( 'userrights-user-editname' ), 'user', 'username', 30, $this->mTarget ) . '</p>';
                $form .= '<p>' . Xml::submitButton( wfMsg( 'editusergroup' ) ) . '</p>';
@@ -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 (file)
index 2bfcbf1..0000000
+++ /dev/null
@@ -1,152 +0,0 @@
-<?php\r
-\r
-/*\r
- * Created on Sep 11, 2007\r
- * API for MediaWiki 1.8+\r
- *\r
- * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License along\r
- * with this program; if not, write to the Free Software Foundation, Inc.,\r
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
- * http://www.gnu.org/copyleft/gpl.html\r
- */\r
-\r
-if (!defined('MEDIAWIKI')) {\r
-       // Eclipse helper - will be ignored in production\r
-       require_once ("ApiBase.php");\r
-}\r
-\r
-/**\r
- * @addtogroup API\r
- */\r
-class ApiChangeRights extends ApiBase {\r
-\r
-       public function __construct($main, $action) {\r
-               parent :: __construct($main, $action);\r
-       }\r
-\r
-       public function execute() {\r
-               global $wgUser, $wgRequest;\r
-               $this->getMain()->requestWriteMode();\r
-               \r
-               if(wfReadOnly())\r
-                       $this->dieUsage('The wiki is in read-only mode', 'readonly');\r
-               $params = $this->extractRequestParams();\r
-\r
-               $ur = new UserrightsPage($wgRequest);\r
-               $allowed = $ur->changeableGroups();\r
-               $res = array();\r
-               \r
-               $u = $ur->fetchUser_real($params['user']);\r
-               if(is_array($u))\r
-                       switch($u[0])\r
-                       {\r
-                               case UserrightsPage::FETCHUSER_NO_INTERWIKI:\r
-                                       $this->dieUsage("You don't have permission to change users' rights on other wikis", 'nointerwiki');\r
-                               case UserrightsPage::FETCHUSER_NO_DATABASE:\r
-                                       $this->dieUsage("Database ``{$u[1]}'' does not exist or is not local", 'nosuchdatabase');\r
-                               case UserrightsPage::FETCHUSER_NO_USER:\r
-                                       $this->dieUsage("You specified an empty username, or none at all", 'emptyuser');\r
-                               case UserrightsPage::FETCHUSER_NOSUCH_USERID:\r
-                                       $this->dieUsage("There is no user with ID ``{$u[1]}''", 'nosuchuserid');\r
-                               case UserrightsPage::FETCHUSER_NOSUCH_USERNAME:\r
-                                       $this->dieUsage("There is no user with username ``{$u[1]}''", 'nosuchusername');\r
-                               default:\r
-                                       $this->dieDebug(__METHOD__, "UserrightsPage::fetchUser_real() returned an unknown error ({$u[0]})");\r
-                       }\r
-\r
-               $curgroups = $u->getGroups();\r
-               if($params['listgroups'])\r
-               {\r
-                       $res['user'] = $u->getName();\r
-                       $res['allowedgroups'] = $allowed;\r
-                       $res['ingroups'] = $curgroups;\r
-                       $this->getResult()->setIndexedTagName($res['ingroups'], 'group');\r
-                       $this->getResult()->setIndexedTagName($res['allowedgroups']['add'], 'group');\r
-                       $this->getResult()->setIndexedTagName($res['allowedgroups']['remove'], 'group');\r
-               }\r
-;\r
-               if($params['gettoken'])\r
-               {\r
-                       $res['changerightstoken'] = $wgUser->editToken($u->getName());\r
-                       $this->getResult()->addValue(null, $this->getModuleName(), $res);\r
-                       return;\r
-               }\r
-\r
-               if(empty($params['addto']) && empty($params['rmfrom']))\r
-                       $this->dieUsage('At least one of the addto and rmfrom parameters must be set', 'noaddrm');\r
-               if(is_null($params['token']))\r
-                       $this->dieUsage('The token parameter must be set', 'notoken');\r
-               if(!$wgUser->matchEditToken($params['token'], $u->getName()))\r
-                       $this->dieUsage('Invalid token', 'badtoken');\r
-\r
-               $dbw = wfGetDb(DB_MASTER);\r
-               $dbw->begin();\r
-               $ur->saveUserGroups($u, $params['rmfrom'], $params['addto'], $params['reason']);\r
-               $dbw->commit();\r
-               $res['user'] = $u->getName();\r
-               $res['addedto'] = (array)$params['addto'];\r
-               $res['removedfrom'] = (array)$params['rmfrom'];\r
-               $res['reason'] = $params['reason'];\r
-\r
-               $this->getResult()->setIndexedTagName($res['addedto'], 'group');\r
-               $this->getResult()->setIndexedTagName($res['removedfrom'], 'group');\r
-               $this->getResult()->addValue(null, $this->getModuleName(), $res);\r
-       }\r
-\r
-       protected function getAllowedParams() {\r
-               return array (\r
-                       'user' => null,\r
-                       'token' => null,\r
-                       'gettoken' => false,\r
-                       'listgroups' => false,\r
-                       'addto' => array(\r
-                               ApiBase :: PARAM_ISMULTI => true,\r
-                       ),\r
-                       'rmfrom' => array(\r
-                               ApiBase :: PARAM_ISMULTI => true,\r
-                       ),\r
-                       'reason' => ''\r
-               );\r
-       }\r
-\r
-       protected function getParamDescription() {\r
-               return array (\r
-                       'user' => 'The user you want to add to or remove from groups.',\r
-                       'token' => 'A changerights token previously obtained through the gettoken parameter.',\r
-                       'gettoken' => 'Output a token. Note that the user parameter still has to be set.',\r
-                       'listgroups' => 'List the groups the user is in, and the ones you can add them to and remove them from.',\r
-                       'addto' => 'Pipe-separated list of groups to add this user to',\r
-                       'rmfrom' => 'Pipe-separated list of groups to remove this user from',\r
-                       'reason' => 'Reason for change (optional)'\r
-               );\r
-       }\r
-\r
-       protected function getDescription() {\r
-               return array(\r
-                       'Add or remove a user from certain groups.'\r
-               );\r
-       }\r
-\r
-       protected function getExamples() {\r
-               return array (\r
-                       'api.php?action=changerights&user=Bob&gettoken&listgroups',\r
-                       'api.php?action=changerights&user=Bob&token=123ABC&addto=sysop&reason=Promoting%20per%20RFA'\r
-               );\r
-       }\r
-\r
-       public function getVersion() {\r
-               return __CLASS__ . ': $Id: ApiChangeRights.php 28216 2007-12-06 18:33:18Z vasilievvv $';\r
-       }\r
-}\r
index 9c9ce5c..5509c31 100644 (file)
@@ -69,8 +69,7 @@ class ApiMain extends ApiBase {
                'protect' => 'ApiProtect',
                'block' => 'ApiBlock',
                'unblock' => 'ApiUnblock',
-               'move' => 'ApiMove',
-               'changerights' => 'ApiChangeRights'
+               'move' => 'ApiMove'
        );
 
        /**