* Made lines from initialiseMessages() appear as list items during installation * Moved the bulk of the localisation data from the Language*.php files to the Messages*.php files. Deleted most of the Languages*.php files. * Introduced "stub global" framework to provide deferred initialisation of core modules. * Removed placeholder values for $wgTitle and $wgArticle, these variables will now be null during the initialisation process, until they are set by index.php or another entry point. * Added DBA cache type, for BDB-style caches. * Removed custom date format functions, replacing them with a format string in the style of PHP's date(). Used string identifiers instead of integer identifiers, in both the language files and user preferences. Migration should be transparent in most cases. * Simplified the initialisation API for LoadBalancer objects. * Removed the broken altencoding feature. * Moved default user options and toggles from Language to User. Language objects are still able to define default preference overrides and extra user toggles, via a slightly different interface. * Don't include the date option in the parser cache rendering hash unless $wgUseDynamicDates is enabled. * Merged LanguageUtf8 with Language. Removed LanguageUtf8.php. * Removed inclusion of language files from the bottom of Language.php. This is now consistently done from Language::factory(). * Add the name of the executing maintenance script to the debug log. Start the profiler during maintenance scripts. * Added "serialized" directory, for storing precompiled data in serialized form.
144 lines
3.9 KiB
PHP
144 lines
3.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Class to implement stub globals, which are globals that delay loading the
|
|
* their associated module code by deferring initialisation until the first
|
|
* method call.
|
|
*
|
|
* Note on unstub loops:
|
|
*
|
|
* Unstub loops (infinite recursion) sometimes occur when a constructor calls
|
|
* another function, and the other function calls some method of the stub. The
|
|
* best way to avoid this is to make constructors as lightweight as possible,
|
|
* deferring any initialisation which depends on other modules. As a last
|
|
* resort, you can use StubObject::isRealObject() to break the loop, but as a
|
|
* general rule, the stub object mechanism should be transparent, and code
|
|
* which refers to it should be kept to a minimum.
|
|
*/
|
|
class StubObject {
|
|
var $mGlobal, $mClass, $mParams;
|
|
function __construct( $global = null, $class = null, $params = array() ) {
|
|
$this->mGlobal = $global;
|
|
$this->mClass = $class;
|
|
$this->mParams = $params;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
function _call( $name, $args ) {
|
|
$this->_unstub( $name, 5 );
|
|
return call_user_func_array( array( $GLOBALS[$this->mGlobal], $name ), $args );
|
|
}
|
|
|
|
function _newObject() {
|
|
return wfCreateObject( $this->mClass, $this->mParams );
|
|
}
|
|
|
|
function __call( $name, $args ) {
|
|
return $this->_call( $name, $args );
|
|
}
|
|
|
|
/**
|
|
* This is public, for the convenience of external callers wishing to access
|
|
* properties, e.g. eval.php
|
|
*/
|
|
function _unstub( $name = '_unstub', $level = 2 ) {
|
|
static $recursionLevel = 0;
|
|
if ( get_class( $GLOBALS[$this->mGlobal] ) != $this->mClass ) {
|
|
$fname = __METHOD__.'-'.$this->mGlobal;
|
|
wfProfileIn( $fname );
|
|
$caller = self::_getCaller( $level );
|
|
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();
|
|
--$recursionLevel;
|
|
wfProfileOut( $fname );
|
|
}
|
|
}
|
|
}
|
|
|
|
class StubContLang extends StubObject {
|
|
function __construct() {
|
|
parent::__construct( 'wgContLang' );
|
|
}
|
|
|
|
function __call( $name, $args ) {
|
|
return StubObject::_call( $name, $args );
|
|
}
|
|
|
|
function _newObject() {
|
|
global $wgContLanguageCode;
|
|
$obj = Language::factory( $wgContLanguageCode );
|
|
$obj->initEncoding();
|
|
$obj->initContLang();
|
|
return $obj;
|
|
}
|
|
}
|
|
class StubUserLang extends StubObject {
|
|
function __construct() {
|
|
parent::__construct( 'wgLang' );
|
|
}
|
|
|
|
function __call( $name, $args ) {
|
|
return $this->_call( $name, $args );
|
|
}
|
|
|
|
function _newObject() {
|
|
global $wgLanguageCode, $wgContLanguageCode, $wgRequest, $wgUser, $wgContLang;
|
|
// wgLanguageCode now specifically means the UI language
|
|
$wgLanguageCode = $wgRequest->getText('uselang', '');
|
|
if ($wgLanguageCode == '')
|
|
$wgLanguageCode = $wgUser->getOption('language');
|
|
# Validate $wgLanguageCode
|
|
if( empty( $wgLanguageCode ) || !preg_match( '/^[a-z]+(-[a-z]+)?$/', $wgLanguageCode ) ) {
|
|
$wgLanguageCode = $wgContLanguageCode;
|
|
}
|
|
|
|
if( $wgLanguageCode == $wgContLanguageCode ) {
|
|
return $wgContLang;
|
|
} else {
|
|
$obj = Language::factory( $wgLanguageCode );
|
|
return $obj;
|
|
}
|
|
}
|
|
}
|
|
class StubUser extends StubObject {
|
|
function __construct() {
|
|
parent::__construct( 'wgUser' );
|
|
}
|
|
|
|
function __call( $name, $args ) {
|
|
return $this->_call( $name, $args );
|
|
}
|
|
|
|
function _newObject() {
|
|
global $wgCommandLineMode;
|
|
if( $wgCommandLineMode ) {
|
|
$user = new User;
|
|
$user->setLoaded( true );
|
|
} else {
|
|
$user = User::loadFromSession();
|
|
}
|
|
return $user;
|
|
}
|
|
}
|
|
|
|
?>
|