# HG changeset patch # User Dan Fuhry # Date 1288249531 14400 # Node ID f9bee9b125ee673a9e2eab94e2662c400438e446 # Parent 5d9f6ecf748ebc395c48b9d17db89aab0ee629ea Parser updates. Added the "styled" keyword to wikitables to allow them to be styled using the current theme's standard table skinning, and changes to how the image tag parser decides how to display an image (framed, inline or raw). diff -r 5d9f6ecf748e -r f9bee9b125ee includes/render.php --- a/includes/render.php Thu Oct 28 03:04:24 2010 -0400 +++ b/includes/render.php Thu Oct 28 03:05:31 2010 -0400 @@ -1163,6 +1163,7 @@ $filename =& $matches[1][$i]; // apply recursion (hack? @todo could this be done with (?R) in PCRE?) + // this allows other elements such as internal/external links to be embedded in image captions $tag_pos = strpos($text, $full_tag); $tag_end_pos = $tag_pos + strlen($full_tag); while ( get_char_count($full_tag, ']') < get_char_count($full_tag, '[') && $tag_end_pos < strlen($text) ) @@ -1180,9 +1181,9 @@ $width = null; $height = null; $scale_type = null; - $raw_display = false; $clear = null; $caption = null; + $display_type = 'inline'; // trim tag and parse particles $tag_trim = rtrim(ltrim($full_tag, '['), ']'); @@ -1201,12 +1202,13 @@ case 'left': case 'right': $clear = $param; + $display_type = 'framed'; break; case 'thumb': $scale_type = 'thumb'; break; case 'raw': - $raw_display = true; + $display_type = 'raw'; break; default: // height specification @@ -1218,7 +1220,7 @@ } // not the height, so see if a plugin took this over // this hook requires plugins to return true if they modified anything - $code = $plugins->setHook('img_tag_parse_params'); + $code = $plugins->setHook('img_tag_parse_params', true); foreach ( $code as $cmd ) { if ( eval($cmd) ) @@ -1263,7 +1265,7 @@ // $img_tag .= 'width="' . $r_width . '" height="' . $r_height . '" '; // } - $img_tag .= 'style="border-width: 0px; /* background-color: white; */" '; + $img_tag .= 'style="border-width: 0px;" '; $code = $plugins->setHook('img_tag_parse_img'); foreach ( $code as $cmd ) @@ -1276,7 +1278,7 @@ $s_full_tag = self::escape_parser_hint_attrib($full_tag); $complete_tag = ''; - if ( !empty($scale_type) && !$raw_display ) + if ( $display_type == 'framed' ) { $complete_tag .= '
element? $indent_level = 0; # indent level of the table - foreach ( $t AS $k => $x ) + $row_count = 0; + foreach ( $t AS $k => $line ) { - $x = trim ( $x ) ; - $fc = substr ( $x , 0 , 1 ) ; - if ( preg_match( '/^(:*)\{\|(.*)$/', $x, $matches ) ) { + $line = trim ( $line ) ; + $first_char = substr ( $line , 0 , 1 ) ; + if ( preg_match( '/^(:*)\{\|(.*)$/', $line, $matches ) ) { $indent_level = strlen( $matches[1] ); $attributes = unstripForHTML( $matches[2] ); + $styled_table = false; + if ( trim($attributes) == "styled" ) + { + $attributes='cellspacing="1" cellpadding="4"'; + $styled_table = true; + } $t[$k] = str_repeat( '
', $indent_level ) . + ( $styled_table ? '
' : '' ) . '' ; array_push ( $td , false ) ; array_push ( $ltd , '' ) ; @@ -74,8 +82,8 @@ array_push ( $has_opened_tr, false ); } else if ( count ( $td ) == 0 ) { } # Don't do any of the following - else if ( '|}' == substr ( $x , 0 , 2 ) ) { - $z = "" . substr ( $x , 2); + else if ( '|}' == substr ( $line , 0 , 2 ) ) { + $z = "" . ( $styled_table ? '
' : '' ) . substr ( $line , 2); $l = array_pop ( $ltd ) ; if ( !array_pop ( $has_opened_tr ) ) $z = "" . $z ; if ( array_pop ( $tr ) ) $z = '' . $z ; @@ -83,9 +91,10 @@ array_pop ( $ltr ) ; $t[$k] = $z . str_repeat( '
', $indent_level ); } - else if ( '|-' == substr ( $x , 0 , 2 ) ) { # Allows for |--------------- - $x = substr ( $x , 1 ) ; - while ( $x != '' && substr ( $x , 0 , 1 ) == '-' ) $x = substr ( $x , 1 ) ; + else if ( '|-' == substr ( $line , 0 , 2 ) ) { # Allows for |--------------- + $row_count++; + $line = substr ( $line , 1 ) ; + while ( $line != '' && substr ( $line , 0 , 1 ) == '-' ) $line = substr ( $line , 1 ) ; $z = '' ; $l = array_pop ( $ltd ) ; array_pop ( $has_opened_tr ); @@ -97,17 +106,17 @@ array_push ( $tr , false ) ; array_push ( $td , false ) ; array_push ( $ltd , '' ) ; - $attributes = unstripForHTML( $x ); + $attributes = unstripForHTML( $line ); array_push ( $ltr , fixTagAttributes( $attributes, 'tr' ) ) ; } - else if ( '|' == $fc || '!' == $fc || '|+' == substr ( $x , 0 , 2 ) ) { # Caption - # $x is a table row - if ( '|+' == substr ( $x , 0 , 2 ) ) { - $fc = '+' ; - $x = substr ( $x , 1 ) ; + else if ( '|' == $first_char || '!' == $first_char || '|+' == substr ( $line , 0 , 2 ) ) { # Caption + # $line is a table row + if ( '|+' == substr ( $line , 0 , 2 ) ) { + $first_char = '+' ; + $line = substr ( $line , 1 ) ; } - $after = substr ( $x , 1 ) ; - if ( $fc == '!' ) $after = str_replace ( '!!' , '||' , $after ) ; + $after = substr ( $line , 1 ) ; + if ( $first_char == '!' ) $after = str_replace ( '!!' , '||' , $after ) ; // Split up multiple cells on the same line. // FIXME: This can result in improper nesting of tags processed @@ -121,7 +130,7 @@ foreach ( $after AS $theline ) { $z = '' ; - if ( $fc != '+' ) + if ( $first_char != '+' ) { $tra = array_pop ( $ltr ) ; if ( !array_pop ( $tr ) ) $z = '\n" ; @@ -133,9 +142,9 @@ $l = array_pop ( $ltd ) ; if ( array_pop ( $td ) ) $z = '' . $z ; - if ( $fc == '|' ) $l = 'td' ; - else if ( $fc == '!' ) $l = 'th' ; - else if ( $fc == '+' ) $l = 'caption' ; + if ( $first_char == '|' ) $l = 'td' ; + else if ( $first_char == '!' ) $l = 'th' ; + else if ( $first_char == '+' ) $l = 'caption' ; else $l = '' ; array_push ( $ltd , $l ) ; @@ -146,10 +155,21 @@ if ( strpos( $y[0], '[[' ) !== false ) { $y = array ($theline); } + $attr_append = ''; + if ( $styled_table && $l == 'td' ) + { + $rowclass = 1 + ($row_count % 2); + $attr_append .= ' class="row' . $rowclass . '"'; + } if ( count ( $y ) == 1 ) - $y = "{$z}<{$l}>{$y[0]}" ; - else { + { + $y = "{$z}<{$l}{$attr_append}>{$y[0]}" ; + } + else + { $attributes = unstripForHTML( $y[0] ); + if ( !strstr($attributes, "class=") ) + $attributes .= $attr_append; $y = "{$z}<{$l}".fixTagAttributes($attributes, $l).">{$y[1]}" ; } $t[$k] .= $y ;