http://www.mediawiki.org/wiki/Special:Code/MediaWiki/95064

Revision: 95064
Author:   maxsem
Date:     2011-08-20 05:38:38 +0000 (Sat, 20 Aug 2011)
Log Message:
-----------
WikiHiero: rewrote generateTables.php to be an ordinary maintenance script

Modified Paths:
--------------
    trunk/extensions/wikihiero/generateTables.php
    trunk/extensions/wikihiero/wh_list.php
    trunk/extensions/wikihiero/wikihiero.body.php

Modified: trunk/extensions/wikihiero/generateTables.php
===================================================================
--- trunk/extensions/wikihiero/generateTables.php       2011-08-20 05:01:33 UTC 
(rev 95063)
+++ trunk/extensions/wikihiero/generateTables.php       2011-08-20 05:38:38 UTC 
(rev 95064)
@@ -1,100 +1,81 @@
 <?php
 
-//////////////////////////////////////////////////////////////////////////
-//
-// WikiHiero - A PHP convert from text using "Manual for the encoding of
-// hieroglyphic texts for computer input" syntax to HTML entities (table and
-// images).
-//
-// Copyright (C) 2004 Guillaume Blanchard (Aoineko)
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-//
-//////////////////////////////////////////////////////////////////////////
+/**
+ * WikiHiero - A PHP convert from text using "Manual for the encoding of
+ * hieroglyphic texts for computer input" syntax to HTML entities (table and
+ * images).
+ *
+ * Copyright (C) 2004 Guillaume Blanchard (Aoineko)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ */
 
-echo "This script is insecure and shouldn't be used on a public wiki.\n";
-exit( 1 );
-
-
-include "wh_main.php";
-
-if ( array_key_exists( "lang", $_GET ) ) {
-       $lang = $_GET["lang"];
-} else {
-       $lang = "fr";
+$IP = getenv( 'MW_INSTALL_PATH' );
+if ( $IP === false ) {
+       $IP = dirname( __FILE__ ) . '/../..';
 }
-?>
-<html lang=<?php echo htmlspecialchars( $lang ); ?>>
-  <head>
-    <title>WikiHiero - Table generator</title>
-    <meta http-equiv="Content-type" content="text/html; charset=UTF-8">
-    <link rel="shortcut icon" href="/favicon.ico">
-  </head>
-  <body bgcolor="#DDDDDD">
+require_once( "$IP/maintenance/Maintenance.php" );
 
-    <big><?php echo "WikiHiero v" . WH_VER_MAJ . "." . WH_VER_MED . "." . 
WH_VER_MIN; ?></big>
+class GenerateWikiHieroTables extends Maintenance {
 
-    <br /><br />Parsing hieroglyph files and creating tables...<br /><br />
+       public function __construct() {
+               parent::__construct();
+               $this->mDescription = 'Generate tables with hieroglyph 
information';
+               // if ( !MWInit::classExists( 'WikiHiero' ) ) {
+                       // $this->error( "Please install WikiHiero first!\n", 
true );
+               // }
+       }
+       
+       public function execute() {
+               $wh_prefabs = "\$wh_prefabs = array(\n";
+               $wh_files   = "\$wh_files   = array(\n";
 
-    <?php
+               $imgDir = dirname( __FILE__ ) . '/img/';
 
-    $wh_prefabs = "\$wh_prefabs = array(\n";
-    $wh_files   = "\$wh_files   = array(\n";
+               if ( is_dir( $imgDir ) ) {
+                       $dh = opendir( $imgDir );
+                       if ( $dh ) {
+                               while ( ( $file = readdir( $dh ) ) !== false ) {
+                                       if ( stristr( $file, WikiHiero::IMG_EXT 
) ) {
+                                               list( $width, $height, $type, 
$attr ) = getimagesize( $imgDir . $file );
+                                               $wh_files .= "  \"" . 
WikiHiero::getCode( $file ) . "\" => array( $width, $height ),\n";
+                                               if ( strchr( $file, '&' ) ) {
+                                                       $wh_prefabs .= "  \"" . 
WikiHiero::getCode( $file ) . "\",\n";
+                                               }
+                                       }
+                               }
+                               closedir( $dh );
+                       }
+               } else {
+                       $this->error( "Images directory $imgDir not found!\n", 
true );
+               }
 
-    $img_dir = dirname( __FILE__ ) . '/img/';
+               $wh_prefabs .= ");";
+               $wh_files .= ");";
 
-    if ( is_dir( $img_dir ) )
-    {
-           $dh = opendir( $img_dir );
-      if ( $dh )
-      {
-        while ( ( $file = readdir( $dh ) ) !== false )
-        {
-          if ( stristr( $file, WH_IMG_EXT ) )
-          {
-            list( $width, $height, $type, $attr ) = getimagesize( $img_dir . 
$file );
-            $wh_files .= "  \"" . WH_GetCode( $file ) . "\" => array( $width, 
$height ),\n";
-            if ( strchr( $file, '&' ) )
-              $wh_prefabs .= "  \"" . WH_GetCode( $file ) . "\",\n";
-          }
-        }
-        closedir( $dh );
-      }
-    }
+               $file = fopen( 'wh_list.php', 'w+' );
+               fwrite( $file, "<?php\n\n" );
+               fwrite( $file, '// File created by generateTables.php version ' 
. WikiHiero::VERSION . "\n" );
+               fwrite( $file, '// ' . date( 'Y/m/d \a\t H:i' ) . "\n\n" );
+               fwrite( $file, "global \$wh_prefabs, \$wh_files;\n\n" );
+               fwrite( $file, "$wh_prefabs\n\n" );
+               fwrite( $file, "$wh_files\n\n" );
+               fclose( $file );
+       }
+}
 
