jenkins-bot has submitted this change and it was merged.

Change subject: Refactor image addition
......................................................................


Refactor image addition

The only visible change is that <img> titles now don't show image code for
Horus names and such, like cartouches were treated before.

Change-Id: I1563934d7e9dad26ca18729f0d40b6932aa1f9bf
---
M tests.txt
M wikihiero.body.php
M wikihiero.php
3 files changed, 55 insertions(+), 44 deletions(-)

Approvals:
  Kaldari: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/tests.txt b/tests.txt
index d46f364..040e04f 100644
--- a/tests.txt
+++ b/tests.txt
@@ -3,7 +3,7 @@
 !! input
 <hiero>A1 - B2 D3</hiero>
 !! result
-<table class="mw-hiero-table mw-hiero-outer" dir="ltr"><tr><td> <table 
class="mw-hiero-table"><tr> <td><img style='margin: 1px; height: 38px;' 
src='/extensions/wikihiero/img/hiero_A1.png' title='A1' alt='A1' 
/></td><td><img style='margin: 1px; height: 38px;' 
src='/extensions/wikihiero/img/hiero_B2.png' title='B2' alt='B2' 
/></td><td><img style='margin: 1px; height: 20px;' 
src='/extensions/wikihiero/img/hiero_D3.png' title='D3' alt='D3' 
/></td></tr></table> </td></tr></table>
+<table class="mw-hiero-table mw-hiero-outer" dir="ltr"><tr><td> <table 
class="mw-hiero-table"><tr> <td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_A1.png" height="38" title="A1" alt="A1" 
/></td><td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_B2.png" height="38" title="B2" alt="B2" 
/></td><td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_D3.png" height="20" title="D3" alt="D3" 
/></td></tr></table> </td></tr></table>
 
 !! end
 
@@ -21,7 +21,7 @@
 !! input
 <hiero>a:A1</hiero>
 !! result
-<table class="mw-hiero-table mw-hiero-outer" dir="ltr"><tr><td> <table 
class="mw-hiero-table"><tr> <td><img style='margin: 1px; height: 38px;' 
src='/extensions/wikihiero/img/hiero_a&amp;A1.png' title='a&amp;A1' 
alt='a&amp;A1' /></td> </tr></table> </td></tr></table>
+<table class="mw-hiero-table mw-hiero-outer" dir="ltr"><tr><td> <table 
class="mw-hiero-table"><tr> <td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_a&amp;A1.png" height="38" title="a&amp;A1" 
alt="a&amp;A1" /></td> </tr></table> </td></tr></table>
 
 !! end
 
@@ -30,7 +30,7 @@
 !! input
 <hiero><h1 A h1></hiero>
 !! result
-<table class="mw-hiero-table mw-hiero-outer" dir="ltr"><tr><td> <table 
class="mw-hiero-table"><tr> <td><img style='margin: 1px; ' 
src='/extensions/wikihiero/img/hiero_Cah1.png' title='Cah1 [&lt;h1]' 
alt='&lt;h1' /></td><td><table class="mw-hiero-table"><tr><td 
class='mw-hiero-box' style='height: 2px;'></td></tr><tr><td><table 
class="mw-hiero-table"><tr><td><img style='margin: 1px; height: 38px;' 
src='/extensions/wikihiero/img/hiero_G1.png' title='G1 [A]' alt='A' 
/></td></tr></table></td></tr><tr><td class='mw-hiero-box' style='height: 
2px;'></td></tr></table></td><td><img style='margin: 1px; ' 
src='/extensions/wikihiero/img/hiero_Cah1a.png' title='Cah1a [h1&gt;]' 
alt='h1&gt;' /></td></tr></table> </td></tr></table>
+<table class="mw-hiero-table mw-hiero-outer" dir="ltr"><tr><td> <table 
class="mw-hiero-table"><tr> <td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_Cah1.png" title="&lt;h1" alt="&lt;h1" 
/></td><td><table class="mw-hiero-table"><tr><td class="mw-hiero-box" 
style="height: 2px;"></td></tr><tr><td><table 
class="mw-hiero-table"><tr><td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_G1.png" height="38" title="G1 [A]" alt="A" 
/></td></tr></table></td></tr><tr><td class="mw-hiero-box" style="height: 
2px;"></td></tr></table></td><td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_Cah1a.png" title="h1>" alt="h1>" 
/></td></tr></table> </td></tr></table>
 
 !! end
 
