*
* @var array
*/
- protected static $globalSettings = array(
+ protected static $globalSettings = [
'ResourceLoaderSources',
'ResourceLoaderLESSVars',
'ResourceLoaderLESSImportPaths',
'AvailableRights',
'ContentHandlers',
'ConfigRegistry',
+ 'CentralIdLookupProviders',
'RateLimits',
'RecentChangesFlags',
'MediaHandlers',
'APIPropModules',
'APIListModules',
'ValidSkinNames',
- );
+ 'FeedClasses',
+ ];
/**
* Mapping of global settings to their specific merge strategies.
* @see getExtractedInfo
* @var array
*/
- protected static $mergeStrategies = array(
+ protected static $mergeStrategies = [
'wgGroupPermissions' => 'array_plus_2d',
'wgRevokePermissions' => 'array_plus_2d',
'wgHooks' => 'array_merge_recursive',
- // credits are handled in the ExtensionRegistry
- // 'wgExtensionCredits' => 'array_merge_recursive',
+ 'wgExtensionCredits' => 'array_merge_recursive',
'wgExtraGenderNamespaces' => 'array_plus',
'wgNamespacesWithSubpages' => 'array_plus',
'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',
'description',
'descriptionmsg',
'license-name',
- );
+ ];
/**
* Things that are not 'attributes', but are not in
*
* @var array
*/
- protected static $notAttributes = array(
+ protected static $notAttributes = [
'callback',
'Hooks',
'namespaces',
'AutoloadClasses',
'manifest_version',
'load_composer_autoloader',
- );
+ ];
/**
* Stuff that is going to be set to $GLOBALS
*
* @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
*
* @var array
*/
- protected $attributes = array();
+ protected $attributes = [];
/**
* @param string $path
$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 );
}
}
}
}
}
- 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];
? $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;
}
}
+ /**
+ * @param string $path
+ * @param array $info
+ * @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];
}
}
- $this->credits[$credits['name']] = $credits;
+ $name = $credits['name'];
+
+ // If someone is loading the same thing twice, throw
+ // a nice error (T121493)
+ if ( isset( $this->credits[$name] ) ) {
+ $firstPath = $this->credits[$name]['path'];
+ $secondPath = $credits['path'];
+ throw new Exception( "It was attempted to load $name twice, from $firstPath and $secondPath." );
+ }
+
+ $this->credits[$name] = $credits;
+ $this->globals['wgExtensionCredits'][$credits['type']][] = $credits;
}
/**
}
/**
+ * @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 );
}
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 ) ) {