00001 <?php
00031 $optionsWithArgs = array( 'report' );
00032
00033 require_once( 'commandLine.inc' );
00034
00035 class DumpRenderer {
00036 function __construct( $dir ) {
00037 $this->stderr = fopen( "php://stderr", "wt" );
00038 $this->outputDirectory = $dir;
00039 $this->count = 0;
00040 }
00041
00042 function handleRevision( $rev ) {
00043 $title = $rev->getTitle();
00044 if (!$title) {
00045 fprintf( $this->stderr, "Got bogus revision with null title!" );
00046 return;
00047 }
00048 $display = $title->getPrefixedText();
00049
00050 $this->count++;
00051
00052 $sanitized = rawurlencode( $display );
00053 $filename = sprintf( "%s/wiki-%07d-%s.html",
00054 $this->outputDirectory,
00055 $this->count,
00056 $sanitized );
00057 fprintf( $this->stderr, "%s\n", $filename, $display );
00058
00059
00060 $user = new User();
00061 $parser = new Parser();
00062 $options = ParserOptions::newFromUser( $user );
00063
00064 $output = $parser->parse( $rev->getText(), $title, $options );
00065
00066 file_put_contents( $filename,
00067 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " .
00068 "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" .
00069 "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" .
00070 "<head>\n" .
00071 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n" .
00072 "<title>" . htmlspecialchars( $display ) . "</title>\n" .
00073 "</head>\n" .
00074 "<body>\n" .
00075 $output->getText() .
00076 "</body>\n" .
00077 "</html>" );
00078 }
00079
00080 function run() {
00081 $this->startTime = wfTime();
00082
00083 $file = fopen( 'php://stdin', 'rt' );
00084 $source = new ImportStreamSource( $file );
00085 $importer = new WikiImporter( $source );
00086
00087 $importer->setRevisionCallback(
00088 array( &$this, 'handleRevision' ) );
00089
00090 return $importer->doImport();
00091 }
00092 }
00093
00094 if( isset( $options['output-dir'] ) ) {
00095 $dir = $options['output-dir'];
00096 } else {
00097 wfDie( "Must use --output-dir=/some/dir\n" );
00098 }
00099 $render = new DumpRenderer( $dir );
00100 $render->run();
00101
00102