@@ -39,7 +39,7 @@
 !! input
 <hiero>< A ></hiero>
 !! result
-<table class="mw-hiero-table mw-hiero-outer" dir="ltr"><tr><td> <table 
class="mw-hiero-table"><tr> <td><img 
src='/extensions/wikihiero/img/hiero_Ca1.png' height='44' title='&lt;' 
alt='&lt;' /></td><td><table class="mw-hiero-table"><tr><td 
class='mw-hiero-box' style='height: 2px;'></td></tr><tr><td><table 
class="mw-hiero-table"><tr><td><img style='margin: 1px; height: 38px;' 
src='/extensions/wikihiero/img/hiero_G1.png' title='G1 [A]' alt='A' 
/></td></tr></table></td></tr><tr><td class='mw-hiero-box' style='height: 
2px;'></td></tr></table></td><td><img 
src='/extensions/wikihiero/img/hiero_Ca2.png' height='44' title='&gt;' 
alt='&gt;' /></td></tr></table> </td></tr></table>
+<table class="mw-hiero-table mw-hiero-outer" dir="ltr"><tr><td> <table 
class="mw-hiero-table"><tr> <td><img 
src="/extensions/wikihiero/img/hiero_Ca1.png" height="44" title="&lt;" 
alt="&lt;" /></td><td><table class="mw-hiero-table"><tr><td 
class="mw-hiero-box" style="height: 2px;"></td></tr><tr><td><table 
class="mw-hiero-table"><tr><td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_G1.png" height="38" title="G1 [A]" alt="A" 
/></td></tr></table></td></tr><tr><td class="mw-hiero-box" style="height: 
2px;"></td></tr></table></td><td><img 
src="/extensions/wikihiero/img/hiero_Ca2.png" height="44" title=">" alt=">" 
/></td></tr></table> </td></tr></table>
 
 !! end
 
@@ -48,7 +48,7 @@
 !! input
 <hiero>A1!B1 ! C1</hiero>
 !! result
-<table class="mw-hiero-table mw-hiero-outer" dir="ltr"><tr><td> <table 
class="mw-hiero-table"><tr> <td><img style='margin: 1px; height: 38px;' 
src='/extensions/wikihiero/img/hiero_A1.png' title='A1' alt='A1' 
/></td></tr></table><table class="mw-hiero-table"><tr> <td><img style='margin: 
1px; height: 38px;' src='/extensions/wikihiero/img/hiero_B1.png' title='B1' 
alt='B1' /></td></tr></table><table class="mw-hiero-table"><tr> <td><img 
style='margin: 1px; height: 38px;' src='/extensions/wikihiero/img/hiero_C1.png' 
title='C1' alt='C1' /></td></tr></table> </td></tr></table>
+<table class="mw-hiero-table mw-hiero-outer" dir="ltr"><tr><td> <table 
class="mw-hiero-table"><tr> <td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_A1.png" height="38" title="A1" alt="A1" 
/></td></tr></table><table class="mw-hiero-table"><tr> <td><img style="margin: 
1px;" src="/extensions/wikihiero/img/hiero_B1.png" height="38" title="B1" 
alt="B1" /></td></tr></table><table class="mw-hiero-table"><tr> <td><img 
style="margin: 1px;" src="/extensions/wikihiero/img/hiero_C1.png" height="38" 
title="C1" alt="C1" /></td></tr></table> </td></tr></table>
 
 !! end
 
@@ -58,7 +58,7 @@
 <hiero>M23-X1:R4-X8-Q2:D4-W17-R14-G4-R8-O29:V30-U23 !
 N26-D58-O49:Z1-F13:N31-V30:N16:N21*Z1-D45:N25</hiero>
 !! result
