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',
87 * Stuff that is going to be set to $GLOBALS
89 * Some keys are pre-set to arrays so we can += to them
93 protected $globals = array(
94 'wgExtensionMessagesFiles' => array(),
95 'wgMessagesDirs' => array(),
99 * Things that should be define()'d
103 protected $defines = array();
106 * Things to be called once registration of these extensions are done
110 protected $callbacks = array();
115 protected $credits = array();
118 * Any thing else in the $info that hasn't
119 * already been processed
123 protected $attributes = array();
126 * @param string $path
130 public function extractInfo( $path, array $info ) {
131 $this->extractConfig( $info );
132 $this->extractHooks( $info );
133 $dir = dirname( $path );
134 $this->extractExtensionMessagesFiles( $dir, $info );
135 $this->extractMessagesDirs( $dir, $info );
136 $this->extractNamespaces( $info );
137 $this->extractResourceLoaderModules( $dir, $info );
138 $this->extractParserTestFiles( $dir, $info );
139 if ( isset( $info['callback'] ) ) {
140 $this->callbacks
[] = $info['callback'];
143 $this->extractCredits( $path, $info );
144 foreach ( $info as $key => $val ) {
145 if ( in_array( $key, self
::$globalSettings ) ) {
146 $this->storeToArray( "wg$key", $val, $this->globals
);
147 // Ignore anything that starts with a @
148 } elseif ( $key[0] !== '@' && !in_array( $key, self
::$notAttributes )
149 && !in_array( $key, self
::$creditsAttributes )
151 $this->storeToArray( $key, $val, $this->attributes
);
156 public function getExtractedInfo() {
158 'globals' => $this->globals
,
159 'defines' => $this->defines
,
160 'callbacks' => $this->callbacks
,
161 'credits' => $this->credits
,
162 'attributes' => $this->attributes
,
166 protected function extractHooks( array $info ) {
167 if ( isset( $info['Hooks'] ) ) {
168 foreach ( $info['Hooks'] as $name => $value ) {
169 foreach ( (array)$value as $callback ) {
170 $this->globals
['wgHooks'][$name][] = $callback;
177 * Register namespaces with the appropriate global settings
181 protected function extractNamespaces( array $info ) {
182 if ( isset( $info['namespaces'] ) ) {
183 foreach ( $info['namespaces'] as $ns ) {
185 $this->defines
[$ns['constant']] = $id;
186 $this->globals
['wgExtraNamespaces'][$id] = $ns['name'];
187 if ( isset( $ns['gender'] ) ) {
188 $this->globals
['wgExtraGenderNamespaces'][$id] = $ns['gender'];
190 if ( isset( $ns['subpages'] ) && $ns['subpages'] ) {
191 $this->globals
['wgNamespacesWithSubpages'][$id] = true;
193 if ( isset( $ns['content'] ) && $ns['content'] ) {
194 $this->globals
['wgContentNamespaces'][] = $id;
196 if ( isset( $ns['defaultcontentmodel'] ) ) {
197 $this->globals
['wgNamespaceContentModels'][$id] = $ns['defaultcontentmodel'];
203 protected function extractResourceLoaderModules( $dir, array $info ) {
204 $defaultPaths = isset( $info['ResourceFileModulePaths'] )
205 ?
$info['ResourceFileModulePaths']
207 if ( isset( $defaultPaths['localBasePath'] ) ) {
208 $defaultPaths['localBasePath'] = "$dir/{$defaultPaths['localBasePath']}";
211 foreach ( array( 'ResourceModules', 'ResourceModuleSkinStyles' ) as $setting ) {
212 if ( isset( $info[$setting] ) ) {
213 foreach ( $info[$setting] as $name => $data ) {
214 if ( isset( $data['localBasePath'] ) ) {
215 $data['localBasePath'] = "$dir/{$data['localBasePath']}";
217 if ( $defaultPaths ) {
218 $data +
= $defaultPaths;
220 $this->globals
["wg$setting"][$name] = $data;
226 protected function extractExtensionMessagesFiles( $dir, array $info ) {
227 if ( isset( $info['ExtensionMessagesFiles'] ) ) {
228 $this->globals
["wgExtensionMessagesFiles"] +
= array_map( function( $file ) use ( $dir ) {
230 }, $info['ExtensionMessagesFiles'] );
235 * Set message-related settings, which need to be expanded to use
241 protected function extractMessagesDirs( $dir, array $info ) {
242 if ( isset( $info['MessagesDirs'] ) ) {
243 foreach ( $info['MessagesDirs'] as $name => $files ) {
244 foreach ( (array)$files as $file ) {
245 $this->globals
["wgMessagesDirs"][$name][] = "$dir/$file";
251 protected function extractCredits( $path, array $info ) {
254 'type' => isset( $info['type'] ) ?
$info['type'] : 'other',
256 foreach ( self
::$creditsAttributes as $attr ) {
257 if ( isset( $info[$attr] ) ) {
258 $credits[$attr] = $info[$attr];
262 $this->credits
[$credits['name']] = $credits;
266 * Set configuration settings
267 * @todo In the future, this should be done via Config interfaces
271 protected function extractConfig( array $info ) {
272 if ( isset( $info['config'] ) ) {
273 foreach ( $info['config'] as $key => $val ) {
274 if ( $key[0] !== '@' ) {
275 $this->globals
["wg$key"] = $val;
281 protected function extractParserTestFiles( $dir, array $info ) {
282 if ( isset( $info['ParserTestFiles'] ) ) {
283 foreach ( $info['ParserTestFiles'] as $path ) {
284 $this->globals
['wgParserTestFiles'][] = "$dir/$path";
290 * @param string $name
291 * @param mixed $value
292 * @param array &$array
294 protected function storeToArray( $name, $value, &$array ) {
295 if ( isset( $array[$name] ) ) {
296 $array[$name] = array_merge_recursive( $array[$name], $value );
298 $array[$name] = $value;