Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / installer / InstallDocFormatter.php
blobd62dbb96cff8893a23cd6922377f8c377a317eb1
1 <?php
3 /**
4 * Installer-specific wikitext formatting.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
21 * @file
24 namespace MediaWiki\Installer;
26 class InstallDocFormatter {
27 /** @var string */
28 private $text;
30 public static function format( $text ) {
31 return ( new self( $text ) )->execute();
34 protected function __construct( $text ) {
35 $this->text = $text;
38 protected function execute() {
39 $text = $this->text;
40 // Use Unix line endings, escape some wikitext stuff
41 $text = str_replace( [ '<', '{{', '[[', '__', "\r" ],
42 [ '&lt;', '&#123;&#123;', '&#91;&#91;', '&#95;&#95;', '' ], $text );
43 // join word-wrapped lines into one
44 do {
45 $prev = $text;
46 $text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
47 } while ( $text != $prev );
48 // Replace tab indents with colons
49 $text = preg_replace( '/^\t\t/m', '::', $text );
50 $text = preg_replace( '/^\t/m', ':', $text );
52 $linkStart = '<span class="config-plainlink">[';
53 $linkEnd = ' $0]</span>';
55 // turn (Tnnnn) into links
56 $text = preg_replace(
57 '/T\d+/',
58 "{$linkStart}https://phabricator.wikimedia.org/$0{$linkEnd}",
59 $text
62 // turn (bug nnnn) into links
63 $text = preg_replace(
64 '/bug (\d+)/',
65 "{$linkStart}https://bugzilla.wikimedia.org/$1{$linkEnd}",
66 $text
69 // add links to manual to every global variable mentioned
70 return preg_replace(
71 '/\$wg[a-z0-9_]+/i',
72 "{$linkStart}https://www.mediawiki.org/wiki/Manual:$0{$linkEnd}",
73 $text