r96686 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96685‎ | r96686 | r96687 >
Date:20:10, 9 September 2011
Author:maxsem
Status:ok
Tags:
Comment:
New feature: hieroglyph mirroring, e.g. Amun must face Ra in C12\-C2
Modified paths:
  • /trunk/extensions/wikihiero/SpecialHieroglyphs.php (modified) (history)
  • /trunk/extensions/wikihiero/modules/ext.wikihiero.Special.css (modified) (history)
  • /trunk/extensions/wikihiero/tests.txt (modified) (history)
  • /trunk/extensions/wikihiero/wikihiero.body.php (modified) (history)
  • /trunk/extensions/wikihiero/wikihiero.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/wikihiero/tests.txt
@@ -52,3 +52,12 @@
5353 <table class='mw-hiero-table mw-hiero-outer' dir='ltr'><tr><td> <table class="mw-hiero-table"><tr> <td><img style='margin:1px;' height='38' src='/extensions/wikihiero/img/hiero_M23.png' title='M23' alt='M23' /></td><td><img style='margin:1px;' height='11' src='/extensions/wikihiero/img/hiero_X1.png' title='X1' alt='X1' /><br /><img style='margin:1px;' height='15' src='/extensions/wikihiero/img/hiero_R4.png' title='R4' alt='R4' /></td> <td><img style='margin:1px;' height='38' src='/extensions/wikihiero/img/hiero_X8.png' title='X8' alt='X8' /></td><td><img style='margin:1px;' height='24' src='/extensions/wikihiero/img/hiero_Q2.png' title='Q2' alt='Q2' /><br /><img style='margin:1px;' height='12' src='/extensions/wikihiero/img/hiero_D4.png' title='D4' alt='D4' /></td> <td><img style='margin:1px;' height='38' src='/extensions/wikihiero/img/hiero_W17.png' title='W17' alt='W17' /></td><td><img style='margin:1px;' height='38' src='/extensions/wikihiero/img/hiero_R14.png' title='R14' alt='R14' /></td><td><img style='margin:1px;' height='38' src='/extensions/wikihiero/img/hiero_G4.png' title='G4' alt='G4' /></td><td><img style='margin:1px;' height='38' src='/extensions/wikihiero/img/hiero_R8.png' title='R8' alt='R8' /></td><td><img style='margin:1px;' height='7' src='/extensions/wikihiero/img/hiero_O29.png' title='O29' alt='O29' /><br /><img style='margin:1px;' height='12' src='/extensions/wikihiero/img/hiero_V30.png' title='V30' alt='V30' /></td> <td><img style='margin:1px;' height='38' src='/extensions/wikihiero/img/hiero_U23.png' title='U23' alt='U23' /></td></tr></table><table class="mw-hiero-table"><tr> <td><img style='margin:1px;' height='15' src='/extensions/wikihiero/img/hiero_N26.png' title='N26' alt='N26' /></td><td><img style='margin:1px;' height='35' src='/extensions/wikihiero/img/hiero_D58.png' title='D58' alt='D58' /></td><td><img style='margin:1px;' height='18' src='/extensions/wikihiero/img/hiero_O49.png' title='O49' alt='O49' /><br /><img style='margin:1px;' height='16' src='/extensions/wikihiero/img/hiero_Z1.png' title='Z1' alt='Z1' /></td> <td><img style='margin:1px;' height='22' src='/extensions/wikihiero/img/hiero_F13.png' title='F13' alt='F13' /><br /><img style='margin:1px;' height='17' src='/extensions/wikihiero/img/hiero_N31.png' title='N31' alt='N31' /></td> <td><img style='margin:1px;' height='12' src='/extensions/wikihiero/img/hiero_V30.png' title='V30' alt='V30' /><br /><img style='margin:1px;' height='9' src='/extensions/wikihiero/img/hiero_N16.png' title='N16' alt='N16' /><br /><img style='margin:1px;' height='11' src='/extensions/wikihiero/img/hiero_N21.png' title='N21' alt='N21' /> <img style='margin:1px;' height='16' src='/extensions/wikihiero/img/hiero_Z1.png' title='Z1' alt='Z1' /></td> <td><img style='margin:1px;' height='24' src='/extensions/wikihiero/img/hiero_D45.png' title='D45' alt='D45' /><br /><img style='margin:1px;' height='16' src='/extensions/wikihiero/img/hiero_N25.png' title='N25' alt='N25' /></td> </tr></table> </td></tr></table>
5454
5555 !! end
 56+
 57+!! test
 58+WikiHiero - image mirroring
 59+!! input
 60+<hiero>A1\-A1</hiero>
 61+!! result
 62+<table class='mw-hiero-table mw-hiero-outer' dir='ltr'><tr><td> <table class="mw-hiero-table"><tr> <td><img class="mw-mirrored" style='margin:1px;' height='38' src='/extensions/wikihiero/img/hiero_A1.png' title='A1' alt='A1' /></td><td><img style='margin:1px;' height='38' src='/extensions/wikihiero/img/hiero_A1.png' title='A1' alt='A1' /></td></tr></table> </td></tr></table>
 63+
 64+!! end
Index: trunk/extensions/wikihiero/SpecialHieroglyphs.php
@@ -27,6 +27,7 @@
2828 array( 'code' => ':', 'message' => 'wikihiero-superposition', 'example' => 'p:t' ),
2929 array( 'code' => ':', 'message' => 'wikihiero-juxtaposition', 'example' => 'p*t' ),
3030 array( 'code' => '!', 'message' => 'wikihiero-eol', 'example' => 'A1-B1 ! C1-D1' ),
 31+ array( 'code' => '\\', 'message' => 'wikihiero-mirror', 'example' => 'A1\-A1' ),
