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 
75  return $this->configItems['public'][$name] ?? $this->configItems['private'][$name];
76  }
77 
88  public function getAll() {
89  return array_merge( $this->configItems['private'], $this->configItems['public'] );
90  }
91 
97  public function getPublic() {
98  return $this->configItems['public'];
99  }
100 
109  public function getValueOf( $name ) {
110  $config = $this->get( $name );
111  if ( !isset( $config['configregistry'] ) ) {
112  return $config['value'];
113  }
114 
115  return $this->configFactory->makeConfig( $config['configregistry'] )->get( $name );
116  }
117 
126  public function getDescriptionOf( $name ) {
127  $config = $this->get( $name );
128  if ( isset( $config['descriptionmsg'] ) ) {
129  return wfMessage( $config['descriptionmsg'] )->escaped();
130  }
131  if ( isset( $config['description'] ) ) {
132  return htmlspecialchars( $config['description'] );
133  }
134  return '';
135  }
136 
152  public function add( $name, array $config ) {
153  if ( $this->has( $name ) ) {
154  throw new \ConfigException( 'A configuration with the name ' . $name .
155  'does already exist. It is provided by: ' .
156  $this->get( $name )['providedby'] );
157  }
158  if ( isset( $config['public'] ) && $config['public'] ) {
159  $this->configItems['public'][$name] = $config;
160  } else {
161  $this->configItems['private'][$name] = $config;
162  }
163  }
164 
172  public function isEmpty( $includePrivate = false ) {
173  if ( $includePrivate ) {
174  return empty( $this->configItems['private'] ) &&
175  empty( $this->configItems[ 'public'] );
176  }
177  return empty( $this->configItems['public'] );
178  }
179 
189  public function salvage( SalvageableService $other ) {
190  Assert::parameterType( self::class, $other, '$other' );
191 
193  $otherCurrentObj = $other->current();
194  foreach ( $other->configItems['public'] as $name => $otherConfig ) {
195  if ( isset( $this->configItems['public'][$name] ) ) {
196  continue;
197  }
198 
199  $this->add( $name, $otherConfig );
200 
201  // recover the pointer of the other config repository
202  if ( $otherCurrentObj === $otherConfig ) {
203  end( $this->configItems['public'] );
204  }
205  }
206  foreach ( $other->configItems['private'] as $name => $otherConfig ) {
207  if ( isset( $this->configItems['private'][$name] ) ) {
208  continue;
209  }
210 
211  $this->add( $name, $otherConfig );
212 
213  // recover the pointer of the other config repository
214  if ( $otherCurrentObj === $otherConfig ) {
215  end( $this->configItems['private'] );
216  }
217  }
218 
219  // disable $other
220  $other->configItems = [];
221  }
222 }
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.
SalvageableService defines an interface for services that are able to salvage state from a previous i...
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:271
Object which holds currently registered configuration options.
add( $name, array $config)
Adds the definition of a configuration to this repository.
getAll()
Returns an array of all configuration items saved in this ConfigRepository.