-<table class="mw-hiero-table mw-hiero-outer" dir="ltr"><tr><td> <table 
class="mw-hiero-table"><tr> <td><img style='margin: 1px; height: 38px;' 
src='/extensions/wikihiero/img/hiero_M23.png' title='M23' alt='M23' 
/></td><td><img style='margin: 1px; height: 11px;' 
src='/extensions/wikihiero/img/hiero_X1.png' title='X1' alt='X1' /><br /><img 
style='margin: 1px; height: 15px;' src='/extensions/wikihiero/img/hiero_R4.png' 
title='R4' alt='R4' /></td> <td><img style='margin: 1px; height: 38px;' 
src='/extensions/wikihiero/img/hiero_X8.png' title='X8' alt='X8' 
/></td><td><img style='margin: 1px; height: 24px;' 
src='/extensions/wikihiero/img/hiero_Q2.png' title='Q2' alt='Q2' /><br /><img 
style='margin: 1px; height: 12px;' src='/extensions/wikihiero/img/hiero_D4.png' 
title='D4' alt='D4' /></td> <td><img style='margin: 1px; height: 38px;' 
src='/extensions/wikihiero/img/hiero_W17.png' title='W17' alt='W17' 
/></td><td><img style='margin: 1px; height: 38px;' 
src='/extensions/wikihiero/img/hiero_R14.png' title='R14' alt='R14' 
/></td><td><img style='margin: 1px; height: 38px;' 
src='/extensions/wikihiero/img/hiero_G4.png' title='G4' alt='G4' 
/></td><td><img style='margin: 1px; height: 38px;' 
src='/extensions/wikihiero/img/hiero_R8.png' title='R8' alt='R8' 
/></td><td><img style='margin: 1px; height: 7px;' 
src='/extensions/wikihiero/img/hiero_O29.png' title='O29' alt='O29' /><br 
/><img style='margin: 1px; height: 12px;' 
src='/extensions/wikihiero/img/hiero_V30.png' title='V30' alt='V30' /></td> 
<td><img style='margin: 1px; height: 38px;' 
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: 15px;' src='/extensions/wikihiero/img/hiero_N26.png' title='N26' 
alt='N26' /></td><td><img style='margin: 1px; height: 35px;' 
src='/extensions/wikihiero/img/hiero_D58.png' title='D58' alt='D58' 
/></td><td><img style='margin: 1px; height: 18px;' 
src='/extensions/wikihiero/img/hiero_O49.png' title='O49' alt='O49' /><br 
/><img style='margin: 1px; height: 16px;' 
src='/extensions/wikihiero/img/hiero_Z1.png' title='Z1' alt='Z1' /></td> 
<td><img style='margin: 1px; height: 22px;' 
src='/extensions/wikihiero/img/hiero_F13.png' title='F13' alt='F13' /><br 
/><img style='margin: 1px; height: 17px;' 
src='/extensions/wikihiero/img/hiero_N31.png' title='N31' alt='N31' /></td> 
<td><img style='margin: 1px; height: 12px;' 
src='/extensions/wikihiero/img/hiero_V30.png' title='V30' alt='V30' /><br 
/><img style='margin: 1px; height: 9px;' 
src='/extensions/wikihiero/img/hiero_N16.png' title='N16' alt='N16' /><br 
/><img style='margin: 1px; height: 11px;' 
src='/extensions/wikihiero/img/hiero_N21.png' title='N21' alt='N21' /> <img 
style='margin: 1px; height: 16px;' src='/extensions/wikihiero/img/hiero_Z1.png' 
title='Z1' alt='Z1' /></td> <td><img style='margin: 1px; height: 24px;' 
src='/extensions/wikihiero/img/hiero_D45.png' title='D45' alt='D45' /><br 
/><img style='margin: 1px; height: 16px;' 
src='/extensions/wikihiero/img/hiero_N25.png' title='N25' alt='N25' /></td> 
</tr></table> </td></tr></table>
+<table class="mw-hiero-table mw-hiero-outer" dir="ltr"><tr><td> <table 
class="mw-hiero-table"><tr> <td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_M23.png" height="38" title="M23" alt="M23" 
/></td><td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_X1.png" height="11" title="X1" alt="X1" 
/><br /><img style="margin: 1px;" src="/extensions/wikihiero/img/hiero_R4.png" 
height="15" title="R4" alt="R4" /></td> <td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_X8.png" height="38" title="X8" alt="X8" 
/></td><td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_Q2.png" height="24" title="Q2" alt="Q2" 
/><br /><img style="margin: 1px;" src="/extensions/wikihiero/img/hiero_D4.png" 
height="12" title="D4" alt="D4" /></td> <td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_W17.png" height="38" title="W17" alt="W17" 
/></td><td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_R14.png" height="38" title="R14" alt="R14" 
/></td><td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_G4.png" height="38" title="G4" alt="G4" 
/></td><td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_R8.png" height="38" title="R8" alt="R8" 
/></td><td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_O29.png" height="7" title="O29" alt="O29" 
/><br /><img style="margin: 1px;" src="/extensions/wikihiero/img/hiero_V30.png" 
height="12" title="V30" alt="V30" /></td> <td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_U23.png" height="38" title="U23" alt="U23" 
/></td></tr></table><table class="mw-hiero-table"><tr> <td><img style="margin: 
1px;" src="/extensions/wikihiero/img/hiero_N26.png" height="15" title="N26" 
alt="N26" /></td><td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_D58.png" height="35" title="D58" alt="D58" 
/></td><td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_O49.png" height="18" title="O49" alt="O49" 
/><br /><img style="margin: 1px;" src="/extensions/wikihiero/img/hiero_Z1.png" 
height="16" title="Z1" alt="Z1" /></td> <td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_F13.png" height="22" title="F13" alt="F13" 
/><br /><img style="margin: 1px;" src="/extensions/wikihiero/img/hiero_N31.png" 
height="17" title="N31" alt="N31" /></td> <td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_V30.png" height="12" title="V30" alt="V30" 
/><br /><img style="margin: 1px;" src="/extensions/wikihiero/img/hiero_N16.png" 
height="9" title="N16" alt="N16" /><br /><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_N21.png" height="11" title="N21" alt="N21" 
/> <img style="margin: 1px;" src="/extensions/wikihiero/img/hiero_Z1.png" 
height="16" title="Z1" alt="Z1" /></td> <td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_D45.png" height="24" title="D45" alt="D45" 
/><br /><img style="margin: 1px;" src="/extensions/wikihiero/img/hiero_N25.png" 
height="16" title="N25" alt="N25" /></td> </tr></table> </td></tr></table>
 
 !! end
 
