| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
use MediaWiki\Installer\InstallDocFormatter; |
| 25 |
use MediaWiki\Parser\ParserOptions; |
| 26 |
use MediaWiki\Title\Title; |
| 27 |
|
| 28 |
|
| 29 |
require_once __DIR__ . '/Maintenance.php'; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 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 |
|
| 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 |
|
| 87 |
$maintClass = FormatInstallDoc::class; |
| 88 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 89 |
|