10986f2c787fe6b5689a81316e52c391ee51baf2
[lhc/web/wiklou.git] / maintenance / renderDump.php
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 comparitive tests of parsing behavior using real-world data.
6 *
7 * Templates etc are pulled from the local wiki database, not from the dump.
8 *
9 * Copyright (C) 2006 Brion Vibber <brion@pobox.com>
10 * http://www.mediawiki.org/
11 *
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.
16 *
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.
21 *
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
26 *
27 * @package MediaWiki
28 * @subpackage Maintenance
29 */
30
31 $optionsWithArgs = array( 'report' );
32
33 require_once( 'commandLine.inc' );
34 require_once( 'SpecialImport.php' );
35
36 class DumpRenderer {
37 function __construct( $dir ) {
38 $this->stderr = fopen( "php://stderr", "wt" );
39 $this->outputDirectory = $dir;
40 $this->count = 0;
41 }
42
43 function handleRevision( $rev ) {
44 $title = $rev->getTitle();
45 if (!$title) {
46 fprintf( $this->stderr, "Got bogus revision with null title!" );
47 return;
48 }
49 $display = $title->getPrefixedText();
50
51 $this->count++;
52
53 $sanitized = rawurlencode( $display );
54 $filename = sprintf( "%s/wiki-%07d-%s.html",
55 $this->outputDirectory,
56 $this->count,
57 $sanitized );
58 fprintf( $this->stderr, "%s\n", $filename, $display );
59
60 // fixme
61 $user = new User();
62 $parser = new Parser();
63 $options = ParserOptions::newFromUser( $user );
64
65 $output = $parser->parse( $rev->getText(), $title, $options );
66
67 file_put_contents( $filename,
68 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " .
69 "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" .
70 "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" .
71 "<head>\n" .
72 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n" .
73 "<title>" . htmlspecialchars( $display ) . "</title>\n" .
74 "</head>\n" .
75 "<body>\n" .
76 $output->getText() .
77 "</body>\n" .
78 "</html>" );
79 }
80
81 function run() {
82 $this->startTime = wfTime();
83
84 $file = fopen( 'php://stdin', 'rt' );
85 $source = new ImportStreamSource( $file );
86 $importer = new WikiImporter( $source );
87
88 $importer->setRevisionCallback(
89 array( &$this, 'handleRevision' ) );
90
91 return $importer->doImport();
92 }
93 }
94
95 if( isset( $options['output-dir'] ) ) {
96 $dir = $options['output-dir'];
97 } else {
98 wfDie( "Must use --output-dir=/some/dir\n" );
99 }
100 $render = new DumpRenderer( $dir );
101 $render->run();
102
103 ?>