mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Gadgets
synced 2024-12-13 15:58:21 +00:00
519f30355e
Implements: * Gadget definition content and content handler * Basic validation for gadget definition content * GadgetDefinitionNamespace implementation of GadgetRepo * DataUpdates upon editing/deletion of Gadget definition pages * EditFilterMerged hook for improved error messages * 'GadgetsRepoClass' option to switch GadgetRepo implementation used * Lazy-load the GadgetResourceLoaderModule class so we don't need to load each individual gadget object unless its needed Note that Special:Gadgets's export feature intentionally doesn't work yet, and will be fixed in a follow up patch. Bug: T106177 Change-Id: Ib11db5fb0f7b46793bfa956cf1367f1dc1059b1c
70 lines
1.4 KiB
PHP
70 lines
1.4 KiB
PHP
<?php
|
|
|
|
abstract class GadgetRepo {
|
|
|
|
/**
|
|
* @var GadgetRepo|null
|
|
*/
|
|
private static $instance;
|
|
|
|
/**
|
|
* Get the ids of the gadgets provided by this repository
|
|
*
|
|
* It's possible this could be out of sync with what
|
|
* getGadget() will return due to caching
|
|
*
|
|
* @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 ) {
|
|
try {
|
|
$gadget = $this->getGadget( $id );
|
|
} catch ( InvalidArgumentException $e ) {
|
|
continue;
|
|
}
|
|
$list[$gadget->getCategory()][$gadget->getName()] = $gadget;
|
|
}
|
|
|
|
return $list;
|
|
}
|
|
|
|
/**
|
|
* Get the configured default GadgetRepo.
|
|
*
|
|
* @return GadgetRepo
|
|
*/
|
|
public static function singleton() {
|
|
if ( self::$instance === null ) {
|
|
global $wgGadgetsRepoClass; // @todo use Config here
|
|
self::$instance = new $wgGadgetsRepoClass();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
|
|
/**
|
|
* Should only be used by unit tests
|
|
*
|
|
* @param GadgetRepo|null $repo
|
|
*/
|
|
public static function setSingleton( $repo = null ) {
|
|
self::$instance = $repo;
|
|
}
|
|
}
|