MediaWiki  REL1_19
formatInstallDoc.php
Go to the documentation of this file.
00001 <?php
00006 require_once( dirname( __FILE__ ) .'/Maintenance.php' );
00007 
00008 class MaintenanceFormatInstallDoc extends Maintenance {
00009         function __construct() {
00010                 parent::__construct();
00011                 $this->addArg( 'path', 'The file name to format', false );
00012                 $this->addOption( 'outfile', 'The output file name', false, true );
00013                 $this->addOption( 'html', 'Use HTML output format. By default, wikitext is used.' );
00014         }
00015 
00016         function execute() {
00017                 if ( $this->hasArg( 0 ) ) {
00018                         $fileName = $this->getArg( 0 );
00019                         $inFile = fopen( $fileName, 'r' );
00020                         if ( !$inFile ) {
00021                                 $this->error( "Unable to open input file \"$fileName\"" );
00022                                 exit( 1 );
00023                         }
00024                 } else {
00025                         $inFile = STDIN;
00026                 }
00027 
00028                 if ( $this->hasOption( 'outfile' ) ) {
00029                         $fileName = $this->getOption( 'outfile' );
00030                         $outFile = fopen( $fileName, 'w' );
00031                         if ( !$outFile ) {
00032                                 $this->error( "Unable to open output file \"$fileName\"" );
00033                                 exit( 1 );
00034                         }
00035                 } else {
00036                         $outFile = STDOUT;
00037                 }
00038 
00039                 $inText = stream_get_contents( $inFile );
00040                 $outText = InstallDocFormatter::format( $inText );
00041 
00042                 if ( $this->hasOption( 'html' ) ) {
00043                         global $wgParser;
00044                         $opt = new ParserOptions;
00045                         $title = Title::newFromText( 'Text file' );
00046                         $out = $wgParser->parse( $outText, $title, $opt );
00047                         $outText = "<html><body>\n" . $out->getText() . "\n</body></html>\n";
00048                 }
00049 
00050                 fwrite( $outFile, $outText );
00051         }
00052 }
00053 
00054 $maintClass = 'MaintenanceFormatInstallDoc';
00055 require_once( RUN_MAINTENANCE_IF_MAIN );
00056 
00057