X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSanitizer.php;h=2340cd94495e750e484116eabe002a92ef99f32e;hb=098cee210a5a4333690cb466481f5bf789670e8d;hp=96193a74af73436fef701096c0a7f9f87adc0e43;hpb=dd7df34a227f412b81d0c6aff886d7c68f961bb9;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Sanitizer.php b/includes/Sanitizer.php index 96193a74af..2340cd9449 100644 --- a/includes/Sanitizer.php +++ b/includes/Sanitizer.php @@ -359,20 +359,13 @@ class Sanitizer { } /** - * Cleans up HTML, removes dangerous tags and attributes, and - * removes HTML comments - * @param string $text - * @param callable $processCallback Callback to do any variable or parameter - * replacements in HTML attribute values - * @param array|bool $args Arguments for the processing callback + * Return the various lists of recognized tags * @param array $extratags For any extra tags to include * @param array $removetags For any tags (default or extra) to exclude - * @return string + * @return array */ - public static function removeHTMLtags( $text, $processCallback = null, - $args = array(), $extratags = array(), $removetags = array() - ) { - global $wgUseTidy, $wgAllowMicrodataAttributes, $wgAllowImageTag; + public static function getRecognizedTagData( $extratags = array(), $removetags = array() ) { + global $wgAllowMicrodataAttributes, $wgAllowImageTag; static $htmlpairsStatic, $htmlsingle, $htmlsingleonly, $htmlnest, $tabletags, $htmllist, $listtags, $htmlsingleallowed, $htmlelementsStatic, $staticInitialised; @@ -381,7 +374,6 @@ class Sanitizer { // are changed (like in the screwed up test system) we will re-initialise the settings. $globalContext = implode( '-', compact( 'wgAllowMicrodataAttributes', 'wgAllowImageTag' ) ); if ( !$staticInitialised || $staticInitialised != $globalContext ) { - $htmlpairsStatic = array( # Tags that must be closed 'b', 'bdi', 'del', 'i', 'ins', 'u', 'font', 'big', 'small', 'sub', 'sup', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'cite', 'code', 'em', 's', @@ -431,12 +423,44 @@ class Sanitizer { } $staticInitialised = $globalContext; } + # Populate $htmlpairs and $htmlelements with the $extratags and $removetags arrays $extratags = array_flip( $extratags ); $removetags = array_flip( $removetags ); $htmlpairs = array_merge( $extratags, $htmlpairsStatic ); $htmlelements = array_diff_key( array_merge( $extratags, $htmlelementsStatic ), $removetags ); + return array( + 'htmlpairs' => $htmlpairs, + 'htmlsingle' => $htmlsingle, + 'htmlsingleonly' => $htmlsingleonly, + 'htmlnest' => $htmlnest, + 'tabletags' => $tabletags, + 'htmllist' => $htmllist, + 'listtags' => $listtags, + 'htmlsingleallowed' => $htmlsingleallowed, + 'htmlelements' => $htmlelements, + ); + } + + /** + * Cleans up HTML, removes dangerous tags and attributes, and + * removes HTML comments + * @param string $text + * @param callable $processCallback Callback to do any variable or parameter + * replacements in HTML attribute values + * @param array|bool $args Arguments for the processing callback + * @param array $extratags For any extra tags to include + * @param array $removetags For any tags (default or extra) to exclude + * @return string + */ + public static function removeHTMLtags( $text, $processCallback = null, + $args = array(), $extratags = array(), $removetags = array() + ) { + global $wgUseTidy; + + extract( self::getRecognizedTagData( $extratags, $removetags ) ); + # Remove HTML comments $text = Sanitizer::removeHTMLcomments( $text ); $bits = explode( '<', $text ); @@ -463,9 +487,9 @@ class Sanitizer { $badtag = true; } elseif ( $slash ) { # Closing a tag... is it the one we just opened? - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $ot = array_pop( $tagstack ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); if ( $ot != $t ) { if ( isset( $htmlsingleallowed[$ot] ) ) { @@ -473,32 +497,32 @@ class Sanitizer { # and see if we find a match below them $optstack = array(); array_push( $optstack, $ot ); - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $ot = array_pop( $tagstack ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); while ( $ot != $t && isset( $htmlsingleallowed[$ot] ) ) { array_push( $optstack, $ot ); - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $ot = array_pop( $tagstack ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); } if ( $t != $ot ) { # No match. Push the optional elements back again $badtag = true; - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $ot = array_pop( $optstack ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); while ( $ot ) { array_push( $tagstack, $ot ); - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $ot = array_pop( $optstack ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); } } } else { - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); array_push( $tagstack, $ot ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); #
  • can be nested in