-    $wh_prefabs .= ");";
-    $wh_files .= ");";
-
-    echo "<pre>$wh_prefabs<br /><br />";
-    echo "$wh_files<br /><br /></pre>";
-
-    $file = fopen( "wh_list.php", "w+" );
-    fwrite( $file, "<?php\n\n" );
-    fwrite( $file, "// File created by wh_generate.php version " . WH_VER_MAJ 
. "." . WH_VER_MED . "." . WH_VER_MIN . "\n" );
-    fwrite( $file, "// " . date( "Y/m/d at H:i" ) . "\n\n" );
-    fwrite( $file, "global \$wh_prefabs, \$wh_files;\n\n" );
-    fwrite( $file, "$wh_prefabs\n\n" );
-    fwrite( $file, "$wh_files\n\n" );
-    fwrite( $file, "?>" );
-    fclose( $file );
-
-    // if(file_exists("wh_list(0).php"))
-
-    ?>
-
-    <small><?php echo WH_Credit(); ?></small>
-
-  </body>
-</html>
+$maintClass = "GenerateWikiHieroTables";
+require_once( RUN_MAINTENANCE_IF_MAIN );

Modified: trunk/extensions/wikihiero/wh_list.php
===================================================================
--- trunk/extensions/wikihiero/wh_list.php      2011-08-20 05:01:33 UTC (rev 
95063)
+++ trunk/extensions/wikihiero/wh_list.php      2011-08-20 05:38:38 UTC (rev 
95064)
@@ -1,7 +1,7 @@
 <?php
 
-// File created by wh_generate.php version 0.2.14
-// 2006/03/05 pm31 13:04
+// File created by generateTables.php version 0.3.0alpha
+// 2011/08/20 at 07:34
 
 global $wh_prefabs, $wh_files;
 
@@ -300,8 +300,8 @@
   "C9" => array( 20, 38 ),
   "Ca0" => array( 5, 50 ),
   "Ca1" => array( 14, 48 ),
-  "Ca1a" => array( 14, 49 ),
-  "Ca2" => array( 16, 49 ),
+  "Ca1a" => array( 14, 50 ),
+  "Ca2" => array( 16, 50 ),
   "Ca2a" => array( 16, 48 ),
   "Cah1" => array( 5, 48 ),
   "Cah1a" => array( 5, 50 ),

Modified: trunk/extensions/wikihiero/wikihiero.body.php
===================================================================
--- trunk/extensions/wikihiero/wikihiero.body.php       2011-08-20 05:01:33 UTC 
(rev 95063)
+++ trunk/extensions/wikihiero/wikihiero.body.php       2011-08-20 05:38:38 UTC 
(rev 95064)
@@ -57,18 +57,16 @@
 define( "WH_IMG_MARGIN",    1 );    // default value
 define( "WH_CARTOUCHE_WIDTH", 2 );  // default value
 
