From ee5e53bbb328f1d62baf0b53150cc1dc953ffc48 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Fri, 4 Jan 2008 00:28:30 +0000 Subject: [PATCH] More userrights stuff. * Use GET, not POST, when searching for user. * Allow subpage syntax. * Display the form to change rights when you submit a change, so that you can see its effect and adjust if necessary without hitting "search user" again. * Clean up form names a bit so that they look pretty in the URL bar. --- includes/SpecialUserrights.php | 47 ++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/includes/SpecialUserrights.php b/includes/SpecialUserrights.php index 1b1367d40e..639ed3abc7 100644 --- a/includes/SpecialUserrights.php +++ b/includes/SpecialUserrights.php @@ -13,6 +13,11 @@ * @addtogroup SpecialPage */ class UserrightsPage extends SpecialPage { + # The target of the local right-adjuster's interest. Can be gotten from + # either a GET parameter or a subpage-style parameter, so have a member + # variable for it. + protected $mTarget; + public function __construct() { parent::__construct( 'Userrights' ); } @@ -29,8 +34,10 @@ class UserrightsPage extends SpecialPage { /** * Manage forms to be shown according to posted data. * Depending on the submit button used, call a form or a save function. + * + * @param mixed $par String if any subpage provided, else null */ - function execute() { + function execute( $par ) { // If the visitor doesn't have permissions to assign or remove // any groups, it's a bit silly to give them the user search prompt. global $wgUser; @@ -44,30 +51,37 @@ class UserrightsPage extends SpecialPage { return; } + global $wgRequest; + if( $par ) { + $this->mTarget = $par; + } else { + $this->mTarget = $wgRequest->getVal( 'user' ); + } + $this->setHeaders(); // show the general form $this->switchForm(); - global $wgRequest; if( $wgRequest->wasPosted() ) { - // show some more forms - if( $wgRequest->getCheck( 'ssearchuser' ) ) { - $this->editUserGroupsForm( $wgRequest->getVal( 'user-editname' ) ); - } - // save settings if( $wgRequest->getCheck( 'saveusergroups' ) ) { - $username = $wgRequest->getVal( 'user-editname' ); $reason = $wgRequest->getVal( 'user-reason' ); - if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $username ) ) { - $this->saveUserGroups( $username, + if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $this->mTarget ) ) { + $this->saveUserGroups( + $this->mTarget, $wgRequest->getArray( 'removable' ), $wgRequest->getArray( 'available' ), - $reason ); + $reason + ); } } } + + // show some more forms + if( $this->mTarget ) { + $this->editUserGroupsForm( $this->mTarget ); + } } /** @@ -225,12 +239,11 @@ class UserrightsPage extends SpecialPage { * Output a form to allow searching for a user */ function switchForm() { - global $wgOut, $wgRequest; - $username = $wgRequest->getText( 'user-editname' ); - $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->escapeLocalURL(), 'name' => 'uluser' ) ); + global $wgOut; + $form = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $this->getTitle()->escapeLocalURL(), 'name' => 'uluser' ) ); $form .= '
' . wfMsgHtml( 'userrights-lookup-user' ) . ''; - $form .= '

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

'; - $form .= '

' . Xml::submitButton( wfMsg( 'editusergroup' ), array( 'name' => 'ssearchuser' ) ) . '

'; + $form .= '

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

'; + $form .= '

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

'; $form .= '
'; $form .= ''; $wgOut->addHTML( $form ); @@ -274,7 +287,7 @@ class UserrightsPage extends SpecialPage { } $wgOut->addHTML( Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->escapeLocalURL(), 'name' => 'editGroup' ) ) . - Xml::hidden( 'user-editname', $user->getName() ) . + Xml::hidden( 'user', $user->getName() ) . Xml::hidden( 'wpEditToken', $wgUser->editToken( $user->getName() ) ) . Xml::openElement( 'fieldset' ) . Xml::element( 'legend', array(), wfMsg( 'userrights-editusergroup' ) ) . -- 2.20.1