3 * Installer-specific wikitext formatting.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
23 class InstallDocFormatter
{
24 static function format( $text ) {
25 $obj = new self( $text );
26 return $obj->execute();
29 protected function __construct( $text ) {
33 protected function execute() {
35 // Use Unix line endings, escape some wikitext stuff
36 $text = str_replace( array( '<', '{{', '[[', "\r" ),
37 array( '<', '{{', '[[', '' ), $text );
38 // join word-wrapped lines into one
41 $text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
42 } while ( $text != $prev );
43 // Replace tab indents with colons
44 $text = preg_replace( '/^\t\t/m', '::', $text );
45 $text = preg_replace( '/^\t/m', ':', $text );
46 // turn (bug nnnn) into links
47 $text = preg_replace_callback( '/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
48 // add links to manual to every global variable mentioned
49 $text = preg_replace_callback( '/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
53 protected function replaceBugLinks( $matches ) {
54 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
55 $matches[1] . ' bug ' . $matches[1] . ']</span>';
58 protected function replaceConfigLinks( $matches ) {
59 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
60 $matches[1] . ' ' . $matches[1] . ']</span>';