r96956 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96955‎ | r96956 | r96957 >
Date:11:36, 13 September 2011
Author:tstarling
Status:ok (Comments)
Tags:
Comment:
An RTL visual debugging feature. See the comment on RTLDebug.php for the rationale.
Modified paths:
  • /trunk/extensions/RTLDebug (added) (history)
  • /trunk/extensions/RTLDebug/RTLDebug.php (added) (history)
  • /trunk/extensions/RTLDebug/rtl-debug.js (added) (history)

Diff [purge]

Index: trunk/extensions/RTLDebug/rtl-debug.js
@@ -0,0 +1,11 @@
 2+jQuery('*').each( function( index, elt ) {
 3+ var style = window.getComputedStyle( elt, null );
 4+ var background;
 5+ if ( style.getPropertyValue( 'direction' ) == 'rtl' ) {
 6+ background = '#faa';
 7+ } else {
 8+ background = '#afa';
 9+ }
 10+ elt.style.backgroundColor = background;
 11+} );
 12+
Property changes on: trunk/extensions/RTLDebug/rtl-debug.js
___________________________________________________________________
Added: svn:eol-style
113 + native
Index: trunk/extensions/RTLDebug/RTLDebug.php
@@ -0,0 +1,41 @@
 2+<?php
 3+
 4+/*
 5+ * Debugging RTL support is difficult because the effects of choosing the wrong
 6+ * direction for an HTML element depend on the text that that element contains.
 7+ * If the text entirely consists of characters with a strong direction, the
 8+ * display will seem OK regardless of what direction is set on the element, but
 9+ * if you add neutrals (such as punctation), it will break, and if you add
 10+ * characters with both directions, then it will break badly.
 11+ *
 12+ * Thus, it helps to have a visual tool which displays whether a given HTML
 13+ * element is designated RTL or LTR. This extension provides two such features:
 14+ *
 15+ * * After the page is loaded, all RTL elements will be coloured red, and all
 16+ * LTR elements will be coloured green.
 17+ *
 18+ * * An "English (RTL)" option is added to the language options. If this
 19+ * language is selected in user preferences, all user interface text will
 20+ * be backwards: naht rehtar kcah SSC a htiw tpecxe siht ekil fo dniK
 21+ * .noitcerid txet lacigol eht gnisrever
 22+ */
 23+
 24+
 25+$wgResourceModules['ext.rtlDebug'] = array(
 26+ 'scripts' => 'rtl-debug.js',
 27+ 'localBasePath' => dirname( __FILE__ )
 28+);
 29+
 30+$wgHooks['BeforePageDisplay'][] = 'wfRtlDebug_BeforePageDisplay';
 31+$wgExtraLanguageNames['en-rtl'] = 'English (RTL)';
 32+
 33+function wfRtlDebug_BeforePageDisplay( &$out, &$skin ) {
 34+ global $wgLang;
 35+
 36+ $out->addModules( 'ext.rtlDebug' );
 37+ if ( $wgLang->getCode() == 'en-rtl' ) {
 38+ $out->addInlineStyle( '* { unicode-bidi: bidi-override; }' );
 39+ }
 40+ return true;
 41+}
 42+
Property changes on: trunk/extensions/RTLDebug/RTLDebug.php
___________________________________________________________________
Added: svn:eol-style
143 + native

Comments

#Comment by Nikerabbit (talk | contribs)   15:27, 13 September 2011

This is useful. Could be even more useful if it could be activated on request, like debug=true.

#Comment by Catrope (talk | contribs)   15:28, 13 September 2011

That's trivial. I wanted to polish this extension anyway, so I'll implement that too.

Status & tagging log