diff options
Diffstat (limited to 'maintenance/renderDump.php')
-rw-r--r-- | maintenance/renderDump.php | 75 |
1 files changed, 37 insertions, 38 deletions
diff --git a/maintenance/renderDump.php b/maintenance/renderDump.php index 97797792..d36953f8 100644 --- a/maintenance/renderDump.php +++ b/maintenance/renderDump.php @@ -27,42 +27,61 @@ * @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 ); |