MediaWiki REL1_34
InstallDocFormatter.php
Go to the documentation of this file.
1<?php
25 private $text;
26
27 public static function format( $text ) {
28 $obj = new self( $text );
29
30 return $obj->execute();
31 }
32
33 protected function __construct( $text ) {
34 $this->text = $text;
35 }
36
37 protected function execute() {
39 // Use Unix line endings, escape some wikitext stuff
40 $text = str_replace( [ '<', '{{', '[[', '__', "\r" ],
41 [ '&lt;', '&#123;&#123;', '&#91;&#91;', '&#95;&#95;', '' ], $text );
42 // join word-wrapped lines into one
43 do {
44 $prev = $text;
45 $text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
46 } while ( $text != $prev );
47 // Replace tab indents with colons
48 $text = preg_replace( '/^\t\t/m', '::', $text );
49 $text = preg_replace( '/^\t/m', ':', $text );
50
51 $linkStart = '<span class="config-plainlink">[';
52 $linkEnd = ' $0]</span>';
53
54 // turn (Tnnnn) into links
55 $text = preg_replace(
56 '/T\d+/',
57 "{$linkStart}https://phabricator.wikimedia.org/$0{$linkEnd}",
58 $text
59 );
60
61 // turn (bug nnnn) into links
62 $text = preg_replace(
63 '/bug (\d+)/',
64 "{$linkStart}https://bugzilla.wikimedia.org/$1{$linkEnd}",
65 $text
66 );
67
68 // add links to manual to every global variable mentioned
69 $text = preg_replace(
70 '/\$wg[a-z0-9_]+/i',
71 "{$linkStart}https://www.mediawiki.org/wiki/Manual:$0{$linkEnd}",
72 $text
73 );
74
75 return $text;
76 }
77}