X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FHtmlFormatter.php;h=5b8122dccafd347991252712ad8c09b64fe321ab;hb=d7a2302a315b71f8c2ca289c4aca0ff3513fa7cf;hp=83db268e84b565971e213b8667ce908c530c61b3;hpb=58410c60d5d41bb35daea6f6fd6f37f4249210d3;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/HtmlFormatter.php b/includes/HtmlFormatter.php index 83db268e84..5b8122dcca 100644 --- a/includes/HtmlFormatter.php +++ b/includes/HtmlFormatter.php @@ -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( ' <', ' <', $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 '"' => '&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;', '<' => '&lt;', '>' => '&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; } @@ -295,7 +293,6 @@ class HtmlFormatter { $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( ' ', '', $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 = '';