Revert r68230, r68231 (mode="grid" on tables) per CR. It's in the history if anyone...
[lhc/web/wiklou.git] / includes / Sanitizer.php
index 9b88f33..fba0156 100644 (file)
@@ -796,51 +796,6 @@ class Sanitizer {
                }
        }
 
-       /** 
-       * Take an associative array of attribute name/value pairs
-       * and generate a css style representing all the style-related
-       * attributes. If there already a style attribute in the array,
-       * it is also included in the value returned.
-       */
-       static function styleFromAttributes( $attributes ) {
-               $styles = array();
-
-               foreach ( $attributes as $attribute => $value ) {
-                       if ( $attribute == 'bgcolor' ) {
-                               $styles[] = "background-color: $value";
-                       } else if ( $attribute == 'border' ) {
-                               $styles[] = "border-width: $value";
-                       } else if ( $attribute == 'align' ) {
-                               $styles[] = "text-align: $value";
-                       } else if ( $attribute == 'valign' ) {
-                               $styles[] = "vertical-align: $value";
-                       } else if ( $attribute == 'width' ) {
-                               if ( preg_match( '/\d+/', $value ) === false ) {
-                                     $value .= 'px';
-                               }
-
-                               $styles[] = "width: $value";
-                       } else if ( $attribute == 'height' ) {
-                               if ( preg_match( '/\d+/', $value ) === false ) {
-                                     $value .= 'px';
-                               }
-
-                               $styles[] = "height: $value";
-                       } else if ( $attribute == 'nowrap' ) {
-                               if ( $value ) {
-                                       $styles[] = "white-space: nowrap";
-                               }
-                       }
-               }
-
-               if ( isset( $attributes[ 'style' ] ) ) {
-                       $styles[] = $attributes[ 'style' ];
-               } 
-
-               if ( !$styles ) return '';
-               else return implode( '; ', $styles );
-       }
-
        /**
         * Take a tag soup fragment listing an HTML element's attributes
         * and normalize it to well-formed XML, discarding unwanted attributes.
@@ -858,66 +813,24 @@ class Sanitizer {
         *
         * @param $text String
         * @param $element String
-        * @param $defaults Array (optional) associative array of default attributes to splice in. 
-        *                      class and style attributes are combined. Otherwise, values from
-        *                      $attributes take precedence over values from $defaults.
         * @return String
         */
-       static function fixTagAttributes( $text, $element, $defaults = null ) {
+       static function fixTagAttributes( $text, $element ) {
                if( trim( $text ) == '' ) {
                        return '';
                }
 
-               $decoded = Sanitizer::decodeTagAttributes( $text );
-               $stripped = Sanitizer::validateTagAttributes( $decoded, $element );
-               $attribs = Sanitizer::collapseTagAttributes( $stripped, $defaults );
-
-               return $attribs;
-       }
+               $stripped = Sanitizer::validateTagAttributes(
+                       Sanitizer::decodeTagAttributes( $text ), $element );
 
-       /**
-        * Take an associative array or attribute name/value pairs
-        * and collapses it to well-formed XML.
-        * Does not filter attributes.
-        * Output is safe for further wikitext processing, with escaping of
-        * values that could trigger problems.
-        *
-        * - Double-quotes all attribute values
-        * - Prepends space if there are attributes.
-        *
-        * @param $attributes Array is an associative array of attribute name/value pairs. 
-        *                      Assumed to be sanitized already.
-        * @param $defaults Array (optional) associative array of default attributes to splice in. 
-        *                      class and style attributes are combined. Otherwise, values from
-        *                      $attributes take precedence over values from $defaults.
-        * @return String
-        */
-       static function collapseTagAttributes( $attributes, $defaults = null ) {
-               if ( $defaults ) {
-                       foreach( $defaults as $attribute => $value ) {
-                               if ( isset( $attributes[ $attribute ] ) ) {
-                                       if ( $attribute == 'class' ) {
-                                               $value .= ' '. $attributes[ $attribute ];
-                                       } else if ( $attribute == 'style' ) {
-                                               $value .= '; ' . $attributes[ $attribute ];
-                                       } else {
-                                               continue;
-                                       }
-                               }
-
-                               $attributes[ $attribute ] = $value;
-                       }
-               }
-
-               $chunks = array();
-
-               foreach( $attributes as $attribute => $value ) {
+               $attribs = array();
+               foreach( $stripped as $attribute => $value ) {
                        $encAttribute = htmlspecialchars( $attribute );
                        $encValue = Sanitizer::safeEncodeAttribute( $value );
 
-                       $chunks[] = "$encAttribute=\"$encValue\"";
+                       $attribs[] = "$encAttribute=\"$encValue\"";
                }
-               return count( $chunks ) ? ' ' . implode( ' ', $chunks ) : '';
+               return count( $attribs ) ? ' ' . implode( ' ', $attribs ) : '';
        }
 
        /**