$params = $this->extractRequestParams();
if(is_null($params['user']))
$this->dieUsageMsg(array('missingparam', 'user'));
- $user = User::newFromName($params['user']);
- if($user->isAnon())
- $this->dieUsageMsg(array('nosuchuser', $params['user']));
if(is_null($params['token']))
$this->dieUsageMsg(array('missingparam', 'token'));
+
+ $form = new UserrightsPage;
+ $user = $form->fetchUser($params['user']);
+ if($user instanceof WikiErrorMsg)
+ $this->dieUsageMsg(array_merge(
+ (array)$user->getMessageKey(),
+ $user->getMessageArgs()));
if(!$wgUser->matchEditToken($params['token'], $user->getName()))
$this->dieUsageMsg(array('sessionfailure'));
$r['user'] = $user->getName();
list($r['added'], $r['removed']) =
- UserrightsPage::doSaveUserGroups(
+ $form->doSaveUserGroups(
$user, (array)$params['add'],
(array)$params['remove'], $params['reason']);
public function getAllowedParams() {
return array (
- 'user' => array(
- ApiBase :: PARAM_TYPE => 'user'
- ),
+ 'user' => null,
'add' => array(
ApiBase :: PARAM_TYPE => User::getAllGroups(),
ApiBase :: PARAM_ISMULTI => true
global $wgRequest, $wgUser, $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
$user = $this->fetchUser( $username );
- if( !$user ) {
+ if( $user instanceof WikiErrorMsg ) {
+ $wgOut->addWikiMsgArray($user->getMessageKey(), $user->getMessageArgs());
return;
}
$removegroup[] = $group;
}
}
- self::doSaveUserGroups( $user, $addgroup, $removegroup, $reason );
+ $this->doSaveUserGroups( $user, $addgroup, $removegroup, $reason );
}
/**
* @param $reason String: reason for group change
* @return Array: Tuple of added, then removed groups
*/
- static function doSaveUserGroups( $user, $add, $remove, $reason = '' ) {
+ function doSaveUserGroups( $user, $add, $remove, $reason = '' ) {
global $wgUser;
// Validate input set...
wfRunHooks( 'UserRights', array( &$user, $add, $remove ) );
if( $newGroups != $oldGroups ) {
- self::addLogEntry( $user, $oldGroups, $newGroups, $reason );
+ $this->addLogEntry( $user, $oldGroups, $newGroups, $reason );
}
return array( $add, $remove );
}
/**
* Add a rights log entry for an action.
*/
- static function addLogEntry( $user, $oldGroups, $newGroups, $reason ) {
- // Just overriding addLogEntry in a subclass would be cleaner,
- // but that requires PHP 5.3 (late static bindings)
- if( !wfRunHooks( 'UserRightsLogEntry', array( $user, $oldGroups,
- $newGroups, $reason ) ) ) {
- return;
- }
-
+ function addLogEntry( $user, $oldGroups, $newGroups, $reason ) {
$log = new LogPage( 'rights' );
$log->addEntry( 'rights',
$user->getUserPage(),
$reason,
array(
- self::makeGroupNameListForLog( $oldGroups ),
- self::makeGroupNameListForLog( $newGroups )
+ $this->makeGroupNameListForLog( $oldGroups ),
+ $this->makeGroupNameListForLog( $newGroups )
)
);
}
global $wgOut;
$user = $this->fetchUser( $username );
- if( !$user ) {
+ if( $user instanceof WikiErrorMsg ) {
+ $wgOut->addWikiMsgArray($user->getMessageKey(), $user->getMessageArgs());
return;
}
* return a user (or proxy) object for manipulating it.
*
* Side effects: error output for invalid access
- * @return mixed User, UserRightsProxy, or null
+ * @return mixed User, UserRightsProxy, or WikiErrorMsg
*/
function fetchUser( $username ) {
- global $wgOut, $wgUser, $wgUserrightsInterwikiDelimiter;
+ global $wgUser, $wgUserrightsInterwikiDelimiter;
$parts = explode( $wgUserrightsInterwikiDelimiter, $username );
if( count( $parts ) < 2 ) {
list( $name, $database ) = array_map( 'trim', $parts );
if( !$wgUser->isAllowed( 'userrights-interwiki' ) ) {
- $wgOut->addWikiMsg( 'userrights-no-interwiki' );
- return null;
+ return new WikiErrorMsg( 'userrights-no-interwiki' );
}
if( !UserRightsProxy::validDatabase( $database ) ) {
- $wgOut->addWikiMsg( 'userrights-nodatabase', $database );
- return null;
+ return new WikiErrorMsg( 'userrights-nodatabase', $database );
}
}
if( $name == '' ) {
- $wgOut->addWikiMsg( 'nouserspecified' );
- return false;
+ return new WikiErrorMsg( 'nouserspecified' );
}
if( $name{0} == '#' ) {
}
if( !$name ) {
- $wgOut->addWikiMsg( 'noname' );
- return null;
+ return new WikiErrorMsg( 'noname' );
}
}
}
if( !$user || $user->isAnon() ) {
- $wgOut->addWikiMsg( 'nosuchusershort', $username );
- return null;
+ return new WikiErrorMsg( 'nosuchusershort', $username );
}
return $user;
}
- static function makeGroupNameList( $ids ) {
+ function makeGroupNameList( $ids ) {
if( empty( $ids ) ) {
return wfMsgForContent( 'rightsnone' );
} else {
}
}
- static function makeGroupNameListForLog( $ids ) {
+ function makeGroupNameListForLog( $ids ) {
if( empty( $ids ) ) {
return '';
} else {
- return self::makeGroupNameList( $ids );
+ return $this->makeGroupNameList( $ids );
}
}