Permit images uploaded as media to be wrapped in a link
authorAlexander Ebert <ebert@woltlab.com>
Fri, 20 Nov 2020 12:38:01 +0000 (13:38 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 20 Nov 2020 12:38:01 +0000 (13:38 +0100)
wcfsetup/install/files/lib/system/bbcode/WoltLabSuiteMediaBBCode.class.php
wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeImg.class.php

index 332c2a9adb2450900b86e1d6016bb9dbeb5109b3..5c7532d81dd33a0a87b97fd11268339cc1c1b644 100644 (file)
@@ -36,6 +36,16 @@ class WoltLabSuiteMediaBBCode extends AbstractBBCode {
                if ($parser instanceof HtmlBBCodeParser && $parser->getRemoveLinks()) {
                        $removeLinks = true;
                }
+               else {
+                       /** @var \DOMElement $element */
+                       $element = $closingTag['__parents'][0] ?? null;
+                       if ($element && $element->nodeName === 'a') {
+                               // We do permit media elements to be nested inside a link, but we must suppress
+                               // the thumbnail link to be generated. Removing the link technically is meant
+                               // to be something else, but we use it here for backward compatibility.
+                               $removeLinks = true;
+                       }
+               }
                
                /** @var ViewableMedia $media */
                $media = MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.media', $mediaID);
index 898482b39b136d9602a19ed0968b68c7849b7d4f..0d658fa90fc9004c9a1c7dca55ede6c59576f4f4 100644 (file)
@@ -161,6 +161,10 @@ class HtmlInputNodeImg extends AbstractHtmlInputNode {
                $blockElements = HtmlBBCodeParser::getInstance()->getBlockBBCodes();
                while ($parent = $parent->parentNode) {
                        switch ($parent->nodeName) {
+                               case 'a':
+                                       // Permit the media element to be placed inside a link.
+                                       break 2;
+                               
                                case 'blockquote':
                                case 'body':
                                case 'code':