3use Wikimedia\TestingAccessWrapper;
14 $this->dir = __DIR__ .
'/FooBar/extension.json';
15 $this->dirname = dirname( $this->dir );
30 $processor->extractInfo( $this->dir, self::$default + [
31 '@metadata' => [
'foobarbaz' ],
32 'AnAttribute' => [
'omg' ],
33 'AutoloadClasses' => [
'FooBar' =>
'includes/FooBar.php' ],
34 'SpecialPages' => [
'Foo' =>
'SpecialFoo' ],
35 'callback' =>
'FooBar::onRegistration',
38 $extracted = $processor->getExtractedInfo();
39 $attributes = $extracted[
'attributes'];
40 $this->assertArrayHasKey(
'AnAttribute', $attributes );
41 $this->assertArrayNotHasKey(
'@metadata', $attributes );
42 $this->assertArrayNotHasKey(
'AutoloadClasses', $attributes );
44 [
'FooBar' =>
'FooBar::onRegistration' ],
45 $extracted[
'callbacks']
48 [
'Foo' =>
'SpecialFoo' ],
49 $extracted[
'globals'][
'wgSpecialPages']
55 if ( !defined(
'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X' ) ) {
56 define(
'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X', 123456 );
60 $processor->extractInfo( $this->dir, self::$default + [
64 'constant' =>
'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_A',
66 'defaultcontentmodel' =>
'TestModel',
68 'male' =>
'Male test',
69 'female' =>
'Female test',
73 'protection' =>
'userright',
77 'constant' =>
'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X',
79 'defaultcontentmodel' =>
'TestModel'
84 $extracted = $processor->getExtractedInfo();
86 $this->assertArrayHasKey(
87 'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_A',
90 $this->assertArrayNotHasKey(
91 'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X',
96 $extracted[
'defines'][
'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_A'],
100 $this->assertArrayHasKey(
'ExtensionNamespaces', $extracted[
'attributes'] );
101 $this->assertArrayHasKey( 123456, $extracted[
'attributes'][
'ExtensionNamespaces'] );
102 $this->assertArrayHasKey( 332200, $extracted[
'attributes'][
'ExtensionNamespaces'] );
103 $this->assertArrayNotHasKey( 334400, $extracted[
'attributes'][
'ExtensionNamespaces'] );
105 $this->assertSame(
'Test_X', $extracted[
'attributes'][
'ExtensionNamespaces'][123456] );
106 $this->assertSame(
'Test_A', $extracted[
'attributes'][
'ExtensionNamespaces'][332200] );
108 [
'male' =>
'Male test',
'female' =>
'Female test' ],
109 $extracted[
'globals'][
'wgExtraGenderNamespaces'][332200]
112 $this->assertTrue( $extracted[
'globals'][
'wgNamespacesWithSubpages'][332200] );
113 $this->assertArrayNotHasKey( 123456, $extracted[
'globals'][
'wgNamespacesWithSubpages'] );
133 [
'FooBaz' => [
'FooBazCallback' ] ] + $merge,
137 [
'FooBaz' => [
'PriorCallback' ] ],
139 [
'FooBaz' => [
'PriorCallback',
'FooBazCallback' ] ] + $merge,
144 [
'Hooks' => [
'FooBaz' => [
'FooBazCallback' ] ] ] +
self::$default,
145 [
'FooBaz' => [
'FooBazCallback' ] ] + $merge,
149 [
'BarBaz' => [
'BarBazCallback' ] ],
152 'BarBaz' => [
'BarBazCallback' ],
153 'FooBaz' => [
'FooBazCallback' ],
161 'FooBaz' => [
'Callback1' ],
167 [
'Hooks' => [
'FooBaz' => [
'Callback1',
'Callback2' ] ] ] +
self::$default,
169 'FooBaz' => [
'Callback1',
'Callback2' ],
180 $processor->extractInfo( $this->dir, $info, 1 );
181 $extracted = $processor->getExtractedInfo();
182 $this->assertEquals( $expected, $extracted[
'globals'][
'wgHooks'] );
189 'Bar' =>
'somevalue',
201 $processor->extractInfo( $this->dir, $info, 1 );
202 $processor->extractInfo( $this->dir, $info2, 1 );
203 $extracted = $processor->getExtractedInfo();
204 $this->assertEquals(
'somevalue', $extracted[
'globals'][
'wgBar'] );
205 $this->assertEquals( 10, $extracted[
'globals'][
'wgFoo'] );
206 $this->assertArrayNotHasKey(
'wg@IGNORED', $extracted[
'globals'] );
208 $this->assertEquals(
'somevalue', $extracted[
'globals'][
'egBar'] );
215 'Bar' => [
'value' =>
'somevalue' ],
216 'Foo' => [
'value' => 10 ],
217 'Path' => [
'value' =>
'foo.txt',
'path' =>
true ],
223 'merge_strategy' =>
'array_plus',
229 'Bar' => [
'value' =>
'somevalue' ],
231 'config_prefix' =>
'eg',
234 $processor->extractInfo( $this->dir, $info, 2 );
235 $processor->extractInfo( $this->dir, $info2, 2 );
236 $extracted = $processor->getExtractedInfo();
237 $this->assertEquals(
'somevalue', $extracted[
'globals'][
'wgBar'] );
238 $this->assertEquals( 10, $extracted[
'globals'][
'wgFoo'] );
239 $this->assertEquals(
"{$this->dirname}/foo.txt", $extracted[
'globals'][
'wgPath'] );
241 $this->assertEquals(
'somevalue', $extracted[
'globals'][
'egBar'] );
244 $extracted[
'globals'][
'wgNamespaces']
264 $processor->extractInfo( $this->dir, $info, 1 );
265 $processor->extractInfo( $this->dir, $info2, 1 );
275 'Bar' => [
'value' =>
'somevalue' ],
280 'Bar' => [
'value' =>
'somevalue' ],
284 $processor->extractInfo( $this->dir, $info, 2 );
285 $processor->extractInfo( $this->dir, $info2, 2 );
289 $dir = __DIR__ .
'/FooBar/';
292 [
'ExtensionMessagesFiles' => [
'FooBarAlias' =>
'FooBar.alias.php' ] ],
293 [
'wgExtensionMessagesFiles' => [
'FooBarAlias' =>
$dir .
'FooBar.alias.php' ] ]
297 'ExtensionMessagesFiles' => [
298 'FooBarAlias' =>
'FooBar.alias.php',
299 'FooBarMagic' =>
'FooBar.magic.i18n.php',
303 'wgExtensionMessagesFiles' => [
304 'FooBarAlias' =>
$dir .
'FooBar.alias.php',
305 'FooBarMagic' =>
$dir .
'FooBar.magic.i18n.php',
317 $processor->extractInfo( $this->dir,
$input + self::$default, 1 );
318 $out = $processor->getExtractedInfo();
319 foreach ( $expected as $key =>
$value ) {
320 $this->assertEquals(
$value,
$out[
'globals'][$key] );
325 $dir = __DIR__ .
'/FooBar/';
328 [
'MessagesDirs' => [
'VisualEditor' =>
'i18n' ] ],
329 [
'wgMessagesDirs' => [
'VisualEditor' => [
$dir .
'i18n' ] ] ]
332 [
'MessagesDirs' => [
'VisualEditor' => [
'i18n',
'foobar' ] ] ],
333 [
'wgMessagesDirs' => [
'VisualEditor' => [
$dir .
'i18n',
$dir .
'foobar' ] ] ]
343 $processor->extractInfo( $this->dir,
$input + self::$default, 1 );
344 $out = $processor->getExtractedInfo();
345 foreach ( $expected as $key =>
$value ) {
346 $this->assertEquals(
$value,
$out[
'globals'][$key] );
352 $processor->extractInfo( $this->dir, self::$default, 1 );
353 $this->setExpectedException( Exception::class );
354 $processor->extractInfo( $this->dir, self::$default, 1 );
362 $processor->extractInfo( $this->dir,
$input + self::$default, 1 );
363 $out = $processor->getExtractedInfo();
364 foreach ( $expected as $key =>
$value ) {
365 $this->assertEquals(
$value,
$out[
'globals'][$key] );
370 $dir = __DIR__ .
'/FooBar';
376 'ResourceModules' => [
378 'styles' =>
'foobar.js',
379 'localBasePath' =>
'',
380 'remoteExtPath' =>
'FooBar',
386 'wgResourceModules' => [
388 'styles' =>
'foobar.js',
389 'localBasePath' =>
$dir,
390 'remoteExtPath' =>
'FooBar',
399 'ResourceFileModulePaths' => [
400 'localBasePath' =>
'modules',
401 'remoteExtPath' =>
'FooBar/modules',
403 'ResourceModules' => [
406 'styles' =>
'foo.js',
410 'styles' =>
'bar.js',
411 'localBasePath' =>
'subdir',
412 'remoteExtPath' =>
'FooBar/subdir',
416 'class' =>
'FooBarModule',
417 'extra' =>
'argument',
420 'test.class.with.path' => [
421 'class' =>
'FooBarPathModule',
422 'extra' =>
'argument',
423 'localBasePath' =>
'',
429 'wgResourceModules' => [
431 'styles' =>
'foo.js',
432 'localBasePath' =>
"$dir/modules",
433 'remoteExtPath' =>
'FooBar/modules',
436 'styles' =>
'bar.js',
437 'localBasePath' =>
"$dir/subdir",
438 'remoteExtPath' =>
'FooBar/subdir',
441 'class' =>
'FooBarModule',
442 'extra' =>
'argument',
443 'localBasePath' =>
"$dir/modules",
444 'remoteExtPath' =>
'FooBar/modules',
446 'test.class.with.path' => [
447 'class' =>
'FooBarPathModule',
448 'extra' =>
'argument',
449 'localBasePath' =>
$dir,
450 'remoteExtPath' =>
'FooBar/modules',
459 'ResourceFileModulePaths' => [
460 'localBasePath' =>
'',
461 'remoteSkinPath' =>
'FooBar',
463 'ResourceModuleSkinStyles' => [
465 'test.foo' =>
'foo.css',
471 'wgResourceModuleSkinStyles' => [
473 'test.foo' =>
'foo.css',
474 'localBasePath' =>
$dir,
475 'remoteSkinPath' =>
'FooBar',
484 'ResourceFileModulePaths' => [
485 'localBasePath' =>
'',
486 'remoteSkinPath' =>
'FooBar',
488 'ResourceModuleSkinStyles' => [
490 'test.foo' =>
'foo.css',
491 'remoteSkinPath' =>
'BarFoo'
497 'wgResourceModuleSkinStyles' => [
499 'test.foo' =>
'foo.css',
500 'localBasePath' =>
$dir,
501 'remoteSkinPath' =>
'BarFoo',
512 [
'wgAPIModules',
'wgAvailableRights' ],
515 'APIModules' => [
'foobar' =>
'ApiFooBar' ],
516 'AvailableRights' => [
'foobar',
'unfoobar' ],
519 'wgAPIModules' => [
'foobar' =>
'ApiFooBar' ],
520 'wgAvailableRights' => [
'foobar',
'unfoobar' ],
524 [
'wgAPIModules',
'wgAvailableRights' ],
526 'wgAPIModules' => [
'barbaz' =>
'ApiBarBaz' ],
527 'wgAvailableRights' => [
'barbaz' ]
530 'APIModules' => [
'foobar' =>
'ApiFooBar' ],
531 'AvailableRights' => [
'foobar',
'unfoobar' ],
534 'wgAPIModules' => [
'barbaz' =>
'ApiBarBaz',
'foobar' =>
'ApiFooBar' ],
535 'wgAvailableRights' => [
'barbaz',
'foobar',
'unfoobar' ],
539 [
'wgGroupPermissions' ],
541 'wgGroupPermissions' => [
542 'sysop' => [
'delete' ]
546 'GroupPermissions' => [
547 'sysop' => [
'undelete' ],
552 'wgGroupPermissions' => [
553 'sysop' => [
'delete',
'undelete' ],
567 $processor->extractInfo( $this->dir, [
'name' =>
'FooBar' ], 2 );
568 $processor->extractInfo(
590 $info = $processor->getExtractedInfo();
591 $this->assertArrayHasKey(
'FooBarPlugins', $info[
'attributes'] );
592 $this->assertSame( [
'ext.baz.foobar' ], $info[
'attributes'][
'FooBarPlugins'] );
593 $this->assertArrayNotHasKey(
'FizzBuzzMorePlugins', $info[
'attributes'] );
601 $processor->extractInfo(
608 'FizzBuzzMorePlugins' => [
614 $processor->extractInfo(
618 'FizzBuzzMorePlugins' => [
625 $info = $processor->getExtractedInfo();
626 $this->assertArrayHasKey(
'FooBarPlugins', $info[
'attributes'] );
627 $this->assertSame( [
'ext.baz.foobar' ], $info[
'attributes'][
'FooBarPlugins'] );
628 $this->assertArrayHasKey(
'FizzBuzzMorePlugins', $info[
'attributes'] );
630 [
'ext.baz.fizzbuzz',
'ext.bar.fizzbuzz' ],
631 $info[
'attributes'][
'FizzBuzzMorePlugins']
637 $this->setExpectedException(
638 InvalidArgumentException::class,
639 "The value for 'FooBarPlugins' should be an array (from {$this->dir})"
641 $processor->extractInfo(
644 'FooBarPlugins' =>
'ext.baz.foobar',
652 $processor->extractInfo(
655 'ParserTestFiles' => [
656 'tests/parserTests.txt',
657 'tests/extraParserTests.txt',
659 'ServiceWiringFiles' => [
660 'includes/ServiceWiring.php'
665 $globals = $processor->getExtractedInfo()[
'globals'];
666 $this->assertArrayHasKey(
'wgParserTestFiles', $globals );
668 "{$this->dirname}/tests/parserTests.txt",
669 "{$this->dirname}/tests/extraParserTests.txt"
670 ], $globals[
'wgParserTestFiles'] );
671 $this->assertArrayHasKey(
'wgServiceWiringFiles', $globals );
673 "{$this->dirname}/includes/ServiceWiring.php"
674 ], $globals[
'wgServiceWiringFiles'] );
678 $info = self::$default + [
680 'MediaWiki' =>
'>= 1.25.0',
689 $processor->getRequirements( $info )
693 $processor->getRequirements( [] )
700 [
"{$this->dirname}/vendor/autoload.php" ],
701 $processor->getExtraAutoloaderPaths( $this->dirname, [
702 'load_composer_autoloader' =>
true,
714 $globalSettings = TestingAccessWrapper::newFromClass(
715 ExtensionProcessor::class )->globalSettings;
718 $schema = FormatJson::decode(
719 file_get_contents(
"$IP/docs/extension.schema.v$version.json" ),
723 foreach ( $globalSettings as $global ) {
724 if ( !isset( $schema[
'properties'][$global] ) ) {
725 $missing[] = $global;
729 $this->assertEquals( [], $missing,
730 "The following global settings are not documented in docs/extension.schema.json" );
testDuplicateConfigKey2()
RuntimeException.
static array $default
'name' is absolutely required
testDuplicateConfigKey1()
RuntimeException.
testAttributes1()
Attributes under manifest_version 1.
testRegisterHooks( $pre, $info, $expected)
provideRegisterHooks
static provideExtractResourceLoaderModules()
testExtractMessagesDirs( $input, $expected)
provideExtractMessagesDirs
static provideRegisterHooks()
static provideExtractExtensionMessagesFiles()
testExtractExtensionMessagesFiles( $input, $expected)
provideExtractExtensionMessagesFiles
testAttributes1_notarray()
static provideSetToGlobal()
testExtractAttributes()
Attributes under manifest_version 2.
testExtractResourceLoaderModules( $input, $expected)
provideExtractResourceLoaderModules
static provideExtractMessagesDirs()
testExtractPathBasedGlobal()
testGetExtraAutoloaderPaths()
testGlobalSettingsDocumentedInSchema()
Verify that extension.schema.json is in sync with ExtensionProcessor.
array $globals
Stuff that is going to be set to $GLOBALS.
const MERGE_STRATEGY
Special key that defines the merge strategy.
const MANIFEST_VERSION
Version of the highest supported manifest version Note: Update MANIFEST_VERSION_MW_VERSION when chang...
Allow overriding the default value of $this->globals so we can test merging.
__construct( $globals=[])
return true to allow those checks to and false if checking is done remove or add to the links of a group of changes in EnhancedChangesList Hook subscribers can return false to omit this line from recentchanges use this to change the tables headers change it to an object instance and return false override the list derivative used the name of the old file when set the default code will be skipped $pre
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining globals
if(is_array($mode)) switch( $mode) $input