| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
namespace MediaWiki\Installer; |
| 25 |
|
| 26 |
class InstallDocFormatter { |
| 27 |
|
| 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 |
|
| 41 |
$text = str_replace( [ '<', '{{', '[[', '__', "\r" ], |
| 42 |
[ '<', '{{', '[[', '__', '' ], $text ); |
| 43 |
|
| 44 |
do { |
| 45 |
$prev = $text; |
| 46 |
$text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text ); |
| 47 |
} while ( $text != $prev ); |
| 48 |
|
| 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 |
|
| 56 |
$text = preg_replace( |
| 57 |
'/T\d+/', |
| 58 |
"{$linkStart}https://phabricator.wikimedia.org/$0{$linkEnd}", |
| 59 |
$text |
| 60 |
); |
| 61 |
|
| 62 |
|
| 63 |
$text = preg_replace( |
| 64 |
'/bug (\d+)/', |
| 65 |
"{$linkStart}https://bugzilla.wikimedia.org/$1{$linkEnd}", |
| 66 |
$text |
| 67 |
); |
| 68 |
|
| 69 |
|
| 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 |
} |