X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FHtmlFormatter.php;h=b2926d17bc923c6f10f4e7a9c2ad5f528b0ea89f;hb=9a805b816d9aa19611a49d638fab86b7389c8618;hp=ebced709f232db9460ac72acd55409ac0ba0f67e;hpb=d06af57a3139ca49001943621d3187e203681351;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/HtmlFormatter.php b/includes/HtmlFormatter.php index ebced709f2..b2926d17bc 100644 --- a/includes/HtmlFormatter.php +++ b/includes/HtmlFormatter.php @@ -130,10 +130,9 @@ class HtmlFormatter { /** * Removes content we've chosen to remove. The text of the removed elements can be * extracted with the getText method. - * @return array of removed DOMElements + * @return array Array of removed DOMElements */ public function filterContent() { - wfProfileIn( __METHOD__ ); $removals = $this->parseItemsToRemove(); // Bail out early if nothing to do @@ -143,7 +142,6 @@ class HtmlFormatter { }, true ) ) { - wfProfileOut( __METHOD__ ); return array(); } @@ -178,7 +176,7 @@ class HtmlFormatter { // CSS Classes $domElemsToRemove = array(); - $xpath = new DOMXpath( $doc ); + $xpath = new DOMXPath( $doc ); foreach ( $removals['CLASS'] as $classToRemove ) { $elements = $xpath->query( '//*[contains(@class, "' . $classToRemove . '")]' ); @@ -202,14 +200,13 @@ class HtmlFormatter { $removed = array_merge( $removed, $this->removeElements( $elements ) ); } - wfProfileOut( __METHOD__ ); return $removed; } /** * Removes a list of elelments from DOMDocument * @param array|DOMNodeList $elements - * @return array of removed elements + * @return array Array of removed elements */ private function removeElements( $elements ) { $list = $elements; @@ -235,9 +232,8 @@ class HtmlFormatter { * @return string */ private function fixLibXML( $html ) { - wfProfileIn( __METHOD__ ); static $replacements; - if ( ! $replacements ) { + 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( @@ -249,7 +245,6 @@ class HtmlFormatter { } $html = $replacements->replace( $html ); $html = mb_convert_encoding( $html, 'UTF-8', 'HTML-ENTITIES' ); - wfProfileOut( __METHOD__ ); return $html; } @@ -264,10 +259,8 @@ class HtmlFormatter { * @return string Processed HTML */ public function getText( $element = null ) { - wfProfileIn( __METHOD__ ); if ( $this->doc ) { - wfProfileIn( __METHOD__ . '-dom' ); if ( $element !== null && !( $element instanceof DOMElement ) ) { $element = $this->doc->getElementById( $element ); } @@ -283,9 +276,7 @@ class HtmlFormatter { $body->appendChild( $element ); } $html = $this->doc->saveHTML(); - wfProfileOut( __METHOD__ . '-dom' ); - wfProfileIn( __METHOD__ . '-fixes' ); $html = $this->fixLibXml( $html ); if ( wfIsWindows() ) { // Cleanup for CRLF misprocessing of unknown origin on Windows. @@ -294,7 +285,6 @@ class HtmlFormatter { // XML code paths if possible and fix there. $html = str_replace( ' ', '', $html ); } - wfProfileOut( __METHOD__ . '-fixes' ); } else { $html = $this->html; } @@ -302,14 +292,11 @@ class HtmlFormatter { $html = preg_replace( '/|^.*?|<\/body>.*$/s', '', $html ); $html = $this->onHtmlReady( $html ); - wfProfileIn( __METHOD__ . '-flatten' ); if ( $this->elementsToFlatten ) { $elements = implode( '|', $this->elementsToFlatten ); $html = preg_replace( "#]*>#is", '', $html ); } - wfProfileOut( __METHOD__ . '-flatten' ); - wfProfileOut( __METHOD__ ); return $html; } @@ -322,6 +309,7 @@ class HtmlFormatter { * @param string $type The type of selector (ID, CLASS, TAG_CLASS, or TAG) * @param string $rawName The raw name of the selector * @return bool Whether the selector was successfully recognised + * @throws MWException */ protected function parseSelector( $selector, &$type, &$rawName ) { if ( strpos( $selector, '.' ) === 0 ) { @@ -349,7 +337,6 @@ class HtmlFormatter { * @return array */ protected function parseItemsToRemove() { - wfProfileIn( __METHOD__ ); $removals = array( 'ID' => array(), 'TAG' => array(), @@ -371,7 +358,6 @@ class HtmlFormatter { $removals['TAG'][] = 'video'; } - wfProfileOut( __METHOD__ ); return $removals; } }