Merge "Title::getLinkURL(): Allow expanding PROTO_RELATIVE too"
[lhc/web/wiklou.git] / includes / user / User.php
index 5eef0c2..a774aba 100644 (file)
@@ -477,7 +477,7 @@ class User implements IDBAccessObject {
                                $setOpts += Database::getCacheSetOptions( wfGetDB( DB_SLAVE ) );
                                wfDebug( "User: cache miss for user {$this->mId}\n" );
 
-                               $this->loadFromDatabase();
+                               $this->loadFromDatabase( self::READ_NORMAL );
                                $this->loadGroups();
                                $this->loadOptions();
 
@@ -772,15 +772,15 @@ class User implements IDBAccessObject {
                        return self::$idCacheByName[$name];
                }
 
-               $db = ( $flags & self::READ_LATEST )
-                       ? wfGetDB( DB_MASTER )
-                       : wfGetDB( DB_SLAVE );
+               list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
+               $db = wfGetDB( $index );
 
                $s = $db->selectRow(
                        'user',
                        [ 'user_id' ],
                        [ 'user_name' => $nt->getText() ],
-                       __METHOD__
+                       __METHOD__,
+                       $options
                );
 
                if ( $s === false ) {
@@ -806,7 +806,7 @@ class User implements IDBAccessObject {
        }
 
        /**
-        * Does the string match an anonymous IPv4 address?
+        * Does the string match an anonymous IP address?
         *
         * This function exists for username validation, in order to reject
         * usernames which are similar in form to IP addresses. Strings such
@@ -1524,16 +1524,19 @@ class User implements IDBAccessObject {
                global $wgNamespacesToBeSearchedDefault, $wgDefaultUserOptions, $wgContLang, $wgDefaultSkin;
 
                static $defOpt = null;
-               if ( !defined( 'MW_PHPUNIT_TEST' ) && $defOpt !== null ) {
-                       // Disabling this for the unit tests, as they rely on being able to change $wgContLang
-                       // mid-request and see that change reflected in the return value of this function.
-                       // Which is insane and would never happen during normal MW operation
+               static $defOptLang = null;
+
+               if ( $defOpt !== null && $defOptLang === $wgContLang->getCode() ) {
+                       // $wgContLang does not change (and should not change) mid-request,
+                       // but the unit tests change it anyway, and expect this method to
+                       // return values relevant to the current $wgContLang.
                        return $defOpt;
                }
 
                $defOpt = $wgDefaultUserOptions;
                // Default language setting
-               $defOpt['language'] = $wgContLang->getCode();
+               $defOptLang = $wgContLang->getCode();
+               $defOpt['language'] = $defOptLang;
                foreach ( LanguageConverter::$languagesWithVariants as $langCode ) {
                        $defOpt[$langCode == $wgContLang->getCode() ? 'variant' : "variant-$langCode"] = $langCode;
                }