3 class ExtensionProcessor
implements Processor
{
6 * Keys that should be set to $GLOBALS
10 protected static $globalSettings = array(
11 'ResourceLoaderSources',
12 'ResourceLoaderLESSVars',
13 'ResourceLoaderLESSImportPaths',
20 'GroupsRemoveFromSelf',
30 'ExtensionEntryPointListFiles',
50 * Keys that are part of the extension credits
54 protected static $creditsAttributes = array(
66 * Things that are not 'attributes', but are not in
67 * $globalSettings or $creditsAttributes.
71 protected static $notAttributes = array(
75 'ResourceFileModulePaths',
77 'ResourceModuleSkinStyles',
78 'ExtensionMessagesFiles',
88 * Stuff that is going to be set to $GLOBALS
90 * Some keys are pre-set to arrays so we can += to them
94 protected $globals = array(
95 'wgExtensionMessagesFiles' => array(),
96 'wgMessagesDirs' => array(),
100 * Things that should be define()'d
104 protected $defines = array();
107 * Things to be called once registration of these extensions are done
111 protected $callbacks = array();
116 protected $credits = array();
119 * Any thing else in the $info that hasn't
120 * already been processed
124 protected $attributes = array();
127 * @param string $path
129 * @param int $version manifest_version for info
132 public function extractInfo( $path, array $info, $version ) {
133 $this->extractConfig( $info );
134 $this->extractHooks( $info );
135 $dir = dirname( $path );
136 $this->extractExtensionMessagesFiles( $dir, $info );
137 $this->extractMessagesDirs( $dir, $info );
138 $this->extractNamespaces( $info );
139 $this->extractResourceLoaderModules( $dir, $info );
140 $this->extractParserTestFiles( $dir, $info );
141 if ( isset( $info['callback'] ) ) {
142 $this->callbacks
[] = $info['callback'];
145 $this->extractCredits( $path, $info );
146 foreach ( $info as $key => $val ) {
147 if ( in_array( $key, self
::$globalSettings ) ) {
148 $this->storeToArray( "wg$key", $val, $this->globals
);
149 // Ignore anything that starts with a @
150 } elseif ( $key[0] !== '@' && !in_array( $key, self
::$notAttributes )
151 && !in_array( $key, self
::$creditsAttributes )
153 $this->storeToArray( $key, $val, $this->attributes
);
158 public function getExtractedInfo() {
160 'globals' => $this->globals
,
161 'defines' => $this->defines
,
162 'callbacks' => $this->callbacks
,
163 'credits' => $this->credits
,
164 'attributes' => $this->attributes
,
168 protected function extractHooks( array $info ) {
169 if ( isset( $info['Hooks'] ) ) {
170 foreach ( $info['Hooks'] as $name => $value ) {
171 foreach ( (array)$value as $callback ) {
172 $this->globals
['wgHooks'][$name][] = $callback;
179 * Register namespaces with the appropriate global settings
183 protected function extractNamespaces( array $info ) {
184 if ( isset( $info['namespaces'] ) ) {
185 foreach ( $info['namespaces'] as $ns ) {
187 $this->defines
[$ns['constant']] = $id;
188 $this->globals
['wgExtraNamespaces'][$id] = $ns['name'];
189 if ( isset( $ns['gender'] ) ) {
190 $this->globals
['wgExtraGenderNamespaces'][$id] = $ns['gender'];
192 if ( isset( $ns['subpages'] ) && $ns['subpages'] ) {
193 $this->globals
['wgNamespacesWithSubpages'][$id] = true;
195 if ( isset( $ns['content'] ) && $ns['content'] ) {
196 $this->globals
['wgContentNamespaces'][] = $id;
198 if ( isset( $ns['defaultcontentmodel'] ) ) {
199 $this->globals
['wgNamespaceContentModels'][$id] = $ns['defaultcontentmodel'];
205 protected function extractResourceLoaderModules( $dir, array $info ) {
206 $defaultPaths = isset( $info['ResourceFileModulePaths'] )
207 ?
$info['ResourceFileModulePaths']
209 if ( isset( $defaultPaths['localBasePath'] ) ) {
210 $defaultPaths['localBasePath'] = "$dir/{$defaultPaths['localBasePath']}";
213 foreach ( array( 'ResourceModules', 'ResourceModuleSkinStyles' ) as $setting ) {
214 if ( isset( $info[$setting] ) ) {
215 foreach ( $info[$setting] as $name => $data ) {
216 if ( isset( $data['localBasePath'] ) ) {
217 $data['localBasePath'] = "$dir/{$data['localBasePath']}";
219 if ( $defaultPaths ) {
220 $data +
= $defaultPaths;
222 $this->globals
["wg$setting"][$name] = $data;
228 protected function extractExtensionMessagesFiles( $dir, array $info ) {
229 if ( isset( $info['ExtensionMessagesFiles'] ) ) {
230 $this->globals
["wgExtensionMessagesFiles"] +
= array_map( function( $file ) use ( $dir ) {
232 }, $info['ExtensionMessagesFiles'] );
237 * Set message-related settings, which need to be expanded to use
243 protected function extractMessagesDirs( $dir, array $info ) {
244 if ( isset( $info['MessagesDirs'] ) ) {
245 foreach ( $info['MessagesDirs'] as $name => $files ) {
246 foreach ( (array)$files as $file ) {
247 $this->globals
["wgMessagesDirs"][$name][] = "$dir/$file";
253 protected function extractCredits( $path, array $info ) {
256 'type' => isset( $info['type'] ) ?
$info['type'] : 'other',
258 foreach ( self
::$creditsAttributes as $attr ) {
259 if ( isset( $info[$attr] ) ) {
260 $credits[$attr] = $info[$attr];
264 $this->credits
[$credits['name']] = $credits;
268 * Set configuration settings
269 * @todo In the future, this should be done via Config interfaces
273 protected function extractConfig( array $info ) {
274 if ( isset( $info['config'] ) ) {
275 foreach ( $info['config'] as $key => $val ) {
276 if ( $key[0] !== '@' ) {
277 $this->globals
["wg$key"] = $val;
283 protected function extractParserTestFiles( $dir, array $info ) {
284 if ( isset( $info['ParserTestFiles'] ) ) {
285 foreach ( $info['ParserTestFiles'] as $path ) {
286 $this->globals
['wgParserTestFiles'][] = "$dir/$path";
292 * @param string $name
293 * @param array $value
294 * @param array &$array
295 * @throws InvalidArgumentException
297 protected function storeToArray( $name, $value, &$array ) {
298 if ( !is_array( $value ) ) {
299 throw new InvalidArgumentException( "The value for '$name' should be an array" );
301 if ( isset( $array[$name] ) ) {
302 $array[$name] = array_merge_recursive( $array[$name], $value );
304 $array[$name] = $value;