summaryrefslogtreecommitdiff
path: root/maintenance/renderDump.php
diff options
context:
space:
mode:
Diffstat (limited to 'maintenance/renderDump.php')
-rw-r--r--maintenance/renderDump.php41
1 files changed, 29 insertions, 12 deletions
diff --git a/maintenance/renderDump.php b/maintenance/renderDump.php
index d36953f8..78c5b6f3 100644
--- a/maintenance/renderDump.php
+++ b/maintenance/renderDump.php
@@ -27,8 +27,8 @@
* @file
* @ingroup Maintenance
*/
-
-require_once( dirname(__FILE__) . '/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" .
@@ -98,4 +115,4 @@ class DumpRenderer extends Maintenance {
}
$maintClass = "DumpRenderer";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );