MediaWiki  REL1_20
formatInstallDoc.php
Go to the documentation of this file.
00001 <?php
00024 require_once( __DIR__ .'/Maintenance.php' );
00025 
00031 class MaintenanceFormatInstallDoc extends Maintenance {
00032         function __construct() {
00033                 parent::__construct();
00034                 $this->addArg( 'path', 'The file name to format', false );
00035                 $this->addOption( 'outfile', 'The output file name', false, true );
00036                 $this->addOption( 'html', 'Use HTML output format. By default, wikitext is used.' );
00037         }
00038 
00039         function execute() {
00040                 if ( $this->hasArg( 0 ) ) {
00041                         $fileName = $this->getArg( 0 );
00042                         $inFile = fopen( $fileName, 'r' );
00043                         if ( !$inFile ) {
00044                                 $this->error( "Unable to open input file \"$fileName\"" );
00045                                 exit( 1 );
00046                         }
00047                 } else {
00048                         $inFile = STDIN;
00049                 }
00050 
00051                 if ( $this->hasOption( 'outfile' ) ) {
00052                         $fileName = $this->getOption( 'outfile' );
00053                         $outFile = fopen( $fileName, 'w' );
00054                         if ( !$outFile ) {
00055                                 $this->error( "Unable to open output file \"$fileName\"" );
00056                                 exit( 1 );
00057                         }
00058                 } else {
00059                         $outFile = STDOUT;
00060                 }
00061 
00062                 $inText = stream_get_contents( $inFile );
00063                 $outText = InstallDocFormatter::format( $inText );
00064 
00065                 if ( $this->hasOption( 'html' ) ) {
00066                         global $wgParser;
00067                         $opt = new ParserOptions;
00068                         $title = Title::newFromText( 'Text file' );
00069                         $out = $wgParser->parse( $outText, $title, $opt );
00070                         $outText = "<html><body>\n" . $out->getText() . "\n</body></html>\n";
00071                 }
00072 
00073                 fwrite( $outFile, $outText );
00074         }
00075 }
00076 
00077 $maintClass = 'MaintenanceFormatInstallDoc';
00078 require_once( RUN_MAINTENANCE_IF_MAIN );
00079 
00080