Revert r68230, r68231 (mode="grid" on tables) per CR. It's in the history if anyone...
authorChad Horohoe <demon@users.mediawiki.org>
Fri, 10 Dec 2010 16:03:57 +0000 (16:03 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Fri, 10 Dec 2010 16:03:57 +0000 (16:03 +0000)
includes/Sanitizer.php
includes/parser/Parser.php
skins/common/shared.css

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 ) : '';
        }
 
        /**
index a768585..b5b8c7f 100644 (file)
@@ -797,18 +797,6 @@ class Parser {
                $has_opened_tr = array(); # Did this table open a <tr> element?
                $indent_level = 0; # indent level of the table
 
-               $table_tag = 'table';
-               $tr_tag = 'tr';
-               $th_tag = 'th';
-               $td_tag = 'td';
-               $caption_tag = 'caption';
-
-               $extra_table_attribs = null;
-               $extra_tr_attribs = null;
-               $extra_td_attribs = null;
-
-               $convert_style = false;
-
                foreach ( $lines as $outLine ) {
                        $line = trim( $outLine );
 
@@ -825,31 +813,9 @@ class Parser {
                                $indent_level = strlen( $matches[1] );
 
                                $attributes = $this->mStripState->unstripBoth( $matches[2] );
+                               $attributes = Sanitizer::fixTagAttributes( $attributes , 'table' );
 
-                               $attr = Sanitizer::decodeTagAttributes( $attributes );
-
-                               $mode = @$attr['mode'];
-                               if ( !$mode ) $mode = 'data';
-
-                               if ( $mode == 'grid' || $mode == 'layout' ) {
-                                       $table_tag = 'div';
-                                       $tr_tag = 'div';
-                                       $th_tag = 'div';
-                                       $td_tag = 'div';
-                                       $caption_tag = 'div';
-
-                                       $extra_table_attribs = array( 'class' => 'grid-table' );
-                                       $extra_tr_attribs = array( 'class' => 'grid-row' );
-                                       $extra_td_attribs = array( 'class' => 'grid-cell' );
-
-                                       $convert_style = true;
-                               } 
-
-                               if ($convert_style) $attr['style'] = Sanitizer::styleFromAttributes( $attr );
-                               $attr = Sanitizer::validateTagAttributes( $attr, $table_tag );
-                               $attributes = Sanitizer::collapseTagAttributes( $attr, $extra_table_attribs );
-
-                               $outLine = str_repeat( '<dl><dd>' , $indent_level ) . "<$table_tag{$attributes}>";
+                               $outLine = str_repeat( '<dl><dd>' , $indent_level ) . "<table{$attributes}>";
                                array_push( $td_history , false );
                                array_push( $last_tag_history , '' );
                                array_push( $tr_history , false );
@@ -861,15 +827,15 @@ class Parser {
                                continue;
                        } elseif ( substr( $line , 0 , 2 ) === '|}' ) {
                                # We are ending a table
-                               $line = "</$table_tag>" . substr( $line , 2 );
+                               $line = '</table>' . substr( $line , 2 );
                                $last_tag = array_pop( $last_tag_history );
 
                                if ( !array_pop( $has_opened_tr ) ) {
-                                       $line = "<$tr_tag><$td_tag></$td_tag></$tr_tag>{$line}";
+                                       $line = "<tr><td></td></tr>{$line}";
                                }
 
                                if ( array_pop( $tr_history ) ) {
-                                       $line = "</$tr_tag>{$line}";
+                                       $line = "</tr>{$line}";
                                }
 
                                if ( array_pop( $td_history ) ) {
@@ -883,12 +849,7 @@ class Parser {
 
                                # Whats after the tag is now only attributes
                                $attributes = $this->mStripState->unstripBoth( $line );
-
-                               $attr = Sanitizer::decodeTagAttributes( $attributes );
-                               if ($convert_style) $attr['style'] = Sanitizer::styleFromAttributes( $attr );
-                               $attr = Sanitizer::validateTagAttributes( $attr, $tr_tag );
-                               $attributes = Sanitizer::collapseTagAttributes( $attr, $extra_tr_attribs );
-
+                               $attributes = Sanitizer::fixTagAttributes( $attributes, 'tr' );
                                array_pop( $tr_attributes );
                                array_push( $tr_attributes, $attributes );
 
@@ -898,7 +859,7 @@ class Parser {
                                array_push( $has_opened_tr , true );
 
                                if ( array_pop( $tr_history ) ) {
-                                       $line = "</$tr_tag>";
+                                       $line = '</tr>';
                                }
 
                                if ( array_pop( $td_history ) ) {
@@ -936,7 +897,7 @@ class Parser {
                                        if ( $first_character !== '+' ) {
                                                $tr_after = array_pop( $tr_attributes );
                                                if ( !array_pop( $tr_history ) ) {
-                                                       $previous = "<$tr_tag{$tr_after}>\n";
+                                                       $previous = "<tr{$tr_after}>\n";
                                                }
                                                array_push( $tr_history , true );
                                                array_push( $tr_attributes , '' );
@@ -951,11 +912,11 @@ class Parser {
                                        }
 
                                        if ( $first_character === '|' ) {
-                                               $last_tag = $td_tag;
+                                               $last_tag = 'td';
                                        } elseif ( $first_character === '!' ) {
-                                               $last_tag = $th_tag;
+                                               $last_tag = 'th';
                                        } elseif ( $first_character === '+' ) {
-                                               $last_tag = $caption_tag;
+                                               $last_tag = 'caption';
                                        } else {
                                                $last_tag = '';
                                        }
@@ -965,24 +926,15 @@ class Parser {
                                        # A cell could contain both parameters and data
                                        $cell_data = explode( '|' , $cell , 2 );
 
-                                       $attributes = '';
-
                                        # Bug 553: Note that a '|' inside an invalid link should not
                                        # be mistaken as delimiting cell parameters
                                        if ( strpos( $cell_data[0], '[[' ) !== false ) {
-                                               if ($extra_td_attribs) $attributes = Sanitizer::collapseTagAttributes( $extra_td_attribs );
-                                               $cell = "{$previous}<{$last_tag}{$attributes}>{$cell}";
+                                               $cell = "{$previous}<{$last_tag}>{$cell}";
                                        } elseif ( count( $cell_data ) == 1 ) {
-                                               if ($extra_td_attribs) $attributes = Sanitizer::collapseTagAttributes( $extra_td_attribs );
-                                               $cell = "{$previous}<{$last_tag}{$attributes}>{$cell_data[0]}";
+                                               $cell = "{$previous}<{$last_tag}>{$cell_data[0]}";
                                        } else {
                                                $attributes = $this->mStripState->unstripBoth( $cell_data[0] );
-
-                                               $attr = Sanitizer::decodeTagAttributes( $attributes );
-                                               if ($convert_style) $attr['style'] = Sanitizer::styleFromAttributes( $attr );
-                                               $attr = Sanitizer::validateTagAttributes( $attr, $last_tag );
-                                               $attributes = Sanitizer::collapseTagAttributes( $attr, $extra_td_attribs );
-
+                                               $attributes = Sanitizer::fixTagAttributes( $attributes , $last_tag );
                                                $cell = "{$previous}<{$last_tag}{$attributes}>{$cell_data[1]}";
                                        }
 
@@ -996,16 +948,16 @@ class Parser {
                # Closing open td, tr && table
                while ( count( $td_history ) > 0 ) {
                        if ( array_pop( $td_history ) ) {
-                               $out .= "</$td_tag>\n";
+                               $out .= "</td>\n";
                        }
                        if ( array_pop( $tr_history ) ) {
-                               $out .= "</$tr_tag>\n";
+                               $out .= "</tr>\n";
                        }
                        if ( !array_pop( $has_opened_tr ) ) {
-                               $out .= "<$tr_tag><$td_tag></$td_tag></$tr_tag>\n" ;
+                               $out .= "<tr><td></td></tr>\n" ;
                        }
 
-                       $out .= "</$table_tag>\n";
+                       $out .= "</table>\n";
                }
 
                # Remove trailing line-ending (b/c)
@@ -1014,7 +966,7 @@ class Parser {
                }
 
                # special case: don't return empty table
-               if ( $out === "<$table_tag>\n<$tr_tag><$td_tag></$td_tag></$tr_tag>\n</$table_tag>" ) {
+               if ( $out === "<table>\n<tr><td></td></tr>\n</table>" ) {
                        $out = '';
                }
 
index af79237..3d9f4a5 100644 (file)
@@ -883,69 +883,7 @@ td.mw-enhanced-rc {
 a.sortheader {
        margin: 0 0.3em;
 }
-
-.grid-table {
-       display: table;
-}
-
-.grid-row {
-       display: table-row;
-}
-
-.grid-cell {
-       display: table-cell;
-       padding: 0.33ex;
-}
-
-/* Localised ordered list numbering for some languages */
-ol:lang(bcc) li,
-ol:lang(bqi) li,
-ol:lang(fa) li,
-ol:lang(glk) li,
-ol:lang(kk-arab) li,
-ol:lang(mzn) li {
-       list-style-type: -moz-persian;
-       list-style-type: persian;
-}
-
-ol:lang(ckb) li {
-       list-style-type: -moz-arabic-indic;
-       list-style-type: arabic-indic;
-}
-
-ol:lang(bn) li {
-       list-style-type: -moz-bengali;
-       list-style-type: bengali;
-}
-
-/* tooltip styles */
-.mw-help-field-hint {
-       display: none;
-       padding: 0px;
-       padding-left: 15px;
-       margin-left: 2px;
-       margin-bottom: -8px;
-       background-image: url('images/help-question.gif');
-       background-position: left center;
-       background-repeat: no-repeat;
-       color: #0645ad;
-       text-decoration: underline;
-       cursor: pointer;
-       font-size: .8em;
-}
-.mw-help-field-hint:hover {
-       background-image: url('images/help-question-hover.gif');
-}
-.mw-help-field-data {
-       display: block;
-       background-color: #d6f3ff;
-       padding:5px 8px 4px 8px;
-       border: 1px solid #5dc9f4;
-       margin-left: 20px;
-}
 .tipsy { padding: 5px 5px 10px; font-size: 12px; position: absolute; z-index: 100000; overflow: visible; }
 .tipsy-inner { padding: 5px 8px 4px 8px; background-color: #d6f3ff; color: black; border: 1px solid #5dc9f4; max-width: 300px; text-align: left; }
 .tipsy-arrow { position: absolute; background: url( 'images/tipsy-arrow.gif' ) no-repeat top left; width: 13px; height: 13px; }
 .tipsy-se .tipsy-arrow { bottom: -2px; right: 10px; background-position: 0% 100%; }
-
-