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',
51 * Keys that are part of the extension credits
55 protected static $creditsAttributes = array(
67 * Things that are not 'attributes', but are not in
68 * $globalSettings or $creditsAttributes.
72 protected static $notAttributes = array(
76 'ResourceFileModulePaths',
78 'ResourceModuleSkinStyles',
79 '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
131 public function extractInfo( $path, array $info ) {
132 $this->extractConfig( $info );
133 $this->extractHooks( $info );
134 $dir = dirname( $path );
135 $this->extractExtensionMessagesFiles( $dir, $info );
136 $this->extractMessagesDirs( $dir, $info );
137 $this->extractNamespaces( $info );
138 $this->extractResourceLoaderModules( $dir, $info );
139 $this->extractParserTestFiles( $dir, $info );
140 if ( isset( $info['callback'] ) ) {
141 $this->callbacks
[] = $info['callback'];
144 $this->extractCredits( $path, $info );
145 foreach ( $info as $key => $val ) {
146 if ( in_array( $key, self
::$globalSettings ) ) {
147 $this->storeToArray( "wg$key", $val, $this->globals
);
148 // Ignore anything that starts with a @
149 } elseif ( $key[0] !== '@' && !in_array( $key, self
::$notAttributes )
150 && !in_array( $key, self
::$creditsAttributes )
152 $this->storeToArray( $key, $val, $this->attributes
);
157 public function getExtractedInfo() {
159 'globals' => $this->globals
,
160 'defines' => $this->defines
,
161 'callbacks' => $this->callbacks
,
162 'credits' => $this->credits
,
163 'attributes' => $this->attributes
,
167 protected function extractHooks( array $info ) {
168 if ( isset( $info['Hooks'] ) ) {
169 foreach ( $info['Hooks'] as $name => $value ) {
170 foreach ( (array)$value as $callback ) {
171 $this->globals
['wgHooks'][$name][] = $callback;
178 * Register namespaces with the appropriate global settings
182 protected function extractNamespaces( array $info ) {
183 if ( isset( $info['namespaces'] ) ) {
184 foreach ( $info['namespaces'] as $ns ) {
186 $this->defines
[$ns['constant']] = $id;
187 $this->globals
['wgExtraNamespaces'][$id] = $ns['name'];
188 if ( isset( $ns['gender'] ) ) {
189 $this->globals
['wgExtraGenderNamespaces'][$id] = $ns['gender'];
191 if ( isset( $ns['subpages'] ) && $ns['subpages'] ) {
192 $this->globals
['wgNamespacesWithSubpages'][$id] = true;
194 if ( isset( $ns['content'] ) && $ns['content'] ) {
195 $this->globals
['wgContentNamespaces'][] = $id;
197 if ( isset( $ns['defaultcontentmodel'] ) ) {
198 $this->globals
['wgNamespaceContentModels'][$id] = $ns['defaultcontentmodel'];
204 protected function extractResourceLoaderModules( $dir, array $info ) {
205 $defaultPaths = isset( $info['ResourceFileModulePaths'] )
206 ?
$info['ResourceFileModulePaths']
208 if ( isset( $defaultPaths['localBasePath'] ) ) {
209 $defaultPaths['localBasePath'] = "$dir/{$defaultPaths['localBasePath']}";
212 foreach ( array( 'ResourceModules', 'ResourceModuleSkinStyles' ) as $setting ) {
213 if ( isset( $info[$setting] ) ) {
214 foreach ( $info[$setting] as $name => $data ) {
215 if ( isset( $data['localBasePath'] ) ) {
216 $data['localBasePath'] = "$dir/{$data['localBasePath']}";
218 if ( $defaultPaths ) {
219 $data +
= $defaultPaths;
221 $this->globals
["wg$setting"][$name] = $data;
227 protected function extractExtensionMessagesFiles( $dir, array $info ) {
228 if ( isset( $info['ExtensionMessagesFiles'] ) ) {
229 $this->globals
["wgExtensionMessagesFiles"] +
= array_map( function( $file ) use ( $dir ) {
231 }, $info['ExtensionMessagesFiles'] );
236 * Set message-related settings, which need to be expanded to use
242 protected function extractMessagesDirs( $dir, array $info ) {
243 if ( isset( $info['MessagesDirs'] ) ) {
244 foreach ( $info['MessagesDirs'] as $name => $files ) {
245 foreach ( (array)$files as $file ) {
246 $this->globals
["wgMessagesDirs"][$name][] = "$dir/$file";
252 protected function extractCredits( $path, array $info ) {
255 'type' => isset( $info['type'] ) ?
$info['type'] : 'other',
257 foreach ( self
::$creditsAttributes as $attr ) {
258 if ( isset( $info[$attr] ) ) {
259 $credits[$attr] = $info[$attr];
263 $this->credits
[$credits['name']] = $credits;
267 * Set configuration settings
268 * @todo In the future, this should be done via Config interfaces
272 protected function extractConfig( array $info ) {
273 if ( isset( $info['config'] ) ) {
274 foreach ( $info['config'] as $key => $val ) {
275 if ( $key[0] !== '@' ) {
276 $this->globals
["wg$key"] = $val;
282 protected function extractParserTestFiles( $dir, array $info ) {
283 if ( isset( $info['ParserTestFiles'] ) ) {
284 foreach ( $info['ParserTestFiles'] as $path ) {
285 $this->globals
['wgParserTestFiles'][] = "$dir/$path";
291 * @param string $name
292 * @param mixed $value
293 * @param array &$array
295 protected function storeToArray( $name, $value, &$array ) {
296 if ( isset( $array[$name] ) ) {
297 $array[$name] = array_merge_recursive( $array[$name], $value );
299 $array[$name] = $value;