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
|
|
|
|
|
|
2022-03-09 17:39:03 +00:00
|
|
|
namespace MediaWiki\Tests\Registration;
|
|
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
|
use ExtensionProcessor;
|
|
|
|
|
use ExtensionRegistry;
|
|
|
|
|
use FormatJson;
|
|
|
|
|
use InvalidArgumentException;
|
|
|
|
|
use MediaWikiUnitTestCase;
|
|
|
|
|
use RuntimeException;
|
|
|
|
|
use UnexpectedValueException;
|
2017-04-19 19:37:35 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
2018-02-10 06:03:42 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ExtensionProcessor
|
|
|
|
|
*/
|
2022-03-09 17:39:03 +00:00
|
|
|
class ExtensionProcessorTest extends MediaWikiUnitTestCase {
|
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
|
|
|
|
2022-03-24 14:18:07 +00:00
|
|
|
private $extensionPath, $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
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
protected function setUp(): void {
|
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
|
|
|
parent::setUp();
|
2022-03-24 14:18:07 +00:00
|
|
|
$this->extensionPath = self::getExtensionPath();
|
|
|
|
|
$this->dirname = dirname( $this->extensionPath );
|
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
|
|
|
}
|
|
|
|
|
|
2022-03-24 14:18:07 +00:00
|
|
|
private static function getExtensionPath() {
|
|
|
|
|
return __DIR__ . '/fixtures/FooBar/extension.json';
|
2020-02-10 14:47:46 +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
|
|
|
/**
|
|
|
|
|
* '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
|
|
|
|
2020-04-30 19:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* 'name' is absolutely required, and sometimes we require two distinct ones...
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
public static $default2 = [
|
|
|
|
|
'name' => 'FooBar2',
|
|
|
|
|
];
|
|
|
|
|
|
2015-01-13 19:46:53 +00:00
|
|
|
public function testExtractInfo() {
|
|
|
|
|
// Test that attributes that begin with @ are ignored
|
|
|
|
|
$processor = new ExtensionProcessor();
|
2022-03-24 14:18:07 +00:00
|
|
|
$processor->extractInfo( $this->extensionPath, self::$default + [
|
2016-02-17 09:09:32 +00:00
|
|
|
'@metadata' => [ 'foobarbaz' ],
|
|
|
|
|
'AnAttribute' => [ 'omg' ],
|
|
|
|
|
'AutoloadClasses' => [ 'FooBar' => 'includes/FooBar.php' ],
|
2022-03-24 14:18:07 +00:00
|
|
|
'AutoloadNamespaces' => [ '\Foo\Bar\\' => 'includes/foo/bar/' ],
|
2018-02-10 06:03:42 +00:00
|
|
|
'SpecialPages' => [ 'Foo' => 'SpecialFoo' ],
|
|
|
|
|
'callback' => 'FooBar::onRegistration',
|
2016-02-17 09:09:32 +00:00
|
|
|
], 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 );
|
2022-03-24 14:18:07 +00:00
|
|
|
$this->assertArrayNotHasKey( 'AutoloadNamespaces', $attributes );
|
|
|
|
|
$this->assertArrayHasKey( 'autoloaderPaths', $extracted );
|
|
|
|
|
$this->assertArrayHasKey( 'autoloaderClasses', $extracted );
|
|
|
|
|
$this->assertArrayHasKey( 'autoloaderNS', $extracted );
|
2018-02-10 06:03:42 +00:00
|
|
|
$this->assertSame(
|
|
|
|
|
[ 'FooBar' => 'FooBar::onRegistration' ],
|
|
|
|
|
$extracted['callbacks']
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[ 'Foo' => 'SpecialFoo' ],
|
|
|
|
|
$extracted['globals']['wgSpecialPages']
|
|
|
|
|
);
|
2015-01-13 19:46:53 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-24 14:18:07 +00:00
|
|
|
public function testExtractAutoload() {
|
|
|
|
|
// Test that attributes that begin with @ are ignored
|
|
|
|
|
$processor = new ExtensionProcessor();
|
|
|
|
|
$processor->extractInfo( $this->extensionPath, self::$default + [
|
|
|
|
|
'AutoloadClasses' => [ 'FooBar' => 'includes/FooBar.php' ],
|
|
|
|
|
'AutoloadNamespaces' => [ '\Foo\Bar\\' => 'includes/foo/bar/' ],
|
|
|
|
|
'TestAutoloadClasses' => [ 'FooBarTest' => 'tests/FooBarTest.php' ],
|
|
|
|
|
'TestAutoloadNamespaces' => [ '\Foo\Bar\Test\\' => 'tests/foo/bar/' ],
|
|
|
|
|
'load_composer_autoloader' => true,
|
|
|
|
|
], 1 );
|
|
|
|
|
|
|
|
|
|
$extracted = $processor->getExtractedInfo();
|
|
|
|
|
$this->assertArrayHasKey( 'autoloaderPaths', $extracted );
|
|
|
|
|
$this->assertArrayHasKey( 'autoloaderClasses', $extracted );
|
|
|
|
|
$this->assertArrayHasKey( 'autoloaderNS', $extracted );
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[ 'FooBar' => $this->dirname . '/includes/FooBar.php' ],
|
|
|
|
|
$extracted['autoloaderClasses']
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[ '\Foo\Bar\\' => $this->dirname . '/includes/foo/bar/' ],
|
|
|
|
|
$extracted['autoloaderNS']
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[ $this->dirname . '/vendor/autoload.php' ],
|
|
|
|
|
$extracted['autoloaderPaths']
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$extracted = $processor->getExtractedInfo( true );
|
|
|
|
|
$this->assertArrayHasKey( 'autoloaderPaths', $extracted );
|
|
|
|
|
$this->assertArrayHasKey( 'autoloaderClasses', $extracted );
|
|
|
|
|
$this->assertArrayHasKey( 'autoloaderNS', $extracted );
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[
|
|
|
|
|
'FooBar' => $this->dirname . '/includes/FooBar.php',
|
|
|
|
|
'FooBarTest' => $this->dirname . '/tests/FooBarTest.php'
|
|
|
|
|
],
|
|
|
|
|
$extracted['autoloaderClasses']
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[
|
|
|
|
|
'\Foo\Bar\\' => $this->dirname . '/includes/foo/bar/',
|
|
|
|
|
'\Foo\Bar\Test\\' => $this->dirname . '/tests/foo/bar/'
|
|
|
|
|
],
|
|
|
|
|
$extracted['autoloaderNS']
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[ $this->dirname . '/vendor/autoload.php' ],
|
|
|
|
|
$extracted['autoloaderPaths']
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-13 19:39:48 +00:00
|
|
|
public function testExtractSkins() {
|
2021-08-17 17:33:43 +00:00
|
|
|
$this->expectDeprecation();
|
2021-08-13 19:39:48 +00:00
|
|
|
$processor = new ExtensionProcessor();
|
2022-03-24 14:18:07 +00:00
|
|
|
$processor->extractInfo( $this->extensionPath, self::$default + [
|
2021-08-13 19:39:48 +00:00
|
|
|
'ValidSkinNames' => [
|
|
|
|
|
'test-vector' => [
|
|
|
|
|
'class' => 'SkinTestVector',
|
|
|
|
|
],
|
|
|
|
|
'test-vector-empty-args' => [
|
|
|
|
|
'class' => 'SkinTestVector',
|
|
|
|
|
'args' => []
|
|
|
|
|
],
|
|
|
|
|
'test-vector-empty-options' => [
|
|
|
|
|
'class' => 'SkinTestVector',
|
|
|
|
|
'args' => [
|
|
|
|
|
[]
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'test-vector-core-relative' => [
|
|
|
|
|
'class' => 'SkinTestVector',
|
|
|
|
|
'args' => [
|
|
|
|
|
[
|
|
|
|
|
'templateDirectory' => 'skins/Vector/templates',
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'test-vector-skin-relative' => [
|
|
|
|
|
'class' => 'SkinTestVector',
|
|
|
|
|
'args' => [
|
|
|
|
|
[
|
|
|
|
|
'templateDirectory' => 'templates',
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
], 1 );
|
|
|
|
|
$extracted = $processor->getExtractedInfo();
|
|
|
|
|
$validSkins = $extracted['globals']['wgValidSkinNames'];
|
|
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'test-vector', $validSkins );
|
|
|
|
|
$this->assertArrayHasKey( 'test-vector-core-relative', $validSkins );
|
|
|
|
|
$this->assertArrayHasKey( 'test-vector-empty-args', $validSkins );
|
|
|
|
|
$this->assertArrayHasKey( 'test-vector-skin-relative', $validSkins );
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$this->dirname . '/templates',
|
|
|
|
|
$validSkins['test-vector-empty-options']['args'][0]['templateDirectory'],
|
|
|
|
|
'A sensible default is provided.'
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
'skins/Vector/templates',
|
|
|
|
|
$validSkins['test-vector-core-relative']['args'][0]['templateDirectory'],
|
|
|
|
|
'unmodified'
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$this->dirname . '/templates',
|
|
|
|
|
$validSkins['test-vector-skin-relative']['args'][0]['templateDirectory'],
|
|
|
|
|
'modified'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-10 06:03:42 +00:00
|
|
|
public function testExtractNamespaces() {
|
2020-03-16 15:55:45 +00:00
|
|
|
// Test that namespace IDs defined in extension.json can be overwritten locally
|
2017-05-10 16:00:38 +00:00
|
|
|
if ( !defined( 'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X' ) ) {
|
|
|
|
|
define( 'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X', 123456 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$processor = new ExtensionProcessor();
|
2022-03-24 14:18:07 +00:00
|
|
|
$processor->extractInfo( $this->extensionPath, self::$default + [
|
2017-05-10 16:00:38 +00:00
|
|
|
'namespaces' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => 332200,
|
|
|
|
|
'constant' => 'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_A',
|
|
|
|
|
'name' => 'Test_A',
|
2018-02-10 06:03:42 +00:00
|
|
|
'defaultcontentmodel' => 'TestModel',
|
|
|
|
|
'gender' => [
|
|
|
|
|
'male' => 'Male test',
|
|
|
|
|
'female' => 'Female test',
|
|
|
|
|
],
|
|
|
|
|
'subpages' => true,
|
|
|
|
|
'content' => true,
|
|
|
|
|
'protection' => 'userright',
|
2017-05-10 16:00:38 +00:00
|
|
|
],
|
|
|
|
|
[ // Test_X will use ID 123456 not 334400
|
|
|
|
|
'id' => 334400,
|
|
|
|
|
'constant' => 'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X',
|
|
|
|
|
'name' => 'Test_X',
|
2018-02-10 06:03:42 +00:00
|
|
|
'defaultcontentmodel' => 'TestModel'
|
2017-05-10 16:00:38 +00:00
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
], 1 );
|
|
|
|
|
|
|
|
|
|
$extracted = $processor->getExtractedInfo();
|
|
|
|
|
|
|
|
|
|
$this->assertArrayHasKey(
|
|
|
|
|
'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_A',
|
|
|
|
|
$extracted['defines']
|
|
|
|
|
);
|
2020-03-16 15:55:45 +00:00
|
|
|
$this->assertArrayHasKey(
|
2017-05-10 16:00:38 +00:00
|
|
|
'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X',
|
|
|
|
|
$extracted['defines']
|
|
|
|
|
);
|
|
|
|
|
|
2020-03-16 15:55:45 +00:00
|
|
|
$this->assertSame(
|
2021-08-04 17:26:57 +00:00
|
|
|
123456,
|
|
|
|
|
$extracted['defines']['MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X']
|
2020-03-16 15:55:45 +00:00
|
|
|
);
|
|
|
|
|
|
2017-05-10 16:00:38 +00:00
|
|
|
$this->assertSame(
|
2021-08-04 17:26:57 +00:00
|
|
|
332200,
|
|
|
|
|
$extracted['defines']['MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_A']
|
2017-05-10 16:00:38 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'ExtensionNamespaces', $extracted['attributes'] );
|
|
|
|
|
$this->assertArrayHasKey( 123456, $extracted['attributes']['ExtensionNamespaces'] );
|
|
|
|
|
$this->assertArrayHasKey( 332200, $extracted['attributes']['ExtensionNamespaces'] );
|
|
|
|
|
$this->assertArrayNotHasKey( 334400, $extracted['attributes']['ExtensionNamespaces'] );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( 'Test_X', $extracted['attributes']['ExtensionNamespaces'][123456] );
|
|
|
|
|
$this->assertSame( 'Test_A', $extracted['attributes']['ExtensionNamespaces'][332200] );
|
2018-02-10 06:03:42 +00:00
|
|
|
$this->assertSame(
|
|
|
|
|
[ 'male' => 'Male test', 'female' => 'Female test' ],
|
|
|
|
|
$extracted['globals']['wgExtraGenderNamespaces'][332200]
|
|
|
|
|
);
|
|
|
|
|
// A has subpages, X does not
|
|
|
|
|
$this->assertTrue( $extracted['globals']['wgNamespacesWithSubpages'][332200] );
|
|
|
|
|
$this->assertArrayNotHasKey( 123456, $extracted['globals']['wgNamespacesWithSubpages'] );
|
2017-05-10 16:00:38 +00:00
|
|
|
}
|
|
|
|
|
|
2020-02-10 14:47:46 +00:00
|
|
|
public function provideMixedStyleHooks() {
|
|
|
|
|
// Format:
|
|
|
|
|
// Content in extension.json
|
|
|
|
|
// Expected wgHooks
|
|
|
|
|
// Expected Hooks
|
|
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'Hooks' => [ 'FooBaz' => [
|
|
|
|
|
[ 'handler' => 'HandlerObjectCallback' ],
|
|
|
|
|
[ 'handler' => 'HandlerObjectCallback', 'deprecated' => true ],
|
|
|
|
|
'HandlerObjectCallback',
|
|
|
|
|
[ 'FooClass', 'FooMethod' ],
|
|
|
|
|
'GlobalLegacyFunction',
|
|
|
|
|
'FooClass',
|
|
|
|
|
"FooClass::staticMethod"
|
|
|
|
|
] ],
|
|
|
|
|
'HookHandlers' => [
|
|
|
|
|
'HandlerObjectCallback' => [ 'class' => 'FooClass', 'services' => [] ]
|
|
|
|
|
]
|
|
|
|
|
] + self::$default,
|
|
|
|
|
[
|
|
|
|
|
'FooBaz' => [
|
|
|
|
|
[ 'FooClass', 'FooMethod' ],
|
|
|
|
|
'GlobalLegacyFunction',
|
|
|
|
|
'FooClass',
|
|
|
|
|
'FooClass::staticMethod'
|
|
|
|
|
]
|
|
|
|
|
] + [ ExtensionRegistry::MERGE_STRATEGY => 'array_merge_recursive' ],
|
|
|
|
|
[
|
|
|
|
|
'FooBaz' => [
|
2020-04-16 06:20:16 +00:00
|
|
|
[
|
|
|
|
|
'handler' => [
|
|
|
|
|
'class' => 'FooClass',
|
|
|
|
|
'services' => [],
|
|
|
|
|
'name' => 'FooBar-HandlerObjectCallback'
|
|
|
|
|
],
|
2022-03-24 14:18:07 +00:00
|
|
|
'extensionPath' => $this->getExtensionPath()
|
2020-04-16 06:20:16 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'handler' => [
|
|
|
|
|
'class' => 'FooClass',
|
|
|
|
|
'services' => [],
|
|
|
|
|
'name' => 'FooBar-HandlerObjectCallback'
|
|
|
|
|
],
|
|
|
|
|
'deprecated' => true,
|
2022-03-24 14:18:07 +00:00
|
|
|
'extensionPath' => $this->getExtensionPath()
|
2020-04-16 06:20:16 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'handler' => [
|
|
|
|
|
'class' => 'FooClass',
|
|
|
|
|
'services' => [],
|
|
|
|
|
'name' => 'FooBar-HandlerObjectCallback'
|
|
|
|
|
],
|
2022-03-24 14:18:07 +00:00
|
|
|
'extensionPath' => $this->getExtensionPath()
|
2020-04-16 06:20:16 +00:00
|
|
|
]
|
2020-02-10 14:47:46 +00:00
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideNonLegacyHooks() {
|
|
|
|
|
// Format:
|
|
|
|
|
// Current Hooks attribute
|
|
|
|
|
// Content in extension.json
|
|
|
|
|
// Expected Hooks attribute
|
|
|
|
|
return [
|
|
|
|
|
// Hook for "FooBaz": object with handler attribute
|
|
|
|
|
[
|
|
|
|
|
[ 'FooBaz' => [ 'PriorCallback' ] ],
|
|
|
|
|
[
|
|
|
|
|
'Hooks' => [ 'FooBaz' => [ 'handler' => 'HandlerObjectCallback', 'deprecated' => true ] ],
|
|
|
|
|
'HookHandlers' => [
|
|
|
|
|
'HandlerObjectCallback' => [
|
|
|
|
|
'class' => 'FooClass',
|
|
|
|
|
'services' => [],
|
2020-04-16 06:20:16 +00:00
|
|
|
'name' => 'FooBar-HandlerObjectCallback'
|
2020-02-10 14:47:46 +00:00
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
] + self::$default,
|
|
|
|
|
[ 'FooBaz' =>
|
|
|
|
|
[
|
|
|
|
|
'PriorCallback',
|
|
|
|
|
[
|
|
|
|
|
'handler' => [
|
|
|
|
|
'class' => 'FooClass',
|
|
|
|
|
'services' => [],
|
2020-04-16 06:20:16 +00:00
|
|
|
'name' => 'FooBar-HandlerObjectCallback'
|
2020-02-10 14:47:46 +00:00
|
|
|
],
|
2020-04-16 06:20:16 +00:00
|
|
|
'deprecated' => true,
|
2022-03-24 14:18:07 +00:00
|
|
|
'extensionPath' => $this->getExtensionPath()
|
2020-02-10 14:47:46 +00:00
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[]
|
|
|
|
|
],
|
|
|
|
|
// Hook for "FooBaz": string corresponding to a handler definition
|
|
|
|
|
[
|
|
|
|
|
[ 'FooBaz' => [ 'PriorCallback' ] ],
|
|
|
|
|
[
|
|
|
|
|
'Hooks' => [ 'FooBaz' => [ 'HandlerObjectCallback' ] ],
|
|
|
|
|
'HookHandlers' => [
|
|
|
|
|
'HandlerObjectCallback' => [ 'class' => 'FooClass', 'services' => [] ],
|
|
|
|
|
]
|
|
|
|
|
] + self::$default,
|
|
|
|
|
[ 'FooBaz' =>
|
|
|
|
|
[
|
|
|
|
|
'PriorCallback',
|
2020-04-16 06:20:16 +00:00
|
|
|
[
|
|
|
|
|
'handler' => [
|
|
|
|
|
'class' => 'FooClass',
|
|
|
|
|
'services' => [],
|
|
|
|
|
'name' => 'FooBar-HandlerObjectCallback'
|
|
|
|
|
],
|
2022-03-24 14:18:07 +00:00
|
|
|
'extensionPath' => $this->getExtensionPath()
|
2020-04-16 06:20:16 +00:00
|
|
|
],
|
2020-02-10 14:47:46 +00:00
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[]
|
|
|
|
|
],
|
|
|
|
|
// Hook for "FooBaz", string corresponds to handler def. and object with handler attribute
|
|
|
|
|
[
|
|
|
|
|
[ 'FooBaz' => [ 'PriorCallback' ] ],
|
|
|
|
|
[
|
|
|
|
|
'Hooks' => [ 'FooBaz' => [
|
|
|
|
|
[ 'handler' => 'HandlerObjectCallback', 'deprecated' => true ],
|
|
|
|
|
'HandlerObjectCallback2'
|
|
|
|
|
] ],
|
|
|
|
|
'HookHandlers' => [
|
|
|
|
|
'HandlerObjectCallback2' => [ 'class' => 'FooClass', 'services' => [] ],
|
|
|
|
|
'HandlerObjectCallback' => [ 'class' => 'FooClass', 'services' => [] ],
|
|
|
|
|
]
|
|
|
|
|
] + self::$default,
|
|
|
|
|
[ 'FooBaz' =>
|
|
|
|
|
[
|
|
|
|
|
'PriorCallback',
|
2020-04-16 06:20:16 +00:00
|
|
|
[
|
|
|
|
|
'handler' => [
|
|
|
|
|
'name' => 'FooBar-HandlerObjectCallback',
|
|
|
|
|
'class' => 'FooClass',
|
|
|
|
|
'services' => []
|
|
|
|
|
],
|
|
|
|
|
'deprecated' => true,
|
2022-03-24 14:18:07 +00:00
|
|
|
'extensionPath' => $this->getExtensionPath()
|
2020-04-16 06:20:16 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'handler' => [
|
|
|
|
|
'name' => 'FooBar-HandlerObjectCallback2',
|
|
|
|
|
'class' => 'FooClass',
|
|
|
|
|
'services' => [],
|
|
|
|
|
],
|
2022-03-24 14:18:07 +00:00
|
|
|
'extensionPath' => $this->getExtensionPath()
|
2020-04-16 06:20:16 +00:00
|
|
|
]
|
2020-02-10 14:47:46 +00:00
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[]
|
|
|
|
|
],
|
|
|
|
|
// Hook for "FooBaz": string corresponding to a new-style handler definition
|
|
|
|
|
// and legacy style object and method array
|
|
|
|
|
[
|
|
|
|
|
[ 'FooBaz' => [ 'PriorCallback' ] ],
|
|
|
|
|
[
|
|
|
|
|
'Hooks' => [ 'FooBaz' => [
|
|
|
|
|
'HandlerObjectCallback',
|
|
|
|
|
[ 'FooClass', 'FooMethod ' ]
|
|
|
|
|
] ],
|
|
|
|
|
'HookHandlers' => [
|
|
|
|
|
'HandlerObjectCallback' => [ 'class' => 'FooClass', 'services' => [] ],
|
|
|
|
|
]
|
|
|
|
|
] + self::$default,
|
|
|
|
|
[ 'FooBaz' =>
|
|
|
|
|
[
|
|
|
|
|
'PriorCallback',
|
2020-04-16 06:20:16 +00:00
|
|
|
[
|
|
|
|
|
'handler' => [
|
|
|
|
|
'name' => 'FooBar-HandlerObjectCallback',
|
|
|
|
|
'class' => 'FooClass',
|
|
|
|
|
'services' => []
|
|
|
|
|
],
|
2022-03-24 14:18:07 +00:00
|
|
|
'extensionPath' => $this->getExtensionPath()
|
2020-04-16 06:20:16 +00:00
|
|
|
],
|
2020-02-10 14:47:46 +00:00
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[ 'FooClass', 'FooMethod' ]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideLegacyHooks() {
|
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
|
|
|
}
|
|
|
|
|
|
2020-02-10 14:47:46 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideNonLegacyHooks
|
|
|
|
|
*/
|
|
|
|
|
public function testNonLegacyHooks( $pre, $info, $expected ) {
|
|
|
|
|
$processor = new MockExtensionProcessor( [ 'attributes' => [ 'Hooks' => $pre ] ] );
|
2022-03-24 14:18:07 +00:00
|
|
|
$processor->extractInfo( $this->extensionPath, $info, 1 );
|
2020-02-10 14:47:46 +00:00
|
|
|
$extracted = $processor->getExtractedInfo();
|
|
|
|
|
$this->assertEquals( $expected, $extracted['attributes']['Hooks'] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideMixedStyleHooks
|
|
|
|
|
*/
|
|
|
|
|
public function testMixedStyleHooks( $info, $expectedWgHooks, $expectedNewHooks ) {
|
|
|
|
|
$processor = new MockExtensionProcessor();
|
2022-03-24 14:18:07 +00:00
|
|
|
$processor->extractInfo( $this->extensionPath, $info, 1 );
|
2020-02-10 14:47:46 +00:00
|
|
|
$extracted = $processor->getExtractedInfo();
|
|
|
|
|
$this->assertEquals( $expectedWgHooks, $extracted['globals']['wgHooks'] );
|
|
|
|
|
$this->assertEquals( $expectedNewHooks, $extracted['attributes']['Hooks'] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideLegacyHooks
|
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
|
|
|
*/
|
2020-02-10 14:47:46 +00:00
|
|
|
public function testLegacyHooks( $pre, $info, $expected ) {
|
|
|
|
|
$preset = [ 'globals' => [ 'wgHooks' => $pre ] ];
|
|
|
|
|
$processor = new MockExtensionProcessor( $preset );
|
2022-03-24 14:18:07 +00:00
|
|
|
$processor->extractInfo( $this->extensionPath, $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'] );
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 14:47:46 +00:00
|
|
|
public function testRegisterHandlerWithoutDefinition() {
|
|
|
|
|
$info = [
|
|
|
|
|
'Hooks' => [ 'FooBaz' => [ 'handler' => 'NoHandlerDefinition' ] ],
|
|
|
|
|
'HookHandlers' => []
|
|
|
|
|
] + self::$default;
|
|
|
|
|
$processor = new MockExtensionProcessor();
|
2021-01-03 19:42:08 +00:00
|
|
|
$this->expectException( UnexpectedValueException::class );
|
2020-02-10 14:47:46 +00:00
|
|
|
$this->expectExceptionMessage(
|
|
|
|
|
'Missing handler definition for FooBaz in HookHandlers attribute'
|
|
|
|
|
);
|
2022-03-24 14:18:07 +00:00
|
|
|
$processor->extractInfo( $this->extensionPath, $info, 1 );
|
2020-02-10 14:47:46 +00:00
|
|
|
$processor->getExtractedInfo();
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 22:08:21 +00:00
|
|
|
public function testExtractConfig1() {
|
2020-04-30 18:39:29 +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
|
|
|
],
|
2020-04-30 19:46:11 +00:00
|
|
|
] + self::$default2;
|
2022-03-24 14:18:07 +00:00
|
|
|
$processor->extractInfo( $this->extensionPath, $info, 1 );
|
|
|
|
|
$processor->extractInfo( $this->extensionPath, $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
|
|
|
public function testExtractConfig2() {
|
2020-04-30 18:39:29 +00:00
|
|
|
$processor = new ExtensionProcessor();
|
2016-07-22 22:08:21 +00:00
|
|
|
$info = [
|
|
|
|
|
'config' => [
|
|
|
|
|
'Bar' => [ 'value' => 'somevalue' ],
|
|
|
|
|
'Foo' => [ 'value' => 10 ],
|
|
|
|
|
'Path' => [ 'value' => 'foo.txt', 'path' => true ],
|
2019-07-26 09:47:37 +00:00
|
|
|
'PathArray' => [ 'value' => [ 'foo.bar', 'bar.foo', 'bar/foo.txt' ], 'path' => true ],
|
2018-02-10 06:03:42 +00:00
|
|
|
'Namespaces' => [
|
|
|
|
|
'value' => [
|
|
|
|
|
'10' => true,
|
|
|
|
|
'12' => false,
|
|
|
|
|
],
|
|
|
|
|
'merge_strategy' => 'array_plus',
|
|
|
|
|
],
|
2016-07-22 22:08:21 +00:00
|
|
|
],
|
|
|
|
|
] + self::$default;
|
|
|
|
|
$info2 = [
|
|
|
|
|
'config' => [
|
|
|
|
|
'Bar' => [ 'value' => 'somevalue' ],
|
|
|
|
|
],
|
|
|
|
|
'config_prefix' => 'eg',
|
2020-04-30 19:46:11 +00:00
|
|
|
] + self::$default2;
|
2022-03-24 14:18:07 +00:00
|
|
|
$processor->extractInfo( $this->extensionPath, $info, 2 );
|
|
|
|
|
$processor->extractInfo( $this->extensionPath, $info2, 2 );
|
2016-07-22 22:08:21 +00:00
|
|
|
$extracted = $processor->getExtractedInfo();
|
|
|
|
|
$this->assertEquals( 'somevalue', $extracted['globals']['wgBar'] );
|
|
|
|
|
$this->assertEquals( 10, $extracted['globals']['wgFoo'] );
|
|
|
|
|
$this->assertEquals( "{$this->dirname}/foo.txt", $extracted['globals']['wgPath'] );
|
2019-07-26 09:47:37 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
[
|
|
|
|
|
"{$this->dirname}/foo.bar",
|
|
|
|
|
"{$this->dirname}/bar.foo",
|
|
|
|
|
"{$this->dirname}/bar/foo.txt"
|
|
|
|
|
],
|
|
|
|
|
$extracted['globals']['wgPathArray']
|
|
|
|
|
);
|
2016-07-22 22:08:21 +00:00
|
|
|
// Custom prefix:
|
|
|
|
|
$this->assertEquals( 'somevalue', $extracted['globals']['egBar'] );
|
2018-02-10 06:03:42 +00:00
|
|
|
$this->assertSame(
|
|
|
|
|
[ 10 => true, 12 => false, ExtensionRegistry::MERGE_STRATEGY => 'array_plus' ],
|
|
|
|
|
$extracted['globals']['wgNamespaces']
|
|
|
|
|
);
|
2016-07-22 22:08:21 +00:00
|
|
|
}
|
|
|
|
|
|
2017-08-28 15:03:47 +00:00
|
|
|
public function testDuplicateConfigKey1() {
|
2020-04-30 18:39:29 +00:00
|
|
|
$processor = new ExtensionProcessor();
|
2017-08-28 15:03:47 +00:00
|
|
|
$info = [
|
|
|
|
|
'config' => [
|
|
|
|
|
'Bar' => '',
|
|
|
|
|
]
|
|
|
|
|
] + self::$default;
|
|
|
|
|
$info2 = [
|
|
|
|
|
'config' => [
|
|
|
|
|
'Bar' => 'g',
|
|
|
|
|
],
|
2020-04-30 19:46:11 +00:00
|
|
|
] + self::$default2;
|
2019-10-05 04:47:46 +00:00
|
|
|
$this->expectException( RuntimeException::class );
|
2022-03-24 14:18:07 +00:00
|
|
|
$processor->extractInfo( $this->extensionPath, $info, 1 );
|
|
|
|
|
$processor->extractInfo( $this->extensionPath, $info2, 1 );
|
2017-08-28 15:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testDuplicateConfigKey2() {
|
2020-04-30 18:39:29 +00:00
|
|
|
$processor = new ExtensionProcessor();
|
2017-08-28 15:03:47 +00:00
|
|
|
$info = [
|
|
|
|
|
'config' => [
|
|
|
|
|
'Bar' => [ 'value' => 'somevalue' ],
|
|
|
|
|
]
|
|
|
|
|
] + self::$default;
|
|
|
|
|
$info2 = [
|
|
|
|
|
'config' => [
|
|
|
|
|
'Bar' => [ 'value' => 'somevalue' ],
|
|
|
|
|
],
|
2020-04-30 19:46:11 +00:00
|
|
|
] + self::$default2;
|
2019-10-05 04:47:46 +00:00
|
|
|
$this->expectException( RuntimeException::class );
|
2022-03-24 14:18:07 +00:00
|
|
|
$processor->extractInfo( $this->extensionPath, $info, 2 );
|
|
|
|
|
$processor->extractInfo( $this->extensionPath, $info2, 2 );
|
2017-08-28 15:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-23 03:18:31 +00:00
|
|
|
public static function provideExtractExtensionMessagesFiles() {
|
2022-03-24 14:18:07 +00:00
|
|
|
$dir = dirname( self::getExtensionPath() );
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
[ 'ExtensionMessagesFiles' => [ 'FooBarAlias' => 'FooBar.alias.php' ] ],
|
2022-03-24 14:18:07 +00:00
|
|
|
[ 'wgExtensionMessagesFiles' => [ 'FooBarAlias' => $dir . '/FooBar.alias.php' ] ]
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'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' => [
|
2022-03-24 14:18:07 +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
|
|
|
* @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();
|
2022-03-24 14:18:07 +00:00
|
|
|
$processor->extractInfo( $this->extensionPath, $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() {
|
2022-03-24 14:18:07 +00:00
|
|
|
$dir = dirname( self::getExtensionPath() );
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
[ 'MessagesDirs' => [ 'VisualEditor' => 'i18n' ] ],
|
2022-03-24 14:18:07 +00:00
|
|
|
[ 'wgMessagesDirs' => [ 'VisualEditor' => [ $dir . '/i18n' ] ] ]
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[ 'MessagesDirs' => [ 'VisualEditor' => [ 'i18n', 'foobar' ] ] ],
|
2022-03-24 14:18:07 +00:00
|
|
|
[ 'wgMessagesDirs' => [ 'VisualEditor' => [ $dir . '/i18n', $dir . '/foobar' ] ] ]
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2015-01-30 20:56:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-02-06 23:02:26 +00:00
|
|
|
* @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();
|
2022-03-24 14:18:07 +00:00
|
|
|
$processor->extractInfo( $this->extensionPath, $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
|
|
|
public function testExtractCredits() {
|
|
|
|
|
$processor = new ExtensionProcessor();
|
2022-03-24 14:18:07 +00:00
|
|
|
$processor->extractInfo( $this->extensionPath, self::$default, 1 );
|
2019-10-03 22:20:49 +00:00
|
|
|
$this->expectException( Exception::class );
|
2022-03-24 14:18:07 +00:00
|
|
|
$processor->extractInfo( $this->extensionPath, self::$default, 1 );
|
2015-12-30 01:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
2015-02-06 09:46:05 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideExtractResourceLoaderModules
|
|
|
|
|
*/
|
2019-01-18 20:21:35 +00:00
|
|
|
public function testExtractResourceLoaderModules(
|
|
|
|
|
$input,
|
|
|
|
|
array $expectedGlobals,
|
|
|
|
|
array $expectedAttribs = []
|
|
|
|
|
) {
|
2015-02-06 09:46:05 +00:00
|
|
|
$processor = new ExtensionProcessor();
|
2022-03-24 14:18:07 +00:00
|
|
|
$processor->extractInfo( $this->extensionPath, $input + self::$default, 1 );
|
2015-02-06 09:46:05 +00:00
|
|
|
$out = $processor->getExtractedInfo();
|
2019-01-18 20:21:35 +00:00
|
|
|
foreach ( $expectedGlobals as $key => $value ) {
|
2015-02-06 09:46:05 +00:00
|
|
|
$this->assertEquals( $value, $out['globals'][$key] );
|
|
|
|
|
}
|
2019-01-18 20:21:35 +00:00
|
|
|
foreach ( $expectedAttribs as $key => $value ) {
|
|
|
|
|
$this->assertEquals( $value, $out['attributes'][$key] );
|
|
|
|
|
}
|
2015-02-06 09:46:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideExtractResourceLoaderModules() {
|
2022-03-24 14:18:07 +00:00
|
|
|
$dir = dirname( self::getExtensionPath() );
|
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
|
2020-03-09 20:12:45 +00:00
|
|
|
[],
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2020-03-09 20:12:45 +00:00
|
|
|
'ResourceModules' => [
|
2016-02-17 09:09:32 +00:00
|
|
|
'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' => [
|
2018-02-10 06:03:42 +00:00
|
|
|
'localBasePath' => 'modules',
|
|
|
|
|
'remoteExtPath' => 'FooBar/modules',
|
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
|
2020-03-09 20:12:45 +00:00
|
|
|
[],
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2020-03-09 20:12:45 +00:00
|
|
|
'ResourceModules' => [
|
2016-02-17 09:09:32 +00:00
|
|
|
'test.foo' => [
|
2015-02-06 09:46:05 +00:00
|
|
|
'styles' => 'foo.js',
|
2018-02-10 06:03:42 +00:00
|
|
|
'localBasePath' => "$dir/modules",
|
|
|
|
|
'remoteExtPath' => 'FooBar/modules',
|
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',
|
2018-02-10 06:03:42 +00:00
|
|
|
'localBasePath' => "$dir/modules",
|
|
|
|
|
'remoteExtPath' => 'FooBar/modules',
|
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,
|
2018-02-10 06:03:42 +00:00
|
|
|
'remoteExtPath' => 'FooBar/modules',
|
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
|
2020-03-09 20:12:45 +00:00
|
|
|
[],
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2020-03-09 20:12:45 +00:00
|
|
|
'ResourceModuleSkinStyles' => [
|
2016-02-17 09:09:32 +00:00
|
|
|
'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
|
2020-03-09 20:12:45 +00:00
|
|
|
[],
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2020-03-09 20:12:45 +00:00
|
|
|
'ResourceModuleSkinStyles' => [
|
2016-02-17 09:09:32 +00:00
|
|
|
'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
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
2019-01-18 20:21:35 +00:00
|
|
|
'QUnit test module' => [
|
|
|
|
|
// Input
|
|
|
|
|
[
|
|
|
|
|
'QUnitTestModule' => [
|
|
|
|
|
'localBasePath' => '',
|
|
|
|
|
'remoteExtPath' => 'Foo',
|
|
|
|
|
'scripts' => 'bar.js',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
// Expected
|
|
|
|
|
[],
|
|
|
|
|
[
|
|
|
|
|
'QUnitTestModules' => [
|
|
|
|
|
'test.FooBar' => [
|
|
|
|
|
'localBasePath' => $dir,
|
|
|
|
|
'remoteExtPath' => 'Foo',
|
|
|
|
|
'scripts' => 'bar.js',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
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
|
|
|
|
2016-12-02 06:02:28 +00:00
|
|
|
/**
|
|
|
|
|
* Attributes under manifest_version 2
|
|
|
|
|
*/
|
|
|
|
|
public function testExtractAttributes() {
|
|
|
|
|
$processor = new ExtensionProcessor();
|
|
|
|
|
// Load FooBar extension
|
2022-03-24 14:18:07 +00:00
|
|
|
$processor->extractInfo( $this->extensionPath, self::$default, 2 );
|
2016-12-02 06:02:28 +00:00
|
|
|
$processor->extractInfo(
|
2022-03-24 14:18:07 +00:00
|
|
|
$this->extensionPath,
|
2016-12-02 06:02:28 +00:00
|
|
|
[
|
|
|
|
|
'name' => 'Baz',
|
|
|
|
|
'attributes' => [
|
|
|
|
|
// Loaded
|
|
|
|
|
'FooBar' => [
|
|
|
|
|
'Plugins' => [
|
|
|
|
|
'ext.baz.foobar',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
// Not loaded
|
|
|
|
|
'FizzBuzz' => [
|
|
|
|
|
'MorePlugins' => [
|
|
|
|
|
'ext.baz.fizzbuzz',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
2
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$info = $processor->getExtractedInfo();
|
|
|
|
|
$this->assertArrayHasKey( 'FooBarPlugins', $info['attributes'] );
|
|
|
|
|
$this->assertSame( [ 'ext.baz.foobar' ], $info['attributes']['FooBarPlugins'] );
|
|
|
|
|
$this->assertArrayNotHasKey( 'FizzBuzzMorePlugins', $info['attributes'] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Attributes under manifest_version 1
|
|
|
|
|
*/
|
|
|
|
|
public function testAttributes1() {
|
|
|
|
|
$processor = new ExtensionProcessor();
|
|
|
|
|
$processor->extractInfo(
|
2022-03-24 14:18:07 +00:00
|
|
|
$this->extensionPath,
|
2016-12-02 06:02:28 +00:00
|
|
|
[
|
|
|
|
|
'FooBarPlugins' => [
|
|
|
|
|
'ext.baz.foobar',
|
|
|
|
|
],
|
|
|
|
|
'FizzBuzzMorePlugins' => [
|
|
|
|
|
'ext.baz.fizzbuzz',
|
|
|
|
|
],
|
2020-04-30 19:46:11 +00:00
|
|
|
] + self::$default,
|
2016-12-02 06:02:28 +00:00
|
|
|
1
|
|
|
|
|
);
|
2018-02-10 06:03:42 +00:00
|
|
|
$processor->extractInfo(
|
2022-03-24 14:18:07 +00:00
|
|
|
$this->extensionPath,
|
2018-02-10 06:03:42 +00:00
|
|
|
[
|
|
|
|
|
'FizzBuzzMorePlugins' => [
|
|
|
|
|
'ext.bar.fizzbuzz',
|
|
|
|
|
]
|
2020-04-30 19:46:11 +00:00
|
|
|
] + self::$default2,
|
2018-02-10 06:03:42 +00:00
|
|
|
1
|
|
|
|
|
);
|
2016-12-02 06:02:28 +00:00
|
|
|
|
|
|
|
|
$info = $processor->getExtractedInfo();
|
|
|
|
|
$this->assertArrayHasKey( 'FooBarPlugins', $info['attributes'] );
|
|
|
|
|
$this->assertSame( [ 'ext.baz.foobar' ], $info['attributes']['FooBarPlugins'] );
|
|
|
|
|
$this->assertArrayHasKey( 'FizzBuzzMorePlugins', $info['attributes'] );
|
2018-02-10 06:03:42 +00:00
|
|
|
$this->assertSame(
|
|
|
|
|
[ 'ext.baz.fizzbuzz', 'ext.bar.fizzbuzz' ],
|
|
|
|
|
$info['attributes']['FizzBuzzMorePlugins']
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAttributes1_notarray() {
|
|
|
|
|
$processor = new ExtensionProcessor();
|
2019-10-03 22:20:49 +00:00
|
|
|
$this->expectException( InvalidArgumentException::class );
|
|
|
|
|
$this->expectExceptionMessage(
|
2022-03-24 14:18:07 +00:00
|
|
|
"The value for 'FooBarPlugins' should be an array (from {$this->extensionPath})"
|
2018-02-10 06:03:42 +00:00
|
|
|
);
|
|
|
|
|
$processor->extractInfo(
|
2022-03-24 14:18:07 +00:00
|
|
|
$this->extensionPath,
|
2018-02-10 06:03:42 +00:00
|
|
|
[
|
|
|
|
|
'FooBarPlugins' => 'ext.baz.foobar',
|
|
|
|
|
] + self::$default,
|
|
|
|
|
1
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-10 06:21:19 +00:00
|
|
|
public function testExtractPathBasedGlobal() {
|
2018-02-10 06:03:42 +00:00
|
|
|
$processor = new ExtensionProcessor();
|
|
|
|
|
$processor->extractInfo(
|
2022-03-24 14:18:07 +00:00
|
|
|
$this->extensionPath,
|
2018-02-10 06:03:42 +00:00
|
|
|
[
|
|
|
|
|
'ServiceWiringFiles' => [
|
|
|
|
|
'includes/ServiceWiring.php'
|
|
|
|
|
],
|
|
|
|
|
] + self::$default,
|
|
|
|
|
1
|
|
|
|
|
);
|
|
|
|
|
$globals = $processor->getExtractedInfo()['globals'];
|
|
|
|
|
$this->assertArrayHasKey( 'wgServiceWiringFiles', $globals );
|
|
|
|
|
$this->assertSame( [
|
|
|
|
|
"{$this->dirname}/includes/ServiceWiring.php"
|
|
|
|
|
], $globals['wgServiceWiringFiles'] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetRequirements() {
|
|
|
|
|
$info = self::$default + [
|
|
|
|
|
'requires' => [
|
|
|
|
|
'MediaWiki' => '>= 1.25.0',
|
2018-09-08 00:02:53 +00:00
|
|
|
'platform' => [
|
|
|
|
|
'php' => '>= 5.5.9'
|
|
|
|
|
],
|
2018-02-10 06:03:42 +00:00
|
|
|
'extensions' => [
|
|
|
|
|
'Bar' => '*'
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
$processor = new ExtensionProcessor();
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$info['requires'],
|
registration: Add development requirements to extension.json
Extensions can specify development dependencies in extension.json under
the "dev-requires" key. It's identical to the "requires" field.
Any requirement that is needed to pass tests, including but not limited
to, PHPUnit, QUnit, structure, phan, should be documented in this new
field. The main intention is that CI will ensure that all of these
dependencies are satisfied before running tests.
At standard runtime, the development requirements will be ignored by
MediaWiki, since it only checks for real requirements. Scripts can
manually check development requirements by calling
ExtensionRegistry::setCheckDevRequires( true ) before trying to load
things.
If both "requires" and "dev-requires" are present, MediaWiki will merge
the two together, so the environment will need to satisfy both before
proceeding.
Bug: T193824
Change-Id: I9b2936666ee3c96f5c976c7a17f11c437c2c7f48
2019-05-19 09:17:56 +00:00
|
|
|
$processor->getRequirements( $info, false )
|
2018-02-10 06:03:42 +00:00
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[],
|
registration: Add development requirements to extension.json
Extensions can specify development dependencies in extension.json under
the "dev-requires" key. It's identical to the "requires" field.
Any requirement that is needed to pass tests, including but not limited
to, PHPUnit, QUnit, structure, phan, should be documented in this new
field. The main intention is that CI will ensure that all of these
dependencies are satisfied before running tests.
At standard runtime, the development requirements will be ignored by
MediaWiki, since it only checks for real requirements. Scripts can
manually check development requirements by calling
ExtensionRegistry::setCheckDevRequires( true ) before trying to load
things.
If both "requires" and "dev-requires" are present, MediaWiki will merge
the two together, so the environment will need to satisfy both before
proceeding.
Bug: T193824
Change-Id: I9b2936666ee3c96f5c976c7a17f11c437c2c7f48
2019-05-19 09:17:56 +00:00
|
|
|
$processor->getRequirements( [], false )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetDevRequirements() {
|
|
|
|
|
$info = self::$default + [
|
|
|
|
|
'dev-requires' => [
|
|
|
|
|
'MediaWiki' => '>= 1.31.0',
|
|
|
|
|
'platform' => [
|
|
|
|
|
'ext-foo' => '*',
|
|
|
|
|
],
|
|
|
|
|
'skins' => [
|
|
|
|
|
'Baz' => '*',
|
|
|
|
|
],
|
|
|
|
|
'extensions' => [
|
|
|
|
|
'Biz' => '*',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
$processor = new ExtensionProcessor();
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$info['dev-requires'],
|
|
|
|
|
$processor->getRequirements( $info, true )
|
|
|
|
|
);
|
|
|
|
|
// Set some standard requirements, so we can test merging
|
|
|
|
|
$info['requires'] = [
|
|
|
|
|
'MediaWiki' => '>= 1.25.0',
|
|
|
|
|
'platform' => [
|
|
|
|
|
'php' => '>= 5.5.9'
|
|
|
|
|
],
|
|
|
|
|
'extensions' => [
|
|
|
|
|
'Bar' => '*'
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[
|
|
|
|
|
'MediaWiki' => '>= 1.25.0 >= 1.31.0',
|
|
|
|
|
'platform' => [
|
|
|
|
|
'php' => '>= 5.5.9',
|
|
|
|
|
'ext-foo' => '*',
|
|
|
|
|
],
|
|
|
|
|
'extensions' => [
|
|
|
|
|
'Bar' => '*',
|
|
|
|
|
'Biz' => '*',
|
|
|
|
|
],
|
|
|
|
|
'skins' => [
|
|
|
|
|
'Baz' => '*',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
$processor->getRequirements( $info, true )
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// If there's no dev-requires, it just returns requires
|
|
|
|
|
unset( $info['dev-requires'] );
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$info['requires'],
|
|
|
|
|
$processor->getRequirements( $info, true )
|
2018-02-10 06:03:42 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetExtraAutoloaderPaths() {
|
2022-03-24 14:18:07 +00:00
|
|
|
$this->hideDeprecated( 'ExtensionProcessor::getExtraAutoloaderPaths' );
|
2018-02-10 06:03:42 +00:00
|
|
|
$processor = new ExtensionProcessor();
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[ "{$this->dirname}/vendor/autoload.php" ],
|
|
|
|
|
$processor->getExtraAutoloaderPaths( $this->dirname, [
|
|
|
|
|
'load_composer_autoloader' => true,
|
|
|
|
|
] )
|
|
|
|
|
);
|
2016-12-02 06:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-24 14:18:07 +00:00
|
|
|
public function testGetExtractedAutoloadInfo() {
|
|
|
|
|
$processor = new ExtensionProcessor();
|
|
|
|
|
|
|
|
|
|
$processor->extractInfo( $this->extensionPath, [
|
|
|
|
|
'name' => 'Test',
|
|
|
|
|
'AutoloadClasses' => [ 'FooBar' => 'includes/FooBar.php' ],
|
|
|
|
|
'AutoloadNamespaces' => [ '\Foo\Bar\\' => 'includes/foo/bar/' ],
|
|
|
|
|
'TestAutoloadClasses' => [ 'FooBarTest' => 'tests/FooBarTest.php' ],
|
|
|
|
|
'TestAutoloadNamespaces' => [ '\Foo\Bar\Test\\' => 'tests/foo/bar/' ],
|
|
|
|
|
'load_composer_autoloader' => true,
|
|
|
|
|
], 2 );
|
|
|
|
|
|
|
|
|
|
$autoload = $processor->getExtractedAutoloadInfo();
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[ 'FooBar' => $this->dirname . '/includes/FooBar.php' ],
|
|
|
|
|
$autoload['classes']
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[ '\Foo\Bar\\' => $this->dirname . '/includes/foo/bar/' ],
|
|
|
|
|
$autoload['namespaces']
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[ $this->dirname . '/vendor/autoload.php' ],
|
|
|
|
|
$autoload['files']
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$autoload = $processor->getExtractedAutoloadInfo( true );
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[
|
|
|
|
|
'FooBar' => $this->dirname . '/includes/FooBar.php',
|
|
|
|
|
'FooBarTest' => $this->dirname . '/tests/FooBarTest.php'
|
|
|
|
|
],
|
|
|
|
|
$autoload['classes']
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[
|
|
|
|
|
'\Foo\Bar\\' => $this->dirname . '/includes/foo/bar/',
|
|
|
|
|
'\Foo\Bar\Test\\' => $this->dirname . '/tests/foo/bar/'
|
|
|
|
|
],
|
|
|
|
|
$autoload['namespaces']
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[ $this->dirname . '/vendor/autoload.php' ],
|
|
|
|
|
$autoload['files']
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-28 08:38:21 +00:00
|
|
|
/**
|
|
|
|
|
* Verify that extension.schema.json is in sync with ExtensionProcessor
|
|
|
|
|
*
|
|
|
|
|
* @coversNothing
|
|
|
|
|
*/
|
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" );
|
|
|
|
|
}
|
2020-04-30 18:28:44 +00:00
|
|
|
|
|
|
|
|
public function testGetCoreAttribsMerging() {
|
|
|
|
|
$processor = new ExtensionProcessor();
|
|
|
|
|
|
|
|
|
|
$info = self::$default + [
|
|
|
|
|
'TrackingCategories' => [
|
|
|
|
|
'Foo'
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$info2 = self::$default2 + [
|
|
|
|
|
'TrackingCategories' => [
|
|
|
|
|
'Bar'
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
2022-03-24 14:18:07 +00:00
|
|
|
$processor->extractInfo( $this->extensionPath, $info, 2 );
|
|
|
|
|
$processor->extractInfo( $this->extensionPath, $info2, 2 );
|
2020-04-30 18:28:44 +00:00
|
|
|
|
|
|
|
|
$attributes = $processor->getExtractedInfo()['attributes'];
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
[ 'Foo', 'Bar' ],
|
|
|
|
|
$attributes['TrackingCategories']
|
|
|
|
|
);
|
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-02-10 14:47:46 +00:00
|
|
|
* Allow overriding the default value of $this->globals and $this->attributes
|
|
|
|
|
* so we can test merging and hook extraction
|
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 MockExtensionProcessor extends ExtensionProcessor {
|
2020-02-10 14:47:46 +00:00
|
|
|
|
|
|
|
|
public function __construct( $preset = [] ) {
|
|
|
|
|
if ( isset( $preset['globals'] ) ) {
|
|
|
|
|
$this->globals = $preset['globals'] + $this->globals;
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $preset['attributes'] ) ) {
|
|
|
|
|
$this->attributes = $preset['attributes'] + $this->attributes;
|
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
}
|