24require_once __DIR__ .
'/Maintenance.php';
37 private string $outputDirectory;
38 private float $startTime;
43 parent::__construct();
45 'Take page text out of an XML dump file and render basic HTML out to files' );
46 $this->
addOption(
'output-dir',
'The directory to output the HTML files to',
true,
true );
47 $this->
addOption(
'prefix',
'Prefix for the rendered files (defaults to wiki)',
false,
true );
48 $this->
addOption(
'parser',
'Use an alternative parser class',
false,
true );
52 $this->outputDirectory = $this->
getOption(
'output-dir' );
53 $this->prefix = $this->
getOption(
'prefix',
'wiki' );
54 $this->startTime = microtime(
true );
57 $this->prefix .=
'-' . $this->
getOption(
'parser' );
60 $this->
fatalError(
'Parser class configuration temporarily disabled.' );
63 $user = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [
'steal' =>
true ] );
67 ->getWikiImporterFactory()
70 $importer->setRevisionCallback(
72 $importer->setNoticeCallback(
static function ( $msg, $params ) {
73 echo
wfMessage( $msg, $params )->text() .
"\n";
76 $importer->doImport();
78 $delta = microtime(
true ) - $this->startTime;
79 $this->
error(
"Rendered {$this->count} pages in " . round( $delta, 2 ) .
" seconds " );
81 $this->
error( round( $this->count / $delta, 2 ) .
" pages/sec" );
90 $title = $rev->getTitle();
92 $this->
error(
"Got bogus revision with null title!" );
96 $display = $title->getPrefixedText();
100 $sanitized = rawurlencode( $display );
101 $filename = sprintf(
"%s/%s-%07d-%s.html",
102 $this->outputDirectory,
106 $this->
output( sprintf(
"%s\t%s\n", $filename, $display ) );
109 $options = ParserOptions::newFromUser( $user );
111 $content = $rev->getContent();
118 $mutableRev->setId( $rev->getID() );
119 $mutableRev->setTimestamp( $rev->getTimestamp() );
120 $output = $contentRenderer->getParserOutput(
121 $content, $title, $mutableRev, $options
124 file_put_contents( $filename,
125 "<!DOCTYPE html>\n" .
126 "<html lang=\"en\" dir=\"ltr\">\n" .
128 "<meta charset=\"UTF-8\" />\n" .
129 "<meta name=\"color-scheme\" content=\"light dark\">" .
130 "<title>" . htmlspecialchars( $display, ENT_COMPAT ) .
"</title>\n" .
134 $output->runOutputPipeline( $options, [] )->getContentHolderText() .
142require_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.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
error( $err, $die=0)
Throw an error to the user.
getServiceContainer()
Returns the main service container.
getStdin( $len=null)
Return input from stdin.
addDescription( $text)
Set the description text.