MediaWiki master
formatInstallDoc.php
Go to the documentation of this file.
1<?php
26
27require_once __DIR__ . '/Maintenance.php';
28
35 public function __construct() {
36 parent::__construct();
37 $this->addArg( 'path', 'The file name to format', false );
38 $this->addOption( 'outfile', 'The output file name', false, true );
39 $this->addOption( 'html', 'Use HTML output format. By default, wikitext is used.' );
40 }
41
42 public function execute() {
43 if ( $this->hasArg( 0 ) ) {
44 $fileName = $this->getArg( 0 );
45 $inFile = fopen( $fileName, 'r' );
46 if ( !$inFile ) {
47 $this->fatalError( "Unable to open input file \"$fileName\"" );
48 }
49 } else {
50 $inFile = STDIN;
51 }
52
53 if ( $this->hasOption( 'outfile' ) ) {
54 $fileName = $this->getOption( 'outfile' );
55 $outFile = fopen( $fileName, 'w' );
56 if ( !$outFile ) {
57 $this->fatalError( "Unable to open output file \"$fileName\"" );
58 }
59 } else {
60 $outFile = STDOUT;
61 }
62
63 $inText = stream_get_contents( $inFile );
64 $outText = InstallDocFormatter::format( $inText );
65
66 if ( $this->hasOption( 'html' ) ) {
67 $parser = $this->getServiceContainer()->getParser();
68 $opt = ParserOptions::newFromAnon();
69 $title = Title::newFromText( 'Text file' );
70 $out = $parser->parse( $outText, $title, $opt );
71 $outText = "<html><body>\n" . $out->getText() . "\n</body></html>\n";
72 }
73
74 fwrite( $outFile, $outText );
75 }
76}
77
78$maintClass = FormatInstallDoc::class;
79require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script that formats RELEASE-NOTE file to wiki text or HTML markup.
execute()
Do the actual work.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
hasArg( $argId=0)
Does a given argument exist?
hasOption( $name)
Checks to see if a particular option was set.
getServiceContainer()
Returns the main service container.
getArg( $argId=0, $default=null)
Get an argument.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Represents a title within MediaWiki.
Definition Title.php:78