Merge "(bug 32297) Use symbolic names, not offsets for a default timezone."
[lhc/web/wiklou.git] / maintenance / formatInstallDoc.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @ingroup Maintenance
20 */
21
22 require_once( dirname( __FILE__ ) .'/Maintenance.php' );
23
24 class MaintenanceFormatInstallDoc extends Maintenance {
25 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 function execute() {
33 if ( $this->hasArg( 0 ) ) {
34 $fileName = $this->getArg( 0 );
35 $inFile = fopen( $fileName, 'r' );
36 if ( !$inFile ) {
37 $this->error( "Unable to open input file \"$fileName\"" );
38 exit( 1 );
39 }
40 } else {
41 $inFile = STDIN;
42 }
43
44 if ( $this->hasOption( 'outfile' ) ) {
45 $fileName = $this->getOption( 'outfile' );
46 $outFile = fopen( $fileName, 'w' );
47 if ( !$outFile ) {
48 $this->error( "Unable to open output file \"$fileName\"" );
49 exit( 1 );
50 }
51 } else {
52 $outFile = STDOUT;
53 }
54
55 $inText = stream_get_contents( $inFile );
56 $outText = InstallDocFormatter::format( $inText );
57
58 if ( $this->hasOption( 'html' ) ) {
59 global $wgParser;
60 $opt = new ParserOptions;
61 $title = Title::newFromText( 'Text file' );
62 $out = $wgParser->parse( $outText, $title, $opt );
63 $outText = "<html><body>\n" . $out->getText() . "\n</body></html>\n";
64 }
65
66 fwrite( $outFile, $outText );
67 }
68 }
69
70 $maintClass = 'MaintenanceFormatInstallDoc';
71 require_once( RUN_MAINTENANCE_IF_MAIN );
72
73