Commit graph

17 commits

Author SHA1 Message Date
MGChecker
eb6b4d8e7e registration: Add ability to check if a specific extension version is loaded
As it's quite common that extensions and skins interact with each other, it's
useful to have a simple way to check if an extension version satisfies a
given constraint, as extensions change over time.

Bug: T202955
Change-Id: I19f9713caf89d647072a2bd7d598e739be383f4a
2018-09-03 14:37:33 -07:00
Antoine Musso
224864ebdd registration: Initialize PSR-4 namespaces at same stage as normal autoloader
readFromQueue() injects the content of AutoloadClasses to
$wgAutoloadClasses however it missed doing the same for
AutoloadNamespaces.

When using the installer with an extension having AutoloadNamespaces
set, its classes would not be found.

Make ExtensionRegistry append to AutoLoader::$psr4Namespaces, and add
a test to cover the new behavior.

Bug: T195783
Change-Id: Id61155867a4ca7d9bc4a347f8671da74b0fa490b
2018-05-30 13:07:42 -07:00
Kunal Mehta
b165908616 Improve ExtensionRegistry test coverage
Change-Id: Id1b87e020a220c96b42d86485da67d47b9d565f9
2018-05-27 20:36:41 -07:00
Kunal Mehta
f492a981bf Improve ExtensionRegistry test coverage
Change-Id: I7f7445952f057995a3e3215145803affa5aceede
2018-02-12 20:36:50 -08:00
Umherirrender
45da581551 Use ::class to resolve class names in tests
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: Ie541a7baae10ab6f5c13f95ac2ff6598b8f8950c
2018-01-26 22:49:13 +01:00
Marius Hoch
cc433d1ff1 ExtensionRegistry: Properly detect if a global is already set
$foo = null; isset( $foo ); will yield false.

Sometimes we want to explicitly set a config to null, but ExtensionRegistry
is then overriding this variable with the default value.

This is no consistent with the old workflow:
require_once the extension and then override the setting with null.

Bug: T128661
Change-Id: I0654c9369a596e84591fcaa9643703e6b4ccf57e
2018-01-23 10:44:28 -08:00
Roan Kattouw
a8e20be5f3 ExtensionRegistryTest: Illustrate priority in array_replace_recursive test case
When two keys have conflicting values, the value from extension.json wins
when using this merge strategy.

Change-Id: I0222682f3b3fb08f80afc7dda677da7bbfe8e5d1
2016-12-01 00:27:33 +00:00
Yuri Astrakhan
ab224f8211 Added array_replace_recursive merge strategy
For extension registry, add array_replace_recursive merge strategy,
as some extensions/configuration may prefer that to array_merge_recursive.

In some cases, configuration is merged from multiple extensions,
such as JsonConfig's $wgJsonConfigs configuration: ZeroBanner defines

	"JsonZeroConfig": {
		"namespace": 480,
		"nsName": "Zero",
		"isLocal": false,
		"cacheKey": "1"
	}

and mobile.php overrides it with
	$wgJsonConfigs['JsonZeroConfig']['isLocal'] = false;
	$wgJsonConfigs['JsonZeroConfig']['remote'] = [
		'url' => 'https://zero.wikimedia.org/w/api.php',
		'username' => $wmgZeroPortalApiUserName,
		'password' => $wmgZeroPortalApiPassword,
	];

Having identical value 'isLocal' would be converted into an array
if array_merge_recursive is used, but the replace strategy fixes it.

Change-Id: Ica6ddd0ae76f23e60de9b6235c6e2a3f2754a95d
2016-10-24 19:20:04 +00:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
victorbarbu
7489cdfc05 registration: Allow loading composer's autoloader if it exists
Extensions that have composer dependencies can set
 "load_composer_autoloader": true
to load "$dir/vendor/autoload.php" if it exists.

While it is recommended to use composer-merge-plugin to manage
composer dependencies for extensions, using a local autoloader
can be easier for development and is used by ExtensionDistributor.

Bug: T119766
Change-Id: Ib031bef17c8a7d708a5c7878e74967d19217bbc8
2015-12-29 23:20:17 +00:00
Kunal Mehta
0a83ef3cf7 registration: Fix merging of array_plus
We want the local configuration ($GLOBALS[$key]) to override the default
values ($val). This matches what `array_merge` does.

Bug: T112868
Change-Id: I9c333a1fa67d3f24e09ffed3072b2897389f6139
2015-09-17 10:29:02 -07:00
Kunal Mehta
1ebb0f5659 registration: Overhaul merging of globals
Instead of hardcoding specific global settings in ExtensionRegistry,
create specific "merge strategies" that are used to merge globals.

Merge strategies are set for core properties in the ExtensionProcessor,
and extensions can set them for their own configuration settings using
the magic "_merge_strategy" key.

The following merge strategies are included:
* array_merge_recursive - call `array_merge_recursive` on the two arrays
* array_plus - use the "+" operator to combine arrays, preserving
               integer keys
* array_plus_2d - A version of array_plus that works on 2d arrays, used
                  for merging arrays like $wgGroupPermissions
* array_merge - call `array_merge` (default)

This changes the merging of various namespaces related settings to use
array_plus so they actually work.

Bug: T107646
Change-Id: I64cb0553864e3b78b0f203333f58bb73b86a6434
2015-08-02 12:04:25 -07:00
Kunal Mehta
ce5a0c5cd2 registration: Don't override boolean false settings
Our optimization of !$GLOBALS[$key] was affecting settings where a true
setting was being disabled in LocalSettings.php. Now explicitly check it
is an array before overriding it.

Bug: T100767
Change-Id: Id5397e526d66559bfabe6065223b1181a8a9d31e
2015-06-03 08:03:20 -07:00
Kunal Mehta
048b148edb registration: Add test case to demonstrate T98347 is invalid
Change-Id: I0f5c1bfa0d83465beffb1cc5ebaa457169569228
2015-05-15 17:57:12 -07:00
umherirrender
14cc0fdf8e Avoid @backupGlobals in ExtensionRegistryTest
Change-Id: Ia2c764b1c1ee8cff64e1ccdb863e5ef7534a286a
2015-02-22 11:02:15 +01:00
Kunal Mehta
ad64077cbc Fix @backupGlobals annotation in ExtensionRegistryTest
Change-Id: I9a38354030eb2638d7988c0f903fb2181ec17cc6
2015-02-21 22:02:58 +00:00
Kunal Mehta
1b22e7783b registration: Improve merging of arrays
Currently we use array_merge_recursive when merging any array, which is really
only needed for merging $wgHooks entries, and causes issues when trying to
merge default settings if the config is already set.

$wgHooks and $wgGroupPermissions are now special cased when merging, and all
other arrays are just +='d.

Bug: T88665
Bug: T89364
Change-Id: I773a9463d4428aa618c17f848c01b24e04610e95
2015-02-16 23:12:32 +00:00