Update http_session_download, digit2html, lang2po, langmemusage.
authorChad Horohoe <demon@users.mediawiki.org>
Wed, 5 Aug 2009 04:09:02 +0000 (04:09 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Wed, 5 Aug 2009 04:09:02 +0000 (04:09 +0000)
maintenance/http_session_download.php
maintenance/language/digit2html.php
maintenance/language/lang2po.php
maintenance/language/langmemusage.php

index 40c24aa..fa85f6c 100644 (file)
@@ -3,44 +3,59 @@
  * simple entry point to initiate a background download
  * 
  * arguments: 
- * 
- * -sid {$session_id} -usk {$upload_session_key}
+ *  -sid {$session_id} -usk {$upload_session_key}
+ *
+ * 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
+ *
+ * @ingroup Maintenance
  */
 
-global $optionsWithArgs;
-$optionsWithArgs = Array('sid', 'usk');
+require_once( dirname(__FILE__) . '/Maintenance.php' );
 
-//act like a "normal user"
-$wgUseNormalUser = true;
+class HttpSessionDownload extends Maintenance {
+       public function __construct() {
+               parent::__construct();
+               $this->mDescription = "Simple entry point to initiate a background download";
+               $this->addOption( 'sid', 'Session ID', true, true );
+               $this->addOption( 'usk', 'Upload session key', true, true );
+       }
+       
+       public function execute() {
+               global $wgUseNormalUser;
+               wfProfileIn(__METHOD__);
 
-require_once( dirname(__FILE__) . '/commandLine.inc' );
+               // act like a "normal user"
+               $wgUseNormalUser = true;
 
-if(!isset($options['sid']) || !isset($options['usk'])){
-       print<<<EOT
-       simple entry point to initiate a background download
+               //run the download: 
+               Http::doSessionIdDownload( $options['sid'], $options['usk'] );
        
-       Usage: http_session_download.php [options]
-       Options:
-               --sid the session id (required)
-               --usk the upload session key (also required)  
-EOT;
-
-       exit();
+               // close up shop:
+               // Execute any deferred updates
+               wfDoUpdates();
+       
+               // Log what the user did, for book-keeping purposes.    
+               wfLogProfilingData();
+       
+               // Shut down the database before exit
+               wfGetLBFactory()->shutdown();
+       
+               wfProfileOut(__METHOD__);
+       }
 }
-wfProfileIn('http_session_download.php');
-
-//run the download: 
-Http::doSessionIdDownload( $options['sid'], $options['usk'] );
-
-//close up shop:
-// Execute any deferred updates
-wfDoUpdates();
-                       
-// Log what the user did, for book-keeping purposes.   
-wfLogProfilingData();
-                       
-// Shut down the database before exit
-wfGetLBFactory()->shutdown();
 
-wfProfileOut('http_session_download.php');
-?>
\ No newline at end of file
+$maintClass = "HttpSessionDownload";
+require_once( DO_MAINTENANCE );
index 1ac746d..54630af 100644 (file)
@@ -1,29 +1,61 @@
 <?php
 /**
- * @file
+ * 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
+ *
  * @ingroup MaintenanceLanguage
  */
 
-require_once( dirname(__FILE__).'/../commandLine.inc' );
+require_once( dirname(__FILE__).'/../Maintenance.php' );
 
-# A list of unicode numerals is available at:
-# http://www.fileformat.info/info/unicode/category/Nd/list.htm
-$langs = array( 'Ar', 'As', 'Bh', 'Bo', 'Dz', 'Fa', 'Gu', 'Hi', 'Km', 'Kn', 'Ks', 'Lo', 'Ml', 'Mr', 'Ne', 'New', 'Or', 'Pa', 'Pi', 'Sa' );
+class Digit2Html extends Maintenance {
 
-foreach( $langs as $code ) {
-       $filename = Language::getMessagesFileName( $code );
-       echo "Loading language [$code] ... ";
-       unset( $digitTransformTable );
-       require_once( $filename );
-       if( !isset( $digitTransformTable ) ) {
-               print "\$digitTransformTable not found\n";
-               continue;
+       # A list of unicode numerals is available at:
+       # http://www.fileformat.info/info/unicode/category/Nd/list.htm
+       private $mLangs = array( 
+               'Ar', 'As', 'Bh', 'Bo', 'Dz', 
+               'Fa', 'Gu', 'Hi', 'Km', 'Kn', 
+               'Ks', 'Lo', 'Ml', 'Mr', 'Ne', 
+               'New', 'Or', 'Pa', 'Pi', 'Sa' 
+       );
+
+       public function __construct() {
+               parent::__construct();
+               $this->mDescription = "Check digit transformation";
        }
 
-       print "OK\n\$digitTransformTable = array(\n";
-       foreach( $digitTransformTable as $latin => $translation ) {
-               $htmlent = utf8ToHexSequence( $translation );
-               print "'$latin' => '$translation', # &#x$htmlent;\n";
+       public function execute() {
+               foreach( $this->mLangs as $code ) {
+                       $filename = Language::getMessagesFileName( $code );
+                       $this->output( "Loading language [$code] ... " );
+                       unset( $digitTransformTable );
+                       require_once( $filename );
+                       if( !isset( $digitTransformTable ) ) {
+                               $this->error( "\$digitTransformTable not found for lang: $code" );
+                               continue;
+                       }
+
+                       $this->output( "OK\n\$digitTransformTable = array(\n" );
+                       foreach( $digitTransformTable as $latin => $translation ) {
+                               $htmlent = utf8ToHexSequence( $translation );
+                               $this->output( "'$latin' => '$translation', # &#x$htmlent;\n" );
+                       }
+                       $this->output( ");\n" );
+               }
        }
-       print ");\n";
 }
+
+$maintClass = "Digit2Html";
+require_once( DO_MAINTENANCE );
index 1009ed6..c7484d6 100644 (file)
@@ -6,15 +6,27 @@
  *   - generate .po header
  *   - fix escaping of \
  *
- * @file
+ * 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
+ *
  * @ingroup MaintenanceLanguage
  */
 
-$optionsWithArgs[] = 'lang';
-
 /** This is a command line script */
-require_once(dirname(__FILE__).'/../commandLine.inc');
-require_once(dirname(__FILE__).'/languages.inc');
+require_once(dirname(__FILE__) . '/../Maintenance.php' );
+require_once(dirname(__FILE__) . '/languages.inc' );
 
 define('ALL_LANGUAGES',    true);
 define('XGETTEXT_BIN',     'xgettext');
@@ -26,28 +38,45 @@ define('MSGMERGE_OPTIONS', ' -v ');
 
 define('LOCALE_OUTPUT_DIR', $IP.'/locale');
 
+class Lang2Po extends Maintenance {
+       public function __construct() {
+               parent::__construct();
+               $this->mDescription = "";
+               $this->addOption( 'lang', 'a lang code you want to generate a .po for (default: all langs)', false, true );
+       }
 
-if( isset($options['help']) ) { usage(); wfDie(); }
-// default output is WikiText
-if( !isset($options['lang']) ) { $options['lang'] = ALL_LANGUAGES; }
-
-function usage() {
-print <<<END
-Usage: php lang2po.php [--help] [--lang=<langcode>] [--stdout]
-  --help: this message.
-  --lang: a lang code you want to generate a .po for (default: all languages).
-
-END;
-}
-
+       public function execute() {
+               // Generate a template .pot based on source tree
+               $this->output( "Getting 'gettext' default messages from sources:" );
+               $this->generatePot();
+               $this->output( "done.\n" );
+
+
+               $langTool = new languages();
+               if( $this->getOption( 'lang', ALL_LANGUAGES ) === ALL_LANGUAGES ) {
+                       $codes = $langTool->getLanguages();
+               } else {
+                       $codes = array( $this->getOption( 'lang' ) );
+               }
+
+               // Do all languages
+               foreach ( $codes as $langcode) {
+                       $this->output( "Loading messages for $langcode:\n" );
+                       if( !$this->generatePo($langcode, $langTool->getMessages($langcode) ) ) {
+                               $this->error( "ERROR: Failed to write file." );
+                       } else {
+                               $this->output( "Applying template:" );
+                               $this->applyPot($langcode);
+                       }
+               }
+       }
 
-/**
- * Return a dummy header for later edition.
- * @return string A dummy header
- */
-function poHeader() {
-return
-'# SOME DESCRIPTIVE TITLE.
+       /**
+        * Return a dummy header for later edition.
+        * @return string A dummy header
+        */
+       private function poHeader() {
+               return '# SOME DESCRIPTIVE TITLE.
 # Copyright (C) 2005 MediaWiki
 # This file is distributed under the same license as the MediaWiki package.
 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
@@ -65,94 +94,72 @@ msgstr ""
 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"
 ';
-}
-
-/**
- * generate and write a file in .po format.
- *
- * @param string $langcode Code of a language it will process.
- * @param array &$messages Array containing the various messages.
- * @return string Filename where stuff got saved or false.
- */
-function generatePo($langcode, $messages) {
-       $data = poHeader();
-
-       // Generate .po entries
-       foreach($messages['all'] as $identifier => $content) {
-               $data .= "msgid \"$identifier\"\n";
-
-               // Escape backslashes
-               $tmp = str_replace('\\', '\\\\', $content);
-               // Escape doublelquotes
-               $tmp = preg_replace( "/(?<!\\\\)\"/", '\"', $tmp);
-               // Rewrite multilines to gettext format
-               $tmp = str_replace("\n", "\"\n\"", $tmp);
-
-               $data .= 'msgstr "'. $tmp . "\"\n\n";
        }
 
-       // Write the content to a file in locale/XX/messages.po
-       $dir = LOCALE_OUTPUT_DIR.'/'.$langcode;
-       if( !is_dir($dir) ) { mkdir( $dir, 0770 ); }
-       $filename = $dir.'/fromlanguagefile.po';
-
-       $file = fopen( $filename , 'wb' );
-       if( fwrite( $file, $data ) ) {
-               fclose( $file );
-               return $filename;
-       } else {
-               fclose( $file );
-               return false;
+       /**
+        * generate and write a file in .po format.
+        *
+        * @param string $langcode Code of a language it will process.
+        * @param array &$messages Array containing the various messages.
+        * @return string Filename where stuff got saved or false.
+        */
+       private function generatePo($langcode, $messages) {
+               $data = $this->poHeader();
+
+               // Generate .po entries
+               foreach( $messages['all'] as $identifier => $content ) {
+                       $data .= "msgid \"$identifier\"\n";
+
+                       // Escape backslashes
+                       $tmp = str_replace('\\', '\\\\', $content);
+                       // Escape doublelquotes
+                       $tmp = preg_replace( "/(?<!\\\\)\"/", '\"', $tmp);
+                       // Rewrite multilines to gettext format
+                       $tmp = str_replace("\n", "\"\n\"", $tmp);
+
+                       $data .= 'msgstr "'. $tmp . "\"\n\n";
+               }
+
+               // Write the content to a file in locale/XX/messages.po
+               $dir = LOCALE_OUTPUT_DIR.'/'.$langcode;
+               if( !is_dir($dir) ) { mkdir( $dir, 0770 ); }
+               $filename = $dir.'/fromlanguagefile.po';
+       
+               $file = fopen( $filename , 'wb' );
+               if( fwrite( $file, $data ) ) {
+                       fclose( $file );
+                       return $filename;
+               } else {
+                       fclose( $file );
+                       return false;
+               }
        }
-}
-
-function generatePot() {
-       global $IP;
-       $curdir = getcwd();
-       chdir($IP);
-       exec( XGETTEXT_BIN
-         .' '.XGETTEXT_OPTIONS
-         .' -o '.LOCALE_OUTPUT_DIR.'/wfMsg.pot'
-         .' includes/*php'
-         );
-       chdir($curdir);
-}
-
-function applyPot($langcode) {
-       $langdir = LOCALE_OUTPUT_DIR.'/'.$langcode;
-
-       $from = $langdir.'/fromlanguagefile.po';
-       $pot = LOCALE_OUTPUT_DIR.'/wfMsg.pot';
-       $dest = $langdir.'/messages.po';
 
-       // Merge template and generate file to get final .po
-       exec(MSGMERGE_BIN.MSGMERGE_OPTIONS." $from $pot -o $dest ");
-       // delete no more needed file
-//     unlink($from);
-}
-
-// Generate a template .pot based on source tree
-echo "Getting 'gettext' default messages from sources:";
-generatePot();
-echo "done.\n";
-
-
-$langTool = new languages();
-
-if( $options['lang'] === ALL_LANGUAGES ) {
-       $codes = $langTool->getLanguages();
-} else {
-       $codes = array( $options['lang'] );
-}
-
-// Do all languages
-foreach ( $codes as $langcode) {
-       echo "Loading messages for $langcode:\n";
-       if( ! generatePo($langcode, $langTool->getMessages($langcode) ) ) {
-               echo "ERROR: Failed to write file.\n";
-       } else {
-               echo "Applying template:";
-               applyPot($langcode);
+       private function generatePot() {
+               global $IP;
+               $curdir = getcwd();
+               chdir($IP);
+               exec( XGETTEXT_BIN
+                 .' '.XGETTEXT_OPTIONS
+                 .' -o '.LOCALE_OUTPUT_DIR.'/wfMsg.pot'
+                 .' includes/*php'
+                 );
+               chdir($curdir);
+       }
+       
+       private function applyPot($langcode) {
+               $langdir = LOCALE_OUTPUT_DIR.'/'.$langcode;
+       
+               $from = $langdir.'/fromlanguagefile.po';
+               $pot = LOCALE_OUTPUT_DIR.'/wfMsg.pot';
+               $dest = $langdir.'/messages.po';
+       
+               // Merge template and generate file to get final .po
+               exec(MSGMERGE_BIN.MSGMERGE_OPTIONS." $from $pot -o $dest ");
+               // delete no more needed file
+               //      unlink($from);
        }
 }
 
+$maintClass = "Lang2Po";
+require_once( DO_MAINTENANCE );
index 9bfb3cd..7113547 100644 (file)
@@ -3,31 +3,57 @@
  * Dumb program that tries to get the memory usage
  * for each language file.
  *
- * @file
+ * 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
+ *
  * @ingroup MaintenanceLanguage
  */
 
 /** This is a command line script */
-require_once(dirname(__FILE__).'/../commandLine.inc');
-require_once(dirname(__FILE__).'/languages.inc');
+require_once( dirname(__FILE__) . '/../Maintenance.php' );
+require_once( dirname(__FILE__) . '/languages.inc' );
 
-$langtool = new languages();
+class LangMemUsage extends Maintenance {
 
-if ( ! function_exists( 'memory_get_usage' ) )
-       wfDie( "You must compile PHP with --enable-memory-limit\n" );
+       public function __construct() {
+               parent::__construct();
+               $this->mDescription = "Dumb program that tries to get the memory usage\n" .
+                       "for each language file";
+       }
 
-$memlast = $memstart = memory_get_usage();
+       public function execute() {
+               if ( !function_exists( 'memory_get_usage' ) )
+                       $this->error( "You must compile PHP with --enable-memory-limit", true );
 
-print 'Base memory usage: '.$memstart."\n";
+               $langtool = new languages();
+               $memlast = $memstart = memory_get_usage();
 
-foreach ( $langtool->getLanguages() as $langcode ) {
-       Language::factory( $langcode );
-       $memstep = memory_get_usage();
-       printf( "%12s: %d\n", $langcode, ($memstep- $memlast) );
-       $memlast = $memstep;
-}
+               $this->output( "Base memory usage: $memstart\n" );
+       
+               foreach ( $langtool->getLanguages() as $langcode ) {
+                       Language::factory( $langcode );
+                       $memstep = memory_get_usage();
+                       $this->output( sprintf( "%12s: %d\n", $langcode, ($memstep- $memlast) ) );
+                       $memlast = $memstep;
+               }
 
-$memend = memory_get_usage();
+               $memend = memory_get_usage();
 
-echo ' Total Usage: '.($memend - $memstart)."\n";
+               $this->output( ' Total Usage: '.($memend - $memstart)."\n" );
+       }
+}
 
+$maintClass = "LangMemUsage";
+require_once( DO_MAINTENANCE );