r97021 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97020‎ | r97021 | r97022 >
Date:22:37, 13 September 2011
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
RTLDebug: Optimize JS + fix error in ResourceLoaderModules
* Added remoteExtPath so that the extension is also loaded property in more exotic setups (ie. non standard wgExtensionAssetsPath, surprised it worked at all without that)
* Rewrite javascript to not select stuff in the <head>, and use jQuery's .css() and strict comparison to speed up the giant loop
* Using context instead of globals in the BeforePageDisplay hook
Modified paths:
  • /trunk/extensions/RTLDebug/RTLDebug.php (modified) (history)
  • /trunk/extensions/RTLDebug/rtl-debug.js (modified) (history)

Diff [purge]

Index: trunk/extensions/RTLDebug/rtl-debug.js
@@ -1,10 +1,12 @@
2 -(function($) {
3 - $('*').each( function() {
4 - var style = window.getComputedStyle( this, null );
5 - if ( style.getPropertyValue( 'direction' ) == 'rtl' ) {
6 - $(this).addClass( 'mw-rtldebug-rtl' );
7 - } else {
8 - $(this).addClass( 'mw-rtldebug-ltr' );
9 - }
10 - } );
11 -})(jQuery);
 2+( function( $ ) {
 3+
 4+ // Select all elements in the body (we don't need stuff in <head>)
 5+ $( document.body )
 6+ .find( '*' )
 7+ .andSelf() // include body as well
 8+ .each( function() {
 9+ var $el = $( this );
 10+ $el.addClass( $el.css( 'direction' ) === 'rtl' ? 'mw-rtldebug-rtl' : 'mw-rtldebug-ltr' );
 11+ } );
 12+
 13+} )( jQuery );
Index: trunk/extensions/RTLDebug/RTLDebug.php
@@ -24,17 +24,16 @@
2525 $wgResourceModules['ext.rtlDebug'] = array(
2626 'scripts' => 'rtl-debug.js',
2727 'styles' => 'rtl-debug.css',
28 - 'localBasePath' => dirname( __FILE__ )
 28+ 'remoteExtPath' => 'RTLDebug',
 29+ 'localBasePath' => dirname( __FILE__ ),
2930 );
3031
3132 $wgHooks['BeforePageDisplay'][] = 'wfRtlDebug_BeforePageDisplay';
3233 $wgExtraLanguageNames['en-rtl'] = 'English (RTL)';
3334
3435 function wfRtlDebug_BeforePageDisplay( &$out, &$skin ) {
35 - global $wgLang;
36 -
3736 $out->addModules( 'ext.rtlDebug' );
38 - if ( $wgLang->getCode() == 'en-rtl' ) {
 37+ if ( $out->getLang()->getCode() == 'en-rtl' ) {
3938 $out->addInlineStyle( '* { unicode-bidi: bidi-override; }' );
4039 }
4140 return true;

Comments

#Comment by Nikerabbit (talk | contribs)   06:42, 14 September 2011

Feels a bit faster now, but still takes many seconds on complex pages.

#Comment by Catrope (talk | contribs)   10:20, 14 September 2011

A missing or incorrect remoteExtPath only breaks scripts in debug mode. In production mode, the only thing you would notice is 404s for images referenced in CSS styles (because image URLs will be rewritten wrong), unless the images are @embed-ded in which case only IE6 and 7 will get the 404s.

Status & tagging log