38require_once __DIR__ .
'/Maintenance.php';
51 private string $outputDirectory;
52 private float $startTime;
57 parent::__construct();
59 'Take page text out of an XML dump file and render basic HTML out to files' );
60 $this->
addOption(
'output-dir',
'The directory to output the HTML files to',
true,
true );
61 $this->
addOption(
'prefix',
'Prefix for the rendered files (defaults to wiki)',
false,
true );
62 $this->
addOption(
'parser',
'Use an alternative parser class',
false,
true );
66 $this->outputDirectory = $this->
getOption(
'output-dir' );
67 $this->prefix = $this->
getOption(
'prefix',
'wiki' );
68 $this->startTime = microtime(
true );
71 $this->prefix .=
'-' . $this->
getOption(
'parser' );
74 $this->
fatalError(
'Parser class configuration temporarily disabled.' );
77 $user = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [
'steal' =>
true ] );
81 ->getWikiImporterFactory()
84 $importer->setRevisionCallback(
85 [ $this,
'handleRevision' ] );
86 $importer->setNoticeCallback(
static function ( $msg,
$params ) {
90 $importer->doImport();
92 $delta = microtime(
true ) - $this->startTime;
93 $this->
error(
"Rendered {$this->count} pages in " . round( $delta, 2 ) .
" seconds " );
95 $this->
error( round( $this->count / $delta, 2 ) .
" pages/sec" );
106 $this->
error(
"Got bogus revision with null title!" );
110 $display = $title->getPrefixedText();
114 $sanitized = rawurlencode( $display );
115 $filename = sprintf(
"%s/%s-%07d-%s.html",
116 $this->outputDirectory,
120 $this->
output( sprintf(
"%s\t%s\n", $filename, $display ) );
123 $options = ParserOptions::newFromUser( $user );
132 $mutableRev->setId( $rev->
getID() );
134 $output = $contentRenderer->getParserOutput(
135 $content, $title, $mutableRev, $options
138 file_put_contents( $filename,
139 "<!DOCTYPE html>\n" .
140 "<html lang=\"en\" dir=\"ltr\">\n" .
142 "<meta charset=\"UTF-8\" />\n" .
143 "<meta name=\"color-scheme\" content=\"light dark\">" .
144 "<title>" . htmlspecialchars( $display, ENT_COMPAT ) .
"</title>\n" .
148 $output->runOutputPipeline( $options, [] )->getContentHolderText() .
156require_once RUN_MAINTENANCE_IF_MAIN;
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
array $params
The job parameters.
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...
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.
Represents a revision, log entry or upload during the import process.
getContent( $role=SlotRecord::MAIN)