mediawiki-extensions-Gadgets/includes/ServiceWiring.php
Siddharth VP a629d7f71d Introduce MultiGadgetRepo to facilitate repo migration
MultiGadgetRepo is a wrapper around two or more GadgetRepos so that
they can be used at the same, facilitating migration from one repo to
another.

If a gadget appears in both repos, the definition in the first repo
takes precedence, and a warning is shown on Special:Gadgets.

This can be enabled to wrap GadgetDefinitionNamespaceRepo and
MediaWikiGadgetsDefinitionRepo by setting $wgGadgetsRepo to
'json+definition'. In this configuration, once a new JSON definition
exists for the same name, it is used instead of the old one, and the
old one can then safely be removed at a later time in the safe
knowledge that it is no longer used.

Adapted from If3cc5e22e9812d0fd1a9e8e269ea74a7f667dadd

Bug: T140323
Co-authored-by: Kunal Mehta <legoktm@debian.org>
Change-Id: Ibad53629e63ec8713d7a3b84a19838b94600588e
2024-03-02 18:22:04 +00:00

28 lines
1,006 B
PHP

<?php
use MediaWiki\Extension\Gadgets\GadgetRepo;
use MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo;
use MediaWiki\Extension\Gadgets\MediaWikiGadgetsJsonRepo;
use MediaWiki\Extension\Gadgets\MultiGadgetRepo;
use MediaWiki\MediaWikiServices;
return [
'GadgetsRepo' => static function ( MediaWikiServices $services ): GadgetRepo {
$wanCache = $services->getMainWANObjectCache();
$revisionLookup = $services->getRevisionLookup();
switch ( $services->getMainConfig()->get( 'GadgetsRepo' ) ) {
case 'definition':
return new MediaWikiGadgetsDefinitionRepo( $wanCache, $revisionLookup );
case 'json':
return new MediaWikiGadgetsJsonRepo( $wanCache, $revisionLookup );
case 'json+definition':
return new MultiGadgetRepo( [
new MediaWikiGadgetsJsonRepo( $wanCache, $revisionLookup ),
new MediaWikiGadgetsDefinitionRepo( $wanCache, $revisionLookup )
] );
default:
throw new InvalidArgumentException( 'Unexpected value for $wgGadgetsRepo' );
}
},
];