r95064 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95063‎ | r95064 | r95065 >
Date:05:38, 20 August 2011
Author:maxsem
Status:resolved (Comments)
Tags:
Comment:
WikiHiero: rewrote generateTables.php to be an ordinary maintenance script
Modified paths:
  • /trunk/extensions/wikihiero/generateTables.php (modified) (history)
  • /trunk/extensions/wikihiero/wh_list.php (modified) (history)
  • /trunk/extensions/wikihiero/wikihiero.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/wikihiero/wh_list.php
@@ -1,7 +1,7 @@
22 <?php
33
4 -// File created by wh_generate.php version 0.2.14
5 -// 2006/03/05 pm31 13:04
 4+// File created by generateTables.php version 0.3.0alpha
 5+// 2011/08/20 at 07:34
66
77 global $wh_prefabs, $wh_files;
88
@@ -300,8 +300,8 @@
301301 "C9" => array( 20, 38 ),
302302 "Ca0" => array( 5, 50 ),
303303 "Ca1" => array( 14, 48 ),
304 - "Ca1a" => array( 14, 49 ),
305 - "Ca2" => array( 16, 49 ),
 304+ "Ca1a" => array( 14, 50 ),
 305+ "Ca2" => array( 16, 50 ),
306306 "Ca2a" => array( 16, 48 ),
307307 "Cah1" => array( 5, 48 ),
308308 "Cah1a" => array( 5, 50 ),
Index: trunk/extensions/wikihiero/generateTables.php
@@ -1,100 +1,81 @@
22 <?php
33
4 -//////////////////////////////////////////////////////////////////////////
5 -//
6 -// WikiHiero - A PHP convert from text using "Manual for the encoding of
7 -// hieroglyphic texts for computer input" syntax to HTML entities (table and
8 -// images).
9 -//
10 -// Copyright (C) 2004 Guillaume Blanchard (Aoineko)
11 -//
12 -// This program is free software; you can redistribute it and/or
13 -// modify it under the terms of the GNU General Public License
14 -// as published by the Free Software Foundation; either version 2
15 -// of the License, or any later version.
16 -//
17 -// This program is distributed in the hope that it will be useful,
18 -// but WITHOUT ANY WARRANTY; without even the implied warranty of
19 -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 -// GNU General Public License for more details.
21 -//
22 -// You should have received a copy of the GNU General Public License
23 -// along with this program; if not, write to the Free Software
24 -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 -//
26 -//////////////////////////////////////////////////////////////////////////
 4+/**
 5+ * WikiHiero - A PHP convert from text using "Manual for the encoding of
 6+ * hieroglyphic texts for computer input" syntax to HTML entities (table and
 7+ * images).
 8+ *
 9+ * Copyright (C) 2004 Guillaume Blanchard (Aoineko)
 10+ *
 11+ * This program is free software; you can redistribute it and/or modify
 12+ * it under the terms of the GNU General Public License as published by
 13+ * the Free Software Foundation; either version 2 of the License, or
 14+ * (at your option) any later version.
 15+ *
 16+ * This program is distributed in the hope that it will be useful,
 17+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 19+ * GNU General Public License for more details.
 20+ *
 21+ * You should have received a copy of the GNU General Public License along
 22+ * with this program; if not, write to the Free Software Foundation, Inc.,
 23+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 24+ * http://www.gnu.org/copyleft/gpl.html
 25+ */
