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