jenkins-bot has submitted this change and it was merged. Change subject: Make GadgetResourceLoaderModule a simple wrapper around Gadget ......................................................................
Make GadgetResourceLoaderModule a simple wrapper around Gadget Change-Id: Ia402698ec2863b75ea1d2a95b4a7aa57cc29d0d1 --- M Gadgets.hooks.php M SpecialGadgets.php M backend/Gadget.php M backend/GadgetResourceLoaderModule.php 4 files changed, 52 insertions(+), 56 deletions(-) Approvals: Alex Monk: Looks good to me, approved jenkins-bot: Verified diff --git a/Gadgets.hooks.php b/Gadgets.hooks.php index 58819b8..f95ab56 100644 --- a/Gadgets.hooks.php +++ b/Gadgets.hooks.php @@ -309,7 +309,10 @@ foreach ( $gadgets as $gadget ) { $resourceLoader->register( $gadget->getModuleName(), - array( 'object' => $gadget->getModule() ) + array( + 'class' => 'GadgetResourceLoaderModule', + 'gadget' => $gadget + ) ); } return true; diff --git a/SpecialGadgets.php b/SpecialGadgets.php index 98187a8..2d971f6 100644 --- a/SpecialGadgets.php +++ b/SpecialGadgets.php @@ -364,14 +364,12 @@ $exportTitles[] = Title::makeTitleSafe( NS_GADGET, $style ); } - $gadgetModule = $gadget->getModule(); - // Module messages in NS_MEDIAWIKI - foreach( $gadgetModule->getMessages() as $message ) { + foreach( $gadget->getMessages() as $message ) { $message = Title::makeTitleSafe( NS_MEDIAWIKI, $message ); // Add this page and its subpages (for translations) $exportTitles = array_merge( $exportTitles, - $message, + $message, // @fixme this should be an array? $message->getSubpages() ); } diff --git a/backend/Gadget.php b/backend/Gadget.php index f3af5c3..cd6cde7 100644 --- a/backend/Gadget.php +++ b/backend/Gadget.php @@ -282,8 +282,8 @@ } /** - * Get the name of the ResourceLoader source for this gadget's module - * @return string + * Get the GadgetRepo this Gadget belongs to + * @return GadgetRepo */ public function getRepo() { return $this->repo; @@ -425,11 +425,11 @@ } /** - * Get the ResourceLoader module for this gadget, if available. - * @return ResourceLoaderModule object + * Returns a ResourceLoaderWikiModule-style array of pages + * + * @return array */ - public function getModule() { - // Build $pages + public function getPages() { $pages = array(); foreach ( $this->moduleData['scripts'] as $script ) { $pages["Gadget:$script"] = array( 'type' => 'script' ); @@ -438,14 +438,20 @@ $pages["Gadget:$style"] = array( 'type' => 'style' ); } + return $pages; + } + + /** + * Get the ResourceLoader module for this gadget, if available. + * + * This method really shouldn't be called unless there's a + * good reason for it. + * + * @return GadgetResourceLoaderModule + */ + public function getModule() { return new GadgetResourceLoaderModule( - $pages, - (array)$this->moduleData['dependencies'], - (array)$this->moduleData['messages'], - $this->repo->getSource(), - $this->moduleData['position'], - $this->timestamp, - $this->repo->getDB() + array( 'gadget' => $this ) ); } @@ -469,6 +475,14 @@ return $this->moduleData['dependencies']; } + public function getMessages() { + return $this->moduleData['messages']; + } + + public function getPosition() { + return $this->moduleData['position']; + } + /*** Public methods ***/ /** diff --git a/backend/GadgetResourceLoaderModule.php b/backend/GadgetResourceLoaderModule.php index 7e3bc24..ff8ee81 100644 --- a/backend/GadgetResourceLoaderModule.php +++ b/backend/GadgetResourceLoaderModule.php @@ -1,72 +1,53 @@ <?php /** - * ResourceLoader module for a single gadget + * ResourceLoader module for a single gadget, really just a wrapper + * around the Gadget class */ class GadgetResourceLoaderModule extends ResourceLoaderWikiModule { - protected $pages, $dependencies, $messages, $source, $definitiontimestamp; + /** @var Gadget $gadget */ + private $gadget; - /** - * Creates an instance of this class - * @param $pages Array: Associative array of pages in ResourceLoaderWikiModule-compatible - * format, for example: - * array( - * 'MediaWiki:Gadget-foo.js' => array( 'type' => 'script' ), - * 'MediaWiki:Gadget-foo.css' => array( 'type' => 'style' ), - * ) - * @param $dependencies Array: Names of resources this module depends on - * @param $messages Array: Keys of the i18n messages that this module needs - * @param $source String: Name of the source of this module, as defined in ResourceLoader - * @param $position String: Module position ('top' or 'bottom') - * @param $definitiontimestamp String: Last modification timestamp of the gadget metadata - * @param $db Database|null: Remote database object - */ - public function __construct( $pages, $dependencies, $messages, $source, $position, $definitiontimestamp, $db ) { - // TODO refactor this to take a Gadget object instead - $this->pages = $pages; - $this->dependencies = $dependencies; - $this->messages = $messages; - $this->source = $source; - $this->position = $position == 'top' ? 'top' : 'bottom'; - $this->definitiontimestamp = $definitiontimestamp; - $this->db = $db; + public function __construct( array $options ) { + $this->gadget = $options['gadget']; } protected function getDB() { - return $this->db; + return $this->gadget->getRepo()->getDB(); } /** * Overrides the abstract function from ResourceLoaderWikiModule class. * * This method is public because it's used by GadgetTest.php - * @return Array: $pages passed to __construct() + * @param ResourceLoaderContext $context + * @return array */ public function getPages( ResourceLoaderContext $context ) { - return $this->pages; + return $this->gadget->getPages(); } /** * Overrides ResourceLoaderModule::getDependencies() - * @return Array: Names of resources this module depends on + * @return array Names of resources this module depends on */ public function getDependencies() { - return $this->dependencies; + return $this->gadget->getDependencies(); } /** * Overrides ResourceLoaderModule::getMessages() - * @return Array: Keys of messages this module needs + * @return array Keys of messages this module needs */ public function getMessages() { - return $this->messages; + return $this->gadget->getMessages(); } /** * Overrides ResourceLoaderModule::getSource() - * @return String: Name of the source of this module as defined in ResourceLoader + * @return string Name of the source of this module as defined in ResourceLoader */ public function getSource() { - return $this->source; + return $this->gadget->getRepo()->getSource(); } /** @@ -74,17 +55,17 @@ * @return String: Module position, either 'top' or 'bottom' */ public function getPosition() { - return $this->position; + return $this->gadget->getPosition(); } /** * Overrides ResourceLoaderWikiModule::getModifiedTime() to take $definitiontimestamp * into account. - * @param $context ResourceLoaderContext object + * @param ResourceLoaderContext $context * @return int UNIX timestamp */ public function getModifiedTime( ResourceLoaderContext $context ) { $retval = parent::getModifiedTime( $context ); - return max( $retval, wfTimestamp( TS_UNIX, $this->definitiontimestamp ) ); + return max( $retval, wfTimestamp( TS_UNIX, $this->gadget->getTimestamp() ) ); } } -- To view, visit https://gerrit.wikimedia.org/r/154725 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ia402698ec2863b75ea1d2a95b4a7aa57cc29d0d1 Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/Gadgets Gerrit-Branch: RL2 Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com> Gerrit-Reviewer: Alex Monk <kren...@wikimedia.org> Gerrit-Reviewer: Catrope <roan.katt...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits