X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fregistration%2FExtensionProcessor.php;h=7c60aa5af83329de54062363d7ee1b2e4c35913f;hb=a5b975edd132e52ee8ce1c725d8195da941c8b7b;hp=aac0c799840557eb8f66b49b5ba077bab19221ac;hpb=1e296da3d7da4bf095ae228d7f5890f7ef520873;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/registration/ExtensionProcessor.php b/includes/registration/ExtensionProcessor.php index aac0c79984..7c60aa5af8 100644 --- a/includes/registration/ExtensionProcessor.php +++ b/includes/registration/ExtensionProcessor.php @@ -7,7 +7,7 @@ class ExtensionProcessor implements Processor { * * @var array */ - protected static $globalSettings = array( + protected static $globalSettings = [ 'ResourceLoaderSources', 'ResourceLoaderLESSVars', 'ResourceLoaderLESSImportPaths', @@ -46,7 +46,7 @@ class ExtensionProcessor implements Processor { 'APIListModules', 'ValidSkinNames', 'FeedClasses', - ); + ]; /** * Mapping of global settings to their specific merge strategies. @@ -55,7 +55,7 @@ class ExtensionProcessor implements Processor { * @see getExtractedInfo * @var array */ - protected static $mergeStrategies = array( + protected static $mergeStrategies = [ 'wgGroupPermissions' => 'array_plus_2d', 'wgRevokePermissions' => 'array_plus_2d', 'wgHooks' => 'array_merge_recursive', @@ -65,14 +65,15 @@ class ExtensionProcessor implements Processor { 'wgNamespaceContentModels' => 'array_plus', 'wgNamespaceProtection' => 'array_plus', 'wgCapitalLinkOverrides' => 'array_plus', - ); + 'wgRateLimits' => 'array_plus_2d', + ]; /** * Keys that are part of the extension credits * * @var array */ - protected static $creditsAttributes = array( + protected static $creditsAttributes = [ 'name', 'namemsg', 'author', @@ -81,7 +82,7 @@ class ExtensionProcessor implements Processor { 'description', 'descriptionmsg', 'license-name', - ); + ]; /** * Things that are not 'attributes', but are not in @@ -89,7 +90,7 @@ class ExtensionProcessor implements Processor { * * @var array */ - protected static $notAttributes = array( + protected static $notAttributes = [ 'callback', 'Hooks', 'namespaces', @@ -104,7 +105,7 @@ class ExtensionProcessor implements Processor { 'AutoloadClasses', 'manifest_version', 'load_composer_autoloader', - ); + ]; /** * Stuff that is going to be set to $GLOBALS @@ -113,29 +114,29 @@ class ExtensionProcessor implements Processor { * * @var array */ - protected $globals = array( - 'wgExtensionMessagesFiles' => array(), - 'wgMessagesDirs' => array(), - ); + protected $globals = [ + 'wgExtensionMessagesFiles' => [], + 'wgMessagesDirs' => [], + ]; /** * Things that should be define()'d * * @var array */ - protected $defines = array(); + protected $defines = []; /** * Things to be called once registration of these extensions are done * * @var callable[] */ - protected $callbacks = array(); + protected $callbacks = []; /** * @var array */ - protected $credits = array(); + protected $credits = []; /** * Any thing else in the $info that hasn't @@ -143,7 +144,7 @@ class ExtensionProcessor implements Processor { * * @var array */ - protected $attributes = array(); + protected $attributes = []; /** * @param string $path @@ -167,12 +168,12 @@ class ExtensionProcessor implements Processor { $this->extractCredits( $path, $info ); foreach ( $info as $key => $val ) { if ( in_array( $key, self::$globalSettings ) ) { - $this->storeToArray( "wg$key", $val, $this->globals ); + $this->storeToArray( $path, "wg$key", $val, $this->globals ); // Ignore anything that starts with a @ } elseif ( $key[0] !== '@' && !in_array( $key, self::$notAttributes ) && !in_array( $key, self::$creditsAttributes ) ) { - $this->storeToArray( $key, $val, $this->attributes ); + $this->storeToArray( $path, $key, $val, $this->attributes ); } } } @@ -185,17 +186,17 @@ class ExtensionProcessor implements Processor { } } - return array( + return [ 'globals' => $this->globals, 'defines' => $this->defines, 'callbacks' => $this->callbacks, 'credits' => $this->credits, 'attributes' => $this->attributes, - ); + ]; } public function getRequirements( array $info ) { - $requirements = array(); + $requirements = []; $key = ExtensionRegistry::MEDIAWIKI_CORE; if ( isset( $info['requires'][$key] ) ) { $requirements[$key] = $info['requires'][$key]; @@ -252,14 +253,24 @@ class ExtensionProcessor implements Processor { ? $info['ResourceFileModulePaths'] : false; if ( isset( $defaultPaths['localBasePath'] ) ) { - $defaultPaths['localBasePath'] = "$dir/{$defaultPaths['localBasePath']}"; + if ( $defaultPaths['localBasePath'] === '' ) { + // Avoid double slashes (e.g. /extensions/Example//path) + $defaultPaths['localBasePath'] = $dir; + } else { + $defaultPaths['localBasePath'] = "$dir/{$defaultPaths['localBasePath']}"; + } } - foreach ( array( 'ResourceModules', 'ResourceModuleSkinStyles' ) as $setting ) { + foreach ( [ 'ResourceModules', 'ResourceModuleSkinStyles' ] as $setting ) { if ( isset( $info[$setting] ) ) { foreach ( $info[$setting] as $name => $data ) { if ( isset( $data['localBasePath'] ) ) { - $data['localBasePath'] = "$dir/{$data['localBasePath']}"; + if ( $data['localBasePath'] === '' ) { + // Avoid double slashes (e.g. /extensions/Example//path) + $data['localBasePath'] = $dir; + } else { + $data['localBasePath'] = "$dir/{$data['localBasePath']}"; + } } if ( $defaultPaths ) { $data += $defaultPaths; @@ -301,10 +312,10 @@ class ExtensionProcessor implements Processor { * @throws Exception */ protected function extractCredits( $path, array $info ) { - $credits = array( + $credits = [ 'path' => $path, 'type' => isset( $info['type'] ) ? $info['type'] : 'other', - ); + ]; foreach ( self::$creditsAttributes as $attr ) { if ( isset( $info[$attr] ) ) { $credits[$attr] = $info[$attr]; @@ -356,14 +367,15 @@ class ExtensionProcessor implements Processor { } /** + * @param string $path * @param string $name * @param array $value * @param array &$array * @throws InvalidArgumentException */ - protected function storeToArray( $name, $value, &$array ) { + protected function storeToArray( $path, $name, $value, &$array ) { if ( !is_array( $value ) ) { - throw new InvalidArgumentException( "The value for '$name' should be an array" ); + throw new InvalidArgumentException( "The value for '$name' should be an array (from $path)" ); } if ( isset( $array[$name] ) ) { $array[$name] = array_merge_recursive( $array[$name], $value ); @@ -373,7 +385,7 @@ class ExtensionProcessor implements Processor { } public function getExtraAutoloaderPaths( $dir, array $info ) { - $paths = array(); + $paths = []; if ( isset( $info['load_composer_autoloader'] ) && $info['load_composer_autoloader'] === true ) { $path = "$dir/vendor/autoload.php"; if ( file_exists( $path ) ) {