Http::getProxy() method to get proxy configuration
[lhc/web/wiklou.git] / includes / StubObject.php
index fb9b3e4..49155d6 100644 (file)
@@ -58,7 +58,7 @@ class StubObject {
         * @param string $class Name of the class of the real object.
         * @param array $params Parameters to pass to constructor of the real object.
         */
-       function __construct( $global = null, $class = null, $params = array() ) {
+       public function __construct( $global = null, $class = null, $params = array() ) {
                $this->global = $global;
                $this->class = $class;
                $this->params = $params;
@@ -71,7 +71,7 @@ class StubObject {
         * @param object $obj Object to check.
         * @return bool True if $obj is not an instance of StubObject class.
         */
-       static function isRealObject( $obj ) {
+       public static function isRealObject( $obj ) {
                return is_object( $obj ) && !$obj instanceof StubObject;
        }
 
@@ -83,7 +83,7 @@ class StubObject {
         * @param object $obj Object to check.
         * @return void
         */
-       static function unstub( &$obj ) {
+       public static function unstub( &$obj ) {
                if ( $obj instanceof StubObject ) {
                        $obj = $obj->_unstub( 'unstub', 3 );
                }
@@ -100,7 +100,7 @@ class StubObject {
         * @param array $args Arguments
         * @return mixed
         */
-       function _call( $name, $args ) {
+       public function _call( $name, $args ) {
                $this->_unstub( $name, 5 );
                return call_user_func_array( array( $GLOBALS[$this->global], $name ), $args );
        }
@@ -109,8 +109,12 @@ class StubObject {
         * Create a new object to replace this stub object.
         * @return object
         */
-       function _newObject() {
-               return MWFunction::newObj( $this->class, $this->params );
+       public function _newObject() {
+               return ObjectFactory::getObjectFromSpec( array(
+                       'class' => $this->class,
+                       'args' => $this->params,
+                       'closure_expansion' => false,
+               ) );
        }
 
        /**
@@ -121,7 +125,7 @@ class StubObject {
         * @param array $args Arguments
         * @return mixed
         */
-       function __call( $name, $args ) {
+       public function __call( $name, $args ) {
                return $this->_call( $name, $args );
        }
 
@@ -134,10 +138,10 @@ class StubObject {
         * @param string $name Name of the method called in this object.
         * @param int $level Level to go in the stack trace to get the function
         *   who called this function.
-        * @return The unstubbed version of itself
+        * @return object The unstubbed version of itself
         * @throws MWException
         */
-       function _unstub( $name = '_unstub', $level = 2 ) {
+       public function _unstub( $name = '_unstub', $level = 2 ) {
                static $recursionLevel = 0;
 
                if ( !$GLOBALS[$this->global] instanceof StubObject ) {
@@ -146,10 +150,8 @@ class StubObject {
 
                if ( get_class( $GLOBALS[$this->global] ) != $this->class ) {
                        $fname = __METHOD__ . '-' . $this->global;
-                       wfProfileIn( $fname );
                        $caller = wfGetCaller( $level );
                        if ( ++$recursionLevel > 2 ) {
-                               wfProfileOut( $fname );
                                throw new MWException( "Unstub loop detected on call of "
                                        . "\${$this->global}->$name from $caller\n" );
                        }
@@ -157,41 +159,11 @@ class StubObject {
                                . "\${$this->global}::$name from $caller\n" );
                        $GLOBALS[$this->global] = $this->_newObject();
                        --$recursionLevel;
-                       wfProfileOut( $fname );
                        return $GLOBALS[$this->global];
                }
        }
 }
 
-/**
- * Stub object for the content language of this wiki. This object have to be in
- * $wgContLang global.
- *
- * @deprecated since 1.18
- */
-class StubContLang extends StubObject {
-
-       function __construct() {
-               wfDeprecated( __CLASS__, '1.18' );
-               parent::__construct( 'wgContLang' );
-       }
-
-       function __call( $name, $args ) {
-               return $this->_call( $name, $args );
-       }
-
-       /**
-        * @return Language
-        */
-       function _newObject() {
-               global $wgLanguageCode;
-               $obj = Language::factory( $wgLanguageCode );
-               $obj->initEncoding();
-               $obj->initContLang();
-               return $obj;
-       }
-}
-
 /**
  * Stub object for the user language. It depends of the user preferences and
  * "uselang" parameter that can be passed to index.php. This object have to be
@@ -199,18 +171,36 @@ class StubContLang extends StubObject {
  */
 class StubUserLang extends StubObject {
 
-       function __construct() {
+       public function __construct() {
                parent::__construct( 'wgLang' );
        }
 
-       function __call( $name, $args ) {
+       public function __call( $name, $args ) {
                return $this->_call( $name, $args );
        }
 
+       /**
+        * Call Language::findVariantLink after unstubbing $wgLang.
+        *
+        * This method is implemented with a full signature rather than relying on
+        * __call so that the pass-by-reference signature of the proxied method is
+        * honored.
+        *
+        * @param string &$link The name of the link
+        * @param Title &$nt The title object of the link
+        * @param bool $ignoreOtherCond To disable other conditions when
+        *   we need to transclude a template or update a category's link
+        */
+       public function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
+               global $wgLang;
+               $this->_unstub( 'findVariantLink', 3 );
+               $wgLang->findVariantLink( $link, $nt, $ignoreOtherCond );
+       }
+
        /**
         * @return Language
         */
-       function _newObject() {
+       public function _newObject() {
                return RequestContext::getMain()->getLanguage();
        }
 }