@@ -67,7 +67,7 @@
 !! input
 <hiero>A1\-A1</hiero>
 !! result
-<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: 38px;' src='/extensions/wikihiero/img/hiero_A1.png' title='A1' alt='A1' 
/></td><td><img style='margin: 1px; height: 38px;' 
src='/extensions/wikihiero/img/hiero_A1.png' title='A1' alt='A1' 
/></td></tr></table> </td></tr></table>
+<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;" 
src="/extensions/wikihiero/img/hiero_A1.png" height="38" title="A1" alt="A1" 
/></td><td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_A1.png" height="38" title="A1" alt="A1" 
/></td></tr></table> </td></tr></table>
 
 !! end
 
@@ -77,8 +77,8 @@
 <hiero>A1..B1.C1</hiero>
 <hiero>A1 .. B1 . C1</hiero>
 !!result
-<table class="mw-hiero-table mw-hiero-outer" dir="ltr"><tr><td> <table 
class="mw-hiero-table"><tr> <td><img style='margin: 1px; height: 38px;' 
src='/extensions/wikihiero/img/hiero_A1.png' title='A1' alt='A1' 
/></td><td><table class="mw-hiero-table" style="width: 
44px;"><tr><td>&#160;</td></tr></table></td><td><img style='margin: 1px; 
height: 38px;' src='/extensions/wikihiero/img/hiero_B1.png' title='B1' alt='B1' 
/></td><td><table class="mw-hiero-table" style="width: 
22px;"><tr><td>&#160;</td></tr></table></td><td><img style='margin: 1px; 
height: 38px;' src='/extensions/wikihiero/img/hiero_C1.png' title='C1' alt='C1' 
/></td></tr></table> </td></tr></table>
-<table class="mw-hiero-table mw-hiero-outer" dir="ltr"><tr><td> <table 
class="mw-hiero-table"><tr> <td><img style='margin: 1px; height: 38px;' 
src='/extensions/wikihiero/img/hiero_A1.png' title='A1' alt='A1' 
/></td><td><table class="mw-hiero-table" style="width: 
44px;"><tr><td>&#160;</td></tr></table></td><td><img style='margin: 1px; 
height: 38px;' src='/extensions/wikihiero/img/hiero_B1.png' title='B1' alt='B1' 
/></td><td><table class="mw-hiero-table" style="width: 
22px;"><tr><td>&#160;</td></tr></table></td><td><img style='margin: 1px; 
height: 38px;' src='/extensions/wikihiero/img/hiero_C1.png' title='C1' alt='C1' 
/></td></tr></table> </td></tr></table>
+<table class="mw-hiero-table mw-hiero-outer" dir="ltr"><tr><td> <table 
class="mw-hiero-table"><tr> <td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_A1.png" height="38" title="A1" alt="A1" 
/></td><td><table class="mw-hiero-table" style="width: 
44px;"><tr><td>&#160;</td></tr></table></td><td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_B1.png" height="38" title="B1" alt="B1" 
/></td><td><table class="mw-hiero-table" style="width: 
22px;"><tr><td>&#160;</td></tr></table></td><td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_C1.png" height="38" title="C1" alt="C1" 
/></td></tr></table> </td></tr></table>
+<table class="mw-hiero-table mw-hiero-outer" dir="ltr"><tr><td> <table 
class="mw-hiero-table"><tr> <td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_A1.png" height="38" title="A1" alt="A1" 
/></td><td><table class="mw-hiero-table" style="width: 
44px;"><tr><td>&#160;</td></tr></table></td><td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_B1.png" height="38" title="B1" alt="B1" 
/></td><td><table class="mw-hiero-table" style="width: 
22px;"><tr><td>&#160;</td></tr></table></td><td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_C1.png" height="38" title="C1" alt="C1" 
/></td></tr></table> </td></tr></table>
 
 !! end
 
