]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - maintenance/renderDump.php
MediaWiki 1.16.0
[autoinstalls/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  * @file
28  * @ingroup Maintenance
29  */
30  
31 require_once( dirname(__FILE__) . '/Maintenance.php' );
32
33 class DumpRenderer extends Maintenance {
34
35         private $count = 0;
36         private $outputDirectory, $startTime;
37
38         public function __construct() {
39                 parent::__construct();
40                 $this->mDescription = "Take page text out of an XML dump file and render basic HTML out to files";
41                 $this->addOption( 'output-dir', 'The directory to output the HTML files to', true, true );
42         }
43
44         public function execute() {
45                 $this->outputDirectory = $this->getOption( 'output-dir' );
46                 $this->startTime = wfTime();
47
48                 $source = new ImportStreamSource( $this->getStdin() );
49                 $importer = new WikiImporter( $source );
50
51                 $importer->setRevisionCallback(
52                         array( &$this, 'handleRevision' ) );
53
54                 return $importer->doImport();
55         }
56         
57         /**
58          * Callback function for each revision, turn into HTML and save
59          * @param $rev Revision
60          */
61         private function handleRevision( $rev ) {
62                 $title = $rev->getTitle();
63                 if (!$title) {
64                         $this->error( "Got bogus revision with null title!" );
65                         return;
66                 }
67                 $display = $title->getPrefixedText();
68
69                 $this->count++;
70
71                 $sanitized = rawurlencode( $display );
72                 $filename = sprintf( "%s/wiki-%07d-%s.html", 
73                         $this->outputDirectory,
74                         $this->count,
75                         $sanitized );
76                 $this->output( sprintf( $this->stderr, "%s\n", $filename, $display ) );
77
78                 // fixme (what?)
79                 $user = new User();
80                 $parser = new Parser();
81                 $options = ParserOptions::newFromUser( $user );
82
83                 $output = $parser->parse( $rev->getText(), $title, $options );
84
85                 file_put_contents( $filename,
86                         "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " .
87                         "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" .
88                         "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" .
89                         "<head>\n" .
90                         "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n" .
91                         "<title>" . htmlspecialchars( $display ) . "</title>\n" .
92                         "</head>\n" . 
93                         "<body>\n" .
94                         $output->getText() .
95                         "</body>\n" .
96                         "</html>" );
97         }
98 }
99
100 $maintClass = "DumpRenderer";
101 require_once( DO_MAINTENANCE );