Legoktm has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/389793 )
Change subject: Introduce MultiGadgetRepo to help with migration
......................................................................
Introduce MultiGadgetRepo to help with migration
MultiGadgetRepo is a wrapper around other GadgetRepos so both the
MediaWikiDefinition and GadgetDefintionNamespace repositories can be
used at the same time:
$wgGadgetsRepoClass = [
'class' => MultiGadgetRepo::class,
'args' => [ [
GadgetDefinitionNamespaceRepo::class,
MediaWikiGadgetsDefinitionRepo::class
] ]
];
While a class name is still accepted for compatibility, any
ObjectFactory definition can be used for $wgGadgetsRepoClass.
Change-Id: If3cc5e22e9812d0fd1a9e8e269ea74a7f667dadd
---
M extension.json
M includes/GadgetRepo.php
A includes/MultiGadgetRepo.php
3 files changed, 108 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Gadgets
refs/changes/93/389793/1
diff --git a/extension.json b/extension.json
index e7f06a4..48d8e9f 100644
--- a/extension.json
+++ b/extension.json
@@ -72,6 +72,7 @@
"GadgetRepo": "includes/GadgetRepo.php",
"GadgetDefinitionNamespaceRepo":
"includes/GadgetDefinitionNamespaceRepo.php",
"MediaWikiGadgetsDefinitionRepo":
"includes/MediaWikiGadgetsDefinitionRepo.php",
+ "MultiGadgetRepo": "includes/MultiGadgetRepo.php",
"GadgetDefinitionContent":
"includes/content/GadgetDefinitionContent.php",
"GadgetDefinitionContentHandler":
"includes/content/GadgetDefinitionContentHandler.php",
"GadgetDefinitionValidator":
"includes/content/GadgetDefinitionValidator.php",
diff --git a/includes/GadgetRepo.php b/includes/GadgetRepo.php
index 11996f8..3e90002 100644
--- a/includes/GadgetRepo.php
+++ b/includes/GadgetRepo.php
@@ -88,7 +88,11 @@
public static function singleton() {
if ( self::$instance === null ) {
global $wgGadgetsRepoClass; // @todo use Config here
- self::$instance = new $wgGadgetsRepoClass();
+ if ( is_string( $wgGadgetsRepoClass ) ) {
+ self::$instance = new $wgGadgetsRepoClass();
+ } else {
+ self::$instance =
ObjectFactory::getObjectFromSpec( $wgGadgetsRepoClass );
+ }
}
return self::$instance;
}
diff --git a/includes/MultiGadgetRepo.php b/includes/MultiGadgetRepo.php
new file mode 100644
index 0000000..0d81b94
--- /dev/null
+++ b/includes/MultiGadgetRepo.php
@@ -0,0 +1,102 @@
+<?php
+/**
+ * Copyright (C) 2017 Kunal Mehta <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+use MediaWiki\Linker\LinkTarget;
+
+/**
+ * A gadget repository that allows wrapping other gadget
+ * repos during migrations
+ */
+class MultiGadgetRepo extends GadgetRepo {
+
+ /**
+ * @var GadgetRepo[]
+ */
+ private $repos = [];
+
+ /**
+ * @param string[] $classes Class names for GadgetRepos to wrap
+ *
+ * @throws UnexpectedValueException
+ */
+ public function __construct( array $classes ) {
+ foreach ( $classes as $class ) {
+ $instance = new $class();
+ if ( !$instance instanceof GadgetRepo ) {
+ throw new UnexpectedValueException( "Class
$class is not a GadgetRepo" );
+ }
+ $this->repos[] = $instance;
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getGadget( $id ) {
+ foreach ( $this->repos as $repo ) {
+ try {
+ return $repo->getGadget( $id );
+ } catch ( InvalidArgumentException $e ) {
+ // Try next repo
+ }
+ }
+
+ throw new InvalidArgumentException( "No gadget registered for
'$id'" );
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getGadgetIds() {
+ $ids = [];
+ foreach ( $this->repos as $repo ) {
+ $ids = array_merge( $ids, $repo->getGadgetIds() );
+ }
+
+ return $ids;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function handlePageUpdate( LinkTarget $target ) {
+ foreach ( $this->repos as $repo ) {
+ $repo->handlePageUpdate( $target );
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function handlePageCreation( LinkTarget $target ) {
+ foreach ( $this->repos as $repo ) {
+ $repo->handlePageCreation( $target );
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function handlePageDeletion( LinkTarget $target ) {
+ foreach ( $this->repos as $repo ) {
+ $repo->handlePageDeletion( $target );
+ }
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/389793
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If3cc5e22e9812d0fd1a9e8e269ea74a7f667dadd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Gadgets
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits