r110600 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110599‎ | r110600 | r110601 >
Date:19:04, 2 February 2012
Author:catrope
Status:ok (Comments)
Tags:
Comment:
Revert r106007 (Split Gadget modules into two, one for scripts and one for styles): I like the concept of having multiple modules, and I'll probably implement this in the RL2 branch, but this specific implementation has issues (subclassing OutputPage, building its own head items) that were pointed out on CR but never fixed.
Modified paths:
  • /trunk/extensions/Gadgets/Gadgets_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Gadgets/Gadgets_body.php
@@ -11,7 +11,7 @@
1212 * @license GNU General Public Licence 2.0 or later
1313 */
1414
15 -class GadgetHooks extends OutputPage {
 15+class GadgetHooks {
1616 /**
1717 * ArticleSaveComplete hook handler.
1818 *
@@ -125,20 +125,9 @@
126126
127127 foreach ( $gadgets as $g ) {
128128 $module = $g->getModule();
129 - $scriptsModule = $g->getScriptsModule();
130 - $stylesModule = $g->getStylesModule();
131 -
132129 if ( $module ) {
133130 $resourceLoader->register( $g->getModuleName(), $module );
134131 }
135 -
136 - if ( $scriptsModule ) {
137 - $resourceLoader->register( $g->getScriptsModuleName(), $scriptsModule );
138 - }
139 -
140 - if ( $stylesModule ) {
141 - $resourceLoader->register( $g->getStylesModuleName(), $stylesModule );
142 - }
143132 }
144133 return true;
145134
@@ -163,17 +152,13 @@
164153 $lb->setCaller( __METHOD__ );
165154 $pages = array();
166155
167 - $stylesModules = array();
168156 foreach ( $gadgets as $gadget ) {
169157 if ( $gadget->isEnabled( $wgUser ) && $gadget->isAllowed( $wgUser ) ) {
170158 if ( $gadget->hasModule() ) {
 159+ $out->addModuleStyles( $gadget->getModuleName() );
171160 $out->addModules( $gadget->getModuleName() );
172161 }
173162
174 - if ( $gadget->hasStylesModule() ) {
175 - $stylesModules[] = $gadget->getStylesModuleName();
176 - }
177 -
178163 foreach ( $gadget->getLegacyScripts() as $page ) {
179164 $lb->add( NS_MEDIAWIKI, $page );
180165 $pages[] = $page;
@@ -181,18 +166,6 @@
182167 }
183168 }
184169
185 - if ( count( $stylesModules ) ) {
186 - $out->addHeadItem( 'ext.gadget', $out->makeResourceLoaderLink(
187 - $stylesModules, ResourceLoaderModule::TYPE_STYLES
188 - ) . Html::inlineScript(
189 - ResourceLoader::makeLoaderConditionalScript(
190 - ResourceLoader::makeLoaderStateScript(
191 - array_fill_keys( $stylesModules, 'ready' )
192 - )
193 - )
194 - ) );
195 - }
196 -
197170 $lb->execute( __METHOD__ );
198171
199172 $done = array();
@@ -357,27 +330,13 @@
358331 }
359332
360333 /**
361 - * @return String: Name of meta ResourceLoader module for this gadget
 334+ * @return String: Name of ResourceLoader module for this gadget
362335 */
363336 public function getModuleName() {
364337 return "ext.gadget.{$this->name}";
365338 }
366339
367340 /**
368 - * @return String: Name of scripts ResourceLoader module for this gadget
369 - */
370 - public function getScriptsModuleName() {
371 - return "ext.gadget.{$this->name}.scripts";
372 - }
373 -
374 - /**
375 - * @return String: Name of styles ResourceLoader module for this gadget
376 - */
377 - public function getStylesModuleName() {
378 - return "ext.gadget.{$this->name}.styles";
379 - }
380 -
381 - /**
382341 * Checks whether this is an instance of an older version of this class deserialized from cache
383342 * @return Boolean
384343 */
@@ -424,24 +383,12 @@
425384 * @return Boolean: Whether this gadget has resources that can be loaded via ResourceLoader
426385 */
427386 public function hasModule() {
428 - return $this->hasScriptsModule() || $this->hasStylesModule() || count( $this->dependencies );
 387+ return count( $this->styles )
 388+ + ( $this->supportsResourceLoader() ? count( $this->scripts ) : 0 )
 389+ > 0;
429390 }
430391
431392 /**
432 - * @return Boolean: Whether this gadget has scripts module to be loaded via ResourceLoader
433 - */
434 - public function hasScriptsModule() {
435 - return $this->supportsResourceLoader() && ( count( $this->scripts ) > 0 );
436 - }
437 -
438 - /**
439 - * @return Boolean: Whether this gadget has styles module to be loaded via ResourceLoader
440 - */
441 - public function hasStylesModule() {
442 - return count( $this->styles ) > 0;
443 - }
444 -
445 - /**
446393 * @return String: Definition for this gadget from MediaWiki:gadgets-definition
447394 */
448395 public function getDefinition() {
@@ -470,43 +417,17 @@
471418 }
472419
473420 /**
474 - * Returns meta module for ResourceLoader, see getModuleName() for its name.
475 - * Meta module contains no real data to be loaded but has dependencies of
476 - * this gadget's scripts and styles module as well as other dependencies.
477 - * If our gadget has no scripts or styles or dependencies suitable for RL,
478 - * false will be returned.
 421+ * Returns module for ResourceLoader, see getModuleName() for its name.
 422+ * If our gadget has no scripts or styles suitable for RL, false will be returned.
479423 * @return Mixed: GadgetResourceLoaderModule or false
480424 */
481425 public function getModule() {
482 - // Don't omit this. Styles module may be marked as ready with
483 - // mw.loader.state() without dependencies fully resolved.
484 - $dependencies = $this->dependencies;
 426+ $pages = array();
485427
486 - if ( $this->hasScriptsModule() ) {
487 - $dependencies[] = $this->getScriptsModuleName();
 428+ foreach ( $this->styles as $style ) {
 429+ $pages['MediaWiki:' . $style] = array( 'type' => 'style' );
488430 }
489431
490 - if ( $this->hasStylesModule() ) {
491 - $dependencies[] = $this->getStylesModuleName();
492 - }
493 -
494 - if ( !count( $dependencies ) ) {
495 - return false;
496 - }
497 -
498 - return new GadgetResourceLoaderModule( array(), $dependencies );
499 - }
500 -
501 - /**
502 - * Returns scripts module for ResourceLoader, see getScriptsModuleName()
503 - * for its name. This module contains all scripts in the gadget if this
504 - * gadget support ResourceLoader, or false if it doesn't, or there's no
505 - * script at all.
506 - * @return Mixed: GadgetResourceLoaderModule or false
507 - */
508 - public function getScriptsModule() {
509 - $pages = array();
510 -
511432 if ( $this->supportsResourceLoader() ) {
512433 foreach ( $this->scripts as $script ) {
513434 $pages['MediaWiki:' . $script] = array( 'type' => 'script' );
@@ -514,33 +435,13 @@
515436 }
516437
517438 if ( !count( $pages ) ) {
518 - return false;
 439+ return null;
519440 }
520441
521442 return new GadgetResourceLoaderModule( $pages, $this->dependencies );
522443 }
523444
524445 /**
525 - * Returns styles module for ResourceLoader, see getStylesModuleName()
526 - * for its name. This module contains all styles in the gadget, or
527 - * false if there's no style.
528 - * @return Mixed: GadgetResourceLoaderModule or false
529 - */
530 - public function getStylesModule() {
531 - $pages = array();
532 -
533 - foreach ( $this->styles as $style ) {
534 - $pages['MediaWiki:' . $style] = array( 'type' => 'style' );
535 - }
536 -
537 - if ( !count( $pages ) ) {
538 - return false;
539 - }
540 -
541 - return new GadgetResourceLoaderModule( $pages, $this->dependencies );
542 - }
543 -
544 - /**
545446 * Returns list of scripts that don't support ResourceLoader
546447 * @return Array
547448 */

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r106007Followup r100497, r101827: use another way which doesn't look that hacky to l...liangent10:41, 13 December 2011

Comments

#Comment by Aaron Schulz (talk | contribs)   19:07, 2 February 2012

So does this also revert the two revs the reverted rev followed-up?

#Comment by Catrope (talk | contribs)   19:10, 2 February 2012

No, those were actually good. I forgot to mention that: loading styles early was actually done right in r100497. The only thing that r106007 changed was that styles were split out into a separate module and no longer loaded twice. Loading styles twice is not the nicest thing ever but I don't think it's a big issue.

#Comment by Aaron Schulz (talk | contribs)   19:13, 2 February 2012

r100497 added +class GadgetHooks extends OutputPage {, which this is reverted, which looks a bit confusing.

#Comment by Aaron Schulz (talk | contribs)   19:15, 2 February 2012

Ahh, r101828.

#Comment by Catrope (talk | contribs)   19:15, 2 February 2012

That was removed in r101828 and re-added in r106007. Yeah, the history of this whole thing is a bit confusing, it took me a while to decide which intermediate state I liked best and what I should revert to get there.

Status & tagging log