da8600c77ace0a9bc8af169809543e0c5f819efd
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 * Mapping of global settings to their specific merge strategies.
52 * @see ExtensionRegistry::exportExtractedData
53 * @see getExtractedInfo
56 protected static $mergeStrategies = array(
57 'wgGroupPermissions' => 'array_plus_2d',
58 'wgRevokePermissions' => 'array_plus_2d',
59 'wgHooks' => 'array_merge_recursive',
60 'wgExtensionCredits' => 'array_merge_recursive',
61 'wgExtraNamespaces' => 'array_plus',
62 'wgExtraGenderNamespaces' => 'array_plus',
63 'wgNamespacesWithSubpages' => 'array_plus',
64 'wgNamespaceContentModels' => 'array_plus',
68 * Keys that are part of the extension credits
72 protected static $creditsAttributes = array(
84 * Things that are not 'attributes', but are not in
85 * $globalSettings or $creditsAttributes.
89 protected static $notAttributes = array(
93 'ResourceFileModulePaths',
95 'ResourceModuleSkinStyles',
96 'ExtensionMessagesFiles',
106 * Stuff that is going to be set to $GLOBALS
108 * Some keys are pre-set to arrays so we can += to them
112 protected $globals = array(
113 'wgExtensionMessagesFiles' => array(),
114 'wgMessagesDirs' => array(),
118 * Things that should be define()'d
122 protected $defines = array();
125 * Things to be called once registration of these extensions are done
129 protected $callbacks = array();
134 protected $credits = array();
137 * Any thing else in the $info that hasn't
138 * already been processed
142 protected $attributes = array();
145 * @param string $path
147 * @param int $version manifest_version for info
150 public function extractInfo( $path, array $info, $version ) {
151 $this->extractConfig( $info );
152 $this->extractHooks( $info );
153 $dir = dirname( $path );
154 $this->extractExtensionMessagesFiles( $dir, $info );
155 $this->extractMessagesDirs( $dir, $info );
156 $this->extractNamespaces( $info );
157 $this->extractResourceLoaderModules( $dir, $info );
158 $this->extractParserTestFiles( $dir, $info );
159 if ( isset( $info['callback'] ) ) {
160 $this->callbacks
[] = $info['callback'];
163 $this->extractCredits( $path, $info );
164 foreach ( $info as $key => $val ) {
165 if ( in_array( $key, self
::$globalSettings ) ) {
166 $this->storeToArray( "wg$key", $val, $this->globals
);
167 // Ignore anything that starts with a @
168 } elseif ( $key[0] !== '@' && !in_array( $key, self
::$notAttributes )
169 && !in_array( $key, self
::$creditsAttributes )
171 $this->storeToArray( $key, $val, $this->attributes
);
176 public function getExtractedInfo() {
177 // Make sure the merge strategies are set
178 foreach ( $this->globals
as $key => $val ) {
179 if ( isset( self
::$mergeStrategies[$key] ) ) {
180 $this->globals
[$key][ExtensionRegistry
::MERGE_STRATEGY
] = self
::$mergeStrategies[$key];
185 'globals' => $this->globals
,
186 'defines' => $this->defines
,
187 'callbacks' => $this->callbacks
,
188 'credits' => $this->credits
,
189 'attributes' => $this->attributes
,
193 protected function extractHooks( array $info ) {
194 if ( isset( $info['Hooks'] ) ) {
195 foreach ( $info['Hooks'] as $name => $value ) {
196 foreach ( (array)$value as $callback ) {
197 $this->globals
['wgHooks'][$name][] = $callback;
204 * Register namespaces with the appropriate global settings
208 protected function extractNamespaces( array $info ) {
209 if ( isset( $info['namespaces'] ) ) {
210 foreach ( $info['namespaces'] as $ns ) {
212 $this->defines
[$ns['constant']] = $id;
213 $this->globals
['wgExtraNamespaces'][$id] = $ns['name'];
214 if ( isset( $ns['gender'] ) ) {
215 $this->globals
['wgExtraGenderNamespaces'][$id] = $ns['gender'];
217 if ( isset( $ns['subpages'] ) && $ns['subpages'] ) {
218 $this->globals
['wgNamespacesWithSubpages'][$id] = true;
220 if ( isset( $ns['content'] ) && $ns['content'] ) {
221 $this->globals
['wgContentNamespaces'][] = $id;
223 if ( isset( $ns['defaultcontentmodel'] ) ) {
224 $this->globals
['wgNamespaceContentModels'][$id] = $ns['defaultcontentmodel'];
230 protected function extractResourceLoaderModules( $dir, array $info ) {
231 $defaultPaths = isset( $info['ResourceFileModulePaths'] )
232 ?
$info['ResourceFileModulePaths']
234 if ( isset( $defaultPaths['localBasePath'] ) ) {
235 $defaultPaths['localBasePath'] = "$dir/{$defaultPaths['localBasePath']}";
238 foreach ( array( 'ResourceModules', 'ResourceModuleSkinStyles' ) as $setting ) {
239 if ( isset( $info[$setting] ) ) {
240 foreach ( $info[$setting] as $name => $data ) {
241 if ( isset( $data['localBasePath'] ) ) {
242 $data['localBasePath'] = "$dir/{$data['localBasePath']}";
244 if ( $defaultPaths ) {
245 $data +
= $defaultPaths;
247 $this->globals
["wg$setting"][$name] = $data;
253 protected function extractExtensionMessagesFiles( $dir, array $info ) {
254 if ( isset( $info['ExtensionMessagesFiles'] ) ) {
255 $this->globals
["wgExtensionMessagesFiles"] +
= array_map( function( $file ) use ( $dir ) {
257 }, $info['ExtensionMessagesFiles'] );
262 * Set message-related settings, which need to be expanded to use
268 protected function extractMessagesDirs( $dir, array $info ) {
269 if ( isset( $info['MessagesDirs'] ) ) {
270 foreach ( $info['MessagesDirs'] as $name => $files ) {
271 foreach ( (array)$files as $file ) {
272 $this->globals
["wgMessagesDirs"][$name][] = "$dir/$file";
278 protected function extractCredits( $path, array $info ) {
281 'type' => isset( $info['type'] ) ?
$info['type'] : 'other',
283 foreach ( self
::$creditsAttributes as $attr ) {
284 if ( isset( $info[$attr] ) ) {
285 $credits[$attr] = $info[$attr];
289 $this->credits
[$credits['name']] = $credits;
293 * Set configuration settings
294 * @todo In the future, this should be done via Config interfaces
298 protected function extractConfig( array $info ) {
299 if ( isset( $info['config'] ) ) {
300 foreach ( $info['config'] as $key => $val ) {
301 if ( $key[0] !== '@' ) {
302 $this->globals
["wg$key"] = $val;
308 protected function extractParserTestFiles( $dir, array $info ) {
309 if ( isset( $info['ParserTestFiles'] ) ) {
310 foreach ( $info['ParserTestFiles'] as $path ) {
311 $this->globals
['wgParserTestFiles'][] = "$dir/$path";
317 * @param string $name
318 * @param array $value
319 * @param array &$array
320 * @throws InvalidArgumentException
322 protected function storeToArray( $name, $value, &$array ) {
323 if ( !is_array( $value ) ) {
324 throw new InvalidArgumentException( "The value for '$name' should be an array" );
326 if ( isset( $array[$name] ) ) {
327 $array[$name] = array_merge_recursive( $array[$name], $value );
329 $array[$name] = $value;