summaryrefslogtreecommitdiff
path: root/extensions/Gadgets/includes/GadgetRepo.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2015-12-20 09:00:55 +0100
committerPierre Schmitz <pierre@archlinux.de>2015-12-20 09:00:55 +0100
commita2190ac74dd4d7080b12bab90e552d7aa81209ef (patch)
tree8b31f38de9882d18df54cf8d9e0de74167a094eb /extensions/Gadgets/includes/GadgetRepo.php
parent15e69f7b20b6596b9148030acce5b59993b95a45 (diff)
parent257401d8b2cf661adf36c84b0e3fd1cf85e33c22 (diff)
Merge branch 'mw-1.26'
Diffstat (limited to 'extensions/Gadgets/includes/GadgetRepo.php')
-rw-r--r--extensions/Gadgets/includes/GadgetRepo.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/extensions/Gadgets/includes/GadgetRepo.php b/extensions/Gadgets/includes/GadgetRepo.php
new file mode 100644
index 00000000..18bf5b51
--- /dev/null
+++ b/extensions/Gadgets/includes/GadgetRepo.php
@@ -0,0 +1,63 @@
+<?php
+
+abstract class GadgetRepo {
+
+ /**
+ * @var GadgetRepo|null
+ */
+ private static $instance;
+
+ /**
+ * Get the ids of the gadgets provided by this repository
+ *
+ * @return string[]
+ */
+ abstract public function getGadgetIds();
+
+ /**
+ * Get the Gadget object for a given gadget id
+ *
+ * @param string $id
+ * @throws InvalidArgumentException
+ * @return Gadget
+ */
+ abstract public function getGadget( $id );
+
+ /**
+ * Get a list of gadgets sorted by category
+ *
+ * @return array array( 'category' => array( 'name' => $gadget ) )
+ */
+ public function getStructuredList() {
+ $list = array();
+ foreach ( $this->getGadgetIds() as $id ) {
+ $gadget = $this->getGadget( $id );
+ $list[$gadget->getCategory()][$gadget->getName()] = $gadget;
+ }
+
+ return $list;
+ }
+
+ /**
+ * Get the configured default GadgetRepo. Currently
+ * this hardcodes MediaWikiGadgetsDefinitionRepo since
+ * that is the only implementation
+ *
+ * @return GadgetRepo
+ */
+ public static function singleton() {
+ if ( self::$instance === null ) {
+ self::$instance = new MediaWikiGadgetsDefinitionRepo();
+ }
+ return self::$instance;
+ }
+
+ /**
+ * Should only be used by unit tests
+ *
+ * @param GadgetRepo|null $repo
+ */
+ public static function setSingleton( $repo = null ) {
+ self::$instance = $repo;
+ }
+}