X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FrenderDump.php;h=78c5b6f31e0e8909e766db3d404add4ebf834ad2;hb=b17e4b4a24a317b5ea8b0c7687c695cce783c154;hp=f8b97e7c9f05dcb07ee87d67b1133d88d190d6c0;hpb=72a4abe588a7511ed5a92a5e30f889c60d824c1a;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/renderDump.php b/maintenance/renderDump.php index f8b97e7c9f..78c5b6f31e 100644 --- a/maintenance/renderDump.php +++ b/maintenance/renderDump.php @@ -24,44 +24,81 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * - * @addtogroup Maintenance + * @file + * @ingroup Maintenance */ -$optionsWithArgs = array( 'report' ); +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); -require_once( 'commandLine.inc' ); +class DumpRenderer extends Maintenance { -class DumpRenderer { - function __construct( $dir ) { - $this->stderr = fopen( "php://stderr", "wt" ); - $this->outputDirectory = $dir; - $this->count = 0; + private $count = 0; + private $outputDirectory, $startTime; + + 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 ); + $this->addOption( 'prefix', 'Prefix for the rendered files (defaults to wiki)', false, true ); + $this->addOption( 'parser', 'Use an alternative parser class', false, true ); } - function handleRevision( $rev ) { + 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' ) ); + + $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 + */ + public function handleRevision( $rev ) { + global $wgParserConf; + $title = $rev->getTitle(); - if (!$title) { - fprintf( $this->stderr, "Got bogus revision with null title!" ); + if ( !$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", + $filename = sprintf( "%s/%s-%07d-%s.html", $this->outputDirectory, + $this->prefix, $this->count, $sanitized ); - fprintf( $this->stderr, "%s\n", $filename, $display ); - - // fixme + $this->output( sprintf( "%s\n", $filename, $display ) ); + $user = new User(); - $parser = new Parser(); + $parser = new $wgParserConf['class'](); $options = ParserOptions::newFromUser( $user ); - + $output = $parser->parse( $rev->getText(), $title, $options ); - + file_put_contents( $filename, "\n" . @@ -69,33 +106,13 @@ class DumpRenderer { "\n" . "\n" . "" . htmlspecialchars( $display ) . "\n" . - "\n" . + "\n" . "\n" . $output->getText() . "\n" . "" ); } - - 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( RUN_MAINTENANCE_IF_MAIN );