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