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(
65 * Stuff that is going to be set to $GLOBALS
67 * Some keys are pre-set to arrays so we can += to them
71 protected $globals = array(
72 'wgExtensionMessagesFiles' => array(),
73 'wgMessagesDirs' => array(),
77 * Things that should be define()'d
81 protected $defines = array();
84 * Things to be called once registration of these extensions are done
88 protected $callbacks = array();
93 protected $credits = array();
96 * Any thing else in the $info that hasn't
97 * already been processed
101 protected $attributes = array();
104 * List of keys that have already been processed
108 protected $processed = array();
111 * @param string $path
115 public function extractInfo( $path, array $info ) {
116 $this->extractConfig( $info );
117 $this->extractHooks( $info );
118 $dir = dirname( $path );
119 $this->extractExtensionMessagesFiles( $dir, $info );
120 $this->extractMessagesDirs( $dir, $info );
121 $this->extractNamespaces( $info );
122 $this->extractResourceLoaderModules( $dir, $info );
123 if ( isset( $info['callback'] ) ) {
124 $this->callbacks
[] = $info['callback'];
125 $this->processed
[] = 'callback';
128 $this->extractCredits( $path, $info );
129 foreach ( $info as $key => $val ) {
130 if ( in_array( $key, self
::$globalSettings ) ) {
131 $this->storeToArray( "wg$key", $val, $this->globals
);
132 // Ignore anything that starts with a @
133 } elseif ( $key[0] !== '@' && !in_array( $key, $this->processed
) ) {
134 $this->storeToArray( $key, $val, $this->attributes
);
140 public function getExtractedInfo() {
142 'globals' => $this->globals
,
143 'defines' => $this->defines
,
144 'callbacks' => $this->callbacks
,
145 'credits' => $this->credits
,
146 'attributes' => $this->attributes
,
150 protected function extractHooks( array $info ) {
151 if ( isset( $info['Hooks'] ) ) {
152 foreach ( $info['Hooks'] as $name => $callable ) {
153 $this->globals
['wgHooks'][$name][] = $callable;
155 $this->processed
[] = 'Hooks';
160 * Register namespaces with the appropriate global settings
164 protected function extractNamespaces( array $info ) {
165 if ( isset( $info['namespaces'] ) ) {
166 foreach ( $info['namespaces'] as $ns ) {
168 $this->defines
[$ns['constant']] = $id;
169 $this->globals
['wgExtraNamespaces'][$id] = $ns['name'];
170 if ( isset( $ns['gender'] ) ) {
171 $this->globals
['wgExtraGenderNamespaces'][$id] = $ns['gender'];
173 if ( isset( $ns['subpages'] ) && $ns['subpages'] ) {
174 $this->globals
['wgNamespacesWithSubpages'][$id] = true;
176 if ( isset( $ns['content'] ) && $ns['content'] ) {
177 $this->globals
['wgContentNamespaces'][] = $id;
179 if ( isset( $ns['defaultcontentmodel'] ) ) {
180 $this->globals
['wgNamespaceContentModels'][$id] = $ns['defaultcontentmodel'];
183 $this->processed
[] = 'namespaces';
187 protected function extractResourceLoaderModules( $dir, array $info ) {
188 if ( isset( $info['ResourceModules'] ) ) {
189 foreach ( $info['ResourceModules'] as $name => $data ) {
190 if ( isset( $data['localBasePath'] ) ) {
191 $data['localBasePath'] = "$dir/{$data['localBasePath']}";
193 $this->globals
['wgResourceModules'][$name] = $data;
198 protected function extractExtensionMessagesFiles( $dir, array $info ) {
199 if ( isset( $info['ExtensionMessagesFiles'] ) ) {
200 $this->globals
["wgExtensionMessagesFiles"] +
= array_map( function( $file ) use ( $dir ) {
202 }, $info['ExtensionMessagesFiles'] );
203 $this->processed
[] = 'ExtensionMessagesFiles';
208 * Set message-related settings, which need to be expanded to use
214 protected function extractMessagesDirs( $dir, array $info ) {
215 if ( isset( $info['MessagesDirs'] ) ) {
216 foreach ( $info['MessagesDirs'] as $name => $files ) {
217 foreach ( (array)$files as $file ) {
218 $this->globals
["wgMessagesDirs"][$name][] = "$dir/$file";
221 $this->processed
[] = 'MessagesDirs';
225 protected function extractCredits( $path, array $info ) {
228 'type' => isset( $info['type'] ) ?
$info['type'] : 'other',
230 $this->processed
[] = 'type';
231 foreach ( self
::$creditsAttributes as $attr ) {
232 if ( isset( $info[$attr] ) ) {
233 $credits[$attr] = $info[$attr];
234 $this->processed
[] = $attr;
238 $this->credits
[$credits['name']] = $credits;
242 * Set configuration settings
243 * @todo In the future, this should be done via Config interfaces
247 protected function extractConfig( array $info ) {
248 if ( isset( $info['config'] ) ) {
249 foreach ( $info['config'] as $key => $val ) {
250 if ( $key[0] !== '@' ) {
251 $this->globals
["wg$key"] = $val;
254 $this->processed
[] = 'config';
259 * @param string $name
260 * @param mixed $value
261 * @param array &$array
263 protected function storeToArray( $name, $value, &$array ) {
264 if ( isset( $array[$name] ) ) {
265 $array[$name] = array_merge_recursive( $array[$name], $value );
267 $array[$name] = $value;