Merge "Added result properties to action=paraminfo"
[lhc/web/wiklou.git] / maintenance / formatInstallDoc.php
1 <?php
2 /**
3 * @ingroup Maintenance
4 */
5
6 require_once( dirname( __FILE__ ) .'/Maintenance.php' );
7
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.' );
14 }
15
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 );
23 }
24 } else {
25 $inFile = STDIN;
26 }
27
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 );
34 }
35 } else {
36 $outFile = STDOUT;
37 }
38
39 $inText = stream_get_contents( $inFile );
40 $outText = InstallDocFormatter::format( $inText );
41
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";
48 }
49
50 fwrite( $outFile, $outText );
51 }
52 }
53
54 $maintClass = 'MaintenanceFormatInstallDoc';
55 require_once( RUN_MAINTENANCE_IF_MAIN );
56
57