Merge "User: Avoid deprecated Linker::link()"
[lhc/web/wiklou.git] / includes / user / User.php
index ce6bbc3..a1119fa 100644 (file)
@@ -1953,11 +1953,12 @@ class User implements IDBAccessObject {
                $id = $this->getId();
                $userLimit = false;
                $isNewbie = $this->isNewbie();
+               $cache = ObjectCache::getLocalClusterInstance();
 
                if ( $id == 0 ) {
                        // limits for anons
                        if ( isset( $limits['anon'] ) ) {
-                               $keys[wfMemcKey( 'limiter', $action, 'anon' )] = $limits['anon'];
+                               $keys[$cache->makeKey( 'limiter', $action, 'anon' )] = $limits['anon'];
                        }
                } else {
                        // limits for logged-in users
@@ -1966,7 +1967,7 @@ class User implements IDBAccessObject {
                        }
                        // limits for newbie logged-in users
                        if ( $isNewbie && isset( $limits['newbie'] ) ) {
-                               $keys[wfMemcKey( 'limiter', $action, 'user', $id )] = $limits['newbie'];
+                               $keys[$cache->makeKey( 'limiter', $action, 'user', $id )] = $limits['newbie'];
                        }
                }
 
@@ -2003,7 +2004,7 @@ class User implements IDBAccessObject {
                if ( $userLimit !== false ) {
                        list( $max, $period ) = $userLimit;
                        wfDebug( __METHOD__ . ": effective user limit: $max in {$period}s\n" );
-                       $keys[wfMemcKey( 'limiter', $action, 'user', $id )] = $userLimit;
+                       $keys[$cache->makeKey( 'limiter', $action, 'user', $id )] = $userLimit;
                }
 
                // ip-based limits for all ping-limitable users
@@ -2030,8 +2031,6 @@ class User implements IDBAccessObject {
                        }
                }
 
-               $cache = ObjectCache::getLocalClusterInstance();
-
                $triggered = false;
                foreach ( $keys as $key => $limit ) {
                        list( $max, $period ) = $limit;
@@ -2507,7 +2506,7 @@ class User implements IDBAccessObject {
                        $cache->delete( $key, 1 );
                } else {
                        wfGetDB( DB_MASTER )->onTransactionPreCommitOrIdle(
-                               function() use ( $cache, $key ) {
+                               function () use ( $cache, $key ) {
                                        $cache->delete( $key );
                                },
                                __METHOD__
@@ -2540,8 +2539,9 @@ class User implements IDBAccessObject {
        public function touch() {
                $id = $this->getId();
                if ( $id ) {
-                       $key = wfMemcKey( 'user-quicktouched', 'id', $id );
-                       ObjectCache::getMainWANInstance()->touchCheckKey( $key );
+                       $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+                       $key = $cache->makeKey( 'user-quicktouched', 'id', $id );
+                       $cache->touchCheckKey( $key );
                        $this->mQuickTouched = null;
                }
        }
@@ -2568,8 +2568,8 @@ class User implements IDBAccessObject {
 
                if ( $this->mId ) {
                        if ( $this->mQuickTouched === null ) {
-                               $key = wfMemcKey( 'user-quicktouched', 'id', $this->mId );
-                               $cache = ObjectCache::getMainWANInstance();
+                               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+                               $key = $cache->makeKey( 'user-quicktouched', 'id', $this->mId );
 
                                $this->mQuickTouched = wfTimestamp( TS_MW, $cache->getCheckKeyTime( $key ) );
                        }
@@ -3698,7 +3698,7 @@ class User implements IDBAccessObject {
                        }
 
                        // Try to update the DB post-send and only if needed...
-                       DeferredUpdates::addCallableUpdate( function() use ( $title, $oldid ) {
+                       DeferredUpdates::addCallableUpdate( function () use ( $title, $oldid ) {
                                if ( !$this->getNewtalk() ) {
                                        return; // no notifications to clear
                                }
@@ -4182,6 +4182,10 @@ class User implements IDBAccessObject {
                        $this->setToken(); // init token
                }
 
+               if ( !is_string( $this->mName ) ) {
+                       throw new RuntimeException( "User name field is not set." );
+               }
+
                $this->mTouched = $this->newTouchedTimestamp();
 
                $noPass = PasswordFactory::newInvalidPassword()->toString();
@@ -4953,7 +4957,8 @@ class User implements IDBAccessObject {
                }
                $title = UserGroupMembership::getGroupPage( $group );
                if ( $title ) {
-                       return Linker::link( $title, htmlspecialchars( $text ) );
+                       return MediaWikiServices::getInstance()
+                               ->getLinkRenderer()->makeLink( $title, $text );
                } else {
                        return htmlspecialchars( $text );
                }