2726
28 -echo "This script is insecure and shouldn't be used on a public wiki.\n";
29 -exit( 1 );
30 -
31 -
32 -include "wh_main.php";
33 -
34 -if ( array_key_exists( "lang", $_GET ) ) {
35 - $lang = $_GET["lang"];
36 -} else {
37 - $lang = "fr";
 27+$IP = getenv( 'MW_INSTALL_PATH' );
 28+if ( $IP === false ) {
 29+ $IP = dirname( __FILE__ ) . '/../..';
3830 }
39 -?>
40 -<html lang=<?php echo htmlspecialchars( $lang ); ?>>
41 - <head>
42 - <title>WikiHiero - Table generator</title>
43 - <meta http-equiv="Content-type" content="text/html; charset=UTF-8">
44 - <link rel="shortcut icon" href="https://www.mediawiki.org/favicon.ico">
45 - </head>
46 - <body bgcolor="#DDDDDD">
 31+require_once( "$IP/maintenance/Maintenance.php" );
4732
48 - <big><?php echo "WikiHiero v" . WH_VER_MAJ . "." . WH_VER_MED . "." . WH_VER_MIN; ?></big>
 33+class GenerateWikiHieroTables extends Maintenance {
4934
50 - <br /><br />Parsing hieroglyph files and creating tables...<br /><br />
 35+ public function __construct() {
 36+ parent::__construct();
 37+ $this->mDescription = 'Generate tables with hieroglyph information';
 38+ // if ( !MWInit::classExists( 'WikiHiero' ) ) {
 39+ // $this->error( "Please install WikiHiero first!\n", true );
 40+ // }
 41+ }
 42+
 43+ public function execute() {
 44+ $wh_prefabs = "\$wh_prefabs = array(\n";
 45+ $wh_files = "\$wh_files = array(\n";
5146
52 - <?php
 47+ $imgDir = dirname( __FILE__ ) . '/img/';
5348
54 - $wh_prefabs = "\$wh_prefabs = array(\n";
55 - $wh_files = "\$wh_files = array(\n";
 49+ if ( is_dir( $imgDir ) ) {
 50+ $dh = opendir( $imgDir );
 51+ if ( $dh ) {
 52+ while ( ( $file = readdir( $dh ) ) !== false ) {
 53+ if ( stristr( $file, WikiHiero::IMG_EXT ) ) {
 54+ list( $width, $height, $type, $attr ) = getimagesize( $imgDir . $file );
 55+ $wh_files .= " \"" . WikiHiero::getCode( $file ) . "\" => array( $width, $height ),\n";
 56+ if ( strchr( $file, '&' ) ) {
 57+ $wh_prefabs .= " \"" . WikiHiero::getCode( $file ) . "\",\n";
 58+ }
 59+ }
 60+ }
 61+ closedir( $dh );
 62+ }
 63+ } else {
 64+ $this->error( "Images directory $imgDir not found!\n", true );
 65+ }
5666
57 - $img_dir = dirname( __FILE__ ) . '/img/';
 67+ $wh_prefabs .= ");";
 68+ $wh_files .= ");";
5869
59 - if ( is_dir( $img_dir ) )
60 - {
61 - $dh = opendir( $img_dir );
62 - if ( $dh )
63 - {
64 - while ( ( $file = readdir( $dh ) ) !== false )
65 - {
66 - if ( stristr( $file, WH_IMG_EXT ) )
67 - {
68 - list( $width, $height, $type, $attr ) = getimagesize( $img_dir . $file );
69 - $wh_files .= " \"" . WH_GetCode( $file ) . "\" => array( $width, $height ),\n";
70 - if ( strchr( $file, '&' ) )
71 - $wh_prefabs .= " \"" . WH_GetCode( $file ) . "\",\n";
72 - }
73 - }
74 - closedir( $dh );
75 - }
76 - }
 70+ $file = fopen( 'wh_list.php', 'w+' );
 71+ fwrite( $file, "<?php\n\n" );
 72+ fwrite( $file, '// File created by generateTables.php version ' . WikiHiero::VERSION . "\n" );
 73+ fwrite( $file, '// ' . date( 'Y/m/d \a\t H:i' ) . "\n\n" );
 74+ fwrite( $file, "global \$wh_prefabs, \$wh_files;\n\n" );
 75+ fwrite( $file, "$wh_prefabs\n\n" );
 76+ fwrite( $file, "$wh_files\n\n" );
 77+ fclose( $file );
 78+ }
 79+}
7780
78 - $wh_prefabs .= ");";
79 - $wh_files .= ");";
80 -
81 - echo "<pre>$wh_prefabs<br /><br />";
82 - echo "$wh_files<br /><br /></pre>";
83 -
84 - $file = fopen( "wh_list.php", "w+" );
85 - fwrite( $file, "<?php\n\n" );
86 - fwrite( $file, "// File created by wh_generate.php version " . WH_VER_MAJ . "." . WH_VER_MED . "." . WH_VER_MIN . "\n" );
87 - fwrite( $file, "// " . date( "Y/m/d at H:i" ) . "\n\n" );
88 - fwrite( $file, "global \$wh_prefabs, \$wh_files;\n\n" );
89 - fwrite( $file, "$wh_prefabs\n\n" );
90 - fwrite( $file, "$wh_files\n\n" );
91 - fwrite( $file, "?>" );
92 - fclose( $file );
93 -
94 - // if(file_exists("wh_list(0).php"))
95 -
96 - ?>
97 -
98 - <small><?php echo WH_Credit(); ?></small>
99 -
100 - </body>
101 -</html>
 81+$maintClass = "GenerateWikiHieroTables";
 82+require_once( RUN_MAINTENANCE_IF_MAIN );
Index: trunk/extensions/wikihiero/wikihiero.body.php
@@ -57,18 +57,16 @@
5858 define( "WH_IMG_MARGIN", 1 ); // default value
5959 define( "WH_CARTOUCHE_WIDTH", 2 ); // default value
6060
61 -define( "WH_VER_MAJ", 0 );
62 -define( "WH_VER_MED", 2 );
63 -define( "WH_VER_MIN", 14 );
64 -
6561 global $wgExtensionAssetsPath;
6662 define( "WH_IMG_DIR", $wgExtensionAssetsPath . '/wikihiero/img/' );
6763 define( "WH_IMG_PRE", "hiero_" );
68 -define( "WH_IMG_EXT", "png" );
6964
7065 define( "WH_DEBUG_MODE", false );
7166
7267 class WikiHiero {
 68+ const VERSION = '0.3.0alpha';
 69+ const IMG_EXT = 'png';
 70+
7371 private $scale = 100;
7472
7573 public function __construct( $scale = WH_SCALE_DEFAULT ) {
@@ -139,25 +137,25 @@
140138 {
141139 $height = intval( WH_HEIGHT * $this->scale / 100 );
142140 $code = $wh_phonemes[$glyph];
143 - return "<img src='" . htmlspecialchars( WH_IMG_DIR . WH_IMG_PRE . "{$code}." . WH_IMG_EXT ) . "' height='{$height}' title='" . htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />";
 141+ return "<img src='" . htmlspecialchars( WH_IMG_DIR . WH_IMG_PRE . "{$code}." . self::IMG_EXT ) . "' height='{$height}' title='" . htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />";
144142 }
145143 elseif ( $glyph == '>' ) // Render close cartouche
146144 {
147145 $height = intval( WH_HEIGHT * $this->scale / 100 );
148146 $code = $wh_phonemes[$glyph];
149 - return "<img src='" . htmlspecialchars( WH_IMG_DIR . WH_IMG_PRE . "{$code}." . WH_IMG_EXT ) . "' height='{$height}' title='" . htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />";
 147+ return "<img src='" . htmlspecialchars( WH_IMG_DIR . WH_IMG_PRE . "{$code}." . self::IMG_EXT ) . "' height='{$height}' title='" . htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />";
150148 }
151149
152150 if ( array_key_exists( $glyph, $wh_phonemes ) )
153151 {
154152 $code = $wh_phonemes[$glyph];
155153 if ( array_key_exists( $code, $wh_files ) )
156 - return "<img style='margin:" . WH_IMG_MARGIN . "px;' $option src='" . htmlspecialchars( WH_IMG_DIR . WH_IMG_PRE . "{$code}." . WH_IMG_EXT ) . "' title='" . htmlspecialchars( "{$code} [{$glyph}]" ) . "' alt='" . htmlspecialchars( $glyph ) . "' />";
 154+ 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 ) . "' />";
157155 else
158156 return "<font title='" . htmlspecialchars( $code ) . "'>" . htmlspecialchars( $glyph ) . "</font>";
159157 }
160158 elseif ( array_key_exists( $glyph, $wh_files ) )
161 - return "<img style='margin:" . WH_IMG_MARGIN . "px;' $option src='" . htmlspecialchars( WH_IMG_DIR . WH_IMG_PRE . "{$glyph}." . WH_IMG_EXT ) . "' title='" . htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />";
 159+ 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 ) . "' />";
162160 else
163161 return htmlspecialchars( $glyph );
164162 }
@@ -463,6 +461,15 @@
464462 return "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'><tr><td>\n$html\n</td></tr></table>";
465463 }
466464
 465+ /**
 466+ * Get glyph code from file name
 467+ *
 468+ * @param $file string: file name
 469+ * @return string: converted code
 470+ */
 471+ public static function getCode( $file ) {
 472+ return substr( $file, strlen( WH_IMG_PRE ), -( 1 + strlen( self::IMG_EXT ) ) );
 473+ }