@@ -88,6 +88,6 @@
 <hiero>A1<!-- B1 --> C1 D<!--
 fooooo -->1</hiero>
 !! result
-<table class="mw-hiero-table mw-hiero-outer" dir="ltr"><tr><td> <table 
class="mw-hiero-table"><tr> <td><img style='margin: 1px; height: 38px;' 
src='/extensions/wikihiero/img/hiero_A1.png' title='A1' alt='A1' 
/></td><td><img style='margin: 1px; height: 38px;' 
src='/extensions/wikihiero/img/hiero_C1.png' title='C1' alt='C1' 
/></td><td><img style='margin: 1px; height: 19px;' 
src='/extensions/wikihiero/img/hiero_D1.png' title='D1' alt='D1' 
/></td></tr></table> </td></tr></table>
+<table class="mw-hiero-table mw-hiero-outer" dir="ltr"><tr><td> <table 
class="mw-hiero-table"><tr> <td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_A1.png" height="38" title="A1" alt="A1" 
/></td><td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_C1.png" height="38" title="C1" alt="C1" 
/></td><td><img style="margin: 1px;" 
src="/extensions/wikihiero/img/hiero_D1.png" height="19" title="D1" alt="D1" 
/></td></tr></table> </td></tr></table>
 
 !! end
diff --git a/wikihiero.body.php b/wikihiero.body.php
index e82b94b..e84db5c 100644
--- a/wikihiero.body.php
+++ b/wikihiero.body.php
@@ -81,14 +81,14 @@
        /**
         * Renders a glyph
         *
-        * @param $glyph string: glyph's code to render
-        * @param $option string: option to add into <img> tag (use for height)
+        * @param string $glyph: glyph's code to render
+        * @param int|null $height: glyph size in pixels or null to omit
         * @return string: a string to add to the stream
         */
