Go to the documentation of this file.
186 public function get( $settingName, $wiki, $suffix =
null,
$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"];
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"] ) ) {
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'];
280 if ( is_string( $in ) ) {
281 return str_replace( $from, $to, $in );
282 } elseif ( is_array( $in ) ) {
283 foreach ( $in
as $key => $val ) {
284 $in[$key] = $this->
doReplace( $from, $to, $val );
300 public function getAll( $wiki, $suffix =
null,
$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 );
355 $value = $this->
get( $setting, $wiki, $suffix,
$params, $wikiTags );
356 if ( !is_null(
$value ) ) {
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] ) ) {
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 ) {
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'." );
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;
extractVar( $setting, $wiki, $suffix, &$var, $params=[], $wikiTags=[])
Retrieves the value of a given setting, and places it in a variable passed by reference.
$fullLoadDone
Whether or not all data has been loaded.
This is a class for holding configuration settings, particularly for multi-wiki sites.
if(!isset( $args[0])) $lang
getConfig( $wiki, $settings)
Get the resolved (post-setup) configuration of a potentially foreign wiki.
extractAllGlobals( $wiki, $suffix=null, $params=[], $wikiTags=[])
Retrieves the values of all settings, and places them in their corresponding global variables.
unserialize( $serialized)
Allows to change the fields on the form that will be generated $name
wfShellWikiCmd( $script, array $parameters=[], array $options=[])
Generate a shell-escaped command line string to run a MediaWiki cli script.
doReplace( $from, $to, $in)
Type-safe string replace; won't do replacements on non-strings private?
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
getBool( $setting, $wiki, $suffix=null, $wikiTags=[])
Retrieves a configuration setting for a given wiki, forced to a boolean.
siteFromDB( $db)
Work out the site and language name from a database name.
array $cfgCache
Configuration cache for getConfig()
when a variable name is used in a it is silently declared as a new masking the global
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
$GLOBALS['wgAutoloadClasses']['LocalisationUpdate']
$localVHosts
Array of domains that are local and can be handled by the same server.
string array $siteParamsCallback
A callback function that returns an array with the following keys (all optional):
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
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 account incomplete not yet checked for validity & $retval
getAll( $wiki, $suffix=null, $params=[], $wikiTags=[])
Gets all settings for a wiki.
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
static arrayMerge( $array1)
Merge multiple arrays together.
& getLocalDatabases()
Retrieves an array of local databases.
$wikis
Array of wikis, should be the same as $wgLocalDatabases.
string array $fullLoadCallback
Optional callback to load full configuration data.
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
$settings
The whole array of settings.
extractGlobal( $setting, $wiki, $suffix=null, $params=[], $wikiTags=[])
Retrieves the value of a given setting, and places it in its corresponding global variable.
getSetting( $settingName, $wiki, array $params)
Really retrieves a configuration setting for a given wiki.
mergeParams( $wiki, $suffix, array $params, array $wikiTags)
Merge params between the ones passed to the function and the ones given by self::$siteParamsCallback ...
extractGlobalSetting( $setting, $wiki, $params)
$suffixes
Array of suffixes, for self::siteFromDB()
the array() calling protocol came about after MediaWiki 1.4rc1.
getWikiParams( $wiki)
Return specific settings for $wiki See the documentation of self::$siteParamsCallback for more in-dep...
wfShellExec( $cmd, &$retval=null, $environ=[], $limits=[], $options=[])
Execute a shell command, with time and memory limits mirrored from the PHP configuration if supported...
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