Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
FormatInstallDoc
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 2
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 1
42
1<?php
2/**
3 * Format RELEASE-NOTE file to wiki text or HTML markup.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Maintenance
22 */
23
24use MediaWiki\Installer\InstallDocFormatter;
25use MediaWiki\Title\Title;
26
27require_once __DIR__ . '/Maintenance.php';
28
29/**
30 * Maintenance script that formats RELEASE-NOTE file to wiki text or HTML markup.
31 *
32 * @ingroup Maintenance
33 */
34class FormatInstallDoc extends Maintenance {
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;