]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - maintenance/renderDump.php
MediaWiki 1.11.0
[autoinstallsdev/mediawiki.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 comparative 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
34 class DumpRenderer {
35         function __construct( $dir ) {
36                 $this->stderr = fopen( "php://stderr", "wt" );
37                 $this->outputDirectory = $dir;
38                 $this->count = 0;
39         }
40
41         function handleRevision( $rev ) {
42                 $title = $rev->getTitle();
43                 if (!$title) {
44                         fprintf( $this->stderr, "Got bogus revision with null title!" );
45                         return;
46                 }
47                 $display = $title->getPrefixedText();
48                 
49                 $this->count++;
50                 
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 );
57                 
58                 // fixme
59                 $user = new User();
60                 $parser = new Parser();
61                 $options = ParserOptions::newFromUser( $user );
62                 
63                 $output = $parser->parse( $rev->getText(), $title, $options );
64                 
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>" );
77         }
78
79         function run() {
80                 $this->startTime = wfTime();
81
82                 $file = fopen( 'php://stdin', 'rt' );
83                 $source = new ImportStreamSource( $file );
84                 $importer = new WikiImporter( $source );
85
86                 $importer->setRevisionCallback(
87                         array( &$this, 'handleRevision' ) );
88
89                 return $importer->doImport();
90         }
91 }
92
93 if( isset( $options['output-dir'] ) ) {
94         $dir = $options['output-dir'];
95 } else {
96         wfDie( "Must use --output-dir=/some/dir\n" );
97 }
98 $render = new DumpRenderer( $dir );
99 $render->run();
100
101