r108300: also destroy the repo/backend singletons for upload test
[mediawiki.git] / maintenance / formatInstallDoc.php
blob9acc16a70a494a3e2fc0120eca455da798855ae9
1 <?php
3 require_once( dirname( __FILE__ ) .'/Maintenance.php' );
5 class MaintenanceFormatInstallDoc extends Maintenance {
6 function __construct() {
7 parent::__construct();
8 $this->addArg( 'path', 'The file name to format', false );
9 $this->addOption( 'outfile', 'The output file name', false, true );
10 $this->addOption( 'html', 'Use HTML output format. By default, wikitext is used.' );
13 function execute() {
14 if ( $this->hasArg( 0 ) ) {
15 $fileName = $this->getArg( 0 );
16 $inFile = fopen( $fileName, 'r' );
17 if ( !$inFile ) {
18 $this->error( "Unable to open input file \"$fileName\"" );
19 exit( 1 );
21 } else {
22 $inFile = STDIN;
25 if ( $this->hasOption( 'outfile' ) ) {
26 $fileName = $this->getOption( 'outfile' );
27 $outFile = fopen( $fileName, 'w' );
28 if ( !$outFile ) {
29 $this->error( "Unable to open output file \"$fileName\"" );
30 exit( 1 );
32 } else {
33 $outFile = STDOUT;
36 $inText = stream_get_contents( $inFile );
37 $outText = InstallDocFormatter::format( $inText );
39 if ( $this->hasOption( 'html' ) ) {
40 global $wgParser;
41 $opt = new ParserOptions;
42 $title = Title::newFromText( 'Text file' );
43 $out = $wgParser->parse( $outText, $title, $opt );
44 $outText = "<html><body>\n" . $out->getText() . "\n</body></html>\n";
47 fwrite( $outFile, $outText );
51 $maintClass = 'MaintenanceFormatInstallDoc';
52 require_once( RUN_MAINTENANCE_IF_MAIN );