Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 29 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
FormatInstallDoc | |
0.00% |
0 / 29 |
|
0.00% |
0 / 2 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 25 |
|
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 | |
24 | use MediaWiki\Installer\InstallDocFormatter; |
25 | use MediaWiki\Maintenance\Maintenance; |
26 | use MediaWiki\Parser\ParserOptions; |
27 | use MediaWiki\Title\Title; |
28 | |
29 | // @codeCoverageIgnoreStart |
30 | require_once __DIR__ . '/Maintenance.php'; |
31 | // @codeCoverageIgnoreEnd |
32 | |
33 | /** |
34 | * Maintenance script that formats RELEASE-NOTE file to wiki text or HTML markup. |
35 | * |
36 | * @ingroup Maintenance |
37 | */ |
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.' ); |
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; |
89 | require_once RUN_MAINTENANCE_IF_MAIN; |
90 | // @codeCoverageIgnoreEnd |