-define( "WH_VER_MAJ",       0 );
-define( "WH_VER_MED",       2 );
-define( "WH_VER_MIN",       14 );
-
 global $wgExtensionAssetsPath;
 define( "WH_IMG_DIR",       $wgExtensionAssetsPath . '/wikihiero/img/' );
 define( "WH_IMG_PRE",       "hiero_" );
-define( "WH_IMG_EXT",       "png" );
 
 define( "WH_DEBUG_MODE",    false );
 
 class WikiHiero {
+       const VERSION = '0.3.0alpha';
+       const IMG_EXT = 'png';
+
        private $scale = 100;
 
        public function __construct( $scale = WH_SCALE_DEFAULT ) {
@@ -139,25 +137,25 @@
                {
                  $height = intval( WH_HEIGHT * $this->scale / 100 );
                  $code = $wh_phonemes[$glyph];
-                 return "<img src='" . htmlspecialchars( WH_IMG_DIR . 
WH_IMG_PRE . "{$code}." . WH_IMG_EXT ) . "' height='{$height}' title='" . 
htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />";
+                 return "<img src='" . htmlspecialchars( WH_IMG_DIR . 
WH_IMG_PRE . "{$code}." . self::IMG_EXT ) . "' height='{$height}' title='" . 
htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />";
                }
                elseif ( $glyph == '>' ) // Render close cartouche
                {
                  $height = intval( WH_HEIGHT * $this->scale / 100 );
                  $code = $wh_phonemes[$glyph];
-                 return "<img src='" . htmlspecialchars( WH_IMG_DIR . 
WH_IMG_PRE . "{$code}." . WH_IMG_EXT ) . "' height='{$height}' title='" . 
htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />";
+                 return "<img src='" . htmlspecialchars( WH_IMG_DIR . 
WH_IMG_PRE . "{$code}." . self::IMG_EXT ) . "' height='{$height}' title='" . 
htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />";
                }
 
                if ( array_key_exists( $glyph, $wh_phonemes ) )
                {
                  $code = $wh_phonemes[$glyph];
                  if ( array_key_exists( $code, $wh_files ) )
-                       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 ) . "' />";
+                       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 ) . "' />";
                  else
                        return "<font title='" . htmlspecialchars( $code ) . 
"'>" . htmlspecialchars( $glyph ) . "</font>";
                }
                elseif ( array_key_exists( $glyph, $wh_files ) )
-                 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 ) . "' />";
+                 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 ) . "' />";
                else
                  return htmlspecialchars( $glyph );
        }
@@ -463,6 +461,15 @@
                return "<table class='mw-hiero-table mw-hiero-outer' 
dir='ltr'><tr><td>\n$html\n</td></tr></table>";
        }
 
+       /**
+        * Get glyph code from file name
+        *
+        * @param $file string: file name
+        * @return string: converted code
+        */
+       public static function getCode( $file ) {
+                       return substr( $file, strlen( WH_IMG_PRE ), -( 1 + 
strlen( self::IMG_EXT ) ) );
+       }
 }
 
 // ========================================================================
@@ -971,35 +978,3 @@
   "<"       => "(",    // cartouche
   ">"       => ")|",
 );
-
-// ========================================================================
-// F U N C T I O N S
-
-
-// ========================================================================
-//
-// W i k i H i e r o
-//
-
-// ------------------------------------------------------------------------
-// WH_GetCode - Get glyph code from file name
-// ------------------------------------------------------------------------
-// file   << file name
-// return >> string with converted code
-// ------------------------------------------------------------------------
-function WH_GetCode( $file ) {
-               return substr( $file, strlen( WH_IMG_PRE ), -( 1 + strlen( 
WH_IMG_EXT ) ) );
-}
-
-// ------------------------------------------------------------------------
-// WH_Credit - Get glyph code from file name
-// ------------------------------------------------------------------------
-// return >> credit string
-// ------------------------------------------------------------------------
-function WH_Credit() {
-       $html = "";
-       $html .= "<b>WikiHiero v" . WH_VER_MAJ . "." . WH_VER_MED . "." . 
WH_VER_MIN . "</b>\n";
-       $html .= "by Guillaume Blanchard (Aoineko) under GPL (2004).<br />\n";
-       $html .= "Hieroglyph credit: S. Rosmorduc, G. Watson, J. Hirst (under 
GFDL).\n";
-       return $html;
-}


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

Reply via email to