split getHooksFromDoc() function
[lhc/web/wiklou.git] / maintenance / formatInstallDoc.php
1 <?php
2
3 require_once( dirname( __FILE__ ) .'/Maintenance.php' );
4
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.' );
11 }
12
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 );
20 }
21 } else {
22 $inFile = STDIN;
23 }
24
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 );
31 }
32 } else {
33 $outFile = STDOUT;
34 }
35
36 $inText = stream_get_contents( $inFile );
37 $outText = InstallDocFormatter::format( $inText );
38
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";
45 }
46
47 fwrite( $outFile, $outText );
48 }
49 }
50
51 $maintClass = 'MaintenanceFormatInstallDoc';
52 require_once( RUN_MAINTENANCE_IF_MAIN );
53
54