MediaWiki REL1_34
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
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}
static singleton()
Get the configured default GadgetRepo.
Class representing a list of resources for one gadget, basically a wrapper around the Gadget class.
getTargets()
Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile'].
getDependencies(ResourceLoaderContext $context=null)
Overrides ResourceLoaderModule::getDependencies()
getPages(ResourceLoaderContext $context)
Overrides the function from ResourceLoaderWikiModule class.
getMessages()
Get the messages needed for this module.
getType()
Overrides ResourceLoaderWikiModule::getType()
Wrapper for one gadget.
Definition Gadget.php:17
supportsResourceLoader()
Definition Gadget.php:204
getStyles()
Definition Gadget.php:234
static newEmptyGadget( $id)
Get a placeholder object to use if a gadget doesn't exist.
Definition Gadget.php:104
getScripts()
Definition Gadget.php:227
Context object that contains information about the state of a specific ResourceLoader web request.
Abstraction for ResourceLoader modules which pull from wiki pages.
$context
Definition load.php:45