Some UI cleanup
[mediawiki.git] / maintenance / renderDump.php
blob4b6322d50a7a251c024428b4811b97d5acb4cadf
1 <?php
2 /**
3 * Take page text out of an XML dump file and render basic HTML out to files.
4 * This is *NOT* suitable for publishing or offline use; it's intended for
5 * running comparative tests of parsing behavior using real-world data.
7 * Templates etc are pulled from the local wiki database, not from the dump.
9 * Copyright (C) 2006 Brion Vibber <brion@pobox.com>
10 * http://www.mediawiki.org/
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 * http://www.gnu.org/copyleft/gpl.html
27 * @addtogroup Maintenance
30 $optionsWithArgs = array( 'report' );
32 require_once( 'commandLine.inc' );
34 class DumpRenderer {
35 function __construct( $dir ) {
36 $this->stderr = fopen( "php://stderr", "wt" );
37 $this->outputDirectory = $dir;
38 $this->count = 0;
41 function handleRevision( $rev ) {
42 $title = $rev->getTitle();
43 if (!$title) {
44 fprintf( $this->stderr, "Got bogus revision with null title!" );
45 return;
47 $display = $title->getPrefixedText();
49 $this->count++;
51 $sanitized = rawurlencode( $display );
52 $filename = sprintf( "%s/wiki-%07d-%s.html",
53 $this->outputDirectory,
54 $this->count,
55 $sanitized );
56 fprintf( $this->stderr, "%s\n", $filename, $display );
58 // fixme
59 $user = new User();
60 $parser = new Parser();
61 $options = ParserOptions::newFromUser( $user );
63 $output = $parser->parse( $rev->getText(), $title, $options );
65 file_put_contents( $filename,
66 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " .
67 "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" .
68 "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" .
69 "<head>\n" .
70 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n" .
71 "<title>" . htmlspecialchars( $display ) . "</title>\n" .
72 "</head>\n" .
73 "<body>\n" .
74 $output->getText() .
75 "</body>\n" .
76 "</html>" );
79 function run() {
80 $this->startTime = wfTime();
82 $file = fopen( 'php://stdin', 'rt' );
83 $source = new ImportStreamSource( $file );
84 $importer = new WikiImporter( $source );
86 $importer->setRevisionCallback(
87 array( &$this, 'handleRevision' ) );
89 return $importer->doImport();
93 if( isset( $options['output-dir'] ) ) {
94 $dir = $options['output-dir'];
95 } else {
96 wfDie( "Must use --output-dir=/some/dir\n" );
98 $render = new DumpRenderer( $dir );
99 $render->run();