Localisation updates from https://translatewiki.net.
[lhc/web/wiklou.git] / includes / User.php
index 34af4c5..c2db67a 100644 (file)
@@ -134,6 +134,7 @@ class User implements IDBAccessObject {
                'import',
                'importupload',
                'ipblock-exempt',
+               'managechangetags',
                'markbotedits',
                'mergehistory',
                'minoredit',
@@ -324,7 +325,6 @@ class User implements IDBAccessObject {
                if ( $this->mLoadedItems === true ) {
                        return;
                }
-               wfProfileIn( __METHOD__ );
 
                // Set it now to avoid infinite recursion in accessors
                $this->mLoadedItems = true;
@@ -353,10 +353,8 @@ class User implements IDBAccessObject {
                                Hooks::run( 'UserLoadAfterLoadFromSession', array( $this ) );
                                break;
                        default:
-                               wfProfileOut( __METHOD__ );
                                throw new MWException( "Unrecognised value for User->mFrom: \"{$this->mFrom}\"" );
                }
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -1019,7 +1017,6 @@ class User implements IDBAccessObject {
         * @param string|bool $name
         */
        public function loadDefaults( $name = false ) {
-               wfProfileIn( __METHOD__ );
 
                $passwordFactory = self::getPasswordFactory();
 
@@ -1051,7 +1048,6 @@ class User implements IDBAccessObject {
 
                Hooks::run( 'UserLoadDefaults', array( $this, $name ) );
 
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -1489,7 +1485,6 @@ class User implements IDBAccessObject {
                        return;
                }
 
-               wfProfileIn( __METHOD__ );
                wfDebug( __METHOD__ . ": checking...\n" );
 
                // Initialize data...
@@ -1564,7 +1559,6 @@ class User implements IDBAccessObject {
                // Extensions
                Hooks::run( 'GetBlockedStatus', array( &$this ) );
 
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -1596,7 +1590,6 @@ class User implements IDBAccessObject {
         * @return bool True if blacklisted.
         */
        public function inDnsBlacklist( $ip, $bases ) {
-               wfProfileIn( __METHOD__ );
 
                $found = false;
                // @todo FIXME: IPv6 ???  (http://bugs.php.net/bug.php?id=33170)
@@ -1631,7 +1624,6 @@ class User implements IDBAccessObject {
                        }
                }
 
-               wfProfileOut( __METHOD__ );
                return $found;
        }
 
@@ -1648,7 +1640,6 @@ class User implements IDBAccessObject {
                if ( !$wgProxyList ) {
                        return false;
                }
-               wfProfileIn( __METHOD__ );
 
                if ( !is_array( $wgProxyList ) ) {
                        // Load from the specified file
@@ -1665,7 +1656,6 @@ class User implements IDBAccessObject {
                } else {
                        $ret = false;
                }
-               wfProfileOut( __METHOD__ );
                return $ret;
        }
 
@@ -1717,8 +1707,6 @@ class User implements IDBAccessObject {
                }
 
                global $wgMemc;
-               wfProfileIn( __METHOD__ );
-               wfProfileIn( __METHOD__ . '-' . $action );
 
                $limits = $wgRateLimits[$action];
                $keys = array();
@@ -1799,8 +1787,6 @@ class User implements IDBAccessObject {
                        }
                }
 
-               wfProfileOut( __METHOD__ . '-' . $action );
-               wfProfileOut( __METHOD__ );
                return $triggered;
        }
 
@@ -1835,7 +1821,6 @@ class User implements IDBAccessObject {
         */
        public function isBlockedFrom( $title, $bFromSlave = false ) {
                global $wgBlockAllowsUTEdit;
-               wfProfileIn( __METHOD__ );
 
                $blocked = $this->isBlocked( $bFromSlave );
                $allowUsertalk = ( $wgBlockAllowsUTEdit ? $this->mAllowUsertalk : false );
@@ -1848,7 +1833,6 @@ class User implements IDBAccessObject {
 
                Hooks::run( 'UserIsBlockedFrom', array( $this, $title, &$blocked, &$allowUsertalk ) );
 
-               wfProfileOut( __METHOD__ );
                return $blocked;
        }
 
@@ -2930,7 +2914,6 @@ class User implements IDBAccessObject {
         */
        public function getEffectiveGroups( $recache = false ) {
                if ( $recache || is_null( $this->mEffectiveGroups ) ) {
-                       wfProfileIn( __METHOD__ );
                        $this->mEffectiveGroups = array_unique( array_merge(
                                $this->getGroups(), // explicit groups
                                $this->getAutomaticGroups( $recache ) // implicit groups
@@ -2939,7 +2922,6 @@ class User implements IDBAccessObject {
                        Hooks::run( 'UserEffectiveGroups', array( &$this, &$this->mEffectiveGroups ) );
                        // Force reindexation of groups when a hook has unset one of them
                        $this->mEffectiveGroups = array_values( array_unique( $this->mEffectiveGroups ) );
-                       wfProfileOut( __METHOD__ );
                }
                return $this->mEffectiveGroups;
        }
@@ -2953,7 +2935,6 @@ class User implements IDBAccessObject {
         */
        public function getAutomaticGroups( $recache = false ) {
                if ( $recache || is_null( $this->mImplicitGroups ) ) {
-                       wfProfileIn( __METHOD__ );
                        $this->mImplicitGroups = array( '*' );
                        if ( $this->getId() ) {
                                $this->mImplicitGroups[] = 'user';
@@ -2968,7 +2949,6 @@ class User implements IDBAccessObject {
                                // as getEffectiveGroups() depends on this function
                                $this->mEffectiveGroups = null;
                        }
-                       wfProfileOut( __METHOD__ );
                }
                return $this->mImplicitGroups;
        }
@@ -3008,7 +2988,6 @@ class User implements IDBAccessObject {
 
                if ( $this->mEditCount === null ) {
                        /* Populate the count, if it has not been populated yet */
-                       wfProfileIn( __METHOD__ );
                        $dbr = wfGetDB( DB_SLAVE );
                        // check if the user_editcount field has been initialized
                        $count = $dbr->selectField(
@@ -3022,7 +3001,6 @@ class User implements IDBAccessObject {
                                $count = $this->initEditCount();
                        }
                        $this->mEditCount = $count;
-                       wfProfileOut( __METHOD__ );
                }
                return (int)$this->mEditCount;
        }
@@ -3031,20 +3009,24 @@ class User implements IDBAccessObject {
         * Add the user to the given group.
         * This takes immediate effect.
         * @param string $group Name of the group to add
+        * @return bool
         */
        public function addGroup( $group ) {
-               if ( Hooks::run( 'UserAddGroup', array( $this, &$group ) ) ) {
-                       $dbw = wfGetDB( DB_MASTER );
-                       if ( $this->getId() ) {
-                               $dbw->insert( 'user_groups',
-                                       array(
-                                               'ug_user' => $this->getID(),
-                                               'ug_group' => $group,
-                                       ),
-                                       __METHOD__,
-                                       array( 'IGNORE' ) );
-                       }
+               if ( !Hooks::run( 'UserAddGroup', array( $this, &$group ) ) ) {
+                       return false;
                }
+
+               $dbw = wfGetDB( DB_MASTER );
+               if ( $this->getId() ) {
+                       $dbw->insert( 'user_groups',
+                               array(
+                                       'ug_user' => $this->getID(),
+                                       'ug_group' => $group,
+                               ),
+                               __METHOD__,
+                               array( 'IGNORE' ) );
+               }
+
                $this->loadGroups();
                $this->mGroups[] = $group;
                // In case loadGroups was not called before, we now have the right twice.
@@ -3057,31 +3039,39 @@ class User implements IDBAccessObject {
                $this->mRights = null;
 
                $this->invalidateCache();
+
+               return true;
        }
 
        /**
         * Remove the user from the given group.
         * This takes immediate effect.
         * @param string $group Name of the group to remove
+        * @return bool
         */
        public function removeGroup( $group ) {
                $this->load();
-               if ( Hooks::run( 'UserRemoveGroup', array( $this, &$group ) ) ) {
-                       $dbw = wfGetDB( DB_MASTER );
-                       $dbw->delete( 'user_groups',
-                               array(
-                                       'ug_user' => $this->getID(),
-                                       'ug_group' => $group,
-                               ), __METHOD__ );
-                       // Remember that the user was in this group
-                       $dbw->insert( 'user_former_groups',
-                               array(
-                                       'ufg_user' => $this->getID(),
-                                       'ufg_group' => $group,
-                               ),
-                               __METHOD__,
-                               array( 'IGNORE' ) );
+               if ( !Hooks::run( 'UserRemoveGroup', array( $this, &$group ) ) ) {
+                       return false;
                }
+
+               $dbw = wfGetDB( DB_MASTER );
+               $dbw->delete( 'user_groups',
+                       array(
+                               'ug_user' => $this->getID(),
+                               'ug_group' => $group,
+                       ), __METHOD__
+               );
+               // Remember that the user was in this group
+               $dbw->insert( 'user_former_groups',
+                       array(
+                               'ufg_user' => $this->getID(),
+                               'ufg_group' => $group,
+                       ),
+                       __METHOD__,
+                       array( 'IGNORE' )
+               );
+
                $this->loadGroups();
                $this->mGroups = array_diff( $this->mGroups, array( $group ) );
 
@@ -3091,6 +3081,8 @@ class User implements IDBAccessObject {
                $this->mRights = null;
 
                $this->invalidateCache();
+
+               return true;
        }
 
        /**
@@ -3815,8 +3807,6 @@ class User implements IDBAccessObject {
        public function checkPassword( $password ) {
                global $wgAuth, $wgLegacyEncoding;
 
-               $section = new ProfileSection( __METHOD__ );
-
                $this->loadPasswords();
 
                // Certain authentication plugins do NOT want to save
@@ -4471,7 +4461,7 @@ class User implements IDBAccessObject {
                if ( $title ) {
                        return Linker::link( $title, htmlspecialchars( $text ) );
                } else {
-                       return $text;
+                       return htmlspecialchars( $text );
                }
        }
 
@@ -4764,7 +4754,7 @@ class User implements IDBAccessObject {
                if ( $action === true ) {
                        $action = 'byemail';
                } elseif ( $action === false ) {
-                       if ( $this->getName() == $wgUser->getName() ) {
+                       if ( $this->equals( $wgUser ) ) {
                                $action = 'create';
                        } else {
                                $action = 'create2';
@@ -5049,4 +5039,15 @@ class User implements IDBAccessObject {
                        return Status::newFatal( 'badaccess-group0' );
                }
        }
+
+       /**
+        * Checks if two user objects point to the same user.
+        *
+        * @since 1.25
+        * @param User $user
+        * @return bool
+        */
+       public function equals( User $user ) {
+               return $this->getName() === $user->getName();
+       }
 }