MediaWiki  1.34.0
GadgetResourceLoaderModule.php
Go to the documentation of this file.
1 <?php
2 
11  private $id;
12 
16  private $gadget;
17 
21  public function __construct( array $options ) {
22  $this->id = $options['id'];
23  }
24 
28  private function getGadget() {
29  if ( !$this->gadget ) {
30  try {
31  $this->gadget = GadgetRepo::singleton()->getGadget( $this->id );
32  } catch ( InvalidArgumentException $e ) {
33  // Fallback to a placeholder object...
34  $this->gadget = Gadget::newEmptyGadget( $this->id );
35  }
36  }
37 
38  return $this->gadget;
39  }
40 
46  protected function getPages( ResourceLoaderContext $context ) {
47  $gadget = $this->getGadget();
48  $pages = [];
49 
50  foreach ( $gadget->getStyles() as $style ) {
51  $pages[$style] = [ 'type' => 'style' ];
52  }
53 
55  foreach ( $gadget->getScripts() as $script ) {
56  $pages[$script] = [ 'type' => 'script' ];
57  }
58  }
59 
60  return $pages;
61  }
62 
68  public function getDependencies( ResourceLoaderContext $context = null ) {
69  return $this->getGadget()->getDependencies();
70  }
71 
76  public function getType() {
77  return $this->getGadget()->getType() === 'styles'
78  ? ResourceLoaderModule::LOAD_STYLES
79  : ResourceLoaderModule::LOAD_GENERAL;
80  }
81 
82  public function getMessages() {
83  return $this->getGadget()->getMessages();
84  }
85 
86  public function getTargets() {
87  return $this->getGadget()->getTargets();
88  }
89 
90  public function getGroup() {
91  return 'site';
92  }
93 }
GadgetResourceLoaderModule\getPages
getPages(ResourceLoaderContext $context)
Overrides the function from ResourceLoaderWikiModule class.
Definition: GadgetResourceLoaderModule.php:46
ResourceLoaderContext
Context object that contains information about the state of a specific ResourceLoader web request.
Definition: ResourceLoaderContext.php:33
GadgetResourceLoaderModule\getDependencies
getDependencies(ResourceLoaderContext $context=null)
Overrides ResourceLoaderModule::getDependencies()
Definition: GadgetResourceLoaderModule.php:68
GadgetResourceLoaderModule\getTargets
getTargets()
Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile'].
Definition: GadgetResourceLoaderModule.php:86
Gadget\supportsResourceLoader
supportsResourceLoader()
Definition: Gadget.php:204
Gadget\getStyles
getStyles()
Definition: Gadget.php:234
ResourceLoaderWikiModule
Abstraction for ResourceLoader modules which pull from wiki pages.
Definition: ResourceLoaderWikiModule.php:53
Gadget\getScripts
getScripts()
Definition: Gadget.php:227
GadgetResourceLoaderModule\getGroup
getGroup()
Get group name.
Definition: GadgetResourceLoaderModule.php:90
Gadget
Wrapper for one gadget.
Definition: Gadget.php:17
GadgetResourceLoaderModule\getGadget
getGadget()
Definition: GadgetResourceLoaderModule.php:28
GadgetResourceLoaderModule\$id
string $id
Definition: GadgetResourceLoaderModule.php:11
GadgetRepo\singleton
static singleton()
Get the configured default GadgetRepo.
Definition: GadgetRepo.php:88
GadgetResourceLoaderModule\getType
getType()
Overrides ResourceLoaderWikiModule::getType()
Definition: GadgetResourceLoaderModule.php:76
Gadget\newEmptyGadget
static newEmptyGadget( $id)
Get a placeholder object to use if a gadget doesn't exist.
Definition: Gadget.php:104
GadgetResourceLoaderModule
Class representing a list of resources for one gadget, basically a wrapper around the Gadget class.
Definition: GadgetResourceLoaderModule.php:7
$context
$context
Definition: load.php:45
GadgetResourceLoaderModule\$gadget
Gadget $gadget
Definition: GadgetResourceLoaderModule.php:16
GadgetResourceLoaderModule\getMessages
getMessages()
Get the messages needed for this module.
Definition: GadgetResourceLoaderModule.php:82
GadgetResourceLoaderModule\__construct
__construct(array $options)
Definition: GadgetResourceLoaderModule.php:21