ApiParse: don't reparse language link titles
[mediawiki.git] / maintenance / formatInstallDoc.php
blob505c01462411cb1a8f464c65394fd6fe065368ab
1 <?php
2 /**
3 * Format RELEASE-NOTE file to wiki text or HTML markup.
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.
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.
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
20 * @file
21 * @ingroup Maintenance
24 use MediaWiki\Installer\InstallDocFormatter;
25 use MediaWiki\Title\Title;
27 // @codeCoverageIgnoreStart
28 require_once __DIR__ . '/Maintenance.php';
29 // @codeCoverageIgnoreEnd
31 /**
32 * Maintenance script that formats RELEASE-NOTE file to wiki text or HTML markup.
34 * @ingroup Maintenance
36 class FormatInstallDoc extends Maintenance {
37 public function __construct() {
38 parent::__construct();
39 $this->addArg( 'path', 'The file name to format', false );
40 $this->addOption( 'outfile', 'The output file name', false, true );
41 $this->addOption( 'html', 'Use HTML output format. By default, wikitext is used.' );
44 public function execute() {
45 if ( $this->hasArg( 0 ) ) {
46 $fileName = $this->getArg( 0 );
47 $inFile = fopen( $fileName, 'r' );
48 if ( !$inFile ) {
49 $this->fatalError( "Unable to open input file \"$fileName\"" );
51 } else {
52 $inFile = STDIN;
55 if ( $this->hasOption( 'outfile' ) ) {
56 $fileName = $this->getOption( 'outfile' );
57 $outFile = fopen( $fileName, 'w' );
58 if ( !$outFile ) {
59 $this->fatalError( "Unable to open output file \"$fileName\"" );
61 } else {
62 $outFile = STDOUT;
65 $inText = stream_get_contents( $inFile );
66 $outText = InstallDocFormatter::format( $inText );
68 if ( $this->hasOption( 'html' ) ) {
69 $parser = $this->getServiceContainer()->getParser();
70 $opt = ParserOptions::newFromAnon();
71 $title = Title::newFromText( 'Text file' );
72 $out = $parser->parse( $outText, $title, $opt );
73 $outText = "<html><body>\n" .
74 // TODO T371008 consider if using the Content framework makes sense instead of creating the pipeline
75 $this->getServiceContainer()->getDefaultOutputPipeline()
76 ->run( $out, $opt, [] )
77 ->getContentHolderText()
78 . "\n</body></html>\n";
81 fwrite( $outFile, $outText );
85 // @codeCoverageIgnoreStart
86 $maintClass = FormatInstallDoc::class;
87 require_once RUN_MAINTENANCE_IF_MAIN;
88 // @codeCoverageIgnoreEnd