Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Outputs.php |
— | — | @@ -31,6 +31,43 @@ |
32 | 32 | protected static $mHeadItems = array(); |
33 | 33 | |
34 | 34 | /** |
| 35 | + * Adds rousource loader modules or other head items. |
| 36 | + * Falls back on requireHeadItemOld if the Resource Loader (MW >1.17) is not available. |
| 37 | + * |
| 38 | + * @param mixed $id |
| 39 | + * @param string $item |
| 40 | + */ |
| 41 | + public static function requireHeadItem( $id, $item = '' ) { |
| 42 | + global $wgVersion; |
| 43 | + |
| 44 | + // Use the b/c method when the resource loader is not available. |
| 45 | + if ( !method_exists( 'OutputPage', 'addModules' ) ) { |
| 46 | + return self::requireHeadItemOld( $id, $item ); |
| 47 | + } |
| 48 | + |
| 49 | + if ( is_numeric( $id ) ) { |
| 50 | + global $wgOut; |
| 51 | + switch ( $id ) { |
| 52 | + case SMW_HEADER_TOOLTIP: |
| 53 | + $wgOut->addModules( 'ext.smw.tooltips' ); |
| 54 | + break; |
| 55 | + case SMW_HEADER_SORTTABLE: |
| 56 | + $wgOut->addModules( 'ext.smw.sorttable' ); |
| 57 | + break; |
| 58 | + case SMW_HEADER_STYLE: |
| 59 | + $wgOut->addModules( 'ext.smw.style' ); |
| 60 | + break; |
| 61 | + } |
| 62 | + } |
| 63 | + else { |
| 64 | + // This should not be used anymore; use the RL directly. |
| 65 | + self::$mHeadItems[$id] = $item; |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Method for backward compatibility with MW pre-1.17. |
| 71 | + * |
35 | 72 | * Announce that some head item (usually CSS or JavaScript) is required to |
36 | 73 | * display the content just created. The function is called with an ID that |
37 | 74 | * is one of SMW's SMW_HEADER_... constants, or a string ID followed by the |
— | — | @@ -46,14 +83,13 @@ |
47 | 84 | * to be called "soon" -- there might always be other hooks first that commit the |
48 | 85 | * existing data wrongly, depending on installed extensions and background jobs! |
49 | 86 | * |
| 87 | + * @since 1.5.3 |
| 88 | + * |
50 | 89 | * @param $id string or predefined constant for identifying a head item |
51 | 90 | * @param $item string containing a complete HTML-compatibly text snippet that |
52 | 91 | * should go into the HTML header; only required if $id is no built-in constant. |
53 | | - * |
54 | | - * FIXME: switch on precence of the resource loader (introduced in MW 1.17). |
55 | | - * SMW_sorttable.js uses addOnloadHook and breaks as it is now on 1.17. |
56 | 92 | */ |
57 | | - static public function requireHeadItem( $id, $item = '' ) { |
| 93 | + protected static function requireHeadItemOld( $id, $item ) { |
58 | 94 | if ( is_numeric( $id ) ) { |
59 | 95 | global $smwgScriptPath; |
60 | 96 | |
— | — | @@ -78,7 +114,7 @@ |
79 | 115 | } |
80 | 116 | } else { // custom head item |
81 | 117 | self::$mHeadItems[$id] = $item; |
82 | | - } |
| 118 | + } |
83 | 119 | } |
84 | 120 | |
85 | 121 | /** |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php |
— | — | @@ -1,11 +1,16 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | 5 | * Global functions used for setting up the Semantic MediaWiki extension. |
5 | | - * @file |
| 6 | + * |
| 7 | + * @file SMW_Setup.php |
6 | 8 | * @ingroup SMW |
7 | 9 | */ |
8 | 10 | |
| 11 | +// The SMW version number. |
9 | 12 | define( 'SMW_VERSION', '1.5.3 alpha' ); |
| 13 | + |
| 14 | +// A flag used to indicate SMW defines a semantic extension type for extension crdits. |
10 | 15 | define( 'SEMANTIC_EXTENSION_TYPE', true ); |
11 | 16 | |
12 | 17 | require_once( 'SMW_GlobalFunctions.php' ); |
— | — | @@ -49,6 +54,8 @@ |
50 | 55 | |
51 | 56 | $wgHooks['ParserTestTables'][] = 'smwfOnParserTestTables'; |
52 | 57 | $wgHooks['AdminLinks'][] = 'smwfAddToAdminLinks'; |
| 58 | + |
| 59 | + $wgHooks['ResourceLoaderRegisterModules'][] = 'smwfRegisterResourceLoaderModules'; |
53 | 60 | |
54 | 61 | if ( version_compare( $wgVersion, '1.17alpha', '>=' ) ) { |
55 | 62 | // For MediaWiki 1.17 alpha and later. |
— | — | @@ -494,3 +501,41 @@ |
495 | 502 | |
496 | 503 | wfProfileOut( 'smwfInitContentLanguage (SMW)' ); |
497 | 504 | } |
| 505 | + |
| 506 | +/** |
| 507 | + * Register the resource modules for the resource loader. |
| 508 | + * |
| 509 | + * @since 1.5.3 |
| 510 | + * |
| 511 | + * @param ResourceLoader $resourceLoader |
| 512 | + * |
| 513 | + * @return true |
| 514 | + */ |
| 515 | +function smwfRegisterResourceLoaderModules( ResourceLoader &$resourceLoader ) { |
| 516 | + global $smwgScriptPath, $wgContLang; |
| 517 | + |
| 518 | + $modules = array( |
| 519 | + 'ext.smw.style' => array( |
| 520 | + 'styles' => $smwgScriptPath . ( $wgContLang->isRTL() ? '/skins/SMW_custom_rtl.css' : '/skins/SMW_custom.css' ) |
| 521 | + ), |
| 522 | + 'ext.smw.tooltips' => array( |
| 523 | + 'scripts' => $smwgScriptPath . '/skins/SMW_tooltip.js', |
| 524 | + 'dependencies' => array( |
| 525 | + 'mediawiki.legacy.wikibits', |
| 526 | + 'ext.smw.style' |
| 527 | + ) |
| 528 | + ), |
| 529 | + 'ext.smw.sorttable' => array( |
| 530 | + 'scripts' => $smwgScriptPath . '/skins/SMW_sorttable.js', |
| 531 | + 'dependencies' => 'ext.smw.style' |
| 532 | + ) |
| 533 | + ); |
| 534 | + |
| 535 | + foreach ( $modules as $name => $resources ) { |
| 536 | + $resourceLoader->register( $name, new ResourceLoaderFileModule( |
| 537 | + array_merge_recursive( $resources, array( 'group' => 'ext.smw' ) ) |
| 538 | + ) ); |
| 539 | + } |
| 540 | + |
| 541 | + return true; |
| 542 | +} |
\ No newline at end of file |
Index: trunk/extensions/SemanticMediaWiki/skins/SMW_tooltip.js |
— | — | @@ -173,7 +173,7 @@ |
174 | 174 | bottom: 42, |
175 | 175 | left: 33, |
176 | 176 | right: 40 |
177 | | -} |
| 177 | +}; |
178 | 178 | |
179 | 179 | /*pixels from boundary of the whole bubble div to the tip of the arrow*/ |
180 | 180 | BubbleTT._arrowOffsets = { |
— | — | @@ -181,7 +181,7 @@ |
182 | 182 | bottom: 9, |
183 | 183 | left: 1, |
184 | 184 | right: 8 |
185 | | -} |
| 185 | +}; |
186 | 186 | |
187 | 187 | BubbleTT._bubblePadding = 15; |
188 | 188 | BubbleTT._bubblePointOffset = 15; |
— | — | @@ -252,7 +252,7 @@ |
253 | 253 | divImg.style.top = top + "px"; |
254 | 254 | setImg(divImg, url, width, height); |
255 | 255 | divInner.appendChild(divImg); |
256 | | - } |
| 256 | + }; |
257 | 257 | |
258 | 258 | createImg(imagePath + "bubble-top-left.png", 0, 0, margins.left, margins.top); |
259 | 259 | createImg(imagePath + "bubble-top.png", margins.left, 0, contentWidth, margins.top); |
— | — | @@ -378,7 +378,7 @@ |
379 | 379 | } |
380 | 380 | } |
381 | 381 | bubble.content.appendChild(div); |
382 | | -} |
| 382 | +}; |
383 | 383 | |
384 | 384 | |
385 | 385 | /*================================================================== |
— | — | @@ -505,11 +505,11 @@ |
506 | 506 | return handler(elmt, evt, target); |
507 | 507 | } |
508 | 508 | return true; |
509 | | - } |
| 509 | + }; |
510 | 510 | |
511 | 511 | if (BubbleTT.Platform.browser.isIE) { |
512 | 512 | elmt.attachEvent("on" + eventName, handler2); |
513 | 513 | } else { |
514 | 514 | elmt.addEventListener(eventName, handler2, false); |
515 | 515 | } |
516 | | -}; |
| 516 | +}; |
\ No newline at end of file |