X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FUser.php;h=e25bc1fc1007f7a55311c14dd28595cf256c9548;hb=c1bf30c2e55a7bae04b3c5e232f5017ed79bbd80;hp=fe4118782bbfab4246f6d83da106e31e64c480ef;hpb=e173358375ba68a5bbbc1cbe97ad3f6ea25ca813;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/User.php b/includes/User.php index fe4118782b..e25bc1fc10 100644 --- a/includes/User.php +++ b/includes/User.php @@ -357,21 +357,14 @@ class User implements IDBAccessObject { * @return bool False if the ID does not exist, true otherwise */ public function loadFromId() { - global $wgMemc; if ( $this->mId == 0 ) { $this->loadDefaults(); return false; } // Try cache - $key = wfMemcKey( 'user', 'id', $this->mId ); - $data = $wgMemc->get( $key ); - if ( !is_array( $data ) || $data['mVersion'] != self::VERSION ) { - // Object is expired, load from DB - $data = false; - } - - if ( !$data ) { + $cache = $this->loadFromCache(); + if ( !$cache ) { wfDebug( "User: cache miss for user {$this->mId}\n" ); // Load from DB if ( !$this->loadFromDatabase() ) { @@ -379,12 +372,6 @@ class User implements IDBAccessObject { return false; } $this->saveToCache(); - } else { - wfDebug( "User: got user {$this->mId} from cache\n" ); - // Restore from cache - foreach ( self::$mCacheVars as $name ) { - $this->$name = $data[$name]; - } } $this->mLoadedItems = true; @@ -392,6 +379,37 @@ class User implements IDBAccessObject { return true; } + /** + * Load user data from shared cache, given mId has already been set. + * + * @return bool false if the ID does not exist or data is invalid, true otherwise + * @since 1.25 + */ + public function loadFromCache() { + global $wgMemc; + + if ( $this->mId == 0 ) { + $this->loadDefaults(); + return false; + } + + $key = wfMemcKey( 'user', 'id', $this->mId ); + $data = $wgMemc->get( $key ); + if ( !is_array( $data ) || $data['mVersion'] < self::VERSION ) { + // Object is expired + return false; + } + + wfDebug( "User: got user {$this->mId} from cache\n" ); + + // Restore from cache + foreach ( self::$mCacheVars as $name ) { + $this->$name = $data[$name]; + } + + return true; + } + /** * Save user data to the shared cache */ @@ -829,7 +847,7 @@ class User implements IDBAccessObject { * @param int $ts Optional timestamp to convert, default 0 for the current time */ public function expirePassword( $ts = 0 ) { - $this->load(); + $this->loadPasswords(); $timestamp = wfTimestamp( TS_MW, $ts ); $this->mPasswordExpires = $timestamp; $this->saveSettings(); @@ -1885,7 +1903,6 @@ class User implements IDBAccessObject { return $this->mLocked; } global $wgAuth; - StubObject::unstub( $wgAuth ); $authUser = $wgAuth->getUserInstance( $this ); $this->mLocked = (bool)$authUser->isLocked(); return $this->mLocked; @@ -1903,7 +1920,6 @@ class User implements IDBAccessObject { $this->getBlockedStatus(); if ( !$this->mHideName ) { global $wgAuth; - StubObject::unstub( $wgAuth ); $authUser = $wgAuth->getUserInstance( $this ); $this->mHideName = (bool)$authUser->isHidden(); } @@ -2335,11 +2351,7 @@ class User implements IDBAccessObject { $this->setToken(); $passwordFactory = self::getPasswordFactory(); - if ( $str === null ) { - $this->mPassword = $passwordFactory->newFromCiphertext( null ); - } else { - $this->mPassword = $passwordFactory->newFromPlaintext( $str ); - } + $this->mPassword = $passwordFactory->newFromPlaintext( $str ); $this->mNewpassword = $passwordFactory->newFromCiphertext( null ); $this->mNewpassTime = null; @@ -2384,14 +2396,11 @@ class User implements IDBAccessObject { public function setNewpassword( $str, $throttle = true ) { $this->loadPasswords(); + $this->mNewpassword = self::getPasswordFactory()->newFromPlaintext( $str ); if ( $str === null ) { - $this->mNewpassword = ''; $this->mNewpassTime = null; - } else { - $this->mNewpassword = self::getPasswordFactory()->newFromPlaintext( $str ); - if ( $throttle ) { - $this->mNewpassTime = wfTimestampNow(); - } + } elseif ( $throttle ) { + $this->mNewpassTime = wfTimestampNow(); } } @@ -2733,7 +2742,7 @@ class User implements IDBAccessObject { foreach ( $columns as $column ) { foreach ( $rows as $row ) { - $checkmatrixOptions["$prefix-$column-$row"] = true; + $checkmatrixOptions["$prefix$column-$row"] = true; } } @@ -3086,10 +3095,8 @@ class User implements IDBAccessObject { /** * Check if user is allowed to access a feature / make an action * - * @internal param \String $varargs permissions to test + * @param string $permissions,... Permissions to test * @return bool True if user is allowed to perform *any* of the given actions - * - * @return bool */ public function isAllowedAny( /*...*/ ) { $permissions = func_get_args(); @@ -3103,7 +3110,7 @@ class User implements IDBAccessObject { /** * - * @internal param $varargs string + * @param string $permissions,... Permissions to test * @return bool True if the user is allowed to perform *all* of the given actions */ public function isAllowedAll( /*...*/ ) { @@ -3790,12 +3797,14 @@ 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 // domain passwords in a mysql database, so we should // check this (in case $wgAuth->strict() is false). - if ( $wgAuth->authenticate( $this->getName(), $password ) ) { return true; } elseif ( $wgAuth->strict() ) { @@ -3994,10 +4003,10 @@ class User implements IDBAccessObject { $sender = new MailAddress( $wgPasswordSender, wfMessage( 'emailsender' )->inContentLanguage()->text() ); } else { - $sender = new MailAddress( $from ); + $sender = MailAddress::newFromUser( $from ); } - $to = new MailAddress( $this ); + $to = MailAddress::newFromUser( $this ); return UserMailer::send( $to, $sender, $subject, $body, $replyto ); }