MaxSem has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/160068

Change subject: Factor out void block creation
......................................................................

Factor out void block creation

Change-Id: I4a06ab215273f2212bfb4556b0e74a2f6f2e81d6
---
M wikihiero.body.php
1 file changed, 24 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/wikihiero 
refs/changes/68/160068/1

diff --git a/wikihiero.body.php b/wikihiero.body.php
index 5bf8a32..29f4245 100644
--- a/wikihiero.body.php
+++ b/wikihiero.body.php
@@ -91,20 +91,20 @@
                        $imageClass = 'class="mw-mirrored" ';
                }
                $glyph = $this->extractCode( $glyph );
+
                if ( $glyph == '..' ) { // Render void block
-                       $width = self::MAX_HEIGHT;
-                       return "<table class=\"mw-hiero-table\" style=\"width: 
{$width}px;\"><tr><td>&#160;</td></tr></table>";
+                       return $this->renderVoidBlock( self::MAX_HEIGHT );
                }
-               elseif ( $glyph == '.' ) { // Render half-width void block
-                       $width = self::MAX_HEIGHT / 2;
-                       return "<table class=\"mw-hiero-table\" style=\"width: 
{$width}px;\"><tr><td>&#160;</td></tr></table>";
+               if ( $glyph == '.' ) { // Render half-width void block
+                       return $this->renderVoidBlock( self::MAX_HEIGHT / 2 );
                }
-               elseif ( $glyph == '<' ) { // Render open cartouche
+
+               if ( $glyph == '<' ) { // Render open cartouche
                        $height = intval( self::MAX_HEIGHT * $this->scale / 100 
);
                        $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 ) . "' />";
                }
-               elseif ( $glyph == '>' ) { // Render close cartouche
+               if ( $glyph == '>' ) { // Render close cartouche
                        $height = intval( self::MAX_HEIGHT * $this->scale / 100 
);
                        $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 ) . "' />";
@@ -124,6 +124,23 @@
                }
        }
 
+       /**
+        * Returns HTML for a void block
+        * @param int $width
+        * @return string
+        */
+       private function renderVoidBlock( $width ) {
+               $width = intval( $width );
+               return Html::rawElement(
+                       'table',
+                       array(
+                               'class' => 'mw-hiero-table',
+                           'style' => "width: {$width}px;",
+                       ),
+                       '<tr><td>&#160;</td></tr>'
+               );
+       }
+
        private function isMirrored( $glyph ) {
                return substr( $glyph, -1 ) == '\\';
        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4a06ab215273f2212bfb4556b0e74a2f6f2e81d6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/wikihiero
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>

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

Reply via email to