Index: trunk/phase3/maintenance/formatInstallDoc.php |
— | — | @@ -0,0 +1,54 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +require_once( dirname( __FILE__ ) .'/Maintenance.php' ); |
| 5 | + |
| 6 | +class MaintenanceFormatInstallDoc extends Maintenance { |
| 7 | + function __construct() { |
| 8 | + parent::__construct(); |
| 9 | + $this->addArg( 'path', 'The file name to format', false ); |
| 10 | + $this->addOption( 'outfile', 'The output file name', false, true ); |
| 11 | + $this->addOption( 'html', 'Use HTML output format. By default, wikitext is used.' ); |
| 12 | + } |
| 13 | + |
| 14 | + function execute() { |
| 15 | + if ( $this->hasArg( 0 ) ) { |
| 16 | + $fileName = $this->getArg( 0 ); |
| 17 | + $inFile = fopen( $fileName, 'r' ); |
| 18 | + if ( !$inFile ) { |
| 19 | + $this->error( "Unable to open input file \"$fileName\"" ); |
| 20 | + exit( 1 ); |
| 21 | + } |
| 22 | + } else { |
| 23 | + $inFile = STDIN; |
| 24 | + } |
| 25 | + |
| 26 | + if ( $this->hasOption( 'outfile' ) ) { |
| 27 | + $fileName = $this->getOption( 'outfile' ); |
| 28 | + $outFile = fopen( $fileName, 'w' ); |
| 29 | + if ( !$outFile ) { |
| 30 | + $this->error( "Unable to open output file \"$fileName\"" ); |
| 31 | + exit( 1 ); |
| 32 | + } |
| 33 | + } else { |
| 34 | + $outFile = STDOUT; |
| 35 | + } |
| 36 | + |
| 37 | + $inText = stream_get_contents( $inFile ); |
| 38 | + $outText = InstallDocFormatter::format( $inText ); |
| 39 | + |
| 40 | + if ( $this->hasOption( 'html' ) ) { |
| 41 | + global $wgParser; |
| 42 | + $opt = new ParserOptions; |
| 43 | + $title = Title::newFromText( 'Text file' ); |
| 44 | + $out = $wgParser->parse( $outText, $title, $opt ); |
| 45 | + $outText = "<html><body>\n" . $out->getText() . "\n</body></html>\n"; |
| 46 | + } |
| 47 | + |
| 48 | + fwrite( $outFile, $outText ); |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +$maintClass = 'MaintenanceFormatInstallDoc'; |
| 53 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
| 54 | + |
| 55 | + |
Property changes on: trunk/phase3/maintenance/formatInstallDoc.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 56 | + native |
Index: trunk/phase3/includes/installer/InstallDocFormatter.php |
— | — | @@ -0,0 +1,42 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class InstallDocFormatter { |
| 5 | + static function format( $text ) { |
| 6 | + $obj = new self( $text ); |
| 7 | + return $obj->execute(); |
| 8 | + } |
| 9 | + |
| 10 | + protected function __construct( $text ) { |
| 11 | + $this->text = $text; |
| 12 | + } |
| 13 | + |
| 14 | + protected function execute() { |
| 15 | + $text = $this->text; |
| 16 | + // Use Unix line endings, escape some wikitext stuff |
| 17 | + $text = str_replace( array( '<', '{{', '[[', "\r" ), |
| 18 | + array( '<', '{{', '[[', '' ), $text ); |
| 19 | + // join word-wrapped lines into one |
| 20 | + do { |
| 21 | + $prev = $text; |
| 22 | + $text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text ); |
| 23 | + } while ( $text != $prev ); |
| 24 | + // Replace tab indents with colons |
| 25 | + $text = preg_replace( '/^\t\t/m', '::', $text ); |
| 26 | + $text = preg_replace( '/^\t/m', ':', $text ); |
| 27 | + // turn (bug nnnn) into links |
| 28 | + $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text ); |
| 29 | + // add links to manual to every global variable mentioned |
| 30 | + $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text ); |
| 31 | + return $text; |
| 32 | + } |
| 33 | + |
| 34 | + protected function replaceBugLinks( $matches ) { |
| 35 | + return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' . |
| 36 | + $matches[1] . ' bug ' . $matches[1] . ']</span>'; |
| 37 | + } |
| 38 | + |
| 39 | + protected function replaceConfigLinks( $matches ) { |
| 40 | + return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' . |
| 41 | + $matches[1] . ' ' . $matches[1] . ']</span>'; |
| 42 | + } |
| 43 | +} |
Property changes on: trunk/phase3/includes/installer/InstallDocFormatter.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 44 | + native |
Index: trunk/phase3/includes/installer/WebInstallerPage.php |
— | — | @@ -1200,45 +1200,16 @@ |
1201 | 1201 | |
1202 | 1202 | public function execute() { |
1203 | 1203 | $text = $this->getFileContents(); |
1204 | | - $text = $this->formatTextFile( $text ); |
| 1204 | + $text = InstallDocFormatter::format( $text ); |
1205 | 1205 | $this->parent->output->addWikiText( $text ); |
1206 | 1206 | $this->startForm(); |
1207 | 1207 | $this->endForm( false ); |
1208 | 1208 | } |
1209 | 1209 | |
1210 | | - public function getFileContents() { |
| 1210 | + public function getFileContents() { |
1211 | 1211 | return file_get_contents( dirname( __FILE__ ) . '/../../' . $this->getFileName() ); |
1212 | 1212 | } |
1213 | 1213 | |
1214 | | - protected function formatTextFile( $text ) { |
1215 | | - // Use Unix line endings, escape some wikitext stuff |
1216 | | - $text = str_replace( array( '<', '{{', '[[', "\r" ), |
1217 | | - array( '<', '{{', '[[', '' ), $text ); |
1218 | | - // join word-wrapped lines into one |
1219 | | - do { |
1220 | | - $prev = $text; |
1221 | | - $text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text ); |
1222 | | - } while ( $text != $prev ); |
1223 | | - // Replace tab indents with colons |
1224 | | - $text = preg_replace( '/^\t\t/m', '::', $text ); |
1225 | | - $text = preg_replace( '/^\t/m', ':', $text ); |
1226 | | - // turn (bug nnnn) into links |
1227 | | - $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text ); |
1228 | | - // add links to manual to every global variable mentioned |
1229 | | - $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text ); |
1230 | | - return $text; |
1231 | | - } |
1232 | | - |
1233 | | - private function replaceBugLinks( $matches ) { |
1234 | | - return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' . |
1235 | | - $matches[1] . ' bug ' . $matches[1] . ']</span>'; |
1236 | | - } |
1237 | | - |
1238 | | - private function replaceConfigLinks( $matches ) { |
1239 | | - return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' . |
1240 | | - $matches[1] . ' ' . $matches[1] . ']</span>'; |
1241 | | - } |
1242 | | - |
1243 | 1214 | } |
1244 | 1215 | |
1245 | 1216 | class WebInstaller_Readme extends WebInstaller_Document { |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -458,6 +458,7 @@ |
459 | 459 | 'DatabaseUpdater' => 'includes/installer/DatabaseUpdater.php', |
460 | 460 | 'Ibm_db2Installer' => 'includes/installer/Ibm_db2Installer.php', |
461 | 461 | 'Ibm_db2Updater' => 'includes/installer/Ibm_db2Updater.php', |
| 462 | + 'InstallDocFormatter' => 'includes/installer/InstallDocFormatter.php', |
462 | 463 | 'Installer' => 'includes/installer/Installer.php', |
463 | 464 | 'LBFactory_InstallerFake' => 'includes/installer/Installer.php', |
464 | 465 | 'LocalSettingsGenerator' => 'includes/installer/LocalSettingsGenerator.php', |