Merge "Surround edit notices with appropriate classes"
[lhc/web/wiklou.git] / includes / User.php
index 16a78f6..7ca7d80 100644 (file)
@@ -58,6 +58,12 @@ class User implements IDBAccessObject {
         */
        const MAX_WATCHED_ITEMS_CACHE = 100;
 
+       /**
+        * Exclude user options that are set to their default value.
+        * @since 1.25
+        */
+       const GETOPTIONS_EXCLUDE_DEFAULTS = 1;
+
        /**
         * @var PasswordFactory Lazily loaded factory object for passwords
         */
@@ -318,7 +324,6 @@ class User implements IDBAccessObject {
                if ( $this->mLoadedItems === true ) {
                        return;
                }
-               wfProfileIn( __METHOD__ );
 
                // Set it now to avoid infinite recursion in accessors
                $this->mLoadedItems = true;
@@ -344,13 +349,11 @@ class User implements IDBAccessObject {
                                        // Loading from session failed. Load defaults.
                                        $this->loadDefaults();
                                }
-                               wfRunHooks( 'UserLoadAfterLoadFromSession', array( $this ) );
+                               Hooks::run( 'UserLoadAfterLoadFromSession', array( $this ) );
                                break;
                        default:
-                               wfProfileOut( __METHOD__ );
                                throw new MWException( "Unrecognised value for User->mFrom: \"{$this->mFrom}\"" );
                }
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -703,7 +706,7 @@ class User implements IDBAccessObject {
                static $reservedUsernames = false;
                if ( !$reservedUsernames ) {
                        $reservedUsernames = $wgReservedUsernames;
-                       wfRunHooks( 'UserGetReservedNames', array( &$reservedUsernames ) );
+                       Hooks::run( 'UserGetReservedNames', array( &$reservedUsernames ) );
                }
 
                // Certain names may be reserved for batch processes.
@@ -811,7 +814,7 @@ class User implements IDBAccessObject {
 
                $result = false; //init $result to false for the internal checks
 
-               if ( !wfRunHooks( 'isValidPassword', array( $password, &$result, $this ) ) ) {
+               if ( !Hooks::run( 'isValidPassword', array( $password, &$result, $this ) ) ) {
                        $status->error( $result );
                        return $status;
                }
@@ -873,7 +876,7 @@ class User implements IDBAccessObject {
                        );
                }
                // Give extensions a chance to force an expiration
-               wfRunHooks( 'ResetPasswordExpiration', array( $this, &$newExpire ) );
+               Hooks::run( 'ResetPasswordExpiration', array( $this, &$newExpire ) );
                $this->mPasswordExpires = $newExpire;
        }
 
@@ -1013,7 +1016,6 @@ class User implements IDBAccessObject {
         * @param string|bool $name
         */
        public function loadDefaults( $name = false ) {
-               wfProfileIn( __METHOD__ );
 
                $passwordFactory = self::getPasswordFactory();
 
@@ -1043,9 +1045,8 @@ class User implements IDBAccessObject {
                $this->mRegistration = wfTimestamp( TS_MW );
                $this->mGroups = array();
 
-               wfRunHooks( 'UserLoadDefaults', array( $this, $name ) );
+               Hooks::run( 'UserLoadDefaults', array( $this, $name ) );
 
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -1082,7 +1083,7 @@ class User implements IDBAccessObject {
         */
        private function loadFromSession() {
                $result = null;
-               wfRunHooks( 'UserLoadFromSession', array( $this, &$result ) );
+               Hooks::run( 'UserLoadFromSession', array( $this, &$result ) );
                if ( $result !== null ) {
                        return $result;
                }
@@ -1184,7 +1185,7 @@ class User implements IDBAccessObject {
                                : array()
                );
 
-               wfRunHooks( 'UserLoadFromDatabase', array( $this, &$s ) );
+               Hooks::run( 'UserLoadFromDatabase', array( $this, &$s ) );
 
                if ( $s !== false ) {
                        // Initialise user table data
@@ -1450,7 +1451,7 @@ class User implements IDBAccessObject {
                }
                $defOpt['skin'] = Skin::normalizeKey( $wgDefaultSkin );
 
-               wfRunHooks( 'UserGetDefaultOptions', array( &$defOpt ) );
+               Hooks::run( 'UserGetDefaultOptions', array( &$defOpt ) );
 
                return $defOpt;
        }
@@ -1483,7 +1484,6 @@ class User implements IDBAccessObject {
                        return;
                }
 
-               wfProfileIn( __METHOD__ );
                wfDebug( __METHOD__ . ": checking...\n" );
 
                // Initialize data...
@@ -1556,9 +1556,8 @@ class User implements IDBAccessObject {
                }
 
                // Extensions
-               wfRunHooks( 'GetBlockedStatus', array( &$this ) );
+               Hooks::run( 'GetBlockedStatus', array( &$this ) );
 
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -1590,7 +1589,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)
@@ -1625,7 +1623,6 @@ class User implements IDBAccessObject {
                        }
                }
 
-               wfProfileOut( __METHOD__ );
                return $found;
        }
 
@@ -1642,7 +1639,6 @@ class User implements IDBAccessObject {
                if ( !$wgProxyList ) {
                        return false;
                }
-               wfProfileIn( __METHOD__ );
 
                if ( !is_array( $wgProxyList ) ) {
                        // Load from the specified file
@@ -1659,7 +1655,6 @@ class User implements IDBAccessObject {
                } else {
                        $ret = false;
                }
-               wfProfileOut( __METHOD__ );
                return $ret;
        }
 
@@ -1696,7 +1691,7 @@ class User implements IDBAccessObject {
        public function pingLimiter( $action = 'edit', $incrBy = 1 ) {
                // Call the 'PingLimiter' hook
                $result = false;
-               if ( !wfRunHooks( 'PingLimiter', array( &$this, $action, &$result, $incrBy ) ) ) {
+               if ( !Hooks::run( 'PingLimiter', array( &$this, $action, &$result, $incrBy ) ) ) {
                        return $result;
                }
 
@@ -1711,8 +1706,6 @@ class User implements IDBAccessObject {
                }
 
                global $wgMemc;
-               wfProfileIn( __METHOD__ );
-               wfProfileIn( __METHOD__ . '-' . $action );
 
                $limits = $wgRateLimits[$action];
                $keys = array();
@@ -1793,8 +1786,6 @@ class User implements IDBAccessObject {
                        }
                }
 
-               wfProfileOut( __METHOD__ . '-' . $action );
-               wfProfileOut( __METHOD__ );
                return $triggered;
        }
 
@@ -1829,7 +1820,6 @@ class User implements IDBAccessObject {
         */
        public function isBlockedFrom( $title, $bFromSlave = false ) {
                global $wgBlockAllowsUTEdit;
-               wfProfileIn( __METHOD__ );
 
                $blocked = $this->isBlocked( $bFromSlave );
                $allowUsertalk = ( $wgBlockAllowsUTEdit ? $this->mAllowUsertalk : false );
@@ -1840,9 +1830,8 @@ class User implements IDBAccessObject {
                        wfDebug( __METHOD__ . ": self-talk page, ignoring any blocks\n" );
                }
 
-               wfRunHooks( 'UserIsBlockedFrom', array( $this, $title, &$blocked, &$allowUsertalk ) );
+               Hooks::run( 'UserIsBlockedFrom', array( $this, $title, &$blocked, &$allowUsertalk ) );
 
-               wfProfileOut( __METHOD__ );
                return $blocked;
        }
 
@@ -1892,7 +1881,7 @@ class User implements IDBAccessObject {
                        $ip = $this->getRequest()->getIP();
                }
                $blocked = false;
-               wfRunHooks( 'UserIsBlockedGlobally', array( &$this, $ip, &$blocked ) );
+               Hooks::run( 'UserIsBlockedGlobally', array( &$this, $ip, &$blocked ) );
                $this->mBlockedGlobally = (bool)$blocked;
                return $this->mBlockedGlobally;
        }
@@ -2052,7 +2041,7 @@ class User implements IDBAccessObject {
         */
        public function getNewMessageLinks() {
                $talks = array();
-               if ( !wfRunHooks( 'UserRetrieveNewTalks', array( &$this, &$talks ) ) ) {
+               if ( !Hooks::run( 'UserRetrieveNewTalks', array( &$this, &$talks ) ) ) {
                        return $talks;
                } elseif ( !$this->getNewtalk() ) {
                        return array();
@@ -2429,7 +2418,7 @@ class User implements IDBAccessObject {
         */
        public function getEmail() {
                $this->load();
-               wfRunHooks( 'UserGetEmail', array( $this, &$this->mEmail ) );
+               Hooks::run( 'UserGetEmail', array( $this, &$this->mEmail ) );
                return $this->mEmail;
        }
 
@@ -2439,7 +2428,7 @@ class User implements IDBAccessObject {
         */
        public function getEmailAuthenticationTimestamp() {
                $this->load();
-               wfRunHooks( 'UserGetEmailAuthenticationTimestamp', array( $this, &$this->mEmailAuthenticated ) );
+               Hooks::run( 'UserGetEmailAuthenticationTimestamp', array( $this, &$this->mEmailAuthenticated ) );
                return $this->mEmailAuthenticated;
        }
 
@@ -2454,7 +2443,7 @@ class User implements IDBAccessObject {
                }
                $this->invalidateEmail();
                $this->mEmail = $str;
-               wfRunHooks( 'UserSetEmail', array( $this, &$this->mEmail ) );
+               Hooks::run( 'UserSetEmail', array( $this, &$this->mEmail ) );
        }
 
        /**
@@ -2483,7 +2472,7 @@ class User implements IDBAccessObject {
                        $type = $oldaddr != '' ? 'changed' : 'set';
                        $result = $this->sendConfirmationMail( $type );
                        if ( $result->isGood() ) {
-                               // Say the the caller that a confirmation mail has been sent
+                               // Say to the caller that a confirmation mail has been sent
                                $result->value = 'eauth';
                        }
                } else {
@@ -2547,9 +2536,12 @@ class User implements IDBAccessObject {
        /**
         * Get all user's options
         *
+        * @param int $flags Bitwise combination of:
+        *   User::GETOPTIONS_EXCLUDE_DEFAULTS  Exclude user options that are set
+        *                                      to the default value. (Since 1.25)
         * @return array
         */
-       public function getOptions() {
+       public function getOptions( $flags = 0 ) {
                global $wgHiddenPrefs;
                $this->loadOptions();
                $options = $this->mOptions;
@@ -2566,6 +2558,10 @@ class User implements IDBAccessObject {
                        }
                }
 
+               if ( $flags & self::GETOPTIONS_EXCLUDE_DEFAULTS ) {
+                       $options = array_diff_assoc( $options, self::getDefaultOptions() );
+               }
+
                return $options;
        }
 
@@ -2823,7 +2819,7 @@ class User implements IDBAccessObject {
                        }
                }
 
-               wfRunHooks( 'UserResetAllOptions', array( $this, &$newOptions, $this->mOptions, $resetKinds ) );
+               Hooks::run( 'UserResetAllOptions', array( $this, &$newOptions, $this->mOptions, $resetKinds ) );
 
                $this->mOptions = $newOptions;
                $this->mOptionsLoaded = true;
@@ -2859,7 +2855,7 @@ class User implements IDBAccessObject {
                        return false;
                } else {
                        $https = $this->getBoolOption( 'prefershttps' );
-                       wfRunHooks( 'UserRequiresHTTPS', array( $this, &$https ) );
+                       Hooks::run( 'UserRequiresHTTPS', array( $this, &$https ) );
                        if ( $https ) {
                                $https = wfCanIPUseHTTPS( $this->getRequest()->getIP() );
                        }
@@ -2890,7 +2886,7 @@ class User implements IDBAccessObject {
        public function getRights() {
                if ( is_null( $this->mRights ) ) {
                        $this->mRights = self::getGroupPermissions( $this->getEffectiveGroups() );
-                       wfRunHooks( 'UserGetRights', array( $this, &$this->mRights ) );
+                       Hooks::run( 'UserGetRights', array( $this, &$this->mRights ) );
                        // Force reindexation of rights when a hook has unset one of them
                        $this->mRights = array_values( array_unique( $this->mRights ) );
                }
@@ -2917,16 +2913,14 @@ 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
                        ) );
                        // Hook for additional groups
-                       wfRunHooks( 'UserEffectiveGroups', array( &$this, &$this->mEffectiveGroups ) );
+                       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;
        }
@@ -2940,7 +2934,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';
@@ -2955,7 +2948,6 @@ class User implements IDBAccessObject {
                                // as getEffectiveGroups() depends on this function
                                $this->mEffectiveGroups = null;
                        }
-                       wfProfileOut( __METHOD__ );
                }
                return $this->mImplicitGroups;
        }
@@ -2995,7 +2987,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(
@@ -3009,7 +3000,6 @@ class User implements IDBAccessObject {
                                $count = $this->initEditCount();
                        }
                        $this->mEditCount = $count;
-                       wfProfileOut( __METHOD__ );
                }
                return (int)$this->mEditCount;
        }
@@ -3020,7 +3010,7 @@ class User implements IDBAccessObject {
         * @param string $group Name of the group to add
         */
        public function addGroup( $group ) {
-               if ( wfRunHooks( 'UserAddGroup', array( $this, &$group ) ) ) {
+               if ( Hooks::run( 'UserAddGroup', array( $this, &$group ) ) ) {
                        $dbw = wfGetDB( DB_MASTER );
                        if ( $this->getId() ) {
                                $dbw->insert( 'user_groups',
@@ -3053,7 +3043,7 @@ class User implements IDBAccessObject {
         */
        public function removeGroup( $group ) {
                $this->load();
-               if ( wfRunHooks( 'UserRemoveGroup', array( $this, &$group ) ) ) {
+               if ( Hooks::run( 'UserRemoveGroup', array( $this, &$group ) ) ) {
                        $dbw = wfGetDB( DB_MASTER );
                        $dbw->delete( 'user_groups',
                                array(
@@ -3277,7 +3267,7 @@ class User implements IDBAccessObject {
 
                // If we're working on user's talk page, we should update the talk page message indicator
                if ( $title->getNamespace() == NS_USER_TALK && $title->getText() == $this->getName() ) {
-                       if ( !wfRunHooks( 'UserClearNewTalkNotification', array( &$this, $oldid ) ) ) {
+                       if ( !Hooks::run( 'UserClearNewTalkNotification', array( &$this, $oldid ) ) ) {
                                return;
                        }
 
@@ -3422,7 +3412,7 @@ class User implements IDBAccessObject {
                        $cookies['Token'] = false;
                }
 
-               wfRunHooks( 'UserSetCookies', array( $this, &$session, &$cookies ) );
+               Hooks::run( 'UserSetCookies', array( $this, &$session, &$cookies ) );
 
                foreach ( $session as $name => $value ) {
                        $request->setSessionData( $name, $value );
@@ -3457,7 +3447,7 @@ class User implements IDBAccessObject {
         * Log this user out.
         */
        public function logout() {
-               if ( wfRunHooks( 'UserLogout', array( &$this ) ) ) {
+               if ( Hooks::run( 'UserLogout', array( &$this ) ) ) {
                        $this->doLogout();
                }
        }
@@ -3522,7 +3512,7 @@ class User implements IDBAccessObject {
 
                $this->saveOptions();
 
-               wfRunHooks( 'UserSaveSettings', array( $this ) );
+               Hooks::run( 'UserSaveSettings', array( $this ) );
                $this->clearSharedCache();
                $this->getUserPage()->invalidateCache();
        }
@@ -3802,8 +3792,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
@@ -4120,7 +4108,7 @@ class User implements IDBAccessObject {
                // and fire the ConfirmEmailComplete hook on redundant confirmations.
                if ( !$this->isEmailConfirmed() ) {
                        $this->setEmailAuthenticationTimestamp( wfTimestampNow() );
-                       wfRunHooks( 'ConfirmEmailComplete', array( $this ) );
+                       Hooks::run( 'ConfirmEmailComplete', array( $this ) );
                }
                return true;
        }
@@ -4138,7 +4126,7 @@ class User implements IDBAccessObject {
                $this->mEmailTokenExpires = null;
                $this->setEmailAuthenticationTimestamp( null );
                $this->mEmail = '';
-               wfRunHooks( 'InvalidateEmailComplete', array( $this ) );
+               Hooks::run( 'InvalidateEmailComplete', array( $this ) );
                return true;
        }
 
@@ -4149,7 +4137,7 @@ class User implements IDBAccessObject {
        public function setEmailAuthenticationTimestamp( $timestamp ) {
                $this->load();
                $this->mEmailAuthenticated = $timestamp;
-               wfRunHooks( 'UserSetEmailAuthenticationTimestamp', array( $this, &$this->mEmailAuthenticated ) );
+               Hooks::run( 'UserSetEmailAuthenticationTimestamp', array( $this, &$this->mEmailAuthenticated ) );
        }
 
        /**
@@ -4163,7 +4151,7 @@ class User implements IDBAccessObject {
                        return false;
                }
                $canSend = $this->isEmailConfirmed();
-               wfRunHooks( 'UserCanSendEmail', array( &$this, &$canSend ) );
+               Hooks::run( 'UserCanSendEmail', array( &$this, &$canSend ) );
                return $canSend;
        }
 
@@ -4190,7 +4178,7 @@ class User implements IDBAccessObject {
                global $wgEmailAuthentication;
                $this->load();
                $confirmed = true;
-               if ( wfRunHooks( 'EmailConfirmed', array( &$this, &$confirmed ) ) ) {
+               if ( Hooks::run( 'EmailConfirmed', array( &$this, &$confirmed ) ) ) {
                        if ( $this->isAnon() ) {
                                return false;
                        }
@@ -4348,7 +4336,7 @@ class User implements IDBAccessObject {
                }
 
                // Allow extensions (e.g. OAuth) to say false
-               if ( !wfRunHooks( 'UserIsEveryoneAllowed', array( $right ) ) ) {
+               if ( !Hooks::run( 'UserIsEveryoneAllowed', array( $right ) ) ) {
                        $cache[$right] = false;
                        return false;
                }
@@ -4406,7 +4394,7 @@ class User implements IDBAccessObject {
                        } else {
                                self::$mAllRights = self::$mCoreRights;
                        }
-                       wfRunHooks( 'UserGetAllRights', array( &self::$mAllRights ) );
+                       Hooks::run( 'UserGetAllRights', array( &self::$mAllRights ) );
                }
                return self::$mAllRights;
        }
@@ -4420,7 +4408,7 @@ class User implements IDBAccessObject {
 
                $groups = $wgImplicitGroups;
                # Deprecated, use $wgImplicitGroups instead
-               wfRunHooks( 'UserGetImplicitGroups', array( &$groups ), '1.25' );
+               Hooks::run( 'UserGetImplicitGroups', array( &$groups ), '1.25' );
 
                return $groups;
        }
@@ -4458,7 +4446,7 @@ class User implements IDBAccessObject {
                if ( $title ) {
                        return Linker::link( $title, htmlspecialchars( $text ) );
                } else {
-                       return $text;
+                       return htmlspecialchars( $text );
                }
        }
 
@@ -4476,7 +4464,7 @@ class User implements IDBAccessObject {
                }
                $title = self::getGroupPage( $group );
                if ( $title ) {
-                       $page = $title->getPrefixedText();
+                       $page = $title->getFullText();
                        return "[[$page|$text]]";
                } else {
                        return $text;
@@ -4854,7 +4842,7 @@ class User implements IDBAccessObject {
 
                $this->mOptionsLoaded = true;
 
-               wfRunHooks( 'UserLoadOptions', array( $this, &$this->mOptions ) );
+               Hooks::run( 'UserLoadOptions', array( $this, &$this->mOptions ) );
        }
 
        /**
@@ -4870,7 +4858,7 @@ class User implements IDBAccessObject {
 
                // Allow hooks to abort, for instance to save to a global profile.
                // Reset options to default state before saving.
-               if ( !wfRunHooks( 'UserSaveOptions', array( $this, &$saveOptions ) ) ) {
+               if ( !Hooks::run( 'UserSaveOptions', array( $this, &$saveOptions ) ) ) {
                        return;
                }