2015-07-18 22:40:42 +00:00
|
|
|
<?php
|
|
|
|
|
2017-11-07 19:36:44 +00:00
|
|
|
use MediaWiki\Linker\LinkTarget;
|
|
|
|
|
2015-07-18 22:40:42 +00:00
|
|
|
abstract class GadgetRepo {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var GadgetRepo|null
|
|
|
|
*/
|
|
|
|
private static $instance;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the ids of the gadgets provided by this repository
|
|
|
|
*
|
2015-08-03 06:37:32 +00:00
|
|
|
* It's possible this could be out of sync with what
|
|
|
|
* getGadget() will return due to caching
|
|
|
|
*
|
2015-07-18 22:40:42 +00:00
|
|
|
* @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 );
|
|
|
|
|
2017-11-07 19:36:44 +00:00
|
|
|
/**
|
|
|
|
* Given that the provided page was updated, invalidate
|
|
|
|
* caches if necessary
|
|
|
|
*
|
|
|
|
* @param LinkTarget $target
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handlePageUpdate( LinkTarget $target ) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given that the provided page was created, invalidate
|
|
|
|
* caches if necessary
|
|
|
|
*
|
|
|
|
* @param LinkTarget $target
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handlePageCreation( LinkTarget $target ) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given that the provided page was updated, invalidate
|
|
|
|
* caches if necessary
|
|
|
|
*
|
|
|
|
* @param LinkTarget $target
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handlePageDeletion( LinkTarget $target ) {
|
|
|
|
}
|
|
|
|
|
2015-07-18 22:40:42 +00:00
|
|
|
/**
|
|
|
|
* Get a list of gadgets sorted by category
|
|
|
|
*
|
2016-12-28 10:25:47 +00:00
|
|
|
* @return array [ 'category' => [ 'name' => $gadget ] ]
|
2015-07-18 22:40:42 +00:00
|
|
|
*/
|
|
|
|
public function getStructuredList() {
|
2016-12-28 10:25:47 +00:00
|
|
|
$list = [];
|
2015-07-18 22:40:42 +00:00
|
|
|
foreach ( $this->getGadgetIds() as $id ) {
|
2015-08-03 06:37:32 +00:00
|
|
|
try {
|
|
|
|
$gadget = $this->getGadget( $id );
|
|
|
|
} catch ( InvalidArgumentException $e ) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-07-18 22:40:42 +00:00
|
|
|
$list[$gadget->getCategory()][$gadget->getName()] = $gadget;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-08-03 06:37:32 +00:00
|
|
|
* Get the configured default GadgetRepo.
|
2015-07-18 22:40:42 +00:00
|
|
|
*
|
|
|
|
* @return GadgetRepo
|
|
|
|
*/
|
|
|
|
public static function singleton() {
|
|
|
|
if ( self::$instance === null ) {
|
2021-10-09 00:34:45 +00:00
|
|
|
// @todo use Config here
|
|
|
|
global $wgGadgetsRepoClass;
|
2015-08-03 06:37:32 +00:00
|
|
|
self::$instance = new $wgGadgetsRepoClass();
|
2015-07-18 22:40:42 +00:00
|
|
|
}
|
|
|
|
return self::$instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Should only be used by unit tests
|
|
|
|
*
|
|
|
|
* @param GadgetRepo|null $repo
|
|
|
|
*/
|
|
|
|
public static function setSingleton( $repo = null ) {
|
|
|
|
self::$instance = $repo;
|
|
|
|
}
|
|
|
|
}
|