MediaWiki  1.23.13
renderDump.php
Go to the documentation of this file.
1 <?php
31 require_once __DIR__ . '/Maintenance.php';
32 
39 class DumpRenderer extends Maintenance {
40 
41  private $count = 0;
43 
44  public function __construct() {
45  parent::__construct();
46  $this->mDescription = "Take page text out of an XML dump file and render basic HTML out to files";
47  $this->addOption( 'output-dir', 'The directory to output the HTML files to', true, true );
48  $this->addOption( 'prefix', 'Prefix for the rendered files (defaults to wiki)', false, true );
49  $this->addOption( 'parser', 'Use an alternative parser class', false, true );
50  }
51 
52  public function execute() {
53  $this->outputDirectory = $this->getOption( 'output-dir' );
54  $this->prefix = $this->getOption( 'prefix', 'wiki' );
55  $this->startTime = microtime( true );
56 
57  if ( $this->hasOption( 'parser' ) ) {
58  global $wgParserConf;
59  $wgParserConf['class'] = $this->getOption( 'parser' );
60  $this->prefix .= "-{$wgParserConf['class']}";
61  }
62 
63  $source = new ImportStreamSource( $this->getStdin() );
64  $importer = new WikiImporter( $source );
65 
66  $importer->setRevisionCallback(
67  array( &$this, 'handleRevision' ) );
68 
69  $importer->doImport();
70 
71  $delta = microtime( true ) - $this->startTime;
72  $this->error( "Rendered {$this->count} pages in " . round( $delta, 2 ) . " seconds " );
73  if ( $delta > 0 ) {
74  $this->error( round( $this->count / $delta, 2 ) . " pages/sec" );
75  }
76  $this->error( "\n" );
77  }
78 
83  public function handleRevision( $rev ) {
84  $title = $rev->getTitle();
85  if ( !$title ) {
86  $this->error( "Got bogus revision with null title!" );
87  return;
88  }
89  $display = $title->getPrefixedText();
90 
91  $this->count++;
92 
93  $sanitized = rawurlencode( $display );
94  $filename = sprintf( "%s/%s-%07d-%s.html",
95  $this->outputDirectory,
96  $this->prefix,
97  $this->count,
98  $sanitized );
99  $this->output( sprintf( "%s\n", $filename, $display ) );
100 
101  $user = new User();
103 
104  $content = $rev->getContent();
105  $output = $content->getParserOutput( $title, null, $options );
106 
107  file_put_contents( $filename,
108  "<!DOCTYPE html>\n" .
109  "<html lang=\"en\" dir=\"ltr\">\n" .
110  "<head>\n" .
111  "<meta charset=\"UTF-8\" />\n" .
112  "<title>" . htmlspecialchars( $display ) . "</title>\n" .
113  "</head>\n" .
114  "<body>\n" .
115  $output->getText() .
116  "</body>\n" .
117  "</html>" );
118  }
119 }
120 
121 $maintClass = "DumpRenderer";
122 require_once RUN_MAINTENANCE_IF_MAIN;
WikiImporter
XML file reader for the page data importer.
Definition: Import.php:33
$maintClass
$maintClass
Definition: renderDump.php:121
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
Maintenance\getStdin
getStdin( $len=null)
Return input from stdin.
Definition: Maintenance.php:287
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
DumpRenderer\handleRevision
handleRevision( $rev)
Callback function for each revision, turn into HTML and save.
Definition: renderDump.php:83
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
ImportStreamSource
Definition: Import.php:1630
DumpRenderer\$outputDirectory
$outputDirectory
Definition: renderDump.php:42
DumpRenderer\__construct
__construct()
Default constructor.
Definition: renderDump.php:44
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
DumpRenderer\$count
$count
Definition: renderDump.php:41
$options
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1530
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
DumpRenderer\$startTime
$startTime
Definition: renderDump.php:42
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
$rev
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition: hooks.txt:1337
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:191
$output
& $output
Definition: hooks.txt:375
User
User
Definition: All_system_messages.txt:425
$source
if(PHP_SAPI !='cli') $source
Definition: mwdoc-filter.php:18
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:333
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular param exists.
Definition: Maintenance.php:181
DumpRenderer
Maintenance script that takes page text out of an XML dump file and render basic HTML out to files.
Definition: renderDump.php:39
DumpRenderer\execute
execute()
Do the actual work.
Definition: renderDump.php:52
ParserOptions\newFromUser
static newFromUser( $user)
Get a ParserOptions object from a given user.
Definition: ParserOptions.php:375