Merge "Fix accidential variable overriding in manualWordsTable"
[lhc/web/wiklou.git] / includes / HtmlFormatter.php
index 83db268..5749775 100644 (file)
@@ -27,8 +27,8 @@ class HtmlFormatter {
        private $doc;
 
        private $html;
-       private $itemsToRemove = array();
-       private $elementsToFlatten = array();
+       private $itemsToRemove = [];
+       private $elementsToFlatten = [];
        protected $removeMedia = false;
 
        /**
@@ -74,10 +74,8 @@ class HtmlFormatter {
                        }
 
                        // Workaround for bug that caused spaces before references
-                       // to disappear during processing:
-                       // https://phabricator.wikimedia.org/T55086
-                       //
-                       // Please replace with a better fix if one can be found.
+                       // to disappear during processing: https://phabricator.wikimedia.org/T55086
+                       // TODO: Please replace with a better fix if one can be found.
                        $html = str_replace( ' <', '&#32;<', $html );
 
                        libxml_use_internal_errors( true );
@@ -150,7 +148,7 @@ class HtmlFormatter {
                        },
                        true
                ) ) {
-                       return array();
+                       return [];
                }
 
                $doc = $this->getDoc();
@@ -161,7 +159,7 @@ class HtmlFormatter {
                // over them in a foreach loop. It will seemingly leave the internal
                // iterator on the foreach out of wack and results will be quite
                // strange. Though, making a queue of items to remove seems to work.
-               $domElemsToRemove = array();
+               $domElemsToRemove = [];
                foreach ( $removals['TAG'] as $tagToRemove ) {
                        $tagToRemoveNodes = $doc->getElementsByTagName( $tagToRemove );
                        foreach ( $tagToRemoveNodes as $tagToRemoveNode ) {
@@ -173,7 +171,7 @@ class HtmlFormatter {
                $removed = $this->removeElements( $domElemsToRemove );
 
                // Elements with named IDs
-               $domElemsToRemove = array();
+               $domElemsToRemove = [];
                foreach ( $removals['ID'] as $itemToRemove ) {
                        $itemToRemoveNode = $doc->getElementById( $itemToRemove );
                        if ( $itemToRemoveNode ) {
@@ -183,7 +181,7 @@ class HtmlFormatter {
                $removed = array_merge( $removed, $this->removeElements( $domElemsToRemove ) );
 
                // CSS Classes
-               $domElemsToRemove = array();
+               $domElemsToRemove = [];
                $xpath = new DOMXPath( $doc );
                foreach ( $removals['CLASS'] as $classToRemove ) {
                        $elements = $xpath->query( '//*[contains(@class, "' . $classToRemove . '")]' );
@@ -219,7 +217,7 @@ class HtmlFormatter {
        private function removeElements( $elements ) {
                $list = $elements;
                if ( $elements instanceof DOMNodeList ) {
-                       $list = array();
+                       $list = [];
                        foreach ( $elements as $element ) {
                                $list[] = $element;
                        }
@@ -244,12 +242,12 @@ class HtmlFormatter {
                if ( !$replacements ) {
                        // We don't include rules like '&#34;' => '&amp;quot;' because entities had already been
                        // normalized by libxml. Using this function with input not sanitized by libxml is UNSAFE!
-                       $replacements = new ReplacementArray( array(
+                       $replacements = new ReplacementArray( [
                                '&quot;' => '&amp;quot;',
                                '&amp;' => '&amp;amp;',
                                '&lt;' => '&amp;lt;',
                                '&gt;' => '&amp;gt;',
-                       ) );
+                       ] );
                }
                $html = $replacements->replace( $html );
 
@@ -281,7 +279,7 @@ class HtmlFormatter {
                        }
                        if ( $element ) {
                                $body = $this->doc->getElementsByTagName( 'body' )->item( 0 );
-                               $nodesArray = array();
+                               $nodesArray = [];
                                foreach ( $body->childNodes as $node ) {
                                        $nodesArray[] = $node;
                                }
@@ -292,10 +290,9 @@ class HtmlFormatter {
                        }
                        $html = $this->doc->saveHTML();
 
-                       $html = $this->fixLibXml( $html );
+                       $html = $this->fixLibXML( $html );
                        if ( wfIsWindows() ) {
                                // Cleanup for CRLF misprocessing of unknown origin on Windows.
-                               //
                                // If this error continues in the future, please track it down in the
                                // XML code paths if possible and fix there.
                                $html = str_replace( '&#13;', '', $html );
@@ -352,12 +349,12 @@ class HtmlFormatter {
         * @return array
         */
        protected function parseItemsToRemove() {
-               $removals = array(
-                       'ID' => array(),
-                       'TAG' => array(),
-                       'CLASS' => array(),
-                       'TAG_CLASS' => array(),
-               );
+               $removals = [
+                       'ID' => [],
+                       'TAG' => [],
+                       'CLASS' => [],
+                       'TAG_CLASS' => [],
+               ];
 
                foreach ( $this->itemsToRemove as $itemToRemove ) {
                        $type = '';