2015-08-01 05:17:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2015-08-03 06:37:32 +00:00
|
|
|
* Class representing a list of resources for one gadget, basically a wrapper
|
|
|
|
* around the Gadget class.
|
2015-08-01 05:17:35 +00:00
|
|
|
*/
|
|
|
|
class GadgetResourceLoaderModule extends ResourceLoaderWikiModule {
|
2015-08-03 06:37:32 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Gadget
|
|
|
|
*/
|
|
|
|
private $gadget;
|
2015-08-01 05:17:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an instance of this class
|
|
|
|
*
|
2015-08-03 06:37:32 +00:00
|
|
|
* @param array $options
|
2015-08-01 05:17:35 +00:00
|
|
|
*/
|
2015-08-03 06:37:32 +00:00
|
|
|
public function __construct( array $options ) {
|
|
|
|
$this->id = $options['id'];
|
2015-08-01 05:17:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-08-03 06:37:32 +00:00
|
|
|
* @return Gadget instance this module is about
|
|
|
|
*/
|
|
|
|
private function getGadget() {
|
|
|
|
if ( !$this->gadget ) {
|
|
|
|
try {
|
|
|
|
$this->gadget = GadgetRepo::singleton()->getGadget( $this->id );
|
|
|
|
} catch ( InvalidArgumentException $e ) {
|
|
|
|
// Fallback to a placeholder object...
|
|
|
|
$this->gadget = Gadget::newEmptyGadget( $this->id );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->gadget;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Overrides the function from ResourceLoaderWikiModule class
|
|
|
|
* @param ResourceLoaderContext $context
|
|
|
|
* @return array
|
2015-08-01 05:17:35 +00:00
|
|
|
*/
|
|
|
|
protected function getPages( ResourceLoaderContext $context ) {
|
2015-08-03 06:37:32 +00:00
|
|
|
$gadget = $this->getGadget();
|
|
|
|
$pages = array();
|
|
|
|
|
|
|
|
foreach ( $gadget->getStyles() as $style ) {
|
|
|
|
$pages[$style] = array( 'type' => 'style' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $gadget->supportsResourceLoader() ) {
|
|
|
|
foreach ( $gadget->getScripts() as $script ) {
|
|
|
|
$pages[$script] = array( 'type' => 'script' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $pages;
|
2015-08-01 05:17:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Overrides ResourceLoaderModule::getDependencies()
|
|
|
|
* @param $context ResourceLoaderContext
|
|
|
|
* @return Array: Names of resources this module depends on
|
|
|
|
*/
|
|
|
|
public function getDependencies( ResourceLoaderContext $context = null ) {
|
2015-08-03 06:37:32 +00:00
|
|
|
return $this->getGadget()->getDependencies();
|
2015-08-01 05:17:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Overrides ResourceLoaderModule::getPosition()
|
|
|
|
* @return String: 'bottom' or 'top'
|
|
|
|
*/
|
|
|
|
public function getPosition() {
|
2015-08-03 06:37:32 +00:00
|
|
|
return $this->getGadget()->getPosition();
|
2015-08-01 05:17:35 +00:00
|
|
|
}
|
2015-08-03 06:34:16 +00:00
|
|
|
|
|
|
|
public function getMessages() {
|
2015-08-03 06:37:32 +00:00
|
|
|
return $this->getGadget()->getMessages();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTargets() {
|
|
|
|
return $this->getGadget()->getTargets();
|
2015-08-03 06:34:16 +00:00
|
|
|
}
|
2015-08-01 05:17:35 +00:00
|
|
|
}
|