MediaWiki master
formatInstallDoc.php
Go to the documentation of this file.
1<?php
28
29// @codeCoverageIgnoreStart
30require_once __DIR__ . '/Maintenance.php';
31// @codeCoverageIgnoreEnd
32
39 public function __construct() {
40 parent::__construct();
41 $this->addArg( 'path', 'The file name to format', false );
42 $this->addOption( 'outfile', 'The output file name', false, true );
43 $this->addOption( 'html', 'Use HTML output format. By default, wikitext is used.' );
44 }
45
46 public function execute() {
47 if ( $this->hasArg( 0 ) ) {
48 $fileName = $this->getArg( 0 );
49 $inFile = fopen( $fileName, 'r' );
50 if ( !$inFile ) {
51 $this->fatalError( "Unable to open input file \"$fileName\"" );
52 }
53 } else {
54 $inFile = STDIN;
55 }
56
57 if ( $this->hasOption( 'outfile' ) ) {
58 $fileName = $this->getOption( 'outfile' );
59 $outFile = fopen( $fileName, 'w' );
60 if ( !$outFile ) {
61 $this->fatalError( "Unable to open output file \"$fileName\"" );
62 }
63 } else {
64 $outFile = STDOUT;
65 }
66
67 $inText = stream_get_contents( $inFile );
68 $outText = InstallDocFormatter::format( $inText );
69
70 if ( $this->hasOption( 'html' ) ) {
71 $parser = $this->getServiceContainer()->getParser();
72 $opt = ParserOptions::newFromAnon();
73 $title = Title::newFromText( 'Text file' );
74 $out = $parser->parse( $outText, $title, $opt );
75 $outText = "<html><body>\n" .
76 // TODO T371008 consider if using the Content framework makes sense instead of creating the pipeline
77 $this->getServiceContainer()->getDefaultOutputPipeline()
78 ->run( $out, $opt, [] )
79 ->getContentHolderText()
80 . "\n</body></html>\n";
81 }
82
83 fwrite( $outFile, $outText );
84 }
85}
86
87// @codeCoverageIgnoreStart
88$maintClass = FormatInstallDoc::class;
89require_once RUN_MAINTENANCE_IF_MAIN;
90// @codeCoverageIgnoreEnd
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.
getArg( $argId=0, $default=null)
Get an argument.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
hasArg( $argId=0)
Does a given argument exist?
getServiceContainer()
Returns the main service container.
Set options of the Parser.
Represents a title within MediaWiki.
Definition Title.php:78