API: documentation and cleanup.
[lhc/web/wiklou.git] / includes / StubObject.php
index 1bb76fd..894550c 100644 (file)
@@ -24,21 +24,7 @@ class StubObject {
        }
 
        static function isRealObject( $obj ) {
-               return is_object( $obj ) && !is_a( $obj, 'StubObject' );
-       }
-
-       static function _getCaller( $level ) {
-               $backtrace = debug_backtrace();
-               if ( isset( $backtrace[$level] ) ) {
-                       if ( isset( $backtrace[$level]['class'] ) ) {
-                               $caller = $backtrace[$level]['class'] . '::' . $backtrace[$level]['function'];
-                       } else {
-                               $caller = $backtrace[$level]['function'];
-                       }
-               } else {
-                       $caller = 'unknown';
-               }
-               return $caller;
+               return is_object( $obj ) && !($obj instanceof StubObject);
        }
 
        function _call( $name, $args ) {
@@ -49,7 +35,7 @@ class StubObject {
        function _newObject() {
                return wfCreateObject( $this->mClass, $this->mParams );
        }
-       
+
        function __call( $name, $args ) {
                return $this->_call( $name, $args );
        }
@@ -63,7 +49,7 @@ class StubObject {
                if ( get_class( $GLOBALS[$this->mGlobal] ) != $this->mClass ) {
                        $fname = __METHOD__.'-'.$this->mGlobal;
                        wfProfileIn( $fname );
-                       $caller = self::_getCaller( $level );
+                       $caller = wfGetCaller( $level );
                        if ( ++$recursionLevel > 2 ) {
                                throw new MWException( "Unstub loop detected on call of \${$this->mGlobal}->$name from $caller\n" );
                        }
@@ -103,11 +89,19 @@ class StubUserLang extends StubObject {
 
        function _newObject() {
                global $wgContLanguageCode, $wgRequest, $wgUser, $wgContLang;
-               $code = $wgRequest->getText('uselang', '');
-               if ($code == '')
-                       $code = $wgUser->getOption('language');
+               $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()){
+                       $variant = $wgContLang->getPreferredVariant();
+                       if($variant != $wgContLanguageCode)
+                               $code = $variant;
+               }        
+
                # Validate $code
-               if( empty( $code ) || !preg_match( '/^[a-z]+(-[a-z]+)?$/', $code ) ) {
+               if( empty( $code ) || !preg_match( '/^[a-z-]+$/', $code ) ) {
+                       wfDebug( "Invalid user language code\n" );
                        $code = $wgContLanguageCode;
                }
 
@@ -132,9 +126,9 @@ class StubUser extends StubObject {
                global $wgCommandLineMode;
                if( $wgCommandLineMode ) {
                        $user = new User;
-                       $user->setLoaded( true );
                } else {
-                       $user = User::loadFromSession();
+                       $user = User::newFromSession();
+                       wfRunHooks('AutoAuthenticate',array(&$user));
                }
                return $user;
        }