MediaWiki  1.34.0
GadgetRepo.php
Go to the documentation of this file.
1 <?php
2 
4 
5 abstract class GadgetRepo {
6 
10  private static $instance;
11 
20  abstract public function getGadgetIds();
21 
29  abstract public function getGadget( $id );
30 
39  public function handlePageUpdate( LinkTarget $target ) {
40  }
41 
50  public function handlePageCreation( LinkTarget $target ) {
51  }
52 
61  public function handlePageDeletion( LinkTarget $target ) {
62  }
63 
69  public function getStructuredList() {
70  $list = [];
71  foreach ( $this->getGadgetIds() as $id ) {
72  try {
73  $gadget = $this->getGadget( $id );
74  } catch ( InvalidArgumentException $e ) {
75  continue;
76  }
77  $list[$gadget->getCategory()][$gadget->getName()] = $gadget;
78  }
79 
80  return $list;
81  }
82 
88  public static function singleton() {
89  if ( self::$instance === null ) {
90  global $wgGadgetsRepoClass; // @todo use Config here
91  self::$instance = new $wgGadgetsRepoClass();
92  }
93  return self::$instance;
94  }
95 
101  public static function setSingleton( $repo = null ) {
102  self::$instance = $repo;
103  }
104 }
GadgetRepo\getGadgetIds
getGadgetIds()
Get the ids of the gadgets provided by this repository.
GadgetRepo\getGadget
getGadget( $id)
Get the Gadget object for a given gadget id.
GadgetRepo\$instance
static GadgetRepo null $instance
Definition: GadgetRepo.php:10
GadgetRepo\handlePageCreation
handlePageCreation(LinkTarget $target)
Given that the provided page was created, invalidate caches if necessary.
Definition: GadgetRepo.php:50
GadgetRepo\handlePageDeletion
handlePageDeletion(LinkTarget $target)
Given that the provided page was updated, invalidate caches if necessary.
Definition: GadgetRepo.php:61
GadgetRepo\singleton
static singleton()
Get the configured default GadgetRepo.
Definition: GadgetRepo.php:88
GadgetRepo
Definition: GadgetRepo.php:5
GadgetRepo\handlePageUpdate
handlePageUpdate(LinkTarget $target)
Given that the provided page was updated, invalidate caches if necessary.
Definition: GadgetRepo.php:39
GadgetRepo\setSingleton
static setSingleton( $repo=null)
Should only be used by unit tests.
Definition: GadgetRepo.php:101
MediaWiki\Linker\LinkTarget
Definition: LinkTarget.php:26
GadgetRepo\getStructuredList
getStructuredList()
Get a list of gadgets sorted by category.
Definition: GadgetRepo.php:69