-       private function renderGlyph( $glyph, $option = '' ) {
-               $imageClass = '';
+       private function renderGlyph( $glyph, $height = null ) {
+               $imageClass = null;
                if ( $this->isMirrored( $glyph ) ) {
-                       $imageClass = 'class="mw-mirrored" ';
+                       $imageClass = 'mw-mirrored';
                }
                $glyph = $this->extractCode( $glyph );
 
@@ -99,29 +99,45 @@
                        return $this->renderVoidBlock( self::MAX_HEIGHT / 2 );
                }
 
-               if ( $glyph == '<' ) { // Render open cartouche
-                       $height = self::MAX_HEIGHT;
-                       $code = self::$phonemes[$glyph];
-                       return "<img src='" . htmlspecialchars( 
self::getImagePath() . self::IMAGE_PREFIX . "{$code}." . self::IMAGE_EXT ) . "' 
height='{$height}' title='" . htmlspecialchars( $glyph ) . "' alt='" . 
htmlspecialchars( $glyph ) . "' />";
-               }
-               if ( $glyph == '>' ) { // Render close cartouche
-                       $height = self::MAX_HEIGHT;
-                       $code = self::$phonemes[$glyph];
-                       return "<img src='" . htmlspecialchars( 
self::getImagePath() . self::IMAGE_PREFIX . "{$code}." . self::IMAGE_EXT ) . "' 
height='{$height}' title='" . htmlspecialchars( $glyph ) . "' alt='" . 
htmlspecialchars( $glyph ) . "' />";
+               if ( $glyph == '<' || $glyph == '>' ) { // Render cartouches
+                       return $this->renderGlyphImage( $glyph, 
self::MAX_HEIGHT, null, $imageClass );
                }
 
+               return $this->renderGlyphImage( $glyph, $height, 
self::IMAGE_MARGIN, $imageClass );
+       }
+
+       /**
+        * Renders a glyph into an <img> tag
+        *
+        * @param string $glyph: Glyph to render
+        * @param int|null $height: Image height, if null don't set explicitly
+        * @param int|null $margin: Margin, if null don't set
+        * @param string|null $class: Class for <img> tag
+        * @return string: Rendered HTML
+        */
+       private function renderGlyphImage( $glyph, $height = null, $margin = 
null, $class = null ) {
                if ( array_key_exists( $glyph, self::$phonemes ) ) {
                        $code = self::$phonemes[$glyph];
-                       if ( array_key_exists( $code, self::$files ) ) {
-                               return "<img {$imageClass}style='margin: " . 
self::IMAGE_MARGIN . "px; $option' src='" . htmlspecialchars( 
self::getImagePath() . self::IMAGE_PREFIX . "{$code}." . self::IMAGE_EXT ) . "' 
title='" . htmlspecialchars( "{$code} [{$glyph}]" ) . "' alt='" . 
htmlspecialchars( $glyph ) . "' />";
-                       } else {
-                               return htmlspecialchars( $glyph );
-                       }
-               } elseif ( array_key_exists( $glyph, self::$files ) ) {
-                       return "<img {$imageClass}style='margin: " . 
self::IMAGE_MARGIN . "px; $option' src='" . htmlspecialchars( 
self::getImagePath() . self::IMAGE_PREFIX . "{$glyph}." . self::IMAGE_EXT ) . 
"' title='" . htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph 
) . "' />";
+                       $file = $code;
+                       // Don't show image name for cartouches and such
+                       $title = preg_match( '/^[A-Za-z0-9]+$/', $glyph ) ? 
"{$code} [{$glyph}]" : $glyph;
                } else {
+                       $file = $title = $glyph;
+               }
+               if ( !array_key_exists( $file, self::$files ) ) {
                        return htmlspecialchars( $glyph );
                }
+
+               $style = is_null( $margin ) ? null : "margin: {$margin}px;";
+               $attribs = array(
+                       'class' => $class,
+                   'style' => $style,
+                   'src' => self::getImagePath() . self::IMAGE_PREFIX . 
"{$file}." . self::IMAGE_EXT,
+                   'height' => $height,
+                   'title' => $title,
+                   'alt' => $glyph,
+               );
+               return Html::element( 'img', $attribs );
        }
 
        /**
@@ -233,20 +249,18 @@
                                } elseif ( strchr( $code[0], '<' ) ) { // start 
cartouche
                                        $contentHtml .= '<td>' . 
$this->renderGlyph( $code[0] ) . '</td>';
                                        $is_cartouche = true;
-                                       $contentHtml .= '<td>' . 
self::TABLE_START . "<tr><td class='mw-hiero-box' style='height: "
-                                               . self::CARTOUCHE_WIDTH . 
"px;'></td></tr><tr><td>" . self::TABLE_START . "<tr>";
+                                       $contentHtml .= '<td>' . 
self::TABLE_START . "<tr><td class=\"mw-hiero-box\" style=\"height: "
+                                               . self::CARTOUCHE_WIDTH . 
"px;\"></td></tr><tr><td>" . self::TABLE_START . "<tr>";
 
                                } elseif ( strchr( $code[0], '>' ) ) { // end 
cartouche
-                                       $contentHtml .= 
"</tr></table></td></tr><tr><td class='mw-hiero-box' style='height: "
+                                       $contentHtml .= 
"</tr></table></td></tr><tr><td class=\"mw-hiero-box\" style=\"height: "
                                                . self::CARTOUCHE_WIDTH
-                                               . "px;'></td></tr>" . 
'</table></td>';
+                                               . 
'px;"></td></tr></table></td>';
                                        $is_cartouche = false;
                                        $contentHtml .= '<td>' . 
$this->renderGlyph( $code[0] ) . '</td>';
 
                                } elseif ( $code[0] != "" ) { // assume it's a 
glyph or '..' or '.'
-                                       $option = "height: " . 
$this->resizeGlyph( $code[0], $is_cartouche ) . "px;";
-
-                                       $contentHtml .= '<td>' . 
$this->renderGlyph( $code[0], $option ) . '</td>';
+                                       $contentHtml .= '<td>' . 
$this->renderGlyph( $code[0], $this->resizeGlyph( $code[0], $is_cartouche ) ) . 
'</td>';
                                }
 
                        // block contains more than 1 glyph
@@ -263,9 +277,7 @@
 
                                // test if block exists in the prefabs list
                                if ( in_array( $temp, self::$prefabs ) ) {
-                                       $option = "height: " . 
$this->resizeGlyph( $temp, $is_cartouche ) . "px;";
-
-                                       $contentHtml .= '<td>' . 
$this->renderGlyph( $temp, $option ) . '</td>';
+                                       $contentHtml .= '<td>' . 
$this->renderGlyph( $temp, $this->resizeGlyph( $temp, $is_cartouche ) ) . 
'</td>';
 
                                // block must be manually computed
                                } else {
@@ -316,8 +328,7 @@
 
                                                } else {
                                                        // resize the glyph 
according to the block total height
-                                                       $option = "height: " . 
$this->resizeGlyph( $t, $is_cartouche, $total ) . "px;";
-                                                       $temp .= 
$this->renderGlyph( $t, $option );
+                                                       $temp .= 
$this->renderGlyph( $t, $this->resizeGlyph( $t, $is_cartouche, $total ) );
                                                }
                                        } // end foreach
 
diff --git a/wikihiero.php b/wikihiero.php
index 14edf1a..6840b5a 100644
--- a/wikihiero.php
+++ b/wikihiero.php
@@ -21,7 +21,7 @@
  * http://www.gnu.org/copyleft/gpl.html
  */
 
-define( 'WIKIHIERO_VERSION', '1.0alpha2' );
+define( 'WIKIHIERO_VERSION', '1.1' );
 
 $wgHooks['ParserFirstCallInit'][] = 'wfRegisterWikiHiero';
 $wgHooks['BeforePageDisplay'][] = 'wfHieroBeforePageDisplay';

-- 
To view, visit https://gerrit.wikimedia.org/r/160474
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I1563934d7e9dad26ca18729f0d40b6932aa1f9bf
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/wikihiero
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to