Merge "Fix RequestContextTest screwing up $wgUser"
[lhc/web/wiklou.git] / includes / Sanitizer.php
index 90548fe..6a568c2 100644 (file)
@@ -358,7 +358,7 @@ class Sanitizer {
         * @param string $text
         * @param callable $processCallback Callback to do any variable or parameter
         *   replacements in HTML attribute values
-        * @param array $args Arguments for the processing callback
+        * @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
@@ -459,7 +459,10 @@ class Sanitizer {
                                                $badtag = true;
                                        } elseif ( $slash ) {
                                                # Closing a tag... is it the one we just opened?
-                                               $ot = @array_pop( $tagstack );
+                                               wfSuppressWarnings();
+                                               $ot = array_pop( $tagstack );
+                                               wfRestoreWarnings();
+
                                                if ( $ot != $t ) {
                                                        if ( isset( $htmlsingleallowed[$ot] ) ) {
                                                                # Pop all elements with an optional close tag
@@ -489,7 +492,10 @@ class Sanitizer {
                                                                        }
                                                                }
                                                        } else {
-                                                               @array_push( $tagstack, $ot );
+                                                               wfSuppressWarnings();
+                                                               array_push( $tagstack, $ot );
+                                                               wfRestoreWarnings();
+
                                                                # <li> can be nested in <ul> or <ol>, skip those cases:
                                                                if ( !isset( $htmllist[$ot] ) || !isset( $listtags[$t] ) ) {
                                                                        $badtag = true;
@@ -567,9 +573,16 @@ class Sanitizer {
                } else {
                        # this might be possible using tidy itself
                        foreach ( $bits as $x ) {
-                               preg_match( '/^(\\/?)(\\w+)([^>]*?)(\\/{0,1}>)([^<]*)$/',
-                               $x, $regs );
-                               @list( /* $qbar */, $slash, $t, $params, $brace, $rest ) = $regs;
+                               preg_match(
+                                       '/^(\\/?)(\\w+)([^>]*?)(\\/{0,1}>)([^<]*)$/',
+                                       $x,
+                                       $regs
+                               );
+
+                               wfSuppressWarnings();
+                               list( /* $qbar */, $slash, $t, $params, $brace, $rest ) = $regs;
+                               wfRestoreWarnings();
+
                                $badtag = false;
                                if ( isset( $htmlelements[$t = strtolower( $t )] ) ) {
                                        if ( is_callable( $processCallback ) ) {
@@ -631,8 +644,7 @@ class Sanitizer {
                                # Remove the comment, leading and trailing
                                # spaces, and leave only one newline.
                                $text = substr_replace( $text, "\n", $spaceStart, $spaceLen + 1 );
-                       }
-                       else {
+                       } else {
                                # Remove just the comment.
                                $text = substr_replace( $text, '', $start, $end - $start );
                        }
@@ -1070,7 +1082,7 @@ class Sanitizer {
         *   HTML5 definition of id attribute
         *
         * @param string $id id to escape
-        * @param $options Mixed: string or array of strings (default is array()):
+        * @param string|array $options String or array of strings (default is array()):
         *   'noninitial': This is a non-initial fragment of an id, not a full id,
         *       so don't pay attention if the first character isn't valid at the
         *       beginning of an id.  Only matters if $wgExperimentalHtmlIds is
@@ -1137,7 +1149,7 @@ class Sanitizer {
         * This allows (generally harmless) entities like &#160; to survive.
         *
         * @param string $html HTML to escape
-        * @return string: escaped input
+        * @return string Escaped input
         */
        static function escapeHtmlAllowEntities( $html ) {
                $html = Sanitizer::decodeCharReferences( $html );
@@ -1303,6 +1315,7 @@ class Sanitizer {
                        array( 'Sanitizer', 'normalizeCharReferencesCallback' ),
                        $text );
        }
+
        /**
         * @param string $matches
         * @return string
@@ -1494,11 +1507,11 @@ class Sanitizer {
         */
        static function setupAttributeWhitelist() {
                global $wgAllowRdfaAttributes, $wgAllowMicrodataAttributes;
-
                static $whitelist, $staticInitialised;
+
                $globalContext = implode( '-', compact( 'wgAllowRdfaAttributes', 'wgAllowMicrodataAttributes' ) );
 
-               if ( isset( $whitelist ) && $staticInitialised == $globalContext ) {
+               if ( $whitelist !== null && $staticInitialised == $globalContext ) {
                        return $whitelist;
                }
 
@@ -1839,7 +1852,7 @@ class Sanitizer {
                $rfc5322_atext = "a-z0-9!#$%&'*+\\-\/=?^_`{|}~";
                $rfc1034_ldh_str = "a-z0-9\\-";
 
-               $HTML5_email_regexp = "/
+               $html5_email_regexp = "/
                ^                      # start of string
                [$rfc5322_atext\\.]+    # user part which is liberal :p
                @                      # 'apostrophe'
@@ -1848,6 +1861,6 @@ class Sanitizer {
                $                      # End of string
                /ix"; // case Insensitive, eXtended
 
-               return (bool)preg_match( $HTML5_email_regexp, $addr );
+               return (bool)preg_match( $html5_email_regexp, $addr );
        }
 }