MediaWiki master
InstallDocFormatter.php
Go to the documentation of this file.
1<?php
2
24namespace MediaWiki\Installer;
25
28 private $text;
29
30 public static function format( $text ) {
31 return ( new self( $text ) )->execute();
32 }
33
34 protected function __construct( $text ) {
35 $this->text = $text;
36 }
37
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 );
51
52 $linkStart = '<span class="config-plainlink">[';
53 $linkEnd = ' $0]</span>';
54
55 // turn (Tnnnn) into links
56 $text = preg_replace(
57 '/T\d+/',
58 "{$linkStart}https://phabricator.wikimedia.org/$0{$linkEnd}",
59 $text
60 );
61
62 // turn (bug nnnn) into links
63 $text = preg_replace(
64 '/bug (\d+)/',
65 "{$linkStart}https://bugzilla.wikimedia.org/$1{$linkEnd}",
66 $text
67 );
68
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
74 );
75 }
76}