r74195 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74194‎ | r74195 | r74196 >
Date:09:32, 3 October 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 1.5.3 - usage of the resource loader for the stuff in skins/, with fallback on the old code when the RL is not present.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Outputs.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/skins/SMW_tooltip.js (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Outputs.php
@@ -31,6 +31,43 @@
3232 protected static $mHeadItems = array();
3333
3434 /**
 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+ *
3572 * Announce that some head item (usually CSS or JavaScript) is required to
3673 * display the content just created. The function is called with an ID that
3774 * is one of SMW's SMW_HEADER_... constants, or a string ID followed by the
@@ -46,14 +83,13 @@
4784 * to be called "soon" -- there might always be other hooks first that commit the
4885 * existing data wrongly, depending on installed extensions and background jobs!
4986 *
 87+ * @since 1.5.3
 88+ *
5089 * @param $id string or predefined constant for identifying a head item
5190 * @param $item string containing a complete HTML-compatibly text snippet that
5291 * 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.
5692 */
57 - static public function requireHeadItem( $id, $item = '' ) {
 93+ protected static function requireHeadItemOld( $id, $item ) {
5894 if ( is_numeric( $id ) ) {
5995 global $smwgScriptPath;
6096
@@ -78,7 +114,7 @@
79115 }
80116 } else { // custom head item
81117 self::$mHeadItems[$id] = $item;
82 - }
 118+ }
83119 }
84120
85121 /**
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php
@@ -1,11 +1,16 @@
22 <?php
 3+
34 /**
45 * Global functions used for setting up the Semantic MediaWiki extension.
5 - * @file
 6+ *
 7+ * @file SMW_Setup.php
68 * @ingroup SMW
79 */
810
 11+// The SMW version number.
912 define( 'SMW_VERSION', '1.5.3 alpha' );
 13+
 14+// A flag used to indicate SMW defines a semantic extension type for extension crdits.
1015 define( 'SEMANTIC_EXTENSION_TYPE', true );
1116
1217 require_once( 'SMW_GlobalFunctions.php' );
@@ -49,6 +54,8 @@
5055
5156 $wgHooks['ParserTestTables'][] = 'smwfOnParserTestTables';
5257 $wgHooks['AdminLinks'][] = 'smwfAddToAdminLinks';
 58+
 59+ $wgHooks['ResourceLoaderRegisterModules'][] = 'smwfRegisterResourceLoaderModules';
5360
5461 if ( version_compare( $wgVersion, '1.17alpha', '>=' ) ) {
5562 // For MediaWiki 1.17 alpha and later.
@@ -494,3 +501,41 @@
495502
496503 wfProfileOut( 'smwfInitContentLanguage (SMW)' );
497504 }
 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 @@
174174 bottom: 42,
175175 left: 33,
176176 right: 40
177 -}
 177+};
178178
179179 /*pixels from boundary of the whole bubble div to the tip of the arrow*/
180180 BubbleTT._arrowOffsets = {
@@ -181,7 +181,7 @@
182182 bottom: 9,
183183 left: 1,
184184 right: 8
185 -}
 185+};
186186
187187 BubbleTT._bubblePadding = 15;
188188 BubbleTT._bubblePointOffset = 15;
@@ -252,7 +252,7 @@
253253 divImg.style.top = top + "px";
254254 setImg(divImg, url, width, height);
255255 divInner.appendChild(divImg);
256 - }
 256+ };
257257
258258 createImg(imagePath + "bubble-top-left.png", 0, 0, margins.left, margins.top);
259259 createImg(imagePath + "bubble-top.png", margins.left, 0, contentWidth, margins.top);
@@ -378,7 +378,7 @@
379379 }
380380 }
381381 bubble.content.appendChild(div);
382 -}
 382+};
383383
384384
385385 /*==================================================================
@@ -505,11 +505,11 @@
506506 return handler(elmt, evt, target);
507507 }
508508 return true;
509 - }
 509+ };
510510
511511 if (BubbleTT.Platform.browser.isIE) {
512512 elmt.attachEvent("on" + eventName, handler2);
513513 } else {
514514 elmt.addEventListener(eventName, handler2, false);
515515 }
516 -};
 516+};
\ No newline at end of file

Status & tagging log