MediaWiki  1.23.2
StubObject.php
Go to the documentation of this file.
1 <?php
44 class StubObject {
46 
55  function __construct( $global = null, $class = null, $params = array() ) {
56  $this->mGlobal = $global;
57  $this->mClass = $class;
58  $this->mParams = $params;
59  }
60 
68  static function isRealObject( $obj ) {
69  return is_object( $obj ) && !$obj instanceof StubObject;
70  }
71 
80  static function unstub( $obj ) {
81  if ( $obj instanceof StubObject ) {
82  $obj->_unstub( 'unstub', 3 );
83  }
84  }
85 
97  function _call( $name, $args ) {
98  $this->_unstub( $name, 5 );
99  return call_user_func_array( array( $GLOBALS[$this->mGlobal], $name ), $args );
100  }
101 
106  function _newObject() {
107  return MWFunction::newObj( $this->mClass, $this->mParams );
108  }
109 
118  function __call( $name, $args ) {
119  return $this->_call( $name, $args );
120  }
121 
133  function _unstub( $name = '_unstub', $level = 2 ) {
134  static $recursionLevel = 0;
135 
136  if ( !$GLOBALS[$this->mGlobal] instanceof StubObject ) {
137  return $GLOBALS[$this->mGlobal]; // already unstubbed.
138  }
139 
140  if ( get_class( $GLOBALS[$this->mGlobal] ) != $this->mClass ) {
141  $fname = __METHOD__ . '-' . $this->mGlobal;
142  wfProfileIn( $fname );
143  $caller = wfGetCaller( $level );
144  if ( ++$recursionLevel > 2 ) {
145  wfProfileOut( $fname );
146  throw new MWException( "Unstub loop detected on call of \${$this->mGlobal}->$name from $caller\n" );
147  }
148  wfDebug( "Unstubbing \${$this->mGlobal} on call of \${$this->mGlobal}::$name from $caller\n" );
149  $GLOBALS[$this->mGlobal] = $this->_newObject();
150  --$recursionLevel;
151  wfProfileOut( $fname );
152  }
153  }
154 }
155 
162 class StubContLang extends StubObject {
163 
164  function __construct() {
165  wfDeprecated( __CLASS__, '1.18' );
166  parent::__construct( 'wgContLang' );
167  }
168 
169  function __call( $name, $args ) {
170  return $this->_call( $name, $args );
171  }
172 
176  function _newObject() {
177  global $wgLanguageCode;
178  $obj = Language::factory( $wgLanguageCode );
179  $obj->initEncoding();
180  $obj->initContLang();
181  return $obj;
182  }
183 }
184 
190 class StubUserLang extends StubObject {
191 
192  function __construct() {
193  parent::__construct( 'wgLang' );
194  }
195 
196  function __call( $name, $args ) {
197  return $this->_call( $name, $args );
198  }
199 
203  function _newObject() {
204  return RequestContext::getMain()->getLanguage();
205  }
206 }
StubUserLang\__construct
__construct()
Definition: StubObject.php:192
StubContLang
Stub object for the content language of this wiki.
Definition: StubObject.php:162
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
StubContLang\__call
__call( $name, $args)
Function called by PHP if no function with that name exists in this object.
Definition: StubObject.php:169
StubObject\$mGlobal
$mGlobal
Definition: StubObject.php:45
StubUserLang\__call
__call( $name, $args)
Function called by PHP if no function with that name exists in this object.
Definition: StubObject.php:196
StubObject
Class to implement stub globals, which are globals that delay loading the their associated module cod...
Definition: StubObject.php:44
StubObject\__call
__call( $name, $args)
Function called by PHP if no function with that name exists in this object.
Definition: StubObject.php:118
wfProfileIn
wfProfileIn( $functionname)
Begin profiling of a function.
Definition: Profiler.php:33
$fname
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
Definition: Setup.php:35
$params
$params
Definition: styleTest.css.php:40
StubContLang\__construct
__construct()
Definition: StubObject.php:164
MWException
MediaWiki exception.
Definition: MWException.php:26
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1127
wfProfileOut
wfProfileOut( $functionname='missing')
Stop profiling of a function.
Definition: Profiler.php:46
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
MWFunction\newObj
static newObj( $class, $args=array())
Definition: MWFunction.php:54
wfDebug
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:933
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
StubUserLang
Stub object for the user language.
Definition: StubObject.php:190
StubContLang\_newObject
_newObject()
Definition: StubObject.php:176
StubObject\_call
_call( $name, $args)
Function called if any function exists with that name in this object.
Definition: StubObject.php:97
RequestContext\getMain
static getMain()
Static methods.
Definition: RequestContext.php:420
StubObject\_newObject
_newObject()
Create a new object to replace this stub object.
Definition: StubObject.php:106
$args
if( $line===false) $args
Definition: cdb.php:62
StubObject\$mClass
$mClass
Definition: StubObject.php:45
StubObject\isRealObject
static isRealObject( $obj)
Returns a bool value whenever $obj is a stub object.
Definition: StubObject.php:68
StubObject\unstub
static unstub( $obj)
Unstubs an object, if it is a stub object.
Definition: StubObject.php:80
StubUserLang\_newObject
_newObject()
Definition: StubObject.php:203
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:184
StubObject\_unstub
_unstub( $name='_unstub', $level=2)
This function creates a new object of the real class and replace it in the global variable.
Definition: StubObject.php:133
wfGetCaller
wfGetCaller( $level=2)
Get the name of the function which called this function wfGetCaller( 1 ) is the function with the wfG...
Definition: GlobalFunctions.php:1941
StubObject\$mParams
$mParams
Definition: StubObject.php:45
$GLOBALS
$GLOBALS['IP']
Definition: ComposerHookHandler.php:6
StubObject\__construct
__construct( $global=null, $class=null, $params=array())
Constructor.
Definition: StubObject.php:55