Merge "EditPage: Make input and button widgets infusable"
[mediawiki.git] / includes / installer / InstallDocFormatter.php
blob4163e2f958f9dc4ce2e04d710a982f37d447b1d4
1 <?php
2 /**
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
20 * @file
23 class InstallDocFormatter {
24 static function format( $text ) {
25 $obj = new self( $text );
27 return $obj->execute();
30 protected function __construct( $text ) {
31 $this->text = $text;
34 protected function execute() {
35 $text = $this->text;
36 // Use Unix line endings, escape some wikitext stuff
37 $text = str_replace( [ '<', '{{', '[[', '__', "\r" ],
38 [ '&lt;', '&#123;&#123;', '&#91;&#91;', '&#95;&#95;', '' ], $text );
39 // join word-wrapped lines into one
40 do {
41 $prev = $text;
42 $text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
43 } while ( $text != $prev );
44 // Replace tab indents with colons
45 $text = preg_replace( '/^\t\t/m', '::', $text );
46 $text = preg_replace( '/^\t/m', ':', $text );
48 $linkStart = '<span class="config-plainlink">[';
49 $linkEnd = ' $0]</span>';
51 // turn (Tnnnn) into links
52 $text = preg_replace(
53 '/T\d+/',
54 "{$linkStart}https://phabricator.wikimedia.org/$0{$linkEnd}",
55 $text
58 // turn (bug nnnn) into links
59 $text = preg_replace(
60 '/bug (\d+)/',
61 "{$linkStart}https://bugzilla.wikimedia.org/$1{$linkEnd}",
62 $text
65 // add links to manual to every global variable mentioned
66 $text = preg_replace(
67 '/\$wg[a-z0-9_]+/i',
68 "{$linkStart}https://www.mediawiki.org/wiki/Manual:$0{$linkEnd}",
69 $text
72 return $text;