Index: trunk/extensions/wikihiero/wikihiero.body.php |
— | — | @@ -27,16 +27,11 @@ |
28 | 28 | die( 'Not an entry point' ); |
29 | 29 | } |
30 | 30 | |
31 | | -define( "WH_SCALE_DEFAULT", -1 ); // use default scale |
32 | | - |
33 | | -global $wgExtensionAssetsPath; |
34 | | -define( "WH_IMG_DIR", $wgExtensionAssetsPath . '/wikihiero/img/' ); |
35 | | - |
36 | | - |
37 | 31 | class WikiHiero { |
38 | 32 | const IMAGE_EXT = 'png'; |
39 | 33 | const IMAGE_PREFIX = 'hiero_'; |
40 | 34 | |
| 35 | + const DEFAULT_SCALE = -1; // use default scale |
41 | 36 | const CARTOUCHE_WIDTH = 2; |
42 | 37 | const IMAGE_MARGIN = 1; |
43 | 38 | const MAX_HEIGHT = 44; |
— | — | @@ -47,7 +42,7 @@ |
48 | 43 | |
49 | 44 | private static $phonemes, $prefabs, $files; |
50 | 45 | |
51 | | - public function __construct( $scale = WH_SCALE_DEFAULT ) { |
| 46 | + public function __construct() { |
52 | 47 | self::loadData(); |
53 | 48 | } |
54 | 49 | |
— | — | @@ -117,23 +112,23 @@ |
118 | 113 | elseif ( $glyph == '<' ) { // Render open cartouche |
119 | 114 | $height = intval( self::MAX_HEIGHT * $this->scale / 100 ); |
120 | 115 | $code = self::$phonemes[$glyph]; |
121 | | - return "<img src='" . htmlspecialchars( WH_IMG_DIR . self::IMAGE_PREFIX . "{$code}." . self::IMAGE_EXT ) . "' height='{$height}' title='" . htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />"; |
| 116 | + return "<img src='" . htmlspecialchars( self::getImagePath() . self::IMAGE_PREFIX . "{$code}." . self::IMAGE_EXT ) . "' height='{$height}' title='" . htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />"; |
122 | 117 | } |
123 | 118 | elseif ( $glyph == '>' ) { // Render close cartouche |
124 | 119 | $height = intval( self::MAX_HEIGHT * $this->scale / 100 ); |
125 | 120 | $code = self::$phonemes[$glyph]; |
126 | | - return "<img src='" . htmlspecialchars( WH_IMG_DIR . self::IMAGE_PREFIX . "{$code}." . self::IMAGE_EXT ) . "' height='{$height}' title='" . htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />"; |
| 121 | + return "<img src='" . htmlspecialchars( self::getImagePath() . self::IMAGE_PREFIX . "{$code}." . self::IMAGE_EXT ) . "' height='{$height}' title='" . htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />"; |
127 | 122 | } |
128 | 123 | |
129 | 124 | if ( array_key_exists( $glyph, self::$phonemes ) ) { |
130 | 125 | $code = self::$phonemes[$glyph]; |
131 | 126 | if ( array_key_exists( $code, self::$files ) ) { |
132 | | - return "<img {$imageClass}style='margin:" . self::IMAGE_MARGIN . "px;' $option src='" . htmlspecialchars( WH_IMG_DIR . self::IMAGE_PREFIX . "{$code}." . self::IMAGE_EXT ) . "' title='" . htmlspecialchars( "{$code} [{$glyph}]" ) . "' alt='" . htmlspecialchars( $glyph ) . "' />"; |
| 127 | + 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 ) . "' />"; |
133 | 128 | } else { |
134 | 129 | return htmlspecialchars( $glyph ); |
135 | 130 | } |
136 | 131 | } elseif ( array_key_exists( $glyph, self::$files ) ) { |
137 | | - return "<img {$imageClass}style='margin:" . self::IMAGE_MARGIN . "px;' $option src='" . htmlspecialchars( WH_IMG_DIR . self::IMAGE_PREFIX . "{$glyph}." . self::IMAGE_EXT ) . "' title='" . htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />"; |
| 132 | + 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 ) . "' />"; |
138 | 133 | } else { |
139 | 134 | return htmlspecialchars( $glyph ); |
140 | 135 | } |
— | — | @@ -199,8 +194,8 @@ |
200 | 195 | * @param $line bool: use line (default = false) |
201 | 196 | * @return string: converted code |
202 | 197 | */ |
203 | | - public function render( $hiero, $scale = WH_SCALE_DEFAULT, $line = false ) { |
204 | | - if ( $scale != WH_SCALE_DEFAULT ) { |
| 198 | + public function render( $hiero, $scale = self::DEFAULT_SCALE, $line = false ) { |
| 199 | + if ( $scale != self::DEFAULT_SCALE ) { |
205 | 200 | $this->setScale( $scale ); |
206 | 201 | } |
207 | 202 | |
— | — | @@ -350,7 +345,8 @@ |
351 | 346 | * @return string: URL of images directory |
352 | 347 | */ |
353 | 348 | public static function getImagePath() { |
354 | | - return WH_IMG_DIR; |
| 349 | + global $wgExtensionAssetsPath; |
| 350 | + return "$wgExtensionAssetsPath/wikihiero/img/"; |
355 | 351 | } |
356 | 352 | |
357 | 353 | /** |