r86599 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86598‎ | r86599 | r86600 >
Date:07:27, 21 April 2011
Author:diebuche
Status:ok
Tags:
Comment:
Fix Bug 25794: Disallow multiple table captions & only keep the first
Modified paths:
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/tests/parser/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/parser/parserTests.txt
@@ -1331,7 +1331,40 @@
13321332 </table>
13331333
13341334 !! end
 1335+
13351336 !! test
 1337+Table with multiple captions: Only keep first
 1338+!! input
 1339+{|
 1340+|+ caption 1
 1341+|+ caption 2
 1342+|}
 1343+!! result
 1344+<table>
 1345+<caption>caption 1
 1346+</caption>
 1347+<tr><td></td></tr>
 1348+</table>
 1349+
 1350+!! end
 1351+
 1352+!! test
 1353+Table with multiline caption
 1354+!! input
 1355+{|
 1356+|+ caption 1
 1357+further caption
 1358+|}
 1359+!! result
 1360+<table>
 1361+<caption>caption 1
 1362+further caption
 1363+</caption>
 1364+<tr><td></td></tr>
 1365+</table>
 1366+
 1367+!! end
 1368+!! test
13361369 Table with multiple thead
13371370 !! input
13381371 {|
Index: trunk/phase3/includes/parser/Parser.php
@@ -913,16 +913,17 @@
914914 }
915915
916916 } else if ( $firstChars === '|+' ) {
917 - // a table caption
918 - $line = substr ( $line , 2 );
919 -
920 - $c = $this->getCellAttr( $line , 'caption' );
921 - $table['caption'] = array();
922 - $table['caption']['content'] = $c[0];
923 - if ( isset( $c[1] ) ) $table['caption']['attributes'] = $c[1];
924 - unset( $c );
925 -
926 - $output =& $table['caption'];
 917+ // a table caption, but only proceed if there isn't one already
 918+ if ( !isset ( $table['caption'] ) ) {
 919+ $line = substr ( $line , 2 );
 920+
 921+ $c = $this->getCellAttr( $line , 'caption' );
 922+ $table['caption'] = array();
 923+ $table['caption']['content'] = $c[0];
 924+ if ( isset( $c[1] ) ) $table['caption']['attributes'] = $c[1];
 925+ unset( $c );
 926+ $output =& $table['caption']['content'];
 927+ }
927928 } else if ( $firstChars === '|' || $firstChars === '!' || $firstChars === '!+' ) {
928929 // Which kind of cells are we dealing with
929930 $currentTag = 'td';

Status & tagging log