Catrope has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/381062 )

Change subject: BadImageRemover: Also look for <figure> nodes, and mw:Image/* 
types
......................................................................

BadImageRemover: Also look for <figure> nodes, and mw:Image/* types

Change-Id: I1548fe1f84a6644c06045e9baf17234701944d14
---
M includes/Parsoid/Fixer/BadImageRemover.php
M tests/phpunit/Parsoid/Fixer/BadImageRemoverTest.php
2 files changed, 30 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/62/381062/1

diff --git a/includes/Parsoid/Fixer/BadImageRemover.php 
b/includes/Parsoid/Fixer/BadImageRemover.php
index 3fedf06..c5ba75e 100644
--- a/includes/Parsoid/Fixer/BadImageRemover.php
+++ b/includes/Parsoid/Fixer/BadImageRemover.php
@@ -41,7 +41,7 @@
         * @return string
         */
        public function getXPath() {
-               return '//figure-inline[@typeof="mw:Image"]//img[@resource] | 
//span[@typeof="mw:Image"]//img[@resource]';
+               return 
'//figure[starts-with(@typeof,"mw:Image")]//img[@resource] | 
//figure-inline[starts-with(@typeof,"mw:Image")]//img[@resource] | 
//span[starts-with(@typeof,"mw:Image")]//img[@resource]';
        }
 
        /**
@@ -74,7 +74,7 @@
 
                // Move up the DOM and remove the typeof="mw:Image" node
                $nodeToRemove = $node->parentNode;
-               while ( $nodeToRemove instanceof DOMElement && 
$nodeToRemove->getAttribute( 'typeof' ) !== 'mw:Image' ) {
+               while ( $nodeToRemove instanceof DOMElement && strpos( 
$nodeToRemove->getAttribute( 'typeof' ), 'mw:Image' ) !== 0 ) {
                        $nodeToRemove = $nodeToRemove->parentNode;
                }
                if ( !$nodeToRemove ) {
diff --git a/tests/phpunit/Parsoid/Fixer/BadImageRemoverTest.php 
b/tests/phpunit/Parsoid/Fixer/BadImageRemoverTest.php
index 251f36a..7108d1c 100644
--- a/tests/phpunit/Parsoid/Fixer/BadImageRemoverTest.php
+++ b/tests/phpunit/Parsoid/Fixer/BadImageRemoverTest.php
@@ -19,7 +19,7 @@
        public static function imageRemovalProvider() {
                return [
                        [
-                               'Passes through allowed good images',
+                               'Passes through allowed good inline images',
                                // expected html after filtering
                                '<p><figure-inline class="mw-default-size" 
typeof="mw:Image"><a href="./File:Image.jpg"><img resource="./File:Image.jpg" 
src="//upload.wikimedia.org/wikipedia/commons/7/78/Image.jpg" height="500" 
width="500"></a></figure-inline> and other stuff</p>',
                                // input html
@@ -31,11 +31,23 @@
                        ],
 
                        [
-                               'Passes through allowed good images (with 
legacy span markup)',
+                               'Passes through allowed good inline images 
(with legacy span markup)',
                                // expected html after filtering
                                '<p><span class="mw-default-size" 
typeof="mw:Image"><a href="./File:Image.jpg"><img resource="./File:Image.jpg" 
src="//upload.wikimedia.org/wikipedia/commons/7/78/Image.jpg" height="500" 
width="500"></a></span> and other stuff</p>',
                                // input html
                                '<p><span class="mw-default-size" 
typeof="mw:Image"><a href="./File:Image.jpg"><img resource="./File:Image.jpg" 
src="//upload.wikimedia.org/wikipedia/commons/7/78/Image.jpg" height="500" 
width="500"></a></span> and other stuff</p>',
+                               // accept/decline callback
+                               function () {
+                                       return false;
+                               }
+                       ],
+
+                       [
+                               'Passes through allowed good block images',
+                               // expected html after filtering
+                               '<figure class="mw-default-size" 
typeof="mw:Image/Thumb"><a href="./File:Image.jpg"><img 
resource="./File:Image.jpg" 
src="//upload.wikimedia.org/wikipedia/commons/7/78/Image.jpg" height="500" 
width="500"></a><figcaption>Blah blah</figcaption></figure>',
+                               // input html
+                               '<figure class="mw-default-size" 
typeof="mw:Image/Thumb"><a href="./File:Image.jpg"><img 
resource="./File:Image.jpg" 
src="//upload.wikimedia.org/wikipedia/commons/7/78/Image.jpg" height="500" 
width="500"></a><figcaption>Blah blah</figcaption></figure>',
                                // accept/decline callback
                                function () {
                                        return false;
@@ -55,7 +67,7 @@
                        ],
 
                        [
-                               'Strips declined images',
+                               'Strips declined inline images',
                                // expected html after filtering
                                '<p> and other stuff</p>',
                                // input html
@@ -67,7 +79,7 @@
                        ],
 
                        [
-                               'Strips declined images (with legacy span 
markup)',
+                               'Strips declined inline images (with legacy 
span markup)',
                                // expected html after filtering
                                '<p> and other stuff</p>',
                                // input html
@@ -77,6 +89,18 @@
                                        return true;
                                }
                        ],
+
+                       [
+                               'Strips declined block images',
+                               // expected html after filtering
+                               '',
+                               // input html
+                               '<figure class="mw-default-size" 
typeof="mw:Image/Thumb"><a href="./File:Image.jpg"><img 
resource="./File:Image.jpg" 
src="//upload.wikimedia.org/wikipedia/commons/7/78/Image.jpg" height="500" 
width="500"></a><figcaption>Blah blah</figcaption></figure>',
+                               // accept/decline callback
+                               function () {
+                                       return true;
+                               }
+                       ],
                ];
        }
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/381062
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1548fe1f84a6644c06045e9baf17234701944d14
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to