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->extractMessageSettings( $dir, $info );
120 $this->extractNamespaces( $info );
121 $this->extractResourceLoaderModules( $dir, $info );
122 if ( isset( $info['callback'] ) ) {
123 $this->callbacks
[] = $info['callback'];
124 $this->processed
[] = 'callback';
127 $this->extractCredits( $path, $info );
128 foreach ( $info as $key => $val ) {
129 if ( in_array( $key, self
::$globalSettings ) ) {
130 $this->storeToArray( "wg$key", $val, $this->globals
);
131 // Ignore anything that starts with a @
132 } elseif ( $key[0] !== '@' && !in_array( $key, $this->processed
) ) {
133 $this->storeToArray( $key, $val, $this->attributes
);
139 public function getExtractedInfo() {
141 'globals' => $this->globals
,
142 'defines' => $this->defines
,
143 'callbacks' => $this->callbacks
,
144 'credits' => $this->credits
,
145 'attributes' => $this->attributes
,
149 protected function extractHooks( array $info ) {
150 if ( isset( $info['Hooks'] ) ) {
151 foreach ( $info['Hooks'] as $name => $callable ) {
152 $this->globals
['wgHooks'][$name][] = $callable;
154 $this->processed
[] = 'Hooks';
159 * Register namespaces with the appropriate global settings
163 protected function extractNamespaces( array $info ) {
164 if ( isset( $info['namespaces'] ) ) {
165 foreach ( $info['namespaces'] as $ns ) {
167 $this->defines
[$ns['constant']] = $id;
168 $this->globals
['wgExtraNamespaces'][$id] = $ns['name'];
169 if ( isset( $ns['gender'] ) ) {
170 $this->globals
['wgExtraGenderNamespaces'][$id] = $ns['gender'];
172 if ( isset( $ns['subpages'] ) && $ns['subpages'] ) {
173 $this->globals
['wgNamespacesWithSubpages'][$id] = true;
175 if ( isset( $ns['content'] ) && $ns['content'] ) {
176 $this->globals
['wgContentNamespaces'][] = $id;
178 if ( isset( $ns['defaultcontentmodel'] ) ) {
179 $this->globals
['wgNamespaceContentModels'][$id] = $ns['defaultcontentmodel'];
182 $this->processed
[] = 'namespaces';
186 protected function extractResourceLoaderModules( $dir, array $info ) {
187 if ( isset( $info['ResourceModules'] ) ) {
188 foreach ( $info['ResourceModules'] as $name => $data ) {
189 if ( isset( $data['localBasePath'] ) ) {
190 $data['localBasePath'] = "$dir/{$data['localBasePath']}";
192 $this->globals
['wgResourceModules'][$name] = $data;
198 * Set message-related settings, which need to be expanded to use
204 protected function extractMessageSettings( $dir, array $info ) {
205 foreach ( array( 'ExtensionMessagesFiles', 'MessagesDirs' ) as $key ) {
206 if ( isset( $info[$key] ) ) {
207 foreach ( $info[$key] as $name => $files ) {
208 foreach ( (array)$files as $file ) {
209 $this->globals
["wg$key"][$name][] = "$dir/$file";
212 $this->processed
[] = $key;
217 protected function extractCredits( $path, array $info ) {
220 'type' => isset( $info['type'] ) ?
$info['type'] : 'other',
222 $this->processed
[] = 'type';
223 foreach ( self
::$creditsAttributes as $attr ) {
224 if ( isset( $info[$attr] ) ) {
225 $credits[$attr] = $info[$attr];
226 $this->processed
[] = $attr;
230 $this->credits
[$credits['name']] = $credits;
234 * Set configuration settings
235 * @todo In the future, this should be done via Config interfaces
239 protected function extractConfig( array $info ) {
240 if ( isset( $info['config'] ) ) {
241 foreach ( $info['config'] as $key => $val ) {
242 if ( $key[0] !== '@' ) {
243 $this->globals
["wg$key"] = $val;
246 $this->processed
[] = 'config';
251 * @param string $name
252 * @param mixed $value
253 * @param array &$array
255 protected function storeToArray( $name, $value, &$array ) {
256 if ( isset( $array[$name] ) ) {
257 $array[$name] = array_merge_recursive( $array[$name], $value );
259 $array[$name] = $value;