Improve some queries ordering by rev_timestamp with actor migration READ_NEW
[lhc/web/wiklou.git] / includes / user / User.php
index fe9a5c9..6066c87 100644 (file)
@@ -492,7 +492,7 @@ class User implements IDBAccessObject, UserIdentity {
         * @param int $userId
         */
        public static function purge( $wikiId, $userId ) {
-               $cache = ObjectCache::getMainWANInstance();
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                $key = $cache->makeGlobalKey( 'user', 'id', $wikiId, $userId );
                $cache->delete( $key );
        }
@@ -503,7 +503,10 @@ class User implements IDBAccessObject, UserIdentity {
         * @return string
         */
        protected function getCacheKey( WANObjectCache $cache ) {
-               return $cache->makeGlobalKey( 'user', 'id', wfWikiID(), $this->mId );
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+               $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+
+               return $cache->makeGlobalKey( 'user', 'id', $lbFactory->getLocalDomainID(), $this->mId );
        }
 
        /**
@@ -1814,11 +1817,7 @@ class User implements IDBAccessObject, UserIdentity {
         */
        public static function getDefaultOption( $opt ) {
                $defOpts = self::getDefaultOptions();
-               if ( isset( $defOpts[$opt] ) ) {
-                       return $defOpts[$opt];
-               } else {
-                       return null;
-               }
+               return $defOpts[$opt] ?? null;
        }
 
        /**
@@ -2294,21 +2293,22 @@ class User implements IDBAccessObject, UserIdentity {
         * Check if user is blocked from editing a particular article
         *
         * @param Title $title Title to check
-        * @param bool $bFromSlave Whether to check the replica DB instead of the master
+        * @param bool $fromSlave Whether to check the replica DB instead of the master
         * @return bool
         */
-       public function isBlockedFrom( $title, $bFromSlave = false ) {
-               global $wgBlockAllowsUTEdit;
+       public function isBlockedFrom( $title, $fromSlave = false ) {
+               $blocked = $this->isHidden();
 
-               $blocked = $this->isBlocked( $bFromSlave );
-               $allowUsertalk = ( $wgBlockAllowsUTEdit ? $this->mAllowUsertalk : false );
-               // If a user's name is suppressed, they cannot make edits anywhere
-               if ( !$this->mHideName && $allowUsertalk && $title->getText() === $this->getName()
-                       && $title->getNamespace() == NS_USER_TALK ) {
-                       $blocked = false;
-                       wfDebug( __METHOD__ . ": self-talk page, ignoring any blocks\n" );
+               if ( !$blocked ) {
+                       $block = $this->getBlock( $fromSlave );
+                       if ( $block ) {
+                               $blocked = $block->preventsEdit( $title );
+                       }
                }
 
+               // only for the purpose of the hook. We really don't need this here.
+               $allowUsertalk = $this->mAllowUsertalk;
+
                Hooks::run( 'UserIsBlockedFrom', [ $this, $title, &$blocked, &$allowUsertalk ] );
 
                return $blocked;
@@ -2415,7 +2415,7 @@ class User implements IDBAccessObject, UserIdentity {
         */
        public function isHidden() {
                if ( $this->mHideName !== null ) {
-                       return $this->mHideName;
+                       return (bool)$this->mHideName;
                }
                $this->getBlockedStatus();
                if ( !$this->mHideName ) {
@@ -2425,7 +2425,7 @@ class User implements IDBAccessObject, UserIdentity {
                        $this->mHideName = $authUser && $authUser->isHidden();
                        Hooks::run( 'UserIsHidden', [ $this, &$this->mHideName ] );
                }
-               return $this->mHideName;
+               return (bool)$this->mHideName;
        }
 
        /**
@@ -4515,6 +4515,16 @@ class User implements IDBAccessObject, UserIdentity {
                return $this->mBlock && $this->mBlock->prevents( 'sendemail' );
        }
 
+       /**
+        * Get whether the user is blocked from using Special:Upload
+        *
+        * @return bool
+        */
+       public function isBlockedFromUpload() {
+               $this->getBlockedStatus();
+               return $this->mBlock && $this->mBlock->prevents( 'upload' );
+       }
+
        /**
         * Get whether the user is allowed to create an account.
         * @return bool
@@ -4932,12 +4942,14 @@ class User implements IDBAccessObject, UserIdentity {
                }
                $dbr = wfGetDB( DB_REPLICA );
                $actorWhere = ActorMigration::newMigration()->getWhere( $dbr, 'rev_user', $this );
+               $tsField = isset( $actorWhere['tables']['temp_rev_user'] )
+                       ? 'revactor_timestamp' : 'rev_timestamp';
                $time = $dbr->selectField(
                        [ 'revision' ] + $actorWhere['tables'],
-                       'rev_timestamp',
+                       $tsField,
                        [ $actorWhere['conds'] ],
                        __METHOD__,
-                       [ 'ORDER BY' => 'rev_timestamp ASC' ],
+                       [ 'ORDER BY' => "$tsField ASC" ],
                        $actorWhere['joins']
                );
                if ( !$time ) {