MediaWiki
master
Toggle main menu visibility
formatInstallDoc.php
Go to the documentation of this file.
1
<?php
9
10
use
MediaWiki\Installer\InstallDocFormatter
;
11
use
MediaWiki\Maintenance\Maintenance
;
12
use
MediaWiki\Parser\ParserOptions
;
13
use MediaWiki\Title\Title;
14
15
// @codeCoverageIgnoreStart
16
require_once __DIR__ .
'/Maintenance.php'
;
17
// @codeCoverageIgnoreEnd
18
24
class
FormatInstallDoc
extends
Maintenance
{
25
public
function
__construct
() {
26
parent::__construct();
27
$this->addArg(
'path'
,
'The file name to format'
,
false
);
28
$this->addOption(
'outfile'
,
'The output file name'
,
false
,
true
);
29
$this->addOption(
'html'
,
'Use HTML output format. By default, wikitext is used.'
);
30
}
31
32
public
function
execute
() {
33
if
( $this->hasArg( 0 ) ) {
34
$fileName = $this->getArg( 0 );
35
$inFile = fopen( $fileName,
'r'
);
36
if
( !$inFile ) {
37
$this->fatalError(
"Unable to open input file \"$fileName\""
);
38
}
39
}
else
{
40
$inFile = STDIN;
41
}
42
43
if
( $this->hasOption(
'outfile'
) ) {
44
$fileName = $this->getOption(
'outfile'
);
45
$outFile = fopen( $fileName,
'w'
);
46
if
( !$outFile ) {
47
$this->fatalError(
"Unable to open output file \"$fileName\""
);
48
}
49
}
else
{
50
$outFile = STDOUT;
51
}
52
53
$inText = stream_get_contents( $inFile );
54
$outText =
InstallDocFormatter::format
( $inText );
55
56
if
( $this->hasOption(
'html'
) ) {
57
$parser = $this->getServiceContainer()->getParser();
58
$opt =
ParserOptions::newFromAnon
();
59
$title =
Title::newFromText
(
'Text file'
);
60
$out = $parser->parse( $outText, $title, $opt );
61
$outText =
"<html><body>\n"
.
62
// TODO T371008 consider if using the Content framework makes sense instead of creating the pipeline
63
$this->getServiceContainer()->getDefaultOutputPipeline()
64
->run( $out, $opt, [] )
65
->getContentHolderText()
66
.
"\n</body></html>\n"
;
67
}
68
69
fwrite( $outFile, $outText );
70
}
71
}
72
73
// @codeCoverageIgnoreStart
74
$maintClass
= FormatInstallDoc::class;
75
require_once RUN_MAINTENANCE_IF_MAIN;
76
// @codeCoverageIgnoreEnd
$maintClass
$maintClass
Definition
addChangeTag.php:56
FormatInstallDoc
Maintenance script that formats RELEASE-NOTE file to wiki text or HTML markup.
Definition
formatInstallDoc.php:24
FormatInstallDoc\execute
execute()
Definition
formatInstallDoc.php:32
FormatInstallDoc\__construct
__construct()
Definition
formatInstallDoc.php:25
MediaWiki\Installer\InstallDocFormatter
Definition
InstallDocFormatter.php:12
MediaWiki\Installer\InstallDocFormatter\format
static format(string $text)
Definition
InstallDocFormatter.php:16
MediaWiki\Parser\ParserOptions
Set options of the Parser.
Definition
ParserOptions.php:70
MediaWiki\Parser\ParserOptions\newFromAnon
static newFromAnon()
Get a ParserOptions object for an anonymous user.
Definition
ParserOptions.php:1205
MediaWiki\Title\Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition
Title.php:388
MediaWiki\Maintenance
Definition
applyChangeTag.php:11
maintenance
formatInstallDoc.php
Generated on
for MediaWiki by
1.18.0