Index: trunk/extensions/Gadgets/Gadgets_body.php |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | * @license GNU General Public Licence 2.0 or later |
13 | 13 | */ |
14 | 14 | |
15 | | -class GadgetHooks extends OutputPage { |
| 15 | +class GadgetHooks { |
16 | 16 | /** |
17 | 17 | * ArticleSaveComplete hook handler. |
18 | 18 | * |
— | — | @@ -125,20 +125,9 @@ |
126 | 126 | |
127 | 127 | foreach ( $gadgets as $g ) { |
128 | 128 | $module = $g->getModule(); |
129 | | - $scriptsModule = $g->getScriptsModule(); |
130 | | - $stylesModule = $g->getStylesModule(); |
131 | | - |
132 | 129 | if ( $module ) { |
133 | 130 | $resourceLoader->register( $g->getModuleName(), $module ); |
134 | 131 | } |
135 | | - |
136 | | - if ( $scriptsModule ) { |
137 | | - $resourceLoader->register( $g->getScriptsModuleName(), $scriptsModule ); |
138 | | - } |
139 | | - |
140 | | - if ( $stylesModule ) { |
141 | | - $resourceLoader->register( $g->getStylesModuleName(), $stylesModule ); |
142 | | - } |
143 | 132 | } |
144 | 133 | return true; |
145 | 134 | |
— | — | @@ -163,17 +152,13 @@ |
164 | 153 | $lb->setCaller( __METHOD__ ); |
165 | 154 | $pages = array(); |
166 | 155 | |
167 | | - $stylesModules = array(); |
168 | 156 | foreach ( $gadgets as $gadget ) { |
169 | 157 | if ( $gadget->isEnabled( $wgUser ) && $gadget->isAllowed( $wgUser ) ) { |
170 | 158 | if ( $gadget->hasModule() ) { |
| 159 | + $out->addModuleStyles( $gadget->getModuleName() ); |
171 | 160 | $out->addModules( $gadget->getModuleName() ); |
172 | 161 | } |
173 | 162 | |
174 | | - if ( $gadget->hasStylesModule() ) { |
175 | | - $stylesModules[] = $gadget->getStylesModuleName(); |
176 | | - } |
177 | | - |
178 | 163 | foreach ( $gadget->getLegacyScripts() as $page ) { |
179 | 164 | $lb->add( NS_MEDIAWIKI, $page ); |
180 | 165 | $pages[] = $page; |
— | — | @@ -181,18 +166,6 @@ |
182 | 167 | } |
183 | 168 | } |
184 | 169 | |
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 | | - |
197 | 170 | $lb->execute( __METHOD__ ); |
198 | 171 | |
199 | 172 | $done = array(); |
— | — | @@ -357,27 +330,13 @@ |
358 | 331 | } |
359 | 332 | |
360 | 333 | /** |
361 | | - * @return String: Name of meta ResourceLoader module for this gadget |
| 334 | + * @return String: Name of ResourceLoader module for this gadget |
362 | 335 | */ |
363 | 336 | public function getModuleName() { |
364 | 337 | return "ext.gadget.{$this->name}"; |
365 | 338 | } |
366 | 339 | |
367 | 340 | /** |
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 | | - /** |
382 | 341 | * Checks whether this is an instance of an older version of this class deserialized from cache |
383 | 342 | * @return Boolean |
384 | 343 | */ |
— | — | @@ -424,24 +383,12 @@ |
425 | 384 | * @return Boolean: Whether this gadget has resources that can be loaded via ResourceLoader |
426 | 385 | */ |
427 | 386 | 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; |
429 | 390 | } |
430 | 391 | |
431 | 392 | /** |
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 | | - /** |
446 | 393 | * @return String: Definition for this gadget from MediaWiki:gadgets-definition |
447 | 394 | */ |
448 | 395 | public function getDefinition() { |
— | — | @@ -470,43 +417,17 @@ |
471 | 418 | } |
472 | 419 | |
473 | 420 | /** |
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. |
479 | 423 | * @return Mixed: GadgetResourceLoaderModule or false |
480 | 424 | */ |
481 | 425 | 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(); |
485 | 427 | |
486 | | - if ( $this->hasScriptsModule() ) { |
487 | | - $dependencies[] = $this->getScriptsModuleName(); |
| 428 | + foreach ( $this->styles as $style ) { |
| 429 | + $pages['MediaWiki:' . $style] = array( 'type' => 'style' ); |
488 | 430 | } |
489 | 431 | |
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 | | - |
511 | 432 | if ( $this->supportsResourceLoader() ) { |
512 | 433 | foreach ( $this->scripts as $script ) { |
513 | 434 | $pages['MediaWiki:' . $script] = array( 'type' => 'script' ); |
— | — | @@ -514,33 +435,13 @@ |
515 | 436 | } |
516 | 437 | |
517 | 438 | if ( !count( $pages ) ) { |
518 | | - return false; |
| 439 | + return null; |
519 | 440 | } |
520 | 441 | |
521 | 442 | return new GadgetResourceLoaderModule( $pages, $this->dependencies ); |
522 | 443 | } |
523 | 444 | |
524 | 445 | /** |
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 | | - /** |
545 | 446 | * Returns list of scripts that don't support ResourceLoader |
546 | 447 | * @return Array |
547 | 448 | */ |