26require_once __DIR__ .
'/Maintenance.php';
39 private string $outputDirectory;
40 private float $startTime;
45 parent::__construct();
47 'Take page text out of an XML dump file and render basic HTML out to files' );
48 $this->
addOption(
'output-dir',
'The directory to output the HTML files to',
true,
true );
49 $this->
addOption(
'prefix',
'Prefix for the rendered files (defaults to wiki)',
false,
true );
50 $this->
addOption(
'parser',
'Use an alternative parser class',
false,
true );
54 $this->outputDirectory = $this->
getOption(
'output-dir' );
55 $this->prefix = $this->
getOption(
'prefix',
'wiki' );
56 $this->startTime = microtime(
true );
59 $this->prefix .=
'-' . $this->
getOption(
'parser' );
62 $this->
fatalError(
'Parser class configuration temporarily disabled.' );
65 $user = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [
'steal' =>
true ] );
69 ->getWikiImporterFactory()
72 $importer->setRevisionCallback(
74 $importer->setNoticeCallback(
static function ( $msg, $params ) {
75 echo
wfMessage( $msg, $params )->text() .
"\n";
78 $importer->doImport();
80 $delta = microtime(
true ) - $this->startTime;
81 $this->
error(
"Rendered {$this->count} pages in " . round( $delta, 2 ) .
" seconds " );
83 $this->
error( round( $this->count / $delta, 2 ) .
" pages/sec" );
94 $this->
error(
"Got bogus revision with null title!" );
98 $display = $title->getPrefixedText();
102 $sanitized = rawurlencode( $display );
103 $filename = sprintf(
"%s/%s-%07d-%s.html",
104 $this->outputDirectory,
108 $this->
output( sprintf(
"%s\t%s\n", $filename, $display ) );
111 $options = ParserOptions::newFromUser( $user );
120 $mutableRev->setId( $rev->
getID() );
122 $output = $contentRenderer->getParserOutput(
123 $content, $title, $mutableRev, $options
126 file_put_contents( $filename,
127 "<!DOCTYPE html>\n" .
128 "<html lang=\"en\" dir=\"ltr\">\n" .
130 "<meta charset=\"UTF-8\" />\n" .
131 "<meta name=\"color-scheme\" content=\"light dark\">" .
132 "<title>" . htmlspecialchars( $display, ENT_COMPAT ) .
"</title>\n" .
136 $output->runOutputPipeline( $options, [] )->getContentHolderText() .
144require_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.