3132 );
3233 private $helpColumns = array(
3334 'code',
Index: trunk/extensions/wikihiero/modules/ext.wikihiero.Special.css
@@ -8,3 +8,13 @@
99 .mw-hiero-toc {
1010 text-align: center;
1111 }
 12+
 13+.mw-mirrored {
 14+ -moz-transform: scaleX(-1);
 15+ -o-transform: scaleX(-1);
 16+ -webkit-transform: scaleX(-1);
 17+ transform: scaleX(-1);
 18+ filter: FlipH;
 19+ -ms-filter: "FlipH";
 20+}
 21+
Index: trunk/extensions/wikihiero/wikihiero.body.php
@@ -144,6 +144,11 @@
145145 * @return string: a string to add to the stream
146146 */
147147 private function renderGlyph( $glyph, $option = '' ) {
 148+ $imageClass = '';
 149+ if ( $this->isMirrored( $glyph ) ) {
 150+ $imageClass = 'class="mw-mirrored" ';
 151+ }
 152+ $glyph = $this->extractCode( $glyph );
148153 if ( $glyph == ".." ) { // Render void block
149154 $width = WH_HEIGHT;
150155 return "<table class=\"mw-hiero-table\" style=\"width: {$width}px;\"><tr><td>&#160;</td></tr></table>";
@@ -170,17 +175,27 @@
171176 {
172177 $code = self::$phonemes[$glyph];
173178 if ( array_key_exists( $code, self::$files ) )
174 - return "<img style='margin:" . WH_IMG_MARGIN . "px;' $option src='" . htmlspecialchars( WH_IMG_DIR . WH_IMG_PRE . "{$code}." . self::IMG_EXT ) . "' title='" . htmlspecialchars( "{$code} [{$glyph}]" ) . "' alt='" . htmlspecialchars( $glyph ) . "' />";
 179+ return "<img {$imageClass}style='margin:" . WH_IMG_MARGIN . "px;' $option src='" . htmlspecialchars( WH_IMG_DIR . WH_IMG_PRE . "{$code}." . self::IMG_EXT ) . "' title='" . htmlspecialchars( "{$code} [{$glyph}]" ) . "' alt='" . htmlspecialchars( $glyph ) . "' />";
175180 else
176181 return "<font title='" . htmlspecialchars( $code ) . "'>" . htmlspecialchars( $glyph ) . "</font>";
177182 }
178183 elseif ( array_key_exists( $glyph, self::$files ) )
179 - return "<img style='margin:" . WH_IMG_MARGIN . "px;' $option src='" . htmlspecialchars( WH_IMG_DIR . WH_IMG_PRE . "{$glyph}." . self::IMG_EXT ) . "' title='" . htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />";
 184+ return "<img {$imageClass}style='margin:" . WH_IMG_MARGIN . "px;' $option src='" . htmlspecialchars( WH_IMG_DIR . WH_IMG_PRE . "{$glyph}." . self::IMG_EXT ) . "' title='" . htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />";
180185 else
181186 return htmlspecialchars( $glyph );
182187 }
183188
 189+ private function isMirrored( $glyph ) {
 190+ return substr( $glyph, -1 ) == '\\';
 191+ }
 192+
184193 /**
 194+ * Extracts hieroglyph code from glyph, e.g. A1\ --> A1
 195+ */
 196+ private function extractCode( $glyph ) {
 197+ return preg_replace( '/\\\\.*$/', '', $glyph );
 198+ }
 199+ /**
185200 * Resize a glyph
186201 *
187202 * @param $item string: glyph code
@@ -189,6 +204,7 @@
190205 * @return size
191206 */
192207 private function resizeGlyph( $item, $is_cartouche = false, $total = 0 ) {
 208+ $item = $this->extractCode( $item );
193209 if ( array_key_exists( $item, self::$phonemes ) ) {
194210 $glyph = self::$phonemes[$item];
195211 } else {
@@ -322,7 +338,8 @@
323339 $block[$block_id][$item_id] = $hiero[$char];
324340 $type = WH_TYPE_CODE;
325341
326 - } elseif ( ctype_alnum( $hiero[$char] ) || $hiero[$char] == '.' || $hiero[$char] == '<' || $hiero[$char] == '>' ) {
 342+ } elseif ( ctype_alnum( $hiero[$char] ) || $hiero[$char] == '.' || $hiero[$char] == '<'
 343+ || $hiero[$char] == '>' || $hiero[$char] == '\\' ) {
327344 if ( $type == WH_TYPE_END ) {
328345 $block_id++;
329346 $block[$block_id] = array();
Index: trunk/extensions/wikihiero/wikihiero.i18n.php
@@ -24,6 +24,7 @@
2525 'wikihiero-eol' => 'End of line',
2626 'wikihiero-superposition' => 'Subdivision',
2727 'wikihiero-juxtaposition' => 'Juxtaposition',
 28+ 'wikihiero-mirror' => 'Mirror a hieroglyph',
2829 'wikihiero-load-error' => 'Load error!',
2930 'wikihiero-category-A' => 'A: Man and his occupations',
3031 'wikihiero-category-B' => 'B: Woman and her occupations',

Status & tagging log