Two new parser tests related to bug 6200
[lhc/web/wiklou.git] / maintenance / renderDump.php
index b6758f7..36e35c2 100644 (file)
@@ -28,7 +28,7 @@
  * @ingroup Maintenance
  */
  
-require_once( "Maintenance.php" );
+require_once( dirname( __FILE__ ) . '/Maintenance.php' );
 
 class DumpRenderer extends Maintenance {
 
@@ -39,28 +39,45 @@ class DumpRenderer extends Maintenance {
                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 );
+               $this->addOption( 'prefix', 'Prefix for the rendered files (defaults to wiki)', false, true );
+               $this->addOption( 'parser', 'Use an alternative parser class', false, true );
        }
 
        public function execute() {
                $this->outputDirectory = $this->getOption( 'output-dir' );
+               $this->prefix = $this->getOption( 'prefix', 'wiki' );
                $this->startTime = wfTime();
 
+               if ( $this->hasOption( 'parser' ) ) {
+                       global $wgParserConf;
+                       $wgParserConf['class'] = $this->getOption( 'parser' );
+                       $this->prefix .= "-{$wgParserConf['class']}";
+               }
+
                $source = new ImportStreamSource( $this->getStdin() );
                $importer = new WikiImporter( $source );
 
                $importer->setRevisionCallback(
                        array( &$this, 'handleRevision' ) );
 
-               return $importer->doImport();
+               $importer->doImport();          
+               
+               $delta = wfTime() - $this->startTime;
+               $this->error( "Rendered {$this->count} pages in " . round($delta, 2) . " seconds " );
+               if ($delta > 0)
+                       $this->error( round($this->count / $delta, 2) . " pages/sec" );
+               $this->error( "\n" );
        }
        
        /**
         * Callback function for each revision, turn into HTML and save
         * @param $rev Revision
         */
-       private function handleRevision( $rev ) {
+       public function handleRevision( $rev ) {
+               global $wgParserConf;
+               
                $title = $rev->getTitle();
-               if (!$title) {
+               if ( !$title ) {
                        $this->error( "Got bogus revision with null title!" );
                        return;
                }
@@ -69,15 +86,15 @@ class DumpRenderer extends Maintenance {
                $this->count++;
 
                $sanitized = rawurlencode( $display );
-               $filename = sprintf( "%s/wiki-%07d-%s.html", 
+               $filename = sprintf( "%s/%s-%07d-%s.html",
                        $this->outputDirectory,
+                       $this->prefix,
                        $this->count,
                        $sanitized );
-               $this->output( sprintf( $this->stderr, "%s\n", $filename, $display ) );
+               $this->output( sprintf( "%s\n", $filename, $display ) );
 
-               // fixme (what?)
                $user = new User();
-               $parser = new Parser();
+               $parser = new $wgParserConf['class']();
                $options = ParserOptions::newFromUser( $user );
 
                $output = $parser->parse( $rev->getText(), $title, $options );
@@ -89,7 +106,7 @@ class DumpRenderer extends Maintenance {
                        "<head>\n" .
                        "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n" .
                        "<title>" . htmlspecialchars( $display ) . "</title>\n" .
-                       "</head>\n" . 
+                       "</head>\n" .
                        "<body>\n" .
                        $output->getText() .
                        "</body>\n" .