From 380b76f83599d4a9c4d326c036aeef8416243ba2 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 3 Jun 2006 08:50:22 +0000 Subject: [PATCH] Testing tool to dump out rendered HTML of page input from an XML dump. Not suitable for publishing or offline use (as dumpHTML.php is intended), this is just for comparitive parser testing using real-world data. --- maintenance/renderDump.php | 103 +++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 maintenance/renderDump.php diff --git a/maintenance/renderDump.php b/maintenance/renderDump.php new file mode 100644 index 0000000000..1b832b6454 --- /dev/null +++ b/maintenance/renderDump.php @@ -0,0 +1,103 @@ + + * http://www.mediawiki.org/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @package MediaWiki + * @subpackage Maintenance + */ + +$optionsWithArgs = array( 'report' ); + +require_once( 'commandLine.inc' ); +require_once( 'SpecialImport.php' ); + +class DumpRenderer { + function __construct( $dir ) { + $this->stderr = fopen( "php://stderr", "wt" ); + $this->outputDirectory = $dir; + $this->count = 0; + } + + function handleRevision( $rev ) { + $title = $rev->getTitle(); + if (!$title) { + $this->progress( "Got bogus revision with null title!" ); + return; + } + $display = $title->getPrefixedText(); + + $this->count++; + + $sanitized = rawurlencode( $display ); + $filename = sprintf( "%s/wiki-%07d-%s.html", + $this->outputDirectory, + $this->count, + $sanitized ); + fprintf( $this->stderr, "%s\n", $filename, $display ); + + // fixme + $user = new User(); + $parser = new Parser(); + $options = ParserOptions::newFromUser( $user ); + + $output = $parser->parse( $rev->getText(), $title, $options ); + + file_put_contents( $filename, + "\n" . + "\n" . + "\n" . + "\n" . + "" . htmlspecialchars( $display ) . "\n" . + "\n" . + "\n" . + $output->getText() . + "\n" . + "" ); + } + + function run() { + $this->startTime = wfTime(); + + $file = fopen( 'php://stdin', 'rt' ); + $source = new ImportStreamSource( $file ); + $importer = new WikiImporter( $source ); + + $importer->setRevisionCallback( + array( &$this, 'handleRevision' ) ); + + return $importer->doImport(); + } +} + +if( isset( $options['output-dir'] ) ) { + $dir = $options['output-dir']; +} else { + wfDie( "Must use --output-dir=/some/dir\n" ); +} +$render = new DumpRenderer( $dir ); +$render->run(); + +?> -- 2.20.1