467474 }
468475
469476 // ========================================================================
@@ -971,35 +978,3 @@
972979 "<" => "(", // cartouche
973980 ">" => ")|",
974981 );
975 -
976 -// ========================================================================
977 -// F U N C T I O N S
978 -
979 -
980 -// ========================================================================
981 -//
982 -// W i k i H i e r o
983 -//
984 -
985 -// ------------------------------------------------------------------------
986 -// WH_GetCode - Get glyph code from file name
987 -// ------------------------------------------------------------------------
988 -// file << file name
989 -// return >> string with converted code
990 -// ------------------------------------------------------------------------
991 -function WH_GetCode( $file ) {
992 - return substr( $file, strlen( WH_IMG_PRE ), -( 1 + strlen( WH_IMG_EXT ) ) );
993 -}
994 -
995 -// ------------------------------------------------------------------------
996 -// WH_Credit - Get glyph code from file name
997 -// ------------------------------------------------------------------------
998 -// return >> credit string
999 -// ------------------------------------------------------------------------
1000 -function WH_Credit() {
1001 - $html = "";
1002 - $html .= "<b>WikiHiero v" . WH_VER_MAJ . "." . WH_VER_MED . "." . WH_VER_MIN . "</b>\n";
1003 - $html .= "by Guillaume Blanchard (Aoineko) under GPL (2004).<br />\n";
1004 - $html .= "Hieroglyph credit: S. Rosmorduc, G. Watson, J. Hirst (under GFDL).\n";
1005 - return $html;
1006 -}

Sign-offs

UserFlagDate
Nikerabbitinspected13:46, 20 August 2011

Comments

#Comment by Nikerabbit (talk | contribs)   13:45, 20 August 2011

Just FYI I'm unable to parse the description:

+ * WikiHiero - A PHP convert from text using "Manual for the encoding of
+ * hieroglyphic texts for computer input" syntax to HTML entities (table and
+ * images).

Extra tab:

+	public static function getCode( $file ) {
+			return substr( $file, strlen( WH_IMG_PRE ), -( 1 + strlen( self::IMG_EXT ) ) );
+	}

If this isn't going to be a major change, what is? Maybe just drop some parts of the version string?

+	const VERSION = '0.3.0alpha';
#Comment by MaxSem (talk | contribs)   17:27, 20 August 2011
Just FYI I'm unable to parse the description:

Well, neither do I :P

#Comment by MaxSem (talk | contribs)   19:46, 21 August 2011

Description changed to a more clear one in r95127.

Status & tagging log