Redesign of Special:Userrights.
authorAndrew Garrett <werdna@users.mediawiki.org>
Mon, 31 Mar 2008 12:55:26 +0000 (12:55 +0000)
committerAndrew Garrett <werdna@users.mediawiki.org>
Mon, 31 Mar 2008 12:55:26 +0000 (12:55 +0000)
RELEASE-NOTES
includes/SpecialUserrights.php
languages/messages/MessagesEn.php
skins/common/shared.css

index 215795a..302ae79 100644 (file)
@@ -145,6 +145,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 13540) Date format in confirmation e-mail now matches message language
 * (bug 13554) PHP Notice in old pre-processor when list item is empty.
 * (bug 13556) Don't show a blank form if no image is attached in Special:Upload
+* Redesign of Special:Userrights
 
 === API changes in 1.13 ===
 
index 0e2cf56..8d23aea 100644 (file)
@@ -97,8 +97,7 @@ class UserrightsPage extends SpecialPage {
                                if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $this->mTarget ) ) {
                                        $this->saveUserGroups(
                                                $this->mTarget,
-                                               $wgRequest->getArray( 'removable' ),
-                                               $wgRequest->getArray( 'available' ),
+                                               $wgRequest,
                                                $reason
                                        );
                                }
@@ -121,7 +120,7 @@ class UserrightsPage extends SpecialPage {
         * @param string $reason Reason for group change
         * @return null
         */
-       function saveUserGroups( $username, $removegroup, $addgroup, $reason = '') {
+       function saveUserGroups( $username, $request, $reason = '') {
                global $wgUser, $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
 
                $user = $this->fetchUser( $username );
@@ -129,6 +128,22 @@ class UserrightsPage extends SpecialPage {
                        return;
                }
                
+               $allgroups = User::getAllGroups();
+               $addgroup = array();
+               $removegroup = array();
+               
+               // This could possibly create a highly unlikely race condition if permissions are changed between 
+               //  when the form is loaded and when the form is saved. Ignoring it for the moment.
+               foreach ($allgroups as $group) {
+                       // We'll tell it to remove all unchecked groups, and add all checked groups.
+                       // Later on, this gets filtered for what can actually be removed
+                       if ($request->getCheck( "wpGroup-$group" )) {
+                               $addgroup[] = $group;
+                       } else {
+                               $removegroup[] = $group;
+                       }
+               }
+               
                // Validate input set...
                $changeable = $this->changeableGroups();
                if ($wgUser->getId() != 0 && $wgUser->getId() == $user->getId()) {
@@ -340,23 +355,9 @@ class UserrightsPage extends SpecialPage {
                        Xml::element( 'legend', array(), wfMsg( 'userrights-editusergroup' ) ) .
                        wfMsgExt( 'editinguser', array( 'parse' ), wfEscapeWikiText( $user->getName() ) ) .
                        $grouplist .
-                       $this->explainRights() .
+                       Xml::openElement( 'p') . $this->groupCheckboxes( $groups ) . Xml::closeElement( 'p' ) . 
                        Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-userrights-table-outer' ) ) .
                                "<tr>
-                                       <td></td>
-                                       <td>" .
-                                               Xml::openElement( 'table', array( 'style' => 'width:400px;', 'id' => 'mw-userrights-table-inner' ) ) .  
-                                                       "<tr>
-                                                               <td style='width:50%;'>" . 
-                                                                       $this->removeSelect( $removable ) .
-                                                               "</td>
-                                                               <td style='width:50%;'>" . 
-                                                                       $this->addSelect( $addable ) .
-                                                               "</td>
-                                                       </tr>" .
-                                               Xml::closeElement( 'table' ) .
-                               "</tr>
-                               <tr>
                                        <td colspan='2'>" .
                                                $wgOut->parse( wfMsg( 'userrights-groupshelp' ) ) .
                                        "</td>
@@ -394,55 +395,6 @@ class UserrightsPage extends SpecialPage {
                return $cache[$group];
        }
 
-       /**
-        * Prepare a list of groups the user is able to add and remove
-        *
-        * @return string
-        */
-       private function explainRights() {
-               global $wgUser, $wgLang;
-
-               $out = array();
-               list( $add, $remove, $addself, $rmself ) = array_values( $this->changeableGroups() );
-
-               if( count( $add ) > 0 )
-                       $out[] = wfMsgExt( 'userrights-available-add', 'parseinline', 
-                                       $wgLang->listToText( $add ), count( $add ) );
-               if( count( $remove ) > 0 )
-                       $out[] = wfMsgExt( 'userrights-available-remove', 'parseinline', 
-                                       $wgLang->listToText( $remove ), count( $add ) );
-               if( count( $addself ) > 0 )
-                       $out[] = wfMsgExt( 'userrights-available-add-self', 'parseinline',
-                                       $wgLang->listToText( $addself ), count( $addself ) );
-               if( count( $rmself ) > 0 )
-                       $out[] = wfMsgExt( 'userrights-available-remove-self', 'parseinline',
-                                       $wgLang->listToText( $rmself ), count( $rmself ) );
-
-               return count( $out ) > 0
-                       ? implode( '<br />', $out )
-                       : wfMsgExt( 'userrights-available-none', 'parseinline' );
-       }
-
-       /**
-        * Adds the <select> thingie where you can select what groups to remove
-        *
-        * @param array $groups The groups that can be removed
-        * @return string XHTML <select> element
-        */
-       private function removeSelect( $groups ) {
-               return $this->doSelect( $groups, 'removable' );
-       }
-
-       /**
-        * Adds the <select> thingie where you can select what groups to add
-        *
-        * @param array $groups The groups that can be added
-        * @return string XHTML <select> element
-        */
-       private function addSelect( $groups ) {
-               return $this->doSelect( $groups, 'available' );
-       }
-
        /**
         * Adds the <select> thingie where you can select what groups to add/remove
         *
@@ -450,19 +402,46 @@ class UserrightsPage extends SpecialPage {
         * @param string $name   'removable' or 'available'
         * @return string XHTML <select> element
         */
-       private function doSelect( $groups, $name ) {
-               $ret = wfMsgHtml( "{$this->mName}-groups$name" ) .
-               Xml::openElement( 'select', array(
-                               'name' => "{$name}[]",
-                               'multiple' => 'multiple',
-                               'size' => '6',
-                               'style' => 'width: 100%;'
-                       )
-               );
-               foreach ($groups as $group) {
-                       $ret .= Xml::element( 'option', array( 'value' => $group ), User::getGroupName( $group ) );
+       private function groupCheckboxes( $usergroups ) {
+               $allgroups = User::getAllGroups();
+               $ret = '';
+               
+               if (count($allgroups)>8) {
+                       $column = 1;
+                       $settable_col = '';
+                       $unsettable_col = '';
+               } else {
+                       $column = 0;
                }
-               $ret .= Xml::closeElement( 'select' );
+               
+               foreach ($allgroups as $group) {
+                       $set = in_array( $group, $usergroups );
+                       $disabled = !(
+                               ( $set && $this->canRemove( $group ) ) ||
+                               ( !$set && $this->canAdd( $group ) ) );
+                               
+                       $attr = $disabled ? array( 'disabled' => 'disabled' ) : array();
+                       $checkbox = wfCheckLabel( User::getGroupMember( $group ), "wpGroup-$group",
+                                       "wpGroup-$group", $set, $attr );
+                               
+                       if ($column) {
+                               if ($disabled) {
+                                       $unsettable_col .= "$checkbox<br/>\n";
+                               } else {
+                                       $settable_col .= "$checkbox<br/>\n";
+                               }
+                       } else {
+                               $ret .= " $checkbox ";
+                       }
+               }
+               
+               if ($column) {
+                       $ret .= '<table class="mw-userrights-groups">';
+                       $ret .= '<tr><th>'.wfMsgHtml('userrights-changeable-col').'</th><th>'.wfMsgHtml('userrights-unchangeable-col').'</th></tr>';
+                       $ret .= "<tr><td valign=\"top\">$settable_col</td><td valign=\"top\">$unsettable_col</td></tr>";
+                       $ret .= "</table>";
+               }
+               
                return $ret;
        }
 
@@ -474,7 +453,7 @@ class UserrightsPage extends SpecialPage {
                // $this->changeableGroups()['remove'] doesn't work, of course. Thanks,
                // PHP.
                $groups = $this->changeableGroups();
-               return in_array( $group, $groups['remove'] );
+               return in_array( $group, $groups['remove'] ) || ($this->isself && in_array( $group, $groups['remove-self'] ));
        }
 
        /**
@@ -483,7 +462,7 @@ class UserrightsPage extends SpecialPage {
         */
        private function canAdd( $group ) {
                $groups = $this->changeableGroups();
-               return in_array( $group, $groups['add'] );
+               return in_array( $group, $groups['add'] ) || ($this->isself && in_array( $group, $groups['add-self'] ));
        }
 
        /**
index ce5c4b2..df53d90 100644 (file)
@@ -1382,19 +1382,19 @@ please see math/README to configure.',
 'userrights-groupsmember'          => 'Member of:',
 'userrights-groupsremovable'       => 'Removable groups:',
 'userrights-groupsavailable'       => 'Available groups:',
-'userrights-groupshelp'            => 'Select groups you want the user to be removed from or added to.
-Unselected groups will not be changed.
-You can deselect a group with CTRL + Left Click',
+'userrights-groupshelp'            => 'You may alter the groups this user is in. A checked box means the user is in that group. An unchecked box means the user is not in that group.',
 'userrights-reason'                => 'Reason for change:',
 'userrights-available-none'        => 'You may not alter group membership.',
-'userrights-available-add'         => 'You can add users to {{PLURAL:$2|this group|these groups}}: $1.',
-'userrights-available-remove'      => 'You can remove users from {{PLURAL:$2|this group|these groups}}: $1.',
+'userrights-available-add'         => 'You can add any user to {{PLURAL:$2|this group|these groups}}: $1.',
+'userrights-available-remove'      => 'You can remove any user from {{PLURAL:$2|this group|these groups}}: $1.',
 'userrights-available-add-self'    => 'You can add yourself to {{PLURAL:$2|this group|these groups}}: $1.',
 'userrights-available-remove-self' => 'You can remove yourself from {{PLURAL:$2|this group|these groups}}: $1.',
 'userrights-no-interwiki'          => 'You do not have permission to edit user rights on other wikis.',
 'userrights-nodatabase'            => 'Database $1 does not exist or is not local.',
 'userrights-nologin'               => 'You must [[Special:Userlogin|log in]] with an administrator account to assign user rights.',
 'userrights-notallowed'            => 'Your account does not have permission to assign user rights.',
+'userrights-changeable-col'       => 'Groups you can change',
+'userrights-unchangeable-col'     => 'Groups you cannot change',
 
 # Groups
 'group'               => 'Group:',
index fd96b98..d8cf94f 100644 (file)
@@ -97,3 +97,7 @@ p.mw-ipb-conveniencelinks, p.mw-filedelete-editreasons, p.mw-delete-editreasons
 .mw-search-result-data {
        color: green;
 }
+
+table.mw-userrights-groups * td,table.mw-userrights-groups * th {
+       padding-right: 1.5em;
+}
\ No newline at end of file