[bbcode] allow relative image links

This is useful for CSP when a site is hosted on multiple domains, such as a mirror.
This commit is contained in:
discomrade 2024-08-31 21:28:59 +01:00 committed by Shish
parent 399a56ac79
commit d809b0b18e
2 changed files with 2 additions and 0 deletions

View file

@ -34,6 +34,7 @@ class BBCodeInfo extends ExtensionInfo
Link tags:
<ul>
<li>[img]url[/img]
<li>[img]site://_images/image.jpg[/img]
<li>[url]<a href=\"{self::SHIMMIE_URL}\">https://code.shishnet.org/</a>[/url]
<li>[url=<a href=\"{self::SHIMMIE_URL}\">https://code.shishnet.org/</a>]some text[/url]
<li>[url]site://ext_doc/bbcode[/url]

View file

@ -29,6 +29,7 @@ class BBCode extends FormatterExtension
$text = preg_replace_ex('!\[url\]((?:https?|ftp|irc|mailto)://.*?)\[/url\]!s', '<a href="$1">$1</a>', $text);
$text = preg_replace_ex('!\[email\](.*?)\[/email\]!s', '<a href="mailto:$1">$1</a>', $text);
$text = preg_replace_ex('!\[img\](https?:\/\/.*?)\[/img\]!s', '<img alt="user image" src="$1">', $text);
$text = preg_replace_ex('!\[img\]site://(.*?)(#c\d+)?\[/img\]!s', '<img alt="user image" src="'.make_link('$1$2').'">', $text);
$text = preg_replace_ex('!\[\[([^\|\]]+)\|([^\]]+)\]\]!s', '<a href="'.make_link('wiki/$1').'">$2</a>', $text);
$text = preg_replace_ex('!\[\[([^\]]+)\]\]!s', '<a href="'.make_link('wiki/$1').'">$1</a>', $text);
$text = preg_replace_ex("!\n\s*\n!", "\n\n", $text);