]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - maintenance/renderDump.php
MediaWiki 1.16.0
[autoinstallsdev/mediawiki.git] / maintenance / renderDump.php
index 97797792a0152c51b5fd8496f900d1a79e37beb1..d36953f89f9cc8711726a09bdef9eb627f79d4b6 100644 (file)
  * @file
  * @ingroup Maintenance
  */
+require_once( dirname(__FILE__) . '/Maintenance.php' );
 
-$optionsWithArgs = array( 'report' );
+class DumpRenderer extends Maintenance {
 
-require_once( 'commandLine.inc' );
+       private $count = 0;
+       private $outputDirectory, $startTime;
 
-class DumpRenderer {
-       function __construct( $dir ) {
-               $this->stderr = fopen( "php://stderr", "wt" );
-               $this->outputDirectory = $dir;
-               $this->count = 0;
+       public function __construct() {
+               parent::__construct();
+               $this->mDescription = "Take page text out of an XML dump file and render basic HTML out to files";
+               $this->addOption( 'output-dir', 'The directory to output the HTML files to', true, true );
        }
 
-       function handleRevision( $rev ) {
+       public function execute() {
+               $this->outputDirectory = $this->getOption( 'output-dir' );
+               $this->startTime = wfTime();
+
+               $source = new ImportStreamSource( $this->getStdin() );
+               $importer = new WikiImporter( $source );
+
+               $importer->setRevisionCallback(
+                       array( &$this, 'handleRevision' ) );
+
+               return $importer->doImport();
+       }
+       
+       /**
+        * Callback function for each revision, turn into HTML and save
+        * @param $rev Revision
+        */
+       private function handleRevision( $rev ) {
                $title = $rev->getTitle();
                if (!$title) {
-                       fprintf( $this->stderr, "Got bogus revision with null title!" );
+                       $this->error( "Got bogus revision with null title!" );
                        return;
                }
                $display = $title->getPrefixedText();
-               
+
                $this->count++;
-               
+
                $sanitized = rawurlencode( $display );
                $filename = sprintf( "%s/wiki-%07d-%s.html", 
                        $this->outputDirectory,
                        $this->count,
                        $sanitized );
-               fprintf( $this->stderr, "%s\n", $filename, $display );
-               
-               // fixme
+               $this->output( sprintf( $this->stderr, "%s\n", $filename, $display ) );
+
+               // fixme (what?)
                $user = new User();
                $parser = new Parser();
                $options = ParserOptions::newFromUser( $user );
-               
+
                $output = $parser->parse( $rev->getText(), $title, $options );
-               
+
                file_put_contents( $filename,
                        "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " .
                        "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" .
@@ -76,27 +95,7 @@ class DumpRenderer {
                        "</body>\n" .
                        "</html>" );
        }
-
-       function run() {
-               $this->startTime = wfTime();
-
-               $file = fopen( 'php://stdin', 'rt' );
-               $source = new ImportStreamSource( $file );
-               $importer = new WikiImporter( $source );
-
-               $importer->setRevisionCallback(
-                       array( &$this, 'handleRevision' ) );
-
-               return $importer->doImport();
-       }
 }
 
-if( isset( $options['output-dir'] ) ) {
-       $dir = $options['output-dir'];
-} else {
-       wfDie( "Must use --output-dir=/some/dir\n" );
-}
-$render = new DumpRenderer( $dir );
-$render->run();
-
-
+$maintClass = "DumpRenderer";
+require_once( DO_MAINTENANCE );