MediaWiki  REL1_20
InstallDocFormatter.php
Go to the documentation of this file.
00001 <?php
00023 class InstallDocFormatter {
00024         static function format( $text ) {
00025                 $obj = new self( $text );
00026                 return $obj->execute();
00027         }
00028 
00029         protected function __construct( $text ) {
00030                 $this->text = $text;
00031         }
00032 
00033         protected function execute() {
00034                 $text = $this->text;
00035                 // Use Unix line endings, escape some wikitext stuff
00036                 $text = str_replace( array( '<', '{{', '[[', "\r" ),
00037                         array( '&lt;', '&#123;&#123;', '&#91;&#91;', '' ), $text );
00038                 // join word-wrapped lines into one
00039                 do {
00040                         $prev = $text;
00041                         $text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
00042                 } while ( $text != $prev );
00043                 // Replace tab indents with colons
00044                 $text = preg_replace( '/^\t\t/m', '::', $text );
00045                 $text = preg_replace( '/^\t/m', ':', $text );
00046                 // turn (bug nnnn) into links
00047                 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
00048                 // add links to manual to every global variable mentioned
00049                 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
00050                 return $text;
00051         }
00052 
00053         protected function replaceBugLinks( $matches ) {
00054                 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
00055                         $matches[1] . ' bug ' . $matches[1] . ']</span>';
00056         }
00057 
00058         protected function replaceConfigLinks( $matches ) {
00059                 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
00060                         $matches[1] . ' ' . $matches[1] . ']</span>';
00061         }
00062 }