11use Wikimedia\Assert\Assert;
12use Wikimedia\Services\SalvageableService;
22 private $configFactory;
25 private $configItems = [
31 $this->configFactory = $configFactory;
41 public function has( $name, $alsoPrivate =
false ) {
42 return isset( $this->configItems[
'public'][$name] ) ||
43 ( $alsoPrivate && isset( $this->configItems[
'private'][$name] ) );
54 public function get( $name ) {
55 if ( !$this->
has( $name,
true ) ) {
56 throw new ConfigException(
'The configuration option ' . $name .
' does not exist.' );
59 return $this->configItems[
'public'][$name] ?? $this->configItems[
'private'][$name];
73 return array_merge( $this->configItems[
'private'], $this->configItems[
'public'] );
82 return $this->configItems[
'public'];
94 $config = $this->
get( $name );
95 if ( isset( $config[
'descriptionmsg'] ) ) {
96 return wfMessage( $config[
'descriptionmsg'] )->escaped();
98 if ( isset( $config[
'description'] ) ) {
99 return htmlspecialchars( $config[
'description'] );
119 public function add( $name, array $config ) {
120 if ( $this->
has( $name ) ) {
122 'does already exist. It is provided by: ' .
123 $this->
get( $name )[
'providedby'] );
125 if ( isset( $config[
'public'] ) && $config[
'public'] ) {
126 $this->configItems[
'public'][$name] = $config;
128 $this->configItems[
'private'][$name] = $config;
139 public function isEmpty( $includePrivate =
false ) {
140 if ( $includePrivate ) {
141 return empty( $this->configItems[
'private'] ) &&
142 empty( $this->configItems[
'public'] );
144 return empty( $this->configItems[
'public'] );
156 public function salvage( SalvageableService $other ) {
157 Assert::parameterType( self::class, $other,
'$other' );
159 '@phan-var self $other';
161 foreach ( $other->configItems[
'public'] as $name => $otherConfig ) {
162 if ( isset( $this->configItems[
'public'][$name] ) ) {
166 $this->
add( $name, $otherConfig );
168 foreach ( $other->configItems[
'private'] as $name => $otherConfig ) {
169 if ( isset( $this->configItems[
'private'][$name] ) ) {
173 $this->
add( $name, $otherConfig );
177 $other->configItems = [];
wfMessage( $key,... $params)
This is the function for getting translated interface messages.