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(
66 * Stuff that is going to be set to $GLOBALS
68 * Some keys are pre-set to arrays so we can += to them
72 protected $globals = array(
73 'wgExtensionMessagesFiles' => array(),
74 'wgMessagesDirs' => array(),
78 * Things that should be define()'d
82 protected $defines = array();
85 * Things to be called once registration of these extensions are done
89 protected $callbacks = array();
94 protected $credits = array();
97 * Any thing else in the $info that hasn't
98 * already been processed
102 protected $attributes = array();
105 * List of keys that have already been processed
109 protected $processed = array();
112 * @param string $path
116 public function extractInfo( $path, array $info ) {
117 $this->extractConfig( $info );
118 $this->extractHooks( $info );
119 $dir = dirname( $path );
120 $this->extractExtensionMessagesFiles( $dir, $info );
121 $this->extractMessagesDirs( $dir, $info );
122 $this->extractNamespaces( $info );
123 $this->extractResourceLoaderModules( $dir, $info );
124 if ( isset( $info['callback'] ) ) {
125 $this->callbacks
[] = $info['callback'];
126 $this->processed
[] = 'callback';
129 $this->extractCredits( $path, $info );
130 foreach ( $info as $key => $val ) {
131 if ( in_array( $key, self
::$globalSettings ) ) {
132 $this->storeToArray( "wg$key", $val, $this->globals
);
133 // Ignore anything that starts with a @
134 } elseif ( $key[0] !== '@' && !in_array( $key, $this->processed
) ) {
135 $this->storeToArray( $key, $val, $this->attributes
);
141 public function getExtractedInfo() {
143 'globals' => $this->globals
,
144 'defines' => $this->defines
,
145 'callbacks' => $this->callbacks
,
146 'credits' => $this->credits
,
147 'attributes' => $this->attributes
,
151 protected function extractHooks( array $info ) {
152 if ( isset( $info['Hooks'] ) ) {
153 foreach ( $info['Hooks'] as $name => $callable ) {
154 $this->globals
['wgHooks'][$name][] = $callable;
156 $this->processed
[] = 'Hooks';
161 * Register namespaces with the appropriate global settings
165 protected function extractNamespaces( array $info ) {
166 if ( isset( $info['namespaces'] ) ) {
167 foreach ( $info['namespaces'] as $ns ) {
169 $this->defines
[$ns['constant']] = $id;
170 $this->globals
['wgExtraNamespaces'][$id] = $ns['name'];
171 if ( isset( $ns['gender'] ) ) {
172 $this->globals
['wgExtraGenderNamespaces'][$id] = $ns['gender'];
174 if ( isset( $ns['subpages'] ) && $ns['subpages'] ) {
175 $this->globals
['wgNamespacesWithSubpages'][$id] = true;
177 if ( isset( $ns['content'] ) && $ns['content'] ) {
178 $this->globals
['wgContentNamespaces'][] = $id;
180 if ( isset( $ns['defaultcontentmodel'] ) ) {
181 $this->globals
['wgNamespaceContentModels'][$id] = $ns['defaultcontentmodel'];
184 $this->processed
[] = 'namespaces';
188 protected function extractResourceLoaderModules( $dir, array $info ) {
189 $defaultPaths = isset( $info['ResourceFileModulePaths'] )
190 ?
$info['ResourceFileModulePaths']
192 if ( isset( $defaultPaths['localBasePath'] ) ) {
193 $defaultPaths['localBasePath'] = "$dir/{$defaultPaths['localBasePath']}";
196 if ( isset( $info['ResourceModules'] ) ) {
197 foreach ( $info['ResourceModules'] as $name => $data ) {
198 if ( isset( $data['localBasePath'] ) ) {
199 $data['localBasePath'] = "$dir/{$data['localBasePath']}";
201 if ( $defaultPaths ) {
202 $data +
= $defaultPaths;
204 $this->globals
['wgResourceModules'][$name] = $data;
209 protected function extractExtensionMessagesFiles( $dir, array $info ) {
210 if ( isset( $info['ExtensionMessagesFiles'] ) ) {
211 $this->globals
["wgExtensionMessagesFiles"] +
= array_map( function( $file ) use ( $dir ) {
213 }, $info['ExtensionMessagesFiles'] );
214 $this->processed
[] = 'ExtensionMessagesFiles';
219 * Set message-related settings, which need to be expanded to use
225 protected function extractMessagesDirs( $dir, array $info ) {
226 if ( isset( $info['MessagesDirs'] ) ) {
227 foreach ( $info['MessagesDirs'] as $name => $files ) {
228 foreach ( (array)$files as $file ) {
229 $this->globals
["wgMessagesDirs"][$name][] = "$dir/$file";
232 $this->processed
[] = 'MessagesDirs';
236 protected function extractCredits( $path, array $info ) {
239 'type' => isset( $info['type'] ) ?
$info['type'] : 'other',
241 $this->processed
[] = 'type';
242 foreach ( self
::$creditsAttributes as $attr ) {
243 if ( isset( $info[$attr] ) ) {
244 $credits[$attr] = $info[$attr];
245 $this->processed
[] = $attr;
249 $this->credits
[$credits['name']] = $credits;
253 * Set configuration settings
254 * @todo In the future, this should be done via Config interfaces
258 protected function extractConfig( array $info ) {
259 if ( isset( $info['config'] ) ) {
260 foreach ( $info['config'] as $key => $val ) {
261 if ( $key[0] !== '@' ) {
262 $this->globals
["wg$key"] = $val;
265 $this->processed
[] = 'config';
270 * @param string $name
271 * @param mixed $value
272 * @param array &$array
274 protected function storeToArray( $name, $value, &$array ) {
275 if ( isset( $array[$name] ) ) {
276 $array[$name] = array_merge_recursive( $array[$name], $value );
278 $array[$name] = $value;