Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
<?php
|
|
|
|
|
|
2017-04-19 19:37:35 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
class ExtensionProcessorTest extends MediaWikiTestCase {
|
|
|
|
|
|
2016-07-22 22:08:21 +00:00
|
|
|
private $dir, $dirname;
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
$this->dir = __DIR__ . '/FooBar/extension.json';
|
2016-07-22 22:08:21 +00:00
|
|
|
$this->dirname = dirname( $this->dir );
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 'name' is absolutely required
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
2016-02-17 09:09:32 +00:00
|
|
|
public static $default = [
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
'name' => 'FooBar',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
|
2015-01-13 19:46:53 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ExtensionProcessor::extractInfo
|
|
|
|
|
*/
|
|
|
|
|
public function testExtractInfo() {
|
|
|
|
|
// Test that attributes that begin with @ are ignored
|
|
|
|
|
$processor = new ExtensionProcessor();
|
2016-02-17 09:09:32 +00:00
|
|
|
$processor->extractInfo( $this->dir, self::$default + [
|
|
|
|
|
'@metadata' => [ 'foobarbaz' ],
|
|
|
|
|
'AnAttribute' => [ 'omg' ],
|
|
|
|
|
'AutoloadClasses' => [ 'FooBar' => 'includes/FooBar.php' ],
|
|
|
|
|
], 1 );
|
2015-01-13 19:46:53 +00:00
|
|
|
|
|
|
|
|
$extracted = $processor->getExtractedInfo();
|
|
|
|
|
$attributes = $extracted['attributes'];
|
|
|
|
|
$this->assertArrayHasKey( 'AnAttribute', $attributes );
|
|
|
|
|
$this->assertArrayNotHasKey( '@metadata', $attributes );
|
2015-05-18 06:22:46 +00:00
|
|
|
$this->assertArrayNotHasKey( 'AutoloadClasses', $attributes );
|
2015-01-13 19:46:53 +00:00
|
|
|
}
|
|
|
|
|
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
public static function provideRegisterHooks() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$merge = [ ExtensionRegistry::MERGE_STRATEGY => 'array_merge_recursive' ];
|
2015-05-13 19:30:21 +00:00
|
|
|
// Format:
|
|
|
|
|
// Current $wgHooks
|
|
|
|
|
// Content in extension.json
|
|
|
|
|
// Expected value of $wgHooks
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
// No hooks
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[],
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
self::$default,
|
2015-08-01 07:38:27 +00:00
|
|
|
$merge,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2016-04-29 21:21:40 +00:00
|
|
|
// No current hooks, adding one for "FooBaz" in string format
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[],
|
|
|
|
|
[ 'Hooks' => [ 'FooBaz' => 'FooBazCallback' ] ] + self::$default,
|
|
|
|
|
[ 'FooBaz' => [ 'FooBazCallback' ] ] + $merge,
|
|
|
|
|
],
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
// Hook for "FooBaz", adding another one
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[ 'FooBaz' => [ 'PriorCallback' ] ],
|
|
|
|
|
[ 'Hooks' => [ 'FooBaz' => 'FooBazCallback' ] ] + self::$default,
|
|
|
|
|
[ 'FooBaz' => [ 'PriorCallback', 'FooBazCallback' ] ] + $merge,
|
|
|
|
|
],
|
2016-04-29 21:21:40 +00:00
|
|
|
// No current hooks, adding one for "FooBaz" in verbose array format
|
|
|
|
|
[
|
|
|
|
|
[],
|
|
|
|
|
[ 'Hooks' => [ 'FooBaz' => [ 'FooBazCallback' ] ] ] + self::$default,
|
|
|
|
|
[ 'FooBaz' => [ 'FooBazCallback' ] ] + $merge,
|
|
|
|
|
],
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
// Hook for "BarBaz", adding one for "FooBaz"
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[ 'BarBaz' => [ 'BarBazCallback' ] ],
|
|
|
|
|
[ 'Hooks' => [ 'FooBaz' => 'FooBazCallback' ] ] + self::$default,
|
|
|
|
|
[
|
|
|
|
|
'BarBaz' => [ 'BarBazCallback' ],
|
|
|
|
|
'FooBaz' => [ 'FooBazCallback' ],
|
|
|
|
|
] + $merge,
|
|
|
|
|
],
|
2015-05-13 19:30:21 +00:00
|
|
|
// Callbacks for FooBaz wrapped in an array
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[],
|
|
|
|
|
[ 'Hooks' => [ 'FooBaz' => [ 'Callback1' ] ] ] + self::$default,
|
|
|
|
|
[
|
|
|
|
|
'FooBaz' => [ 'Callback1' ],
|
|
|
|
|
] + $merge,
|
|
|
|
|
],
|
2015-05-13 19:30:21 +00:00
|
|
|
// Multiple callbacks for FooBaz hook
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[],
|
|
|
|
|
[ 'Hooks' => [ 'FooBaz' => [ 'Callback1', 'Callback2' ] ] ] + self::$default,
|
|
|
|
|
[
|
|
|
|
|
'FooBaz' => [ 'Callback1', 'Callback2' ],
|
|
|
|
|
] + $merge,
|
|
|
|
|
],
|
|
|
|
|
];
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ExtensionProcessor::extractHooks
|
|
|
|
|
* @dataProvider provideRegisterHooks
|
|
|
|
|
*/
|
|
|
|
|
public function testRegisterHooks( $pre, $info, $expected ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$processor = new MockExtensionProcessor( [ 'wgHooks' => $pre ] );
|
2015-05-20 01:45:10 +00:00
|
|
|
$processor->extractInfo( $this->dir, $info, 1 );
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
$extracted = $processor->getExtractedInfo();
|
|
|
|
|
$this->assertEquals( $expected, $extracted['globals']['wgHooks'] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-07-20 06:05:35 +00:00
|
|
|
* @covers ExtensionProcessor::extractConfig1
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
*/
|
2016-07-22 22:08:21 +00:00
|
|
|
public function testExtractConfig1() {
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
$processor = new ExtensionProcessor;
|
2016-02-17 09:09:32 +00:00
|
|
|
$info = [
|
|
|
|
|
'config' => [
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
'Bar' => 'somevalue',
|
|
|
|
|
'Foo' => 10,
|
2015-01-27 07:00:07 +00:00
|
|
|
'@IGNORED' => 'yes',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
] + self::$default;
|
|
|
|
|
$info2 = [
|
|
|
|
|
'config' => [
|
2015-08-23 22:56:59 +00:00
|
|
|
'_prefix' => 'eg',
|
|
|
|
|
'Bar' => 'somevalue'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2015-12-30 01:52:11 +00:00
|
|
|
'name' => 'FooBar2',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2015-05-20 01:45:10 +00:00
|
|
|
$processor->extractInfo( $this->dir, $info, 1 );
|
2015-08-23 22:56:59 +00:00
|
|
|
$processor->extractInfo( $this->dir, $info2, 1 );
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
$extracted = $processor->getExtractedInfo();
|
|
|
|
|
$this->assertEquals( 'somevalue', $extracted['globals']['wgBar'] );
|
|
|
|
|
$this->assertEquals( 10, $extracted['globals']['wgFoo'] );
|
2015-01-27 07:00:07 +00:00
|
|
|
$this->assertArrayNotHasKey( 'wg@IGNORED', $extracted['globals'] );
|
2015-08-23 22:56:59 +00:00
|
|
|
// Custom prefix:
|
|
|
|
|
$this->assertEquals( 'somevalue', $extracted['globals']['egBar'] );
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
2016-07-22 22:08:21 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ExtensionProcessor::extractConfig2
|
|
|
|
|
*/
|
|
|
|
|
public function testExtractConfig2() {
|
|
|
|
|
$processor = new ExtensionProcessor;
|
|
|
|
|
$info = [
|
|
|
|
|
'config' => [
|
|
|
|
|
'Bar' => [ 'value' => 'somevalue' ],
|
|
|
|
|
'Foo' => [ 'value' => 10 ],
|
|
|
|
|
'Path' => [ 'value' => 'foo.txt', 'path' => true ],
|
|
|
|
|
],
|
|
|
|
|
] + self::$default;
|
|
|
|
|
$info2 = [
|
|
|
|
|
'config' => [
|
|
|
|
|
'Bar' => [ 'value' => 'somevalue' ],
|
|
|
|
|
],
|
|
|
|
|
'config_prefix' => 'eg',
|
|
|
|
|
'name' => 'FooBar2',
|
|
|
|
|
];
|
|
|
|
|
$processor->extractInfo( $this->dir, $info, 2 );
|
|
|
|
|
$processor->extractInfo( $this->dir, $info2, 2 );
|
|
|
|
|
$extracted = $processor->getExtractedInfo();
|
|
|
|
|
$this->assertEquals( 'somevalue', $extracted['globals']['wgBar'] );
|
|
|
|
|
$this->assertEquals( 10, $extracted['globals']['wgFoo'] );
|
|
|
|
|
$this->assertEquals( "{$this->dirname}/foo.txt", $extracted['globals']['wgPath'] );
|
|
|
|
|
// Custom prefix:
|
|
|
|
|
$this->assertEquals( 'somevalue', $extracted['globals']['egBar'] );
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-23 03:18:31 +00:00
|
|
|
public static function provideExtractExtensionMessagesFiles() {
|
2015-02-06 23:02:26 +00:00
|
|
|
$dir = __DIR__ . '/FooBar/';
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
[ 'ExtensionMessagesFiles' => [ 'FooBarAlias' => 'FooBar.alias.php' ] ],
|
|
|
|
|
[ 'wgExtensionMessagesFiles' => [ 'FooBarAlias' => $dir . 'FooBar.alias.php' ] ]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'ExtensionMessagesFiles' => [
|
2015-02-06 23:02:26 +00:00
|
|
|
'FooBarAlias' => 'FooBar.alias.php',
|
|
|
|
|
'FooBarMagic' => 'FooBar.magic.i18n.php',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'wgExtensionMessagesFiles' => [
|
2015-02-06 23:02:26 +00:00
|
|
|
'FooBarAlias' => $dir . 'FooBar.alias.php',
|
|
|
|
|
'FooBarMagic' => $dir . 'FooBar.magic.i18n.php',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
2015-02-06 23:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-02-23 03:18:31 +00:00
|
|
|
* @covers ExtensionProcessor::extractExtensionMessagesFiles
|
|
|
|
|
* @dataProvider provideExtractExtensionMessagesFiles
|
2015-02-06 23:02:26 +00:00
|
|
|
*/
|
2016-02-23 03:18:31 +00:00
|
|
|
public function testExtractExtensionMessagesFiles( $input, $expected ) {
|
2015-02-06 23:02:26 +00:00
|
|
|
$processor = new ExtensionProcessor();
|
2015-05-20 01:45:10 +00:00
|
|
|
$processor->extractInfo( $this->dir, $input + self::$default, 1 );
|
2015-02-06 23:02:26 +00:00
|
|
|
$out = $processor->getExtractedInfo();
|
|
|
|
|
foreach ( $expected as $key => $value ) {
|
|
|
|
|
$this->assertEquals( $value, $out['globals'][$key] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideExtractMessagesDirs() {
|
2015-01-30 20:56:02 +00:00
|
|
|
$dir = __DIR__ . '/FooBar/';
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
[ 'MessagesDirs' => [ 'VisualEditor' => 'i18n' ] ],
|
|
|
|
|
[ 'wgMessagesDirs' => [ 'VisualEditor' => [ $dir . 'i18n' ] ] ]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[ 'MessagesDirs' => [ 'VisualEditor' => [ 'i18n', 'foobar' ] ] ],
|
|
|
|
|
[ 'wgMessagesDirs' => [ 'VisualEditor' => [ $dir . 'i18n', $dir . 'foobar' ] ] ]
|
|
|
|
|
],
|
|
|
|
|
];
|
2015-01-30 20:56:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-02-06 23:02:26 +00:00
|
|
|
* @covers ExtensionProcessor::extractMessagesDirs
|
|
|
|
|
* @dataProvider provideExtractMessagesDirs
|
2015-01-30 20:56:02 +00:00
|
|
|
*/
|
2015-02-06 23:02:26 +00:00
|
|
|
public function testExtractMessagesDirs( $input, $expected ) {
|
2015-01-30 20:56:02 +00:00
|
|
|
$processor = new ExtensionProcessor();
|
2015-05-20 01:45:10 +00:00
|
|
|
$processor->extractInfo( $this->dir, $input + self::$default, 1 );
|
2015-01-30 20:56:02 +00:00
|
|
|
$out = $processor->getExtractedInfo();
|
|
|
|
|
foreach ( $expected as $key => $value ) {
|
|
|
|
|
$this->assertEquals( $value, $out['globals'][$key] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-30 01:52:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ExtensionProcessor::extractCredits
|
|
|
|
|
*/
|
|
|
|
|
public function testExtractCredits() {
|
|
|
|
|
$processor = new ExtensionProcessor();
|
|
|
|
|
$processor->extractInfo( $this->dir, self::$default, 1 );
|
|
|
|
|
$this->setExpectedException( 'Exception' );
|
|
|
|
|
$processor->extractInfo( $this->dir, self::$default, 1 );
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-06 09:46:05 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ExtensionProcessor::extractResourceLoaderModules
|
|
|
|
|
* @dataProvider provideExtractResourceLoaderModules
|
|
|
|
|
*/
|
|
|
|
|
public function testExtractResourceLoaderModules( $input, $expected ) {
|
|
|
|
|
$processor = new ExtensionProcessor();
|
2015-05-20 01:45:10 +00:00
|
|
|
$processor->extractInfo( $this->dir, $input + self::$default, 1 );
|
2015-02-06 09:46:05 +00:00
|
|
|
$out = $processor->getExtractedInfo();
|
|
|
|
|
foreach ( $expected as $key => $value ) {
|
|
|
|
|
$this->assertEquals( $value, $out['globals'][$key] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideExtractResourceLoaderModules() {
|
2016-02-16 20:39:34 +00:00
|
|
|
$dir = __DIR__ . '/FooBar';
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2015-02-06 09:46:05 +00:00
|
|
|
// Generic module with localBasePath/remoteExtPath specified
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2015-02-06 09:46:05 +00:00
|
|
|
// Input
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
'ResourceModules' => [
|
|
|
|
|
'test.foo' => [
|
2015-02-06 09:46:05 +00:00
|
|
|
'styles' => 'foobar.js',
|
|
|
|
|
'localBasePath' => '',
|
|
|
|
|
'remoteExtPath' => 'FooBar',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
2015-02-06 09:46:05 +00:00
|
|
|
// Expected
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
'wgResourceModules' => [
|
|
|
|
|
'test.foo' => [
|
2015-02-06 09:46:05 +00:00
|
|
|
'styles' => 'foobar.js',
|
|
|
|
|
'localBasePath' => $dir,
|
|
|
|
|
'remoteExtPath' => 'FooBar',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
2015-02-06 09:46:05 +00:00
|
|
|
// ResourceFileModulePaths specified:
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2015-02-06 09:46:05 +00:00
|
|
|
// Input
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
'ResourceFileModulePaths' => [
|
2015-02-06 09:46:05 +00:00
|
|
|
'localBasePath' => '',
|
|
|
|
|
'remoteExtPath' => 'FooBar',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'ResourceModules' => [
|
2015-02-06 09:46:05 +00:00
|
|
|
// No paths
|
2016-02-17 09:09:32 +00:00
|
|
|
'test.foo' => [
|
2015-02-06 09:46:05 +00:00
|
|
|
'styles' => 'foo.js',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2015-02-06 09:46:05 +00:00
|
|
|
// Different paths set
|
2016-02-17 09:09:32 +00:00
|
|
|
'test.bar' => [
|
2015-02-06 09:46:05 +00:00
|
|
|
'styles' => 'bar.js',
|
|
|
|
|
'localBasePath' => 'subdir',
|
|
|
|
|
'remoteExtPath' => 'FooBar/subdir',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2015-02-06 09:46:05 +00:00
|
|
|
// Custom class with no paths set
|
2016-02-17 09:09:32 +00:00
|
|
|
'test.class' => [
|
2015-02-06 09:46:05 +00:00
|
|
|
'class' => 'FooBarModule',
|
|
|
|
|
'extra' => 'argument',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2015-02-06 09:46:05 +00:00
|
|
|
// Custom class with a localBasePath
|
2016-02-17 09:09:32 +00:00
|
|
|
'test.class.with.path' => [
|
2015-02-06 09:46:05 +00:00
|
|
|
'class' => 'FooBarPathModule',
|
|
|
|
|
'extra' => 'argument',
|
|
|
|
|
'localBasePath' => '',
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
],
|
2015-02-06 09:46:05 +00:00
|
|
|
// Expected
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
'wgResourceModules' => [
|
|
|
|
|
'test.foo' => [
|
2015-02-06 09:46:05 +00:00
|
|
|
'styles' => 'foo.js',
|
|
|
|
|
'localBasePath' => $dir,
|
|
|
|
|
'remoteExtPath' => 'FooBar',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'test.bar' => [
|
2015-02-06 09:46:05 +00:00
|
|
|
'styles' => 'bar.js',
|
2016-02-16 20:39:34 +00:00
|
|
|
'localBasePath' => "$dir/subdir",
|
2015-02-06 09:46:05 +00:00
|
|
|
'remoteExtPath' => 'FooBar/subdir',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'test.class' => [
|
2015-02-06 09:46:05 +00:00
|
|
|
'class' => 'FooBarModule',
|
|
|
|
|
'extra' => 'argument',
|
2015-02-11 00:43:12 +00:00
|
|
|
'localBasePath' => $dir,
|
|
|
|
|
'remoteExtPath' => 'FooBar',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'test.class.with.path' => [
|
2015-02-06 09:46:05 +00:00
|
|
|
'class' => 'FooBarPathModule',
|
|
|
|
|
'extra' => 'argument',
|
|
|
|
|
'localBasePath' => $dir,
|
2015-02-11 00:43:12 +00:00
|
|
|
'remoteExtPath' => 'FooBar',
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
2015-04-02 17:12:52 +00:00
|
|
|
// ResourceModuleSkinStyles with file module paths
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2015-04-02 17:12:52 +00:00
|
|
|
// Input
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
'ResourceFileModulePaths' => [
|
2015-04-02 17:12:52 +00:00
|
|
|
'localBasePath' => '',
|
|
|
|
|
'remoteSkinPath' => 'FooBar',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'ResourceModuleSkinStyles' => [
|
|
|
|
|
'foobar' => [
|
2015-04-02 17:12:52 +00:00
|
|
|
'test.foo' => 'foo.css',
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
],
|
2015-04-02 17:12:52 +00:00
|
|
|
// Expected
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
'wgResourceModuleSkinStyles' => [
|
|
|
|
|
'foobar' => [
|
2015-04-02 17:12:52 +00:00
|
|
|
'test.foo' => 'foo.css',
|
|
|
|
|
'localBasePath' => $dir,
|
|
|
|
|
'remoteSkinPath' => 'FooBar',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
2015-04-02 17:12:52 +00:00
|
|
|
// ResourceModuleSkinStyles with file module paths and an override
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2015-04-02 17:12:52 +00:00
|
|
|
// Input
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
'ResourceFileModulePaths' => [
|
2015-04-02 17:12:52 +00:00
|
|
|
'localBasePath' => '',
|
|
|
|
|
'remoteSkinPath' => 'FooBar',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'ResourceModuleSkinStyles' => [
|
|
|
|
|
'foobar' => [
|
2015-04-02 17:12:52 +00:00
|
|
|
'test.foo' => 'foo.css',
|
|
|
|
|
'remoteSkinPath' => 'BarFoo'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
2015-04-02 17:12:52 +00:00
|
|
|
// Expected
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
'wgResourceModuleSkinStyles' => [
|
|
|
|
|
'foobar' => [
|
2015-04-02 17:12:52 +00:00
|
|
|
'test.foo' => 'foo.css',
|
|
|
|
|
'localBasePath' => $dir,
|
|
|
|
|
'remoteSkinPath' => 'BarFoo',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
2015-02-06 09:46:05 +00:00
|
|
|
}
|
|
|
|
|
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
public static function provideSetToGlobal() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
[ 'wgAPIModules', 'wgAvailableRights' ],
|
|
|
|
|
[],
|
|
|
|
|
[
|
|
|
|
|
'APIModules' => [ 'foobar' => 'ApiFooBar' ],
|
|
|
|
|
'AvailableRights' => [ 'foobar', 'unfoobar' ],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'wgAPIModules' => [ 'foobar' => 'ApiFooBar' ],
|
|
|
|
|
'wgAvailableRights' => [ 'foobar', 'unfoobar' ],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[ 'wgAPIModules', 'wgAvailableRights' ],
|
|
|
|
|
[
|
|
|
|
|
'wgAPIModules' => [ 'barbaz' => 'ApiBarBaz' ],
|
|
|
|
|
'wgAvailableRights' => [ 'barbaz' ]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'APIModules' => [ 'foobar' => 'ApiFooBar' ],
|
|
|
|
|
'AvailableRights' => [ 'foobar', 'unfoobar' ],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'wgAPIModules' => [ 'barbaz' => 'ApiBarBaz', 'foobar' => 'ApiFooBar' ],
|
|
|
|
|
'wgAvailableRights' => [ 'barbaz', 'foobar', 'unfoobar' ],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[ 'wgGroupPermissions' ],
|
|
|
|
|
[
|
|
|
|
|
'wgGroupPermissions' => [
|
|
|
|
|
'sysop' => [ 'delete' ]
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'GroupPermissions' => [
|
|
|
|
|
'sysop' => [ 'undelete' ],
|
|
|
|
|
'user' => [ 'edit' ]
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'wgGroupPermissions' => [
|
|
|
|
|
'sysop' => [ 'delete', 'undelete' ],
|
|
|
|
|
'user' => [ 'edit' ]
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
}
|
2016-06-10 20:11:01 +00:00
|
|
|
|
|
|
|
|
public function testGlobalSettingsDocumentedInSchema() {
|
|
|
|
|
global $IP;
|
|
|
|
|
$globalSettings = TestingAccessWrapper::newFromClass(
|
|
|
|
|
ExtensionProcessor::class )->globalSettings;
|
|
|
|
|
|
2016-12-16 19:32:26 +00:00
|
|
|
$version = ExtensionRegistry::MANIFEST_VERSION;
|
2016-06-10 20:11:01 +00:00
|
|
|
$schema = FormatJson::decode(
|
2016-12-16 19:32:26 +00:00
|
|
|
file_get_contents( "$IP/docs/extension.schema.v$version.json" ),
|
2016-06-10 20:11:01 +00:00
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
$missing = [];
|
|
|
|
|
foreach ( $globalSettings as $global ) {
|
|
|
|
|
if ( !isset( $schema['properties'][$global] ) ) {
|
|
|
|
|
$missing[] = $global;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( [], $missing,
|
|
|
|
|
"The following global settings are not documented in docs/extension.schema.json" );
|
|
|
|
|
}
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Allow overriding the default value of $this->globals
|
|
|
|
|
* so we can test merging
|
|
|
|
|
*/
|
|
|
|
|
class MockExtensionProcessor extends ExtensionProcessor {
|
2016-02-17 09:09:32 +00:00
|
|
|
public function __construct( $globals = [] ) {
|
Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.
Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.
The basic flow of loading an extension goes like:
* Get the ExtensionRegistry singleton instance
* ExtensionRegistry takes a filename, reads the file or tries
to get the parsed JSON from APC if possible.
* The JSON is run through a Processor instance,
which registers things with the appropriate
global settings.
* The output of the processor is cached in APC if possible.
* The extension/skin is marked as loaded in the
ExtensionRegistry and a callback function is executed
if one was specified.
For ideal performance, a batch loading method is also provided:
* The absolute path name to the JSON file is queued
in the ExtensionRegistry instance.
* When loadFromQueue() is called, it constructs a hash
unique to the members of the current queue, and sees
if the queue has been cached in APC. If not, it processes
each file individually, and combines the result of each
Processor into one giant array, which is cached in APC.
* The giant array then sets various global settings,
defines constants, and calls callbacks.
To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.
Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2014-10-15 00:31:15 +00:00
|
|
|
$this->globals = $globals + $this->globals;
|
|
|
|
|
}
|
|
|
|
|
}
|