Merge "SpecialWatchlist: Minor cleanup"
[lhc/web/wiklou.git] / includes / specials / SpecialUserrights.php
index d47cf8b..4501736 100644 (file)
@@ -110,6 +110,17 @@ class UserrightsPage extends SpecialPage {
                }
 
                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 ) ) );
@@ -163,7 +174,7 @@ class UserrightsPage extends SpecialPage {
        }
 
        function getSuccessURL() {
-               return $this->getTitle( $this->mTarget )->getFullURL();
+               return $this->getTitle( $this->mTarget )->getFullURL( array( 'success' => 1 ) );
        }
 
        /**
@@ -205,6 +216,8 @@ class UserrightsPage extends SpecialPage {
         * @return Array: Tuple of added, then removed groups
         */
        function doSaveUserGroups( $user, $add, $remove, $reason = '' ) {
+               global $wgAuth;
+
                // Validate input set...
                $isself = ( $user->getName() == $this->getUser()->getName() );
                $groups = $user->getGroups();
@@ -240,6 +253,9 @@ class UserrightsPage extends SpecialPage {
                // Ensure that caches are cleared
                $user->invalidateCache();
 
+               // update groups in external authentication database
+               $wgAuth->updateExternalDBGroups( $user, $add, $remove );
+
                wfDebug( 'oldGroups: ' . print_r( $oldGroups, true ) );
                wfDebug( 'newGroups: ' . print_r( $newGroups, true ) );
                wfRunHooks( 'UserRights', array( &$user, $add, $remove ) );
@@ -547,17 +563,17 @@ class UserrightsPage extends SpecialPage {
                $allgroups = $this->getAllGroups();
                $ret = '';
 
-               # Put all column info into an associative array so that extensions can
-               # more easily manage it.
+               // Put all column info into an associative array so that extensions can
+               // more easily manage it.
                $columns = array( 'unchangeable' => array(), 'changeable' => array() );
 
                foreach ( $allgroups as $group ) {
                        $set = in_array( $group, $usergroups );
-                       # Should the checkbox be disabled?
+                       // Should the checkbox be disabled?
                        $disabled = !(
                                ( $set && $this->canRemove( $group ) ) ||
                                ( !$set && $this->canAdd( $group ) ) );
-                       # Do we need to point out that this action is irreversible?
+                       // Do we need to point out that this action is irreversible?
                        $irreversible = !$disabled && (
                                ( $set && !$this->canAdd( $group ) ) ||
                                ( !$set && !$this->canRemove( $group ) ) );
@@ -575,13 +591,14 @@ class UserrightsPage extends SpecialPage {
                        }
                }
 
-               # Build the HTML table
+               // Build the HTML table
                $ret .= Xml::openElement( 'table', array( 'class' => 'mw-userrights-groups' ) ) .
                        "<tr>\n";
                foreach ( $columns as $name => $column ) {
                        if ( $column === array() ) {
                                continue;
                        }
+                       // Messages: userrights-changeable-col, userrights-unchangeable-col
                        $ret .= Xml::element( 'th', null, $this->msg( 'userrights-' . $name . '-col', count( $column ) )->text() );
                }
                $ret .= "</tr>\n<tr>\n";
@@ -618,8 +635,7 @@ class UserrightsPage extends SpecialPage {
         * @return bool Can we remove the group?
         */
        private function canRemove( $group ) {
-               // $this->changeableGroups()['remove'] doesn't work, of course. Thanks,
-               // PHP.
+               // $this->changeableGroups()['remove'] doesn't work, of course. Thanks, PHP.
                $groups = $this->changeableGroups();
                return in_array( $group, $groups['remove'] ) || ( $this->isself && in_array( $group, $groups['remove-self'] ) );
        }