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
21 * @ingroup Maintenance
24 use MediaWiki\Installer\InstallDocFormatter
;
25 use MediaWiki\Maintenance\Maintenance
;
26 use MediaWiki\Parser\ParserOptions
;
27 use MediaWiki\Title\Title
;
29 // @codeCoverageIgnoreStart
30 require_once __DIR__
. '/Maintenance.php';
31 // @codeCoverageIgnoreEnd
34 * Maintenance script that formats RELEASE-NOTE file to wiki text or HTML markup.
36 * @ingroup Maintenance
38 class FormatInstallDoc
extends Maintenance
{
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.' );
46 public function execute() {
47 if ( $this->hasArg( 0 ) ) {
48 $fileName = $this->getArg( 0 );
49 $inFile = fopen( $fileName, 'r' );
51 $this->fatalError( "Unable to open input file \"$fileName\"" );
57 if ( $this->hasOption( 'outfile' ) ) {
58 $fileName = $this->getOption( 'outfile' );
59 $outFile = fopen( $fileName, 'w' );
61 $this->fatalError( "Unable to open output file \"$fileName\"" );
67 $inText = stream_get_contents( $inFile );
68 $outText = InstallDocFormatter
::format( $inText );
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";
83 fwrite( $outFile, $outText );
87 // @codeCoverageIgnoreStart
88 $maintClass = FormatInstallDoc
::class;
89 require_once RUN_MAINTENANCE_IF_MAIN
;
90 // @codeCoverageIgnoreEnd