27c81482223f9479a1d6b88da30fe1129f3c9c06
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',
29 'ExtensionEntryPointListFiles',
49 * Keys that are part of the extension credits
53 protected static $creditsAttributes = array(
64 * Stuff that is going to be set to $GLOBALS
66 * Some keys are pre-set to arrays so we can += to them
70 protected $globals = array(
71 'wgExtensionMessagesFiles' => array(),
72 'wgMessagesDirs' => array(),
76 * Things that should be define()'d
80 protected $defines = array();
83 * Things to be called once registration of these extensions are done
87 protected $callbacks = array();
92 protected $credits = array();
95 * Any thing else in the $info that hasn't
96 * already been processed
100 protected $attributes = array();
103 * List of keys that have already been processed
107 protected $processed = array();
110 * @param string $path
114 public function extractInfo( $path, array $info ) {
115 $this->extractConfig( $info );
116 $this->extractHooks( $info );
117 $dir = dirname( $path );
118 $this->extractMessageSettings( $dir, $info );
119 $this->extractNamespaces( $info );
120 $this->extractResourceLoaderModules( $dir, $info );
121 if ( isset( $info['callback'] ) ) {
122 $this->callbacks
[] = $info['callback'];
123 $this->processed
[] = 'callback';
126 $this->extractCredits( $path, $info );
127 foreach ( $info as $key => $val ) {
128 if ( in_array( $key, self
::$globalSettings ) ) {
129 $this->storeToArray( "wg$key", $val, $this->globals
);
130 } elseif ( !in_array( $key, $this->processed
) ) {
131 $this->storeToArray( $key, $val, $this->attributes
);
137 public function getExtractedInfo() {
139 'globals' => $this->globals
,
140 'defines' => $this->defines
,
141 'callbacks' => $this->callbacks
,
142 'credits' => $this->credits
,
143 'attributes' => $this->attributes
,
147 protected function extractHooks( array $info ) {
148 if ( isset( $info['Hooks'] ) ) {
149 foreach ( $info['Hooks'] as $name => $callable ) {
150 $this->globals
['wgHooks'][$name][] = $callable;
152 $this->processed
[] = 'Hooks';
157 * Register namespaces with the appropriate global settings
161 protected function extractNamespaces( array $info ) {
162 if ( isset( $info['namespaces'] ) ) {
163 foreach ( $info['namespaces'] as $ns ) {
165 $this->defines
[$ns['constant']] = $id;
166 $this->globals
['wgExtraNamespaces'][$id] = $ns['name'];
167 if ( isset( $ns['gender'] ) ) {
168 $this->globals
['wgExtraGenderNamespaces'][$id] = $ns['gender'];
170 if ( isset( $ns['subpages'] ) && $ns['subpages'] ) {
171 $this->globals
['wgNamespacesWithSubpages'][$id] = true;
173 if ( isset( $ns['content'] ) && $ns['content'] ) {
174 $this->globals
['wgContentNamespaces'][] = $id;
176 if ( isset( $ns['defaultcontentmodel'] ) ) {
177 $this->globals
['wgNamespaceContentModels'][$id] = $ns['defaultcontentmodel'];
180 $this->processed
[] = 'namespaces';
184 protected function extractResourceLoaderModules( $dir, array $info ) {
185 if ( isset( $info['ResourceModules'] ) ) {
186 foreach ( $info['ResourceModules'] as $name => $data ) {
187 if ( isset( $data['localBasePath'] ) ) {
188 $data['localBasePath'] = "$dir/{$data['localBasePath']}";
190 $this->globals
['wgResourceModules'][$name] = $data;
196 * Set message-related settings, which need to be expanded to use
202 protected function extractMessageSettings( $dir, array $info ) {
203 foreach ( array( 'ExtensionMessagesFiles', 'MessagesDirs' ) as $key ) {
204 if ( isset( $info[$key] ) ) {
205 $this->globals
["wg$key"] +
= array_map( function( $file ) use ( $dir ) {
208 $this->processed
[] = $key;
213 protected function extractCredits( $path, array $info ) {
216 'type' => isset( $info['type'] ) ?
$info['type'] : 'other',
218 $this->processed
[] = 'type';
219 foreach ( self
::$creditsAttributes as $attr ) {
220 if ( isset( $info[$attr] ) ) {
221 $credits[$attr] = $info[$attr];
222 $this->processed
[] = $attr;
226 $this->credits
[$credits['name']] = $credits;
230 * Set configuration settings
231 * @todo In the future, this should be done via Config interfaces
235 protected function extractConfig( array $info ) {
236 if ( isset( $info['config'] ) ) {
237 foreach ( $info['config'] as $key => $val ) {
238 $this->globals
["wg$key"] = $val;
240 $this->processed
[] = 'config';
245 * @param string $name
246 * @param mixed $value
247 * @param array &$array
249 protected function storeToArray( $name, $value, &$array ) {
250 if ( isset( $array[$name] ) ) {
251 $array[$name] = array_merge_recursive( $array[$name], $value );
253 $array[$name] = $value;