X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/maintenance/renderDump.php diff --git a/maintenance/renderDump.php b/maintenance/renderDump.php index 78c5b6f3..68a371c3 100644 --- a/maintenance/renderDump.php +++ b/maintenance/renderDump.php @@ -7,7 +7,7 @@ * Templates etc are pulled from the local wiki database, not from the dump. * * Copyright (C) 2006 Brion Vibber - * http://www.mediawiki.org/ + * https://www.mediawiki.org/ * * 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 @@ -28,8 +28,14 @@ * @ingroup Maintenance */ -require_once( dirname( __FILE__ ) . '/Maintenance.php' ); +require_once __DIR__ . '/Maintenance.php'; +/** + * Maintenance script that takes page text out of an XML dump file + * and render basic HTML out to files. + * + * @ingroup Maintenance + */ class DumpRenderer extends Maintenance { private $count = 0; @@ -37,7 +43,8 @@ class DumpRenderer extends Maintenance { public function __construct() { parent::__construct(); - $this->mDescription = "Take page text out of an XML dump file and render basic HTML out to files"; + $this->addDescription( + '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 ); @@ -46,7 +53,7 @@ class DumpRenderer extends Maintenance { public function execute() { $this->outputDirectory = $this->getOption( 'output-dir' ); $this->prefix = $this->getOption( 'prefix', 'wiki' ); - $this->startTime = wfTime(); + $this->startTime = microtime( true ); if ( $this->hasOption( 'parser' ) ) { global $wgParserConf; @@ -55,30 +62,30 @@ class DumpRenderer extends Maintenance { } $source = new ImportStreamSource( $this->getStdin() ); - $importer = new WikiImporter( $source ); + $importer = new WikiImporter( $source, $this->getConfig() ); $importer->setRevisionCallback( - array( &$this, 'handleRevision' ) ); + [ $this, 'handleRevision' ] ); $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" ); + $delta = microtime( true ) - $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 + * @param Revision $rev */ public function handleRevision( $rev ) { - global $wgParserConf; - $title = $rev->getTitle(); if ( !$title ) { $this->error( "Got bogus revision with null title!" ); + return; } $display = $title->getPrefixedText(); @@ -94,17 +101,16 @@ class DumpRenderer extends Maintenance { $this->output( sprintf( "%s\n", $filename, $display ) ); $user = new User(); - $parser = new $wgParserConf['class'](); $options = ParserOptions::newFromUser( $user ); - $output = $parser->parse( $rev->getText(), $title, $options ); + $content = $rev->getContent(); + $output = $content->getParserOutput( $title, null, $options ); file_put_contents( $filename, - "\n" . - "\n" . + "\n" . + "\n" . "\n" . - "\n" . + "\n" . "" . htmlspecialchars( $display ) . "\n" . "\n" . "\n" . @@ -115,4 +121,4 @@ class DumpRenderer extends Maintenance { } $maintClass = "DumpRenderer"; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN;