Make the instantiation tests actually work.
[lhc/web/wiklou.git] / includes / StubObject.php
index ec52e7f..c8731ff 100644 (file)
@@ -88,6 +88,10 @@ class StubObject {
         */
        function _unstub( $name = '_unstub', $level = 2 ) {
                static $recursionLevel = 0;
+
+               if ( !($GLOBALS[$this->mGlobal] instanceof StubObject) )
+                       return $GLOBALS[$this->mGlobal]; // already unstubbed.
+               
                if ( get_class( $GLOBALS[$this->mGlobal] ) != $this->mClass ) {
                        $fname = __METHOD__.'-'.$this->mGlobal;
                        wfProfileIn( $fname );
@@ -95,8 +99,8 @@ class StubObject {
                        if ( ++$recursionLevel > 2 ) {
                                throw new MWException( "Unstub loop detected on call of \${$this->mGlobal}->$name from $caller\n" );
                        }
-                       wfDebug( "Unstubbing \${$this->mGlobal} on call of \${$this->mGlobal}->$name from $caller\n" );
-                       $GLOBALS[$this->mGlobal] = $this->_newObject();
+                       wfDebug( "Unstubbing \${$this->mGlobal} on call of \${$this->mGlobal}::$name from $caller\n" );
+                       $obj = $GLOBALS[$this->mGlobal] = $this->_newObject();
                        --$recursionLevel;
                        wfProfileOut( $fname );
                }
@@ -144,17 +148,11 @@ class StubUserLang extends StubObject {
        function _newObject() {
                global $wgContLanguageCode, $wgRequest, $wgUser, $wgContLang;
                $code = $wgRequest->getVal( 'uselang', $wgUser->getOption( 'language' ) );
-
-               // if variant is explicitely selected, use it instead the one from wgUser
-               // see bug #7605
-               if( $wgContLang->hasVariants() && in_array($code, $wgContLang->getVariants()) ){
-                       $variant = $wgContLang->getPreferredVariant();
-                       if( $variant != $wgContLanguageCode )
-                               $code = $variant;
-               }
+               // BCP 47 - letter case MUST NOT carry meaning
+               $code = strtolower( $code );
 
                # Validate $code
-               if( empty( $code ) || !preg_match( '/^[a-z-]+$/', $code ) ) {
+               if( empty( $code ) || !preg_match( '/^[a-z-]+$/', $code ) || ( $code === 'qqq' ) ) {
                        wfDebug( "Invalid user language code\n" );
                        $code = $wgContLanguageCode;
                }