http://www.mediawiki.org/wiki/Special:Code/MediaWiki/90031

Revision: 90031
Author:   tstarling
Date:     2011-06-14 03:09:49 +0000 (Tue, 14 Jun 2011)
Log Message:
-----------
Maintenance script for exporting the preprocessed wikitext from installer 
document pages, plus relevant refactoring. For use in updating 
http://www.mediawiki.org/wiki/Release_notes/1.17 etc. 

Modified Paths:
--------------
    trunk/phase3/includes/AutoLoader.php
    trunk/phase3/includes/installer/WebInstallerPage.php

Added Paths:
-----------
    trunk/phase3/includes/installer/InstallDocFormatter.php
    trunk/phase3/maintenance/formatInstallDoc.php

Modified: trunk/phase3/includes/AutoLoader.php
===================================================================
--- trunk/phase3/includes/AutoLoader.php        2011-06-14 02:44:18 UTC (rev 
90030)
+++ trunk/phase3/includes/AutoLoader.php        2011-06-14 03:09:49 UTC (rev 
90031)
@@ -458,6 +458,7 @@
        'DatabaseUpdater' => 'includes/installer/DatabaseUpdater.php',
        'Ibm_db2Installer' => 'includes/installer/Ibm_db2Installer.php',
        'Ibm_db2Updater' => 'includes/installer/Ibm_db2Updater.php',
+       'InstallDocFormatter' => 'includes/installer/InstallDocFormatter.php',
        'Installer' => 'includes/installer/Installer.php',
        'LBFactory_InstallerFake' => 'includes/installer/Installer.php',
        'LocalSettingsGenerator' => 
'includes/installer/LocalSettingsGenerator.php',

Added: trunk/phase3/includes/installer/InstallDocFormatter.php
===================================================================
--- trunk/phase3/includes/installer/InstallDocFormatter.php                     
        (rev 0)
+++ trunk/phase3/includes/installer/InstallDocFormatter.php     2011-06-14 
03:09:49 UTC (rev 90031)
@@ -0,0 +1,42 @@
+<?php
+
+class InstallDocFormatter {
+       static function format( $text ) {
+               $obj = new self( $text );
+               return $obj->execute();
+       }
+
+       protected function __construct( $text ) {
+               $this->text = $text;
+       }
+
+       protected function execute() {
+               $text = $this->text;
+               // Use Unix line endings, escape some wikitext stuff
+               $text = str_replace( array( '<', '{{', '[[', "\r" ),
+                       array( '&lt;', '&#123;&#123;', '&#91;&#91;', '' ), 
$text );
+               // join word-wrapped lines into one
+               do {
+                       $prev = $text;
+                       $text = preg_replace( 
"/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
+               } while ( $text != $prev );
+               // Replace tab indents with colons
+               $text = preg_replace( '/^\t\t/m', '::', $text );
+               $text = preg_replace( '/^\t/m', ':', $text );
+               // turn (bug nnnn) into links
+               $text = preg_replace_callback('/bug (\d+)/', array( $this, 
'replaceBugLinks' ), $text );
+               // add links to manual to every global variable mentioned
+               $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( 
$this, 'replaceConfigLinks' ), $text );
+               return $text;
+       }
+
+       protected function replaceBugLinks( $matches ) {
+               return '<span 
class="config-plainlink">[https://bugzilla.wikimedia.org/' .
+                       $matches[1] . ' bug ' . $matches[1] . ']</span>';
+       }
+
+       protected function replaceConfigLinks( $matches ) {
+               return '<span 
class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
+                       $matches[1] . ' ' . $matches[1] . ']</span>';
+       }
+}


Property changes on: trunk/phase3/includes/installer/InstallDocFormatter.php
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: trunk/phase3/includes/installer/WebInstallerPage.php
===================================================================
--- trunk/phase3/includes/installer/WebInstallerPage.php        2011-06-14 
02:44:18 UTC (rev 90030)
+++ trunk/phase3/includes/installer/WebInstallerPage.php        2011-06-14 
03:09:49 UTC (rev 90031)
@@ -1200,45 +1200,16 @@
 
        public  function execute() {
                $text = $this->getFileContents();
-               $text = $this->formatTextFile( $text );
+               $text = InstallDocFormatter::format( $text );
                $this->parent->output->addWikiText( $text );
                $this->startForm();
                $this->endForm( false );
        }
 
-       public  function getFileContents() {
+       public function getFileContents() {
                return file_get_contents( dirname( __FILE__ ) . '/../../' . 
$this->getFileName() );
        }
 
-       protected function formatTextFile( $text ) {
-               // Use Unix line endings, escape some wikitext stuff
-               $text = str_replace( array( '<', '{{', '[[', "\r" ),
-                       array( '&lt;', '&#123;&#123;', '&#91;&#91;', '' ), 
$text );
-               // join word-wrapped lines into one
-               do {
-                       $prev = $text;
-                       $text = preg_replace( 
"/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
-               } while ( $text != $prev );
-               // Replace tab indents with colons
-               $text = preg_replace( '/^\t\t/m', '::', $text );
-               $text = preg_replace( '/^\t/m', ':', $text );
-               // turn (bug nnnn) into links
-               $text = preg_replace_callback('/bug (\d+)/', array( $this, 
'replaceBugLinks' ), $text );
-               // add links to manual to every global variable mentioned
-               $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( 
$this, 'replaceConfigLinks' ), $text );
-               return $text;
-       }
-
-       private function replaceBugLinks( $matches ) {
-               return '<span 
class="config-plainlink">[https://bugzilla.wikimedia.org/' .
-                       $matches[1] . ' bug ' . $matches[1] . ']</span>';
-       }
-
-       private function replaceConfigLinks( $matches ) {
-               return '<span 
class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
-                       $matches[1] . ' ' . $matches[1] . ']</span>';
-       }
-
 }
 
 class WebInstaller_Readme extends WebInstaller_Document {

Added: trunk/phase3/maintenance/formatInstallDoc.php
===================================================================
--- trunk/phase3/maintenance/formatInstallDoc.php                               
(rev 0)
+++ trunk/phase3/maintenance/formatInstallDoc.php       2011-06-14 03:09:49 UTC 
(rev 90031)
@@ -0,0 +1,54 @@
+<?php
+
+require_once( dirname( __FILE__ ) .'/Maintenance.php' );
+
+class MaintenanceFormatInstallDoc extends Maintenance {
+       function __construct() {
+               parent::__construct();
+               $this->addArg( 'path', 'The file name to format', false );
+               $this->addOption( 'outfile', 'The output file name', false, 
true );
+               $this->addOption( 'html', 'Use HTML output format. By default, 
wikitext is used.' );
+       }
+
+       function execute() {
+               if ( $this->hasArg( 0 ) ) {
+                       $fileName = $this->getArg( 0 );
+                       $inFile = fopen( $fileName, 'r' );
+                       if ( !$inFile ) {
+                               $this->error( "Unable to open input file 
\"$fileName\"" );
+                               exit( 1 );
+                       }
+               } else {
+                       $inFile = STDIN;
+               }
+
+               if ( $this->hasOption( 'outfile' ) ) {
+                       $fileName = $this->getOption( 'outfile' );
+                       $outFile = fopen( $fileName, 'w' );
+                       if ( !$outFile ) {
+                               $this->error( "Unable to open output file 
\"$fileName\"" );
+                               exit( 1 );
+                       }
+               } else {
+                       $outFile = STDOUT;
+               }
+
+               $inText = stream_get_contents( $inFile );
+               $outText = InstallDocFormatter::format( $inText );
+
+               if ( $this->hasOption( 'html' ) ) {
+                       global $wgParser;
+                       $opt = new ParserOptions;
+                       $title = Title::newFromText( 'Text file' );
+                       $out = $wgParser->parse( $outText, $title, $opt );
+                       $outText = "<html><body>\n" . $out->getText() . 
"\n</body></html>\n";
+               }
+
+               fwrite( $outFile, $outText );
+       }
+}
+
+$maintClass = 'MaintenanceFormatInstallDoc';
+require_once( RUN_MAINTENANCE_IF_MAIN );
+
+


Property changes on: trunk/phase3/maintenance/formatInstallDoc.php
___________________________________________________________________
Added: svn:eol-style
   + native


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to