r94773 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94772‎ | r94773 | r94774 >
Date:16:42, 17 August 2011
Author:maxsem
Status:resolved
Tags:
Comment:
WikiHiero: replaced inline formatting with CSS, now validates as HTML5
Modified paths:
  • /trunk/extensions/wikihiero/modules (added) (history)
  • /trunk/extensions/wikihiero/modules/ext.wikihiero.css (added) (history)
  • /trunk/extensions/wikihiero/wh_main.php (modified) (history)
  • /trunk/extensions/wikihiero/wikihiero.php (modified) (history)

Diff [purge]

Index: trunk/extensions/wikihiero/wikihiero.php
@@ -24,8 +24,10 @@
2525 //
2626 //////////////////////////////////////////////////////////////////////////
2727
 28+$wgHooks['ParserFirstCallInit'][] = 'wfRegisterWikiHiero';
 29+$wgHooks['BeforePageDisplay'][] = 'wfHieroBeforePageDisplay';
 30+
2831 // Register MediaWiki extension
29 -$wgHooks['ParserFirstCallInit'][] = 'wfRegisterWikiHiero';
3032 $wgExtensionCredits['parserhook'][] = array(
3133 'path' => __FILE__,
3234 'name' => 'WikiHiero',
@@ -37,8 +39,20 @@
3840
3941 $wgAutoloadClasses['WikiHiero'] = dirname( __FILE__ ) . '/wh_main.php';
4042
 43+$wgResourceModules['ext.wikihiero'] = array(
 44+ 'styles' => 'ext.wikihiero.css',
 45+ 'localBasePath' => dirname( __FILE__ ) . '/modules',
 46+ 'remoteExtPath' => 'wikihiero/modules',
 47+);
 48+
 49+// Because <hiero> tag is used rarely, we don't need to load its body on every hook call,
 50+// so we keep our simple hook handlers here.
4151 function wfRegisterWikiHiero( &$parser ) {
4252 $parser->setHook( 'hiero', 'WikiHiero::parserHook' );
4353 return true;
4454 }
4555
 56+function wfHieroBeforePageDisplay( $out ) {
 57+ $out->addModuleStyles( 'ext.wikihiero' );
 58+ return true;
 59+}
Index: trunk/extensions/wikihiero/modules/ext.wikihiero.css
@@ -0,0 +1,14 @@
 2+.mw-hiero-table {
 3+ border: 0;
 4+ border-spacing: 0;
 5+}
 6+
 7+.mw-hiero-pouter {
 8+ display: inline;
 9+}
 10+
 11+.mw-hiero-table td {
 12+ padding: 0;
 13+ align: center;
 14+ vertical-align: middle;
 15+}
Index: trunk/extensions/wikihiero/wh_main.php
@@ -34,10 +34,10 @@
3535
3636 // ========================================================================
3737 // D E F I N E S
38 -define( "WH_TABLE_S", "<table border='0' cellspacing='0' cellpadding='0'>" );
39 -define( "WH_TABLE_E", "</table>" );
40 -define( "WH_TD_S", "<td align='center' valign='middle'>" );
41 -define( "WH_TD_E", "</td>" );
 38+define( "WH_TABLE_S", '<table class="mw-hiero-table">' );
 39+define( "WH_TABLE_E", '</table>' );
 40+define( "WH_TD_S", '<td>' );
 41+define( "WH_TD_E", '</td>' );
4242
4343 define( "WH_MODE_DEFAULT", -1 ); // use default mode
4444 define( "WH_MODE_TEXT", 0 ); // text only
@@ -128,24 +128,24 @@
129129
130130 if ( $glyph == ".." ) { // Render void block
131131 $width = WH_HEIGHT;
132 - return "<table width='{$width}px' border='0' cellspacing='0' cellpadding='0'><tr><td>&#160;</td></tr></table>";
 132+ return "<table class=\"mw-hiero-table\" style=\"width: {$width}px;\"><tr><td>&#160;</td></tr></table>";
133133 }
134134 elseif ( $glyph == "." ) // Render half-width void block
135135 {
136136 $width = WH_HEIGHT / 2;
137 - return "<table width='{$width}px' border='0' cellspacing='0' cellpadding='0'><tr><td>&#160;</td></tr></table>";
 137+ return "<table class=\"mw-hiero-table\" style=\"width: {$width}px;\"><tr><td>&#160;</td></tr></table>";
138138 }
139139 elseif ( $glyph == '<' ) // Render open cartouche
140140 {
141141 $height = intval( WH_HEIGHT * $this->scale / 100 );
142142 $code = $wh_phonemes[$glyph];
143 - return "<img src='" . htmlspecialchars( WH_IMG_DIR . WH_IMG_PRE . "{$code}." . WH_IMG_EXT ) . "' height='{$height}px' title='" . htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />";
 143+ return "<img src='" . htmlspecialchars( WH_IMG_DIR . WH_IMG_PRE . "{$code}." . WH_IMG_EXT ) . "' height='{$height}' title='" . htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />";
144144 }
145145 elseif ( $glyph == '>' ) // Render close cartouche
146146 {
147147 $height = intval( WH_HEIGHT * $this->scale / 100 );
148148 $code = $wh_phonemes[$glyph];
149 - return "<img src='" . htmlspecialchars( WH_IMG_DIR . WH_IMG_PRE . "{$code}." . WH_IMG_EXT ) . "' height='{$height}px' title='" . htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />";
 149+ return "<img src='" . htmlspecialchars( WH_IMG_DIR . WH_IMG_PRE . "{$code}." . WH_IMG_EXT ) . "' height='{$height}' title='" . htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />";
150150 }
151151
152152 if ( array_key_exists( $glyph, $wh_phonemes ) )
@@ -367,7 +367,7 @@
368368 $contentHtml .= WH_TD_S . self::renderGlyph( $code[0] ) . WH_TD_E;
369369
370370 } elseif ( $code[0] != "" ) { // assum is glyph or '..' or '.'
371 - $option = "height='" . $this->resizeGlyph( $code[0], $is_cartouche ) . "px'";
 371+ $option = "height='" . $this->resizeGlyph( $code[0], $is_cartouche ) . "'";
372372
373373 $contentHtml .= WH_TD_S . self::renderGlyph( $code[0], $option ) . WH_TD_E;
374374 }
@@ -387,7 +387,7 @@
388388
389389 // test is block is into tje prefabs list
390390 if ( in_array( $temp, $wh_prefabs ) ) {
391 - $option = "height='" . $this->resizeGlyph( $temp, $is_cartouche ) . "px'";
 391+ $option = "height='" . $this->resizeGlyph( $temp, $is_cartouche ) . "'";
392392
393393 $contentHtml .= WH_TD_S . self::renderGlyph( $temp, $option ) . WH_TD_E;
394394
@@ -440,7 +440,7 @@
441441
442442 } else {
443443 // resize the glyph according to the block total height
444 - $option = "height='" . $this->resizeGlyph( $t, $is_cartouche, $total ) . "px'";
 444+ $option = "height='" . $this->resizeGlyph( $t, $is_cartouche, $total ) . "'";
445445 $temp .= self::renderGlyph( $t, $option );
446446 }
447447 } // end foreach
@@ -460,7 +460,7 @@
461461 $html .= WH_TABLE_S . "<tr>\n" . $tableContentHtml . "</tr>" . WH_TABLE_E;
462462 }
463463
464 - return "<table border='0' cellspacing='0' cellpadding='0' style='display:inline;' class='mw-hierotable' dir='ltr'><tr><td>\n$html\n</td></tr></table>";
 464+ return "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'><tr><td>\n$html\n</td></tr></table>";
465465 }
466466
467467 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r94775Bad MaxSem...reedy16:51, 17 August 2011
r94812Fixed typo in r94773maxsem21:01, 17 August 2011
r96474Backport r95340, partial r94773 from trunk for bug 30485: set override styles...brion19:22, 7 September 2011
r96477Backport r95340, partial r94773 from trunk for bug 30485: set override styles...brion19:43, 7 September 2011
r96481Merge r96474 from 1.17 -- Backport r95340, partial r94773 from trunk for bug ......brion19:51, 7 September 2011

Status & tagging log