Merge "RaggettWrapper: Don't use ReplacementArray"
[lhc/web/wiklou.git] / includes / specials / SpecialUserrights.php
index 6ded6d9..c869528 100644 (file)
@@ -76,6 +76,7 @@ class UserrightsPage extends SpecialPage {
        public function execute( $par ) {
                $user = $this->getUser();
                $request = $this->getRequest();
+               $session = $request->getSession();
                $out = $this->getOutput();
 
                if ( $par !== null ) {
@@ -88,6 +89,10 @@ class UserrightsPage extends SpecialPage {
                        $this->mTarget = trim( $this->mTarget );
                }
 
+               if ( $this->mTarget !== null && User::getCanonicalName( $this->mTarget ) === $user->getName() ) {
+                       $this->isself = true;
+               }
+
                $fetchedStatus = $this->fetchUser( $this->mTarget, true );
                if ( $fetchedStatus->isOK() ) {
                        $this->mFetchedUser = $fetchedStatus->value;
@@ -99,7 +104,13 @@ class UserrightsPage extends SpecialPage {
                }
 
                // show a successbox, if the user rights was saved successfully
-               if ( $request->getCheck( 'success' ) && $this->mFetchedUser !== null ) {
+               if (
+                       $session->get( 'specialUserrightsSaveSuccess' ) &&
+                       $this->mFetchedUser !== null
+               ) {
+                       // Remove session data for the success message
+                       $session->remove( 'specialUserrightsSaveSuccess' );
+
                        $out->addModules( [ 'mediawiki.special.userrights' ] );
                        $out->addModuleStyles( 'mediawiki.notification.convertmessagebox.styles' );
                        $out->addHTML(
@@ -167,6 +178,9 @@ class UserrightsPage extends SpecialPage {
                                        $targetUser
                                );
 
+                               // Set session data for the success message
+                               $session->set( 'specialUserrightsSaveSuccess', 1 );
+
                                $out->redirect( $this->getSuccessURL() );
 
                                return;
@@ -180,7 +194,7 @@ class UserrightsPage extends SpecialPage {
        }
 
        function getSuccessURL() {
-               return $this->getPageTitle( $this->mTarget )->getFullURL( [ 'success' => 1 ] );
+               return $this->getPageTitle( $this->mTarget )->getFullURL();
        }
 
        /**
@@ -236,6 +250,8 @@ class UserrightsPage extends SpecialPage {
                        $groups )
                );
 
+               Hooks::run( 'ChangeUserGroups', [ $this->getUser(), $user, &$add, &$remove ] );
+
                $oldGroups = $user->getGroups();
                $newGroups = $oldGroups;
 
@@ -331,7 +347,7 @@ class UserrightsPage extends SpecialPage {
         * @param bool $writing
         * @return Status
         */
-       public function fetchUser( $username, $writing ) {
+       public function fetchUser( $username, $writing = true ) {
                $parts = explode( $this->getConfig()->get( 'UserrightsInterwikiDelimiter' ), $username );
                if ( count( $parts ) < 2 ) {
                        $name = trim( $username );
@@ -549,9 +565,14 @@ class UserrightsPage extends SpecialPage {
                        Xml::element(
                                'legend',
                                [],
-                               $this->msg( 'userrights-editusergroup', $user->getName() )->text()
+                               $this->msg(
+                                       $canChangeAny ? 'userrights-editusergroup' : 'userrights-viewusergroup',
+                                       $user->getName()
+                               )->text()
                        ) .
-                       $this->msg( 'editinguser' )->params( wfEscapeWikiText( $user->getName() ) )
+                       $this->msg(
+                               $canChangeAny ? 'editinguser' : 'viewinguserrights'
+                       )->params( wfEscapeWikiText( $user->getName() ) )
                                ->rawParams( $userToolLinks )->parse()
                );
                if ( $canChangeAny ) {