MediaWiki  REL1_19
InstallDocFormatter.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class InstallDocFormatter {
00004         static function format( $text ) {
00005                 $obj = new self( $text );
00006                 return $obj->execute();
00007         }
00008 
00009         protected function __construct( $text ) {
00010                 $this->text = $text;
00011         }
00012 
00013         protected function execute() {
00014                 $text = $this->text;
00015                 // Use Unix line endings, escape some wikitext stuff
00016                 $text = str_replace( array( '<', '{{', '[[', "\r" ),
00017                         array( '&lt;', '&#123;&#123;', '&#91;&#91;', '' ), $text );
00018                 // join word-wrapped lines into one
00019                 do {
00020                         $prev = $text;
00021                         $text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
00022                 } while ( $text != $prev );
00023                 // Replace tab indents with colons
00024                 $text = preg_replace( '/^\t\t/m', '::', $text );
00025                 $text = preg_replace( '/^\t/m', ':', $text );
00026                 // turn (bug nnnn) into links
00027                 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
00028                 // add links to manual to every global variable mentioned
00029                 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
00030                 return $text;
00031         }
00032 
00033         protected function replaceBugLinks( $matches ) {
00034                 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
00035                         $matches[1] . ' bug ' . $matches[1] . ']</span>';
00036         }
00037 
00038         protected function replaceConfigLinks( $matches ) {
00039                 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
00040                         $matches[1] . ' ' . $matches[1] . ']</span>';
00041         }
00042 }