MediaWiki  master
ConfigRepository.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\Config;
24 
27 
35  private $configFactory;
36 
38  private $configItems = [
39  'private' => [],
40  'public' => [],
41  ];
42 
47  $this->configFactory = $configFactory;
48  }
49 
57  public function has( $name, $alsoPrivate = false ) {
58  return isset( $this->configItems['public'][$name] ) ||
59  ( $alsoPrivate && isset( $this->configItems['private'][$name] ) );
60  }
61 
70  public function get( $name ) {
71  if ( !$this->has( $name, true ) ) {
72  throw new \ConfigException( 'The configuration option ' . $name . ' does not exist.' );
73  }
74  if ( isset( $this->configItems['public'][$name] ) ) {
75  return $this->configItems['public'][$name];
76  }
77  return $this->configItems['private'][$name];
78  }
79 
90  public function getAll() {
91  return array_merge( $this->configItems['private'], $this->configItems['public'] );
92  }
93 
99  public function getPublic() {
100  return $this->configItems['public'];
101  }
102 
111  public function getValueOf( $name ) {
112  $config = $this->get( $name );
113  if ( !isset( $config['configregistry'] ) ) {
114  return $config['value'];
115  }
116 
117  return $this->configFactory->makeConfig( $config['configregistry'] )->get( $name );
118  }
119 
128  public function getDescriptionOf( $name ) {
129  $config = $this->get( $name );
130  if ( isset( $config['descriptionmsg'] ) ) {
131  return wfMessage( $config['descriptionmsg'] )->escaped();
132  }
133  if ( isset( $config['description'] ) ) {
134  return htmlspecialchars( $config['description'] );
135  }
136  return '';
137  }
138 
154  public function add( $name, array $config ) {
155  if ( $this->has( $name ) ) {
156  throw new \ConfigException( 'A configuration with the name ' . $name .
157  'does already exist. It is provided by: ' .
158  $this->get( $name )['providedby'] );
159  }
160  if ( isset( $config['public'] ) && $config['public'] ) {
161  $this->configItems['public'][$name] = $config;
162  } else {
163  $this->configItems['private'][$name] = $config;
164  }
165  }
166 
174  public function isEmpty( $includePrivate = false ) {
175  if ( $includePrivate ) {
176  return empty( $this->configItems['private'] ) &&
177  empty( $this->configItems[ 'public'] );
178  }
179  return empty( $this->configItems['public'] );
180  }
181 
191  public function salvage( SalvageableService $other ) {
192  Assert::parameterType( self::class, $other, '$other' );
193 
195  $otherCurrentObj = $other->current();
196  foreach ( $other->configItems['public'] as $name => $otherConfig ) {
197  if ( isset( $this->configItems['public'][$name] ) ) {
198  continue;
199  }
200 
201  $this->add( $name, $otherConfig );
202 
203  // recover the pointer of the other config repository
204  if ( $otherCurrentObj === $otherConfig ) {
205  end( $this->configItems['public'] );
206  }
207  }
208  foreach ( $other->configItems['private'] as $name => $otherConfig ) {
209  if ( isset( $this->configItems['private'][$name] ) ) {
210  continue;
211  }
212 
213  $this->add( $name, $otherConfig );
214 
215  // recover the pointer of the other config repository
216  if ( $otherCurrentObj === $otherConfig ) {
217  end( $this->configItems['private'] );
218  }
219  }
220 
221  // disable $other
222  $other->configItems = [];
223  }
224 }
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
Config $config
Definition: MediaWiki.php:43
getPublic()
Returns an array of all public configuration options saved in this ConfigRepository.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
has( $name, $alsoPrivate=false)
Returns true, if this repository contains a configuration with a specific name.
array __construct(\ConfigFactory $configFactory)
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
getValueOf( $name)
Returns the current value of the configuration option.
isEmpty( $includePrivate=false)
Returns true, if there&#39;re no elements in this instance, otherwise false.
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
Definition: distributors.txt:9
getDescriptionOf( $name)
Returns the description of the given config option, This can be either a localized description...
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
Definition: injection.txt:35
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
salvage(SalvageableService $other)
Re-uses existing Cache objects from $other.
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:276
Object which holds currently registered configuration options.
add( $name, array $config)
Adds the definition of a configuration to this repository.
SalvageableService defines an interface for services that are able to salvage state from a previous i...
getAll()
Returns an array of all configuration items saved in this ConfigRepository.