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