MediaWiki
REL1_19
|
00001 <?php 00002 00018 class StubObject { 00019 var $mGlobal, $mClass, $mParams; 00020 00029 function __construct( $global = null, $class = null, $params = array() ) { 00030 $this->mGlobal = $global; 00031 $this->mClass = $class; 00032 $this->mParams = $params; 00033 } 00034 00042 static function isRealObject( $obj ) { 00043 return is_object( $obj ) && !($obj instanceof StubObject); 00044 } 00045 00056 function _call( $name, $args ) { 00057 $this->_unstub( $name, 5 ); 00058 return call_user_func_array( array( $GLOBALS[$this->mGlobal], $name ), $args ); 00059 } 00060 00065 function _newObject() { 00066 return MWFunction::newObj( $this->mClass, $this->mParams ); 00067 } 00068 00076 function __call( $name, $args ) { 00077 return $this->_call( $name, $args ); 00078 } 00079 00090 function _unstub( $name = '_unstub', $level = 2 ) { 00091 static $recursionLevel = 0; 00092 00093 if ( !($GLOBALS[$this->mGlobal] instanceof StubObject) ) { 00094 return $GLOBALS[$this->mGlobal]; // already unstubbed. 00095 } 00096 00097 if ( get_class( $GLOBALS[$this->mGlobal] ) != $this->mClass ) { 00098 $fname = __METHOD__.'-'.$this->mGlobal; 00099 wfProfileIn( $fname ); 00100 $caller = wfGetCaller( $level ); 00101 if ( ++$recursionLevel > 2 ) { 00102 throw new MWException( "Unstub loop detected on call of \${$this->mGlobal}->$name from $caller\n" ); 00103 } 00104 wfDebug( "Unstubbing \${$this->mGlobal} on call of \${$this->mGlobal}::$name from $caller\n" ); 00105 $GLOBALS[$this->mGlobal] = $this->_newObject(); 00106 --$recursionLevel; 00107 wfProfileOut( $fname ); 00108 } 00109 } 00110 } 00111 00118 class StubContLang extends StubObject { 00119 00120 function __construct() { 00121 wfDeprecated( __CLASS__, '1.18' ); 00122 parent::__construct( 'wgContLang' ); 00123 } 00124 00125 function __call( $name, $args ) { 00126 return $this->_call( $name, $args ); 00127 } 00128 00132 function _newObject() { 00133 global $wgLanguageCode; 00134 $obj = Language::factory( $wgLanguageCode ); 00135 $obj->initEncoding(); 00136 $obj->initContLang(); 00137 return $obj; 00138 } 00139 } 00140 00146 class StubUserLang extends StubObject { 00147 00148 function __construct() { 00149 parent::__construct( 'wgLang' ); 00150 } 00151 00152 function __call( $name, $args ) { 00153 return $this->_call( $name, $args ); 00154 } 00155 00159 function _newObject() { 00160 return RequestContext::getMain()->getLanguage(); 00161 } 00162 }