Merge "(bug 37090) Remove Spanish gender aliases."
[mediawiki.git] / maintenance / formatInstallDoc.php
blobb3bb50ca1726a4d3782de06fd8f0689910d8bfbd
1 <?php
2 /**
3 * @ingroup Maintenance
4 */
6 require_once( dirname( __FILE__ ) .'/Maintenance.php' );
8 class MaintenanceFormatInstallDoc extends Maintenance {
9 function __construct() {
10 parent::__construct();
11 $this->addArg( 'path', 'The file name to format', false );
12 $this->addOption( 'outfile', 'The output file name', false, true );
13 $this->addOption( 'html', 'Use HTML output format. By default, wikitext is used.' );
16 function execute() {
17 if ( $this->hasArg( 0 ) ) {
18 $fileName = $this->getArg( 0 );
19 $inFile = fopen( $fileName, 'r' );
20 if ( !$inFile ) {
21 $this->error( "Unable to open input file \"$fileName\"" );
22 exit( 1 );
24 } else {
25 $inFile = STDIN;
28 if ( $this->hasOption( 'outfile' ) ) {
29 $fileName = $this->getOption( 'outfile' );
30 $outFile = fopen( $fileName, 'w' );
31 if ( !$outFile ) {
32 $this->error( "Unable to open output file \"$fileName\"" );
33 exit( 1 );
35 } else {
36 $outFile = STDOUT;
39 $inText = stream_get_contents( $inFile );
40 $outText = InstallDocFormatter::format( $inText );
42 if ( $this->hasOption( 'html' ) ) {
43 global $wgParser;
44 $opt = new ParserOptions;
45 $title = Title::newFromText( 'Text file' );
46 $out = $wgParser->parse( $outText, $title, $opt );
47 $outText = "<html><body>\n" . $out->getText() . "\n</body></html>\n";
50 fwrite( $outFile, $outText );
54 $maintClass = 'MaintenanceFormatInstallDoc';
55 require_once( RUN_MAINTENANCE_IF_MAIN );