MaxSem has uploaded a new change for review. https://gerrit.wikimedia.org/r/83042
Change subject: Remove unused ID whitelists ...................................................................... Remove unused ID whitelists Change-Id: I512156e630cdb63f0d268a3a18877fc313db783b --- M includes/formatters/HtmlFormatter.php M tests/HtmlFormatterTest.php 2 files changed, 5 insertions(+), 30 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/42/83042/1 diff --git a/includes/formatters/HtmlFormatter.php b/includes/formatters/HtmlFormatter.php index ebf1739..2d6e166 100644 --- a/includes/formatters/HtmlFormatter.php +++ b/includes/formatters/HtmlFormatter.php @@ -13,7 +13,6 @@ private $itemsToRemove = array(); private $elementsToFlatten = array(); private $removeImages = false; - private $idWhitelist = array(); private $flattenRedLinks = false; private $imgAlt = true; @@ -101,33 +100,10 @@ } /** - * @param Array|string $ids: Id(s) of content to keep - */ - public function whitelistIds( $ids ) { - $this->idWhitelist = array_merge( $this->idWhitelist, array_flip( (array)$ids ) ); - } - - /** * @param bool $value */ public function useImgAlt( $value ) { $this->imgAlt = $value; - } - - /** - * Checks whether specified element should not be removed due to whitelist - * @param DOMElement $element: Element to check - * @return bool - */ - private function elementNotWhitelisted( DOMElement $element ) { - $idAttribute = $element->getAttributeNode( 'id' ); - if ( $idAttribute ) { - $id = $idAttribute->value; - if ( isset( $this->idWhitelist[$id] ) ) { - return false; - } - } - return true; } /** @@ -156,7 +132,7 @@ foreach ( $removals['TAG'] as $tagToRemove ) { $tagToRemoveNodes = $doc->getElementsByTagName( $tagToRemove ); foreach ( $tagToRemoveNodes as $tagToRemoveNode ) { - if ( $tagToRemoveNode && $this->elementNotWhitelisted( $tagToRemoveNode ) ) { + if ( $tagToRemoveNode ) { if ( $this->imgAlt && $tagToRemoveNode->nodeName == 'img' ) { $domElemsToReplace[] = $tagToRemoveNode; } else { @@ -200,7 +176,7 @@ /** @var $element DOMElement */ foreach ( $elements as $element ) { $classes = $element->getAttribute( 'class' ); - if ( preg_match( "/\b$classToRemove\b/", $classes ) && $element->parentNode && $this->elementNotWhitelisted( $element ) ) { + if ( preg_match( "/\b$classToRemove\b/", $classes ) && $element->parentNode ) { $domElemsToRemove[] = $element; } } @@ -217,7 +193,7 @@ /** @var $element DOMElement */ foreach ( $elements as $element ) { - if ( $element->parentNode && $this->elementNotWhitelisted( $element ) ) { + if ( $element->parentNode ) { $element->parentNode->removeChild( $element ); } } diff --git a/tests/HtmlFormatterTest.php b/tests/HtmlFormatterTest.php index a9a141b..e444735 100644 --- a/tests/HtmlFormatterTest.php +++ b/tests/HtmlFormatterTest.php @@ -34,7 +34,6 @@ }; $removeTags = function( HtmlFormatter $f ) { $f->remove( array( 'table', '.foo', '#bar', 'div.baz' ) ); - $f->whitelistIds( 'jedi' ); }; $flattenSomeStuff = function( HtmlFormatter $f ) { $f->flatten( array( 's', 'div' ) ); @@ -63,10 +62,10 @@ array( '<table><tr><td>foo</td></tr></table><div class="foo">foo</div><div class="foo quux">foo</div><span id="bar">bar</span> <strong class="foo" id="bar">foobar</strong><div class="notfoo">test</div><div class="baz"/> -<span class="baz">baz</span> <span class="foo" id="jedi">jedi</span>', +<span class="baz">baz</span>', '<div class="notfoo">test</div> -<span class="baz">baz</span> <span class="foo" id="jedi">jedi</span>', +<span class="baz">baz</span>', $removeTags, ), // don't flatten tags that start like chosen ones -- To view, visit https://gerrit.wikimedia.org/r/83042 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I512156e630cdb63f0d268a3a18877fc313db783b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: MaxSem <maxsem.w...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits