Make repo configuration independent of ObjectFactory specs

Replace $wgGadgetsRepoClass with $wgGadgetsRepo.

Change-Id: I3dc1e29d1c3c65a18c206e7aa50e5bf31a55cc21
This commit is contained in:
Siddharth VP 2023-12-12 17:18:04 +05:30 committed by Krinkle
parent 561254697d
commit 34a1a297c2
4 changed files with 18 additions and 16 deletions

View file

@ -35,9 +35,8 @@ Caveats
Configuration
-------------
* `$wgGadgetsRepoClass`: configures which GadgetRepo implementation will be used
to source gadgets from. Currently, "MediaWikiGadgetsDefinitionRepo" is the
recommended setting and default. The "GadgetDefinitionNamespaceRepo" is not
ready for production usage yet.
* `$wgGadgetsRepo`: configures which GadgetRepo implementation will be used
to source gadgets from. Currently, "definition" mode is the recommended
setting and default. The "json" mode is not ready for production usage yet.
* `$wgSpecialGadgetUsageActiveUsers`: configures whether or not to show active
user stats on Special:GadgetUsage. True by default.

View file

@ -125,14 +125,8 @@
"includes/ServiceWiring.php"
],
"config": {
"GadgetsRepoClass": {
"value": {
"class": "MediaWiki\\Extension\\Gadgets\\MediaWikiGadgetsDefinitionRepo",
"services": [
"MainWANObjectCache",
"RevisionLookup"
]
}
"GadgetsRepo": {
"value": "definition"
},
"SpecialGadgetUsageActiveUsers": {
"value": true

View file

@ -86,7 +86,7 @@ abstract class GadgetRepo {
* Get the script file name without the "MediaWiki:Gadget-" or "Gadget:" prefix.
* This name is used by the client-side require() so that require("Data.json") resolves
* to either "MediaWiki:Gadget-Data.json" or "Gadget:Data.json" depending on the
* $wgGadgetsRepoClass configuration, enabling easy migration between the configuration modes.
* $wgGadgetsRepo configuration, enabling easy migration between the configuration modes.
*
* @param string $titleText
* @return string

View file

@ -1,12 +1,21 @@
<?php
use MediaWiki\Extension\Gadgets\GadgetDefinitionNamespaceRepo;
use MediaWiki\Extension\Gadgets\GadgetRepo;
use MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo;
use MediaWiki\MediaWikiServices;
return [
'GadgetsRepo' => static function ( MediaWikiServices $services ): GadgetRepo {
/** @var $repo GadgetRepo */
$repo = $services->getObjectFactory()->createObject( $services->getMainConfig()->get( 'GadgetsRepoClass' ) );
return $repo;
$wanCache = $services->getMainWANObjectCache();
$revisionLookup = $services->getRevisionLookup();
switch ( $services->getMainConfig()->get( 'GadgetsRepo' ) ) {
case 'definition':
return new MediaWikiGadgetsDefinitionRepo( $wanCache, $revisionLookup );
case 'json':
return new GadgetDefinitionNamespaceRepo( $wanCache, $revisionLookup );
default:
throw new InvalidArgumentException( 'Unexpected value for $wgGadgetsRepo' );
}
},
];