33require_once __DIR__ .
'/Maintenance.php';
49 parent::__construct();
51 'Take page text out of an XML dump file and render basic HTML out to files' );
52 $this->
addOption(
'output-dir',
'The directory to output the HTML files to',
true,
true );
53 $this->
addOption(
'prefix',
'Prefix for the rendered files (defaults to wiki)',
false,
true );
54 $this->
addOption(
'parser',
'Use an alternative parser class',
false,
true );
58 $this->outputDirectory = $this->
getOption(
'output-dir' );
59 $this->prefix = $this->
getOption(
'prefix',
'wiki' );
60 $this->startTime = microtime(
true );
63 $this->prefix .=
"-{$this->getOption( 'parser' )}";
66 $this->
fatalError(
'Parser class configuration temporarily disabled.' );
70 $importer = MediaWikiServices::getInstance()
71 ->getWikiImporterFactory()
74 $importer->setRevisionCallback(
75 [ $this,
'handleRevision' ] );
76 $importer->setNoticeCallback(
static function ( $msg, $params ) {
77 echo
wfMessage( $msg, $params )->text() .
"\n";
80 $importer->doImport();
83 $this->
error(
"Rendered {$this->count} pages in " . round( $delta, 2 ) .
" seconds " );
85 $this->
error( round( $this->count / $delta, 2 ) .
" pages/sec" );
97 $this->
error(
"Got bogus revision with null title!" );
101 $display =
$title->getPrefixedText();
105 $sanitized = rawurlencode( $display );
106 $filename = sprintf(
"%s/%s-%07d-%s.html",
107 $this->outputDirectory,
111 $this->
output( sprintf(
"%s\n", $filename, $display ) );
114 $options = ParserOptions::newFromUser( $user );
119 file_put_contents( $filename,
120 "<!DOCTYPE html>\n" .
121 "<html lang=\"en\" dir=\"ltr\">\n" .
123 "<meta charset=\"UTF-8\" />\n" .
124 "<title>" . htmlspecialchars( $display ) .
"</title>\n" .
134require_once RUN_MAINTENANCE_IF_MAIN;
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Maintenance script that takes page text out of an XML dump file and render basic HTML out to files.
handleRevision(WikiRevision $rev)
Callback function for each revision, turn into HTML and save.
__construct()
Default constructor.
execute()
Do the actual work.
Imports a XML dump from a file (either from file upload, files on disk, or HTTP)
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
getStdin( $len=null)
Return input from stdin.
hasOption( $name)
Checks to see if a particular option was set.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Represents a revision, log entry or upload during the import process.
getContent( $role=SlotRecord::MAIN)