Jackmcbarn has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/107009


Change subject: Allow all users to view Special:UserRights
......................................................................

Allow all users to view Special:UserRights

Allow Special:UserRights to always be used in read-only mode, rather than
completely locking out users who cannot make modifications with it.

Bug: 25319
Change-Id: I57e9ca4f20fe557e4024c4f5a4865170f02ebb45
---
M includes/specials/SpecialUserrights.php
M languages/messages/MessagesEn.php
M maintenance/language/messages.inc
3 files changed, 42 insertions(+), 92 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/09/107009/1

diff --git a/includes/specials/SpecialUserrights.php 
b/includes/specials/SpecialUserrights.php
index 014408e..71310ea 100644
--- a/includes/specials/SpecialUserrights.php
+++ b/includes/specials/SpecialUserrights.php
@@ -37,31 +37,6 @@
                parent::__construct( 'Userrights' );
        }
 
-       public function isRestricted() {
-               return true;
-       }
-
-       public function userCanExecute( User $user ) {
-               return $this->userCanChangeRights( $user, false );
-       }
-
-       /**
-        * @param User $user
-        * @param bool $checkIfSelf
-        * @return bool
-        */
-       public function userCanChangeRights( $user, $checkIfSelf = true ) {
-               $available = $this->changeableGroups();
-               if ( $user->getId() == 0 ) {
-                       return false;
-               }
-               return !empty( $available['add'] )
-                       || !empty( $available['remove'] )
-                       || ( ( $this->isself || !$checkIfSelf ) &&
-                               ( !empty( $available['add-self'] )
-                                       || !empty( $available['remove-self'] ) 
) );
-       }
-
        /**
         * Manage forms to be shown according to posted data.
         * Depending on the submit button used, call a form or a save function.
@@ -70,9 +45,6 @@
         * @throws UserBlockedError|PermissionsError
         */
        public 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.
-
                $user = $this->getUser();
 
                /*
@@ -94,36 +66,8 @@
 
                $available = $this->changeableGroups();
 
-               if ( $this->mTarget === null ) {
-                       /*
-                        * If the user specified no target, and they can only
-                        * edit their own groups, automatically set them as the
-                        * target.
-                        */
-                       if ( !count( $available['add'] ) && !count( 
$available['remove'] ) ) {
-                               $this->mTarget = $user->getName();
-                       }
-               }
-
                if ( User::getCanonicalName( $this->mTarget ) == 
$user->getName() ) {
                        $this->isself = true;
-               }
-
-               if ( !$this->userCanChangeRights( $user, true ) ) {
-                       if ( $this->isself && $request->getCheck( 'success' ) ) 
{
-                               // bug 48609: if the user just removed its own 
rights, this would
-                               // leads it in a "permissions error" page. In 
that case, show a
-                               // message that it can't anymore use this page 
instead of an error
-                               $this->setHeaders();
-                               $out = $this->getOutput();
-                               $out->wrapWikiMsg( "<div 
class=\"successbox\">\n$1\n</div>", 'userrights-removed-self' );
-                               $out->returnToMain();
-                               return;
-                       }
-
-                       // @todo FIXME: There may be intermediate groups we can 
mention.
-                       $msg = $user->isAnon() ? 'userrights-nologin' : 
'userrights-notallowed';
-                       throw new PermissionsError( null, array( array( $msg ) 
) );
                }
 
                $this->checkReadOnly();
@@ -135,9 +79,7 @@
                $out->addModuleStyles( 'mediawiki.special' );
 
                // show the general form
-               if ( count( $available['add'] ) || count( $available['remove'] 
) ) {
-                       $this->switchForm();
-               }
+               $this->switchForm();
 
                if (
                        $request->wasPosted() &&
@@ -489,38 +431,51 @@
                                Linker::TOOL_LINKS_EMAIL /* Add "send e-mail" 
link */
                );
 
+               list( $groupCheckboxes, $needForm ) = $this->groupCheckboxes( 
$groups, $user );
+
+               if( $needForm ) {
+                       $this->getOutput()->addHTML(
+                               Xml::openElement( 'form', array( 'method' => 
'post', 'action' => $this->getPageTitle()->getLocalURL(), 'name' => 
'editGroup', 'id' => 'mw-userrights-form2' ) ) .
+                               Html::hidden( 'user', $this->mTarget ) .
+                               Html::hidden( 'wpEditToken', 
$this->getUser()->getEditToken( $this->mTarget ) ) .
+                               Html::hidden( 'conflictcheck-originalgroups', 
implode( ',', $user->getGroups() ) ) // Conflict detection
+                       );
+               }
                $this->getOutput()->addHTML(
-                       Xml::openElement( 'form', array( 'method' => 'post', 
'action' => $this->getPageTitle()->getLocalURL(), 'name' => 'editGroup', 'id' 
=> 'mw-userrights-form2' ) ) .
-                       Html::hidden( 'user', $this->mTarget ) .
-                       Html::hidden( 'wpEditToken', 
$this->getUser()->getEditToken( $this->mTarget ) ) .
-                       Html::hidden( 'conflictcheck-originalgroups', implode( 
',', $user->getGroups() ) ) . // Conflict detection
                        Xml::openElement( 'fieldset' ) .
                        Xml::element( 'legend', array(), $this->msg( 
'userrights-editusergroup', $user->getName() )->text() ) .
                        $this->msg( 'editinguser' )->params( wfEscapeWikiText( 
$user->getName() ) )->rawParams( $userToolLinks )->parse() .
                        $this->msg( 'userrights-groups-help', $user->getName() 
)->parse() .
                        $grouplist .
-                       Xml::tags( 'p', null, $this->groupCheckboxes( $groups, 
$user ) ) .
-                       Xml::openElement( 'table', array( 'id' => 
'mw-userrights-table-outer' ) ) .
-                               "<tr>
-                                       <td class='mw-label'>" .
-                                               Xml::label( $this->msg( 
'userrights-reason' )->text(), 'wpReason' ) .
-                                       "</td>
-                                       <td class='mw-input'>" .
-                                               Xml::input( 'user-reason', 60, 
$this->getRequest()->getVal( 'user-reason', false ),
-                                                       array( 'id' => 
'wpReason', 'maxlength' => 255 ) ) .
-                                       "</td>
-                               </tr>
-                               <tr>
-                                       <td></td>
-                                       <td class='mw-submit'>" .
-                                               Xml::submitButton( $this->msg( 
'saveusergroups' )->text(),
-                                                       array( 'name' => 
'saveusergroups' ) + Linker::tooltipAndAccesskeyAttribs( 'userrights-set' ) ) .
-                                       "</td>
-                               </tr>" .
-                       Xml::closeElement( 'table' ) . "\n" .
-                       Xml::closeElement( 'fieldset' ) .
-                       Xml::closeElement( 'form' ) . "\n"
+                       Xml::tags( 'p', null, $groupCheckboxes )
                );
+               if( $needForm ) {
+                       $this->getOutput()->addHTML(
+                               Xml::openElement( 'table', array( 'id' => 
'mw-userrights-table-outer' ) ) .
+                                       "<tr>
+                                               <td class='mw-label'>" .
+                                                       Xml::label( $this->msg( 
'userrights-reason' )->text(), 'wpReason' ) .
+                                               "</td>
+                                               <td class='mw-input'>" .
+                                                       Xml::input( 
'user-reason', 60, $this->getRequest()->getVal( 'user-reason', false ),
+                                                               array( 'id' => 
'wpReason', 'maxlength' => 255 ) ) .
+                                               "</td>
+                                       </tr>
+                                       <tr>
+                                               <td></td>
+                                               <td class='mw-submit'>" .
+                                                       Xml::submitButton( 
$this->msg( 'saveusergroups' )->text(),
+                                                               array( 'name' 
=> 'saveusergroups' ) + Linker::tooltipAndAccesskeyAttribs( 'userrights-set' ) 
) .
+                                               "</td>
+                                       </tr>" .
+                               Xml::closeElement( 'table' ) . "\n"
+                       );
+               }
+               $this->getOutput()->addHTML( Xml::closeElement( 'fieldset' ) );
+               if( $needForm ) {
+                       $this->getOutput()->addHTML( Xml::closeElement( 'form' 
) );
+               }
+               $this->getOutput()->addHTML( "\n" );
        }
 
        /**
@@ -557,7 +512,8 @@
         * @todo Just pass the username string?
         * @param array $usergroups groups the user belongs to
         * @param $user User a user object
-        * @return string XHTML table element with checkboxes
+        * @return array First element: string XHTML table element with 
checkboxes
+        * Second element: boolean Whether any groups are changeable
         */
        private function groupCheckboxes( $usergroups, $user ) {
                $allgroups = $this->getAllGroups();
@@ -627,7 +583,7 @@
                }
                $ret .= Xml::closeElement( 'tr' ) . Xml::closeElement( 'table' 
);
 
-               return $ret;
+               return array( $ret, !empty( $columns['changeable'] ) );
        }
 
        /**
diff --git a/languages/messages/MessagesEn.php 
b/languages/messages/MessagesEn.php
index 0728d28..4b4f9a6 100644
--- a/languages/messages/MessagesEn.php
+++ b/languages/messages/MessagesEn.php
@@ -2025,13 +2025,10 @@
 'userrights-reason'              => 'Reason:',
 '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'          => 'You do not have permission to add or 
remove user rights.',
 'userrights-changeable-col'      => 'Groups you can change',
 'userrights-unchangeable-col'    => 'Groups you cannot change',
 'userrights-irreversible-marker' => '$1*', # only translate this message to 
other languages if you have to change it
 'userrights-conflict'            => 'Conflict of user rights changes! Please 
review and confirm your changes.',
-'userrights-removed-self'        => 'You successfully removed your own rights. 
As such, you are no longer able to access this page.',
 
 # Groups
 'group'               => 'Group:',
diff --git a/maintenance/language/messages.inc 
b/maintenance/language/messages.inc
index 3534810..4a4df0a 100644
--- a/maintenance/language/messages.inc
+++ b/maintenance/language/messages.inc
@@ -1142,13 +1142,10 @@
                'userrights-reason',
                'userrights-no-interwiki',
                'userrights-nodatabase',
-               'userrights-nologin',
-               'userrights-notallowed',
                'userrights-changeable-col',
                'userrights-unchangeable-col',
                'userrights-irreversible-marker',
                'userrights-conflict',
-               'userrights-removed-self',
        ),
        'group' => array(
                'group',

-- 
To view, visit https://gerrit.wikimedia.org/r/107009
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I57e9ca4f20fe557e4024c4f5a4865170f02ebb45
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Jackmcbarn <jackmcb...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to