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 * Stuff that is going to be set to $GLOBALS
69 * Some keys are pre-set to arrays so we can += to them
73 protected $globals = array(
74 'wgExtensionMessagesFiles' => array(),
75 'wgMessagesDirs' => array(),
79 * Things that should be define()'d
83 protected $defines = array();
86 * Things to be called once registration of these extensions are done
90 protected $callbacks = array();
95 protected $credits = array();
98 * Any thing else in the $info that hasn't
99 * already been processed
103 protected $attributes = array();
106 * List of keys that have already been processed
110 protected $processed = array();
113 * @param string $path
117 public function extractInfo( $path, array $info ) {
118 $this->extractConfig( $info );
119 $this->extractHooks( $info );
120 $dir = dirname( $path );
121 $this->extractExtensionMessagesFiles( $dir, $info );
122 $this->extractMessagesDirs( $dir, $info );
123 $this->extractNamespaces( $info );
124 $this->extractResourceLoaderModules( $dir, $info );
125 if ( isset( $info['callback'] ) ) {
126 $this->callbacks
[] = $info['callback'];
127 $this->processed
[] = 'callback';
130 $this->extractCredits( $path, $info );
131 foreach ( $info as $key => $val ) {
132 if ( in_array( $key, self
::$globalSettings ) ) {
133 $this->storeToArray( "wg$key", $val, $this->globals
);
134 // Ignore anything that starts with a @
135 } elseif ( $key[0] !== '@' && !in_array( $key, $this->processed
) ) {
136 $this->storeToArray( $key, $val, $this->attributes
);
142 public function getExtractedInfo() {
144 'globals' => $this->globals
,
145 'defines' => $this->defines
,
146 'callbacks' => $this->callbacks
,
147 'credits' => $this->credits
,
148 'attributes' => $this->attributes
,
152 protected function extractHooks( array $info ) {
153 if ( isset( $info['Hooks'] ) ) {
154 foreach ( $info['Hooks'] as $name => $callable ) {
155 $this->globals
['wgHooks'][$name][] = $callable;
157 $this->processed
[] = 'Hooks';
162 * Register namespaces with the appropriate global settings
166 protected function extractNamespaces( array $info ) {
167 if ( isset( $info['namespaces'] ) ) {
168 foreach ( $info['namespaces'] as $ns ) {
170 $this->defines
[$ns['constant']] = $id;
171 $this->globals
['wgExtraNamespaces'][$id] = $ns['name'];
172 if ( isset( $ns['gender'] ) ) {
173 $this->globals
['wgExtraGenderNamespaces'][$id] = $ns['gender'];
175 if ( isset( $ns['subpages'] ) && $ns['subpages'] ) {
176 $this->globals
['wgNamespacesWithSubpages'][$id] = true;
178 if ( isset( $ns['content'] ) && $ns['content'] ) {
179 $this->globals
['wgContentNamespaces'][] = $id;
181 if ( isset( $ns['defaultcontentmodel'] ) ) {
182 $this->globals
['wgNamespaceContentModels'][$id] = $ns['defaultcontentmodel'];
185 $this->processed
[] = 'namespaces';
189 protected function extractResourceLoaderModules( $dir, array $info ) {
190 $defaultPaths = isset( $info['ResourceFileModulePaths'] )
191 ?
$info['ResourceFileModulePaths']
193 if ( isset( $defaultPaths['localBasePath'] ) ) {
194 $defaultPaths['localBasePath'] = "$dir/{$defaultPaths['localBasePath']}";
197 foreach ( array( 'ResourceModules', 'ResourceModuleSkinStyles' ) as $setting ) {
198 if ( isset( $info[$setting] ) ) {
199 foreach ( $info[$setting] as $name => $data ) {
200 if ( isset( $data['localBasePath'] ) ) {
201 $data['localBasePath'] = "$dir/{$data['localBasePath']}";
203 if ( $defaultPaths ) {
204 $data +
= $defaultPaths;
206 $this->globals
["wg$setting"][$name] = $data;
212 protected function extractExtensionMessagesFiles( $dir, array $info ) {
213 if ( isset( $info['ExtensionMessagesFiles'] ) ) {
214 $this->globals
["wgExtensionMessagesFiles"] +
= array_map( function( $file ) use ( $dir ) {
216 }, $info['ExtensionMessagesFiles'] );
217 $this->processed
[] = 'ExtensionMessagesFiles';
222 * Set message-related settings, which need to be expanded to use
228 protected function extractMessagesDirs( $dir, array $info ) {
229 if ( isset( $info['MessagesDirs'] ) ) {
230 foreach ( $info['MessagesDirs'] as $name => $files ) {
231 foreach ( (array)$files as $file ) {
232 $this->globals
["wgMessagesDirs"][$name][] = "$dir/$file";
235 $this->processed
[] = 'MessagesDirs';
239 protected function extractCredits( $path, array $info ) {
242 'type' => isset( $info['type'] ) ?
$info['type'] : 'other',
244 $this->processed
[] = 'type';
245 foreach ( self
::$creditsAttributes as $attr ) {
246 if ( isset( $info[$attr] ) ) {
247 $credits[$attr] = $info[$attr];
248 $this->processed
[] = $attr;
252 $this->credits
[$credits['name']] = $credits;
256 * Set configuration settings
257 * @todo In the future, this should be done via Config interfaces
261 protected function extractConfig( array $info ) {
262 if ( isset( $info['config'] ) ) {
263 foreach ( $info['config'] as $key => $val ) {
264 if ( $key[0] !== '@' ) {
265 $this->globals
["wg$key"] = $val;
268 $this->processed
[] = 'config';
273 * @param string $name
274 * @param mixed $value
275 * @param array &$array
277 protected function storeToArray( $name, $value, &$array ) {
278 if ( isset( $array[$name] ) ) {
279 $array[$name] = array_merge_recursive( $array[$name], $value );
281 $array[$name] = $value;