181 public function get( $settingName, $wiki, $suffix = null,
$params = [],
184 $params = $this->
mergeParams( $wiki, $suffix, $params, $wikiTags );
185 return $this->
getSetting( $settingName, $wiki, $params );
198 if ( array_key_exists( $settingName, $this->
settings ) ) {
199 $thisSetting =& $this->
settings[$settingName];
202 if ( array_key_exists( $wiki, $thisSetting ) ) {
205 } elseif ( array_key_exists(
"+$wiki", $thisSetting ) && is_array( $thisSetting[
"+$wiki"] ) ) {
206 $retval = $thisSetting[
"+$wiki"];
210 foreach ( $params[
'tags']
as $tag ) {
211 if ( array_key_exists( $tag, $thisSetting ) ) {
212 if ( is_array(
$retval ) && is_array( $thisSetting[$tag] ) ) {
218 } elseif ( array_key_exists(
"+$tag", $thisSetting ) && is_array( $thisSetting[
"+$tag"] ) ) {
226 $suffix = $params[
'suffix'];
227 if ( !is_null( $suffix ) ) {
228 if ( array_key_exists( $suffix, $thisSetting ) ) {
229 if ( is_array(
$retval ) && is_array( $thisSetting[$suffix] ) ) {
232 $retval = $thisSetting[$suffix];
235 } elseif ( array_key_exists(
"+$suffix", $thisSetting )
236 && is_array( $thisSetting[
"+$suffix"] )
246 if ( array_key_exists(
'default', $thisSetting ) ) {
247 if ( is_array(
$retval ) && is_array( $thisSetting[
'default'] ) ) {
250 $retval = $thisSetting[
'default'];
257 if ( !is_null(
$retval ) && count( $params[
'params'] ) ) {
275 if ( is_string( $in ) ) {
276 return str_replace(
$from, $to, $in );
277 } elseif ( is_array( $in ) ) {
278 foreach ( $in
as $key => $val ) {
295 public function getAll( $wiki, $suffix = null, $params = [], $wikiTags = [] ) {
296 $params = $this->
mergeParams( $wiki, $suffix, $params, $wikiTags );
298 foreach ( $this->
settings as $varname => $stuff ) {
301 if ( substr( $varname, 0, 1 ) ==
'+' ) {
303 $var = substr( $varname, 1 );
307 if ( $append && is_array(
$value ) && is_array(
$GLOBALS[$var] ) ) {
310 if ( !is_null(
$value ) ) {
311 $localSettings[$var] =
$value;
314 return $localSettings;
325 public function getBool( $setting, $wiki, $suffix = null, $wikiTags = [] ) {
326 return (
bool)$this->
get( $setting, $wiki, $suffix, [], $wikiTags );
348 $params = [], $wikiTags = []
350 $value = $this->
get( $setting, $wiki, $suffix,
$params, $wikiTags );
351 if ( !is_null(
$value ) ) {
365 $params = [], $wikiTags = []
367 $params = $this->
mergeParams( $wiki, $suffix, $params, $wikiTags );
378 if ( !is_null(
$value ) ) {
379 if ( substr( $setting, 0, 1 ) ==
'+' && is_array(
$value ) ) {
380 $setting = substr( $setting, 1 );
381 if ( is_array(
$GLOBALS[$setting] ) ) {
402 $params = $this->
mergeParams( $wiki, $suffix, $params, $wikiTags );
403 foreach ( $this->
settings as $varName => $setting ) {
424 if ( !is_callable( $this->siteParamsCallback ) ) {
428 $ret = call_user_func_array( $this->siteParamsCallback, [ $this, $wiki ] );
429 # Validate the returned value
430 if ( !is_array(
$ret ) ) {
434 foreach ( $default
as $name => $def ) {
435 if ( !isset(
$ret[
$name] ) || ( is_array( $default[$name] ) && !is_array(
$ret[$name] ) ) ) {
458 if ( is_null(
$ret[
'suffix'] ) ) {
459 $ret[
'suffix'] = $suffix;
462 $ret[
'tags'] = array_unique( array_merge(
$ret[
'tags'], $wikiTags ) );
467 if ( !isset(
$ret[
'params'][
'lang'] ) && !is_null(
$ret[
'lang'] ) ) {
468 $ret[
'params'][
'lang'] =
$ret[
'lang'];
470 if ( !isset(
$ret[
'params'][
'site'] ) && !is_null(
$ret[
'suffix'] ) ) {
471 $ret[
'params'][
'site'] =
$ret[
'suffix'];
486 if ( !is_null( $def[
'suffix'] ) && !is_null( $def[
'lang'] ) ) {
487 return [ $def[
'suffix'], $def[
'lang'] ];
492 foreach ( $this->suffixes
as $altSite => $suffix ) {
493 if ( $suffix ===
'' ) {
497 } elseif ( substr( $db, -strlen( $suffix ) ) == $suffix ) {
498 $site = is_numeric( $altSite ) ? $suffix : $altSite;
499 $lang = substr( $db, 0, strlen( $db ) - strlen( $suffix ) );
504 return [ $site,
$lang ];
526 if ( !preg_match(
'/^wg[A-Z]/', $name ) ) {
527 throw new MWException(
"Variable '$name' does start with 'wg'." );
528 } elseif ( !isset(
$GLOBALS[$name] ) ) {
529 throw new MWException(
"Variable '$name' is not set." );
534 if ( isset( $this->cfgCache[$wiki] ) ) {
535 $res = array_intersect_key( $this->cfgCache[$wiki], array_flip(
$settings ) );
537 return $multi ?
$res : current(
$res );
539 } elseif ( !in_array( $wiki, $this->wikis ) ) {
542 $this->cfgCache[$wiki] = [];
546 "$IP/maintenance/getConfiguration.php",
554 $data = trim(
wfShellExec( $cmd, $retVal, [], [
'memory' => 0 ] ) );
555 if ( $retVal != 0 || !strlen( $data ) ) {
556 throw new MWException(
"Failed to run getConfiguration.php." );
559 if ( !is_array(
$res ) ) {
560 throw new MWException(
"Failed to unserialize configuration array." );
562 $this->cfgCache[$wiki] = $this->cfgCache[$wiki] +
$res;
565 return $multi ?
$res : current(
$res );
576 return in_array( $vhost, $this->localVHosts );
591 $argsCount = func_num_args();
592 for ( $i = 1; $i < $argsCount; $i++ ) {
596 } elseif ( !isset(
$out[$key] ) || !
$out[$key] && !is_numeric( $key ) ) {
600 } elseif ( is_numeric( $key ) ) {
610 if ( $this->fullLoadCallback && !$this->fullLoadDone ) {
611 call_user_func( $this->fullLoadCallback, $this );
612 $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.
magic word the default is to use $key to get the and $key value or $key value text $key value html to format the value $key
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.
isLocalVHost($vhost)
Returns true if the given vhost is handled locally.
& 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