186 public function get( $settingName, $wiki, $suffix = null,
$params = [],
189 $params = $this->
mergeParams( $wiki, $suffix, $params, $wikiTags );
190 return $this->
getSetting( $settingName, $wiki, $params );
203 if ( array_key_exists( $settingName, $this->
settings ) ) {
204 $thisSetting =& $this->
settings[$settingName];
207 if ( array_key_exists( $wiki, $thisSetting ) ) {
210 } elseif ( array_key_exists(
"+$wiki", $thisSetting ) && is_array( $thisSetting[
"+$wiki"] ) ) {
211 $retval = $thisSetting[
"+$wiki"];
215 foreach ( $params[
'tags']
as $tag ) {
216 if ( array_key_exists( $tag, $thisSetting ) ) {
217 if ( is_array(
$retval ) && is_array( $thisSetting[$tag] ) ) {
223 } elseif ( array_key_exists(
"+$tag", $thisSetting ) && is_array( $thisSetting[
"+$tag"] ) ) {
231 $suffix = $params[
'suffix'];
232 if ( !is_null( $suffix ) ) {
233 if ( array_key_exists( $suffix, $thisSetting ) ) {
234 if ( is_array(
$retval ) && is_array( $thisSetting[$suffix] ) ) {
237 $retval = $thisSetting[$suffix];
240 } elseif ( array_key_exists(
"+$suffix", $thisSetting )
241 && is_array( $thisSetting[
"+$suffix"] )
251 if ( array_key_exists(
'default', $thisSetting ) ) {
252 if ( is_array(
$retval ) && is_array( $thisSetting[
'default'] ) ) {
255 $retval = $thisSetting[
'default'];
262 if ( !is_null(
$retval ) && count( $params[
'params'] ) ) {
263 foreach ( $params[
'params']
as $key =>
$value ) {
280 if ( is_string( $in ) ) {
281 return str_replace(
$from, $to, $in );
282 } elseif ( is_array( $in ) ) {
283 foreach ( $in
as $key => $val ) {
300 public function getAll( $wiki, $suffix = null, $params = [], $wikiTags = [] ) {
301 $params = $this->
mergeParams( $wiki, $suffix, $params, $wikiTags );
303 foreach ( $this->
settings as $varname => $stuff ) {
306 if ( substr( $varname, 0, 1 ) ==
'+' ) {
308 $var = substr( $varname, 1 );
312 if ( $append && is_array(
$value ) && is_array(
$GLOBALS[$var] ) ) {
315 if ( !is_null(
$value ) ) {
316 $localSettings[$var] =
$value;
319 return $localSettings;
330 public function getBool( $setting, $wiki, $suffix = null, $wikiTags = [] ) {
331 return (
bool)$this->
get( $setting, $wiki, $suffix, [], $wikiTags );
353 $params = [], $wikiTags = []
355 $value = $this->
get( $setting, $wiki, $suffix,
$params, $wikiTags );
356 if ( !is_null(
$value ) ) {
370 $params = [], $wikiTags = []
372 $params = $this->
mergeParams( $wiki, $suffix, $params, $wikiTags );
383 if ( !is_null(
$value ) ) {
384 if ( substr( $setting, 0, 1 ) ==
'+' && is_array(
$value ) ) {
385 $setting = substr( $setting, 1 );
386 if ( is_array(
$GLOBALS[$setting] ) ) {
407 $params = $this->
mergeParams( $wiki, $suffix, $params, $wikiTags );
408 foreach ( $this->
settings as $varName => $setting ) {
429 if ( !is_callable( $this->siteParamsCallback ) ) {
433 $ret = call_user_func_array( $this->siteParamsCallback, [ $this, $wiki ] );
434 # Validate the returned value
435 if ( !is_array(
$ret ) ) {
439 foreach ( $default
as $name => $def ) {
440 if ( !isset(
$ret[
$name] ) || ( is_array( $default[$name] ) && !is_array(
$ret[$name] ) ) ) {
463 if ( is_null(
$ret[
'suffix'] ) ) {
464 $ret[
'suffix'] = $suffix;
467 $ret[
'tags'] = array_unique( array_merge(
$ret[
'tags'], $wikiTags ) );
472 if ( !isset(
$ret[
'params'][
'lang'] ) && !is_null(
$ret[
'lang'] ) ) {
473 $ret[
'params'][
'lang'] =
$ret[
'lang'];
475 if ( !isset(
$ret[
'params'][
'site'] ) && !is_null(
$ret[
'suffix'] ) ) {
476 $ret[
'params'][
'site'] =
$ret[
'suffix'];
491 if ( !is_null( $def[
'suffix'] ) && !is_null( $def[
'lang'] ) ) {
492 return [ $def[
'suffix'], $def[
'lang'] ];
497 foreach ( $this->suffixes
as $altSite => $suffix ) {
498 if ( $suffix ===
'' ) {
502 } elseif ( substr( $db, -strlen( $suffix ) ) == $suffix ) {
503 $site = is_numeric( $altSite ) ? $suffix : $altSite;
504 $lang = substr( $db, 0, strlen( $db ) - strlen( $suffix ) );
509 return [ $site,
$lang ];
531 if ( !preg_match(
'/^wg[A-Z]/', $name ) ) {
532 throw new MWException(
"Variable '$name' does start with 'wg'." );
533 } elseif ( !isset(
$GLOBALS[$name] ) ) {
534 throw new MWException(
"Variable '$name' is not set." );
539 if ( isset( $this->cfgCache[$wiki] ) ) {
540 $res = array_intersect_key( $this->cfgCache[$wiki], array_flip(
$settings ) );
542 return $multi ?
$res : current(
$res );
544 } elseif ( !in_array( $wiki, $this->wikis ) ) {
547 $this->cfgCache[$wiki] = [];
551 "$IP/maintenance/getConfiguration.php",
559 $data = trim(
wfShellExec( $cmd, $retVal, [], [
'memory' => 0 ] ) );
560 if ( $retVal != 0 || !strlen( $data ) ) {
561 throw new MWException(
"Failed to run getConfiguration.php." );
564 if ( !is_array(
$res ) ) {
565 throw new MWException(
"Failed to unserialize configuration array." );
567 $this->cfgCache[$wiki] = $this->cfgCache[$wiki] +
$res;
570 return $multi ?
$res : current(
$res );
585 $argsCount = func_num_args();
586 for ( $i = 1; $i < $argsCount; $i++ ) {
587 foreach ( func_get_arg( $i )
as $key =>
$value ) {
588 if ( isset(
$out[$key] ) && is_array(
$out[$key] ) && is_array(
$value ) ) {
590 } elseif ( !isset(
$out[$key] ) || !
$out[$key] && !is_numeric( $key ) ) {
594 } elseif ( is_numeric( $key ) ) {
604 if ( $this->fullLoadCallback && !$this->fullLoadDone ) {
605 call_user_func( $this->fullLoadCallback, $this );
606 $this->fullLoadDone =
true;
extractGlobalSetting($setting, $wiki, $params)
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
the array() calling protocol came about after MediaWiki 1.4rc1.
$fullLoadDone
Whether or not all data has been loaded.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
if(!isset($args[0])) $lang
getBool($setting, $wiki, $suffix=null, $wikiTags=[])
Retrieves a configuration setting for a given wiki, forced to a boolean.
wfShellExec($cmd, &$retval=null, $environ=[], $limits=[], $options=[])
Execute a shell command, with time and memory limits mirrored from the PHP configuration if supported...
when a variable name is used in a it is silently declared as a new local masking the global
getSetting($settingName, $wiki, array $params)
Really retrieves a configuration setting for a given wiki.
extractVar($setting, $wiki, $suffix, &$var, $params=[], $wikiTags=[])
Retrieves the value of a given setting, and places it in a variable passed by reference.
mergeParams($wiki, $suffix, array $params, array $wikiTags)
Merge params between the ones passed to the function and the ones given by self::$siteParamsCallback ...
wfShellWikiCmd($script, array $parameters=[], array $options=[])
Generate a shell-escaped command line string to run a MediaWiki cli script.
array $cfgCache
Configuration cache for getConfig()
static arrayMerge($array1)
Merge multiple arrays together.
extractGlobal($setting, $wiki, $suffix=null, $params=[], $wikiTags=[])
Retrieves the value of a given setting, and places it in its corresponding global variable...
string array $siteParamsCallback
A callback function that returns an array with the following keys (all optional): ...
doReplace($from, $to, $in)
Type-safe string replace; won't do replacements on non-strings private?
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books $tag
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
$localVHosts
Array of domains that are local and can be handled by the same server.
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration settings
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
getWikiParams($wiki)
Return specific settings for $wiki See the documentation of self::$siteParamsCallback for more in-dep...
getAll($wiki, $suffix=null, $params=[], $wikiTags=[])
Gets all settings for a wiki.
extractAllGlobals($wiki, $suffix=null, $params=[], $wikiTags=[])
Retrieves the values of all settings, and places them in their corresponding global variables...
string array $fullLoadCallback
Optional callback to load full configuration data.
& getLocalDatabases()
Retrieves an array of local databases.
$settings
The whole array of settings.
$wikis
Array of wikis, should be the same as $wgLocalDatabases.
siteFromDB($db)
Work out the site and language name from a database name.
This is a class for holding configuration settings, particularly for multi-wiki sites.
getConfig($wiki, $settings)
Get the resolved (post-setup) configuration of a potentially foreign wiki.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account incomplete not yet checked for validity & $retval
$suffixes
Array of suffixes, for self::siteFromDB()
Allows to change the fields on the form that will be generated $name