2011-06-14 03:09:49 +00:00
|
|
|
<?php
|
2012-02-08 16:55:54 +00:00
|
|
|
/**
|
2012-07-10 16:50:19 +00:00
|
|
|
* Format RELEASE-NOTE file to wiki text or HTML markup.
|
|
|
|
|
*
|
2012-06-14 12:25:13 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
2012-02-08 16:55:54 +00:00
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2011-06-14 03:09:49 +00:00
|
|
|
|
2024-01-05 18:46:09 +00:00
|
|
|
use MediaWiki\Installer\InstallDocFormatter;
|
2024-10-21 17:06:13 +00:00
|
|
|
use MediaWiki\Parser\ParserOptions;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2019-03-09 22:37:49 +00:00
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2011-06-14 03:09:49 +00:00
|
|
|
|
2012-07-10 16:50:19 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script that formats RELEASE-NOTE file to wiki text or HTML markup.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2018-05-24 01:34:01 +00:00
|
|
|
class FormatInstallDoc extends Maintenance {
|
2019-10-09 18:41:33 +00:00
|
|
|
public function __construct() {
|
2011-06-14 03:09:49 +00:00
|
|
|
parent::__construct();
|
|
|
|
|
$this->addArg( 'path', 'The file name to format', false );
|
|
|
|
|
$this->addOption( 'outfile', 'The output file name', false, true );
|
|
|
|
|
$this->addOption( 'html', 'Use HTML output format. By default, wikitext is used.' );
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 18:41:33 +00:00
|
|
|
public function execute() {
|
2011-06-14 03:09:49 +00:00
|
|
|
if ( $this->hasArg( 0 ) ) {
|
|
|
|
|
$fileName = $this->getArg( 0 );
|
|
|
|
|
$inFile = fopen( $fileName, 'r' );
|
|
|
|
|
if ( !$inFile ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "Unable to open input file \"$fileName\"" );
|
2011-06-14 03:09:49 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$inFile = STDIN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->hasOption( 'outfile' ) ) {
|
|
|
|
|
$fileName = $this->getOption( 'outfile' );
|
|
|
|
|
$outFile = fopen( $fileName, 'w' );
|
|
|
|
|
if ( !$outFile ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "Unable to open output file \"$fileName\"" );
|
2011-06-14 03:09:49 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$outFile = STDOUT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$inText = stream_get_contents( $inFile );
|
|
|
|
|
$outText = InstallDocFormatter::format( $inText );
|
|
|
|
|
|
|
|
|
|
if ( $this->hasOption( 'html' ) ) {
|
2023-08-31 09:21:12 +00:00
|
|
|
$parser = $this->getServiceContainer()->getParser();
|
2020-09-18 15:07:18 +00:00
|
|
|
$opt = ParserOptions::newFromAnon();
|
2011-06-14 03:09:49 +00:00
|
|
|
$title = Title::newFromText( 'Text file' );
|
2019-03-09 22:37:49 +00:00
|
|
|
$out = $parser->parse( $outText, $title, $opt );
|
2024-07-30 17:13:18 +00:00
|
|
|
$outText = "<html><body>\n" .
|
|
|
|
|
// TODO T371008 consider if using the Content framework makes sense instead of creating the pipeline
|
|
|
|
|
$this->getServiceContainer()->getDefaultOutputPipeline()
|
|
|
|
|
->run( $out, $opt, [] )
|
|
|
|
|
->getContentHolderText()
|
|
|
|
|
. "\n</body></html>\n";
|
2011-06-14 03:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fwrite( $outFile, $outText );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-05-24 01:34:01 +00:00
|
|
|
$maintClass = FormatInstallDoc::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|