MediaWiki REL1_37
SkinFactory.php
Go to the documentation of this file.
1<?php
2
24use Wikimedia\ObjectFactory;
25
32
38 private $factoryFunctions = [];
45 private $displayNames = [];
50
57 private $skipSkins;
58
65 public function __construct( ObjectFactory $objectFactory, array $skipSkins ) {
66 $this->objectFactory = $objectFactory;
67 $this->skipSkins = $skipSkins;
68 }
69
84 public function register( $name, $displayName, $spec ) {
85 if ( !is_callable( $spec ) ) {
86 if ( is_array( $spec ) ) {
87 if ( !isset( $spec['args'] ) ) {
88 // make sure name option is set:
89 $spec['args'] = [
90 [ 'name' => $name ]
91 ];
92 }
93 } else {
94 throw new InvalidArgumentException( 'Invalid callback provided' );
95 }
96 }
97 $this->factoryFunctions[$name] = $spec;
98 $this->displayNames[$name] = $displayName;
99 }
100
107 public function getSkinNames() {
108 return $this->displayNames;
109 }
110
117 public function makeSkin( $name ) {
118 if ( !isset( $this->factoryFunctions[$name] ) ) {
119 throw new SkinException( "No registered builder available for $name." );
120 }
121
122 return $this->objectFactory->createObject(
123 $this->factoryFunctions[$name],
124 [
125 'allowCallable' => true,
126 'assertClass' => Skin::class,
127 ]
128 );
129 }
130
139 public function getAllowedSkins() {
140 $allowedSkins = $this->getSkinNames();
141
142 // Internal skins not intended for general use
143 unset( $allowedSkins['fallback'] );
144 unset( $allowedSkins['apioutput'] );
145
146 foreach ( $this->skipSkins as $skip ) {
147 unset( $allowedSkins[$skip] );
148 }
149
150 return $allowedSkins;
151 }
152}
Exceptions for skin-related failures.
Factory class to create Skin objects.
array< string, array|callable > $factoryFunctions
Map of skin name to object factory spec or factory function.
makeSkin( $name)
Create a given Skin using the registered callback for $name.
array $displayNames
Map of name => fallback human-readable name, used when the 'skinname-<skin>' message is not available...
ObjectFactory $objectFactory
getSkinNames()
Returns an associative array of: skin name => human readable name.
getAllowedSkins()
Fetch the list of user-selectable skins in regards to $wgSkipSkins.
string[] $skipSkins
Array of skins that should not be presented in the list of available skins in user preferences,...
__construct(ObjectFactory $objectFactory, array $skipSkins)