r4746 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r4745‎ | r4746 | r4747 >
Date:08:32, 14 August 2004
Author:timwi
Status:old
Tags:
Comment:
Fixes to the bold/italics rendering problems [Bug 40]
http://bugzilla.wikipedia.org/show_bug.cgi?id=40

Also indentation fixes in two places, SCNR
Modified paths:
  • /branches/REL1_3/phase3/includes/Parser.php (modified) (history)

Diff [purge]

Index: branches/REL1_3/phase3/includes/Parser.php
@@ -50,7 +50,7 @@
5151 {
5252 # Persistent:
5353 var $mTagHooks;
54 -
 54+
5555 # Cleared with clearState():
5656 var $mOutput, $mAutonumber, $mDTopen, $mStripState = array();
5757 var $mVariables, $mIncludeCount, $mArgStack, $mLastSection, $mInPre;
@@ -102,9 +102,9 @@
103103 $fixtags = array(
104104 # french spaces, last one Guillemet-left
105105 # only if there is something before the space
106 - '/(.) (\\?|:|;|!|\\302\\273)/i' => '\\1 \\2',
 106+ '/(.) (\\?|:|;|!|\\302\\273)/i' => '\\1 \\2',
107107 # french spaces, Guillemet-right
108 - "/(\\302\\253) /i"=>"\\1 ",
 108+ "/(\\302\\253) /i"=>"\\1 ",
109109 '/<hr *>/i' => '<hr />',
110110 '/<br *>/i' => '<br />',
111111 '/<center *>/i' => '<div class="center">',
@@ -117,10 +117,10 @@
118118 } else {
119119 $fixtags = array(
120120 # french spaces, last one Guillemet-left
121 - '/ (\\?|:|!|\\302\\273)/i' => '&nbsp;\\1',
 121+ '/ (\\?|:|!|\\302\\273)/i' => '&nbsp;\\1',
122122 # french spaces, Guillemet-right
123 - '/(\\302\\253) /i' => '\\1&nbsp;',
124 - '/([^> ]+(&#x30(1|3|9);)[^< ]*)/i' => '<span class="diacrit">\\1</span>',
 123+ '/(\\302\\253) /i' => '\\1&nbsp;',
 124+ '/([^> ]+(&#x30(1|3|9);)[^< ]*)/i' => '<span class="diacrit">\\1</span>',
125125 '/<center *>/i' => '<div class="center">',
126126 '/<\\/center *>/i' => '</div>'
127127 );
@@ -199,7 +199,7 @@
200200 $pre_content = array();
201201 $comment_content = array();
202202 $ext_content = array();
203 -
 203+
204204 # Replace any instances of the placeholders
205205 $uniq_prefix = UNIQ_PREFIX;
206206 #$text = str_replace( $uniq_prefix, wfHtmlEscapeFirst( $uniq_prefix ), $text );
@@ -266,7 +266,7 @@
267267 $state['math'] = $state['math'] + $math_content;
268268 $state['pre'] = $state['pre'] + $pre_content;
269269 $state['comment'] = $state['comment'] + $comment_content;
270 -
 270+
271271 foreach( $ext_content as $tag => $array ) {
272272 if ( array_key_exists( $tag, $state ) ) {
273273 $state[$tag] = $state[$tag] + $array;
@@ -297,7 +297,7 @@
298298
299299 return $text;
300300 }
301 - # always call this after unstrip() to preserve the order
 301+ # always call this after unstrip() to preserve the order
302302 function unstripNoWiki( $text, &$state ) {
303303 # Must expand in reverse order, otherwise nested tags will be corrupted
304304 for ( $content = end($state['nowiki']); $content !== false; $content = prev( $state['nowiki'] ) ) {
@@ -423,8 +423,8 @@
424424
425425 # FIXME: add limits
426426 $t = wfStrencode( $this->mTitle->getDBKey() );
427 - $sql = "SELECT DISTINCT cur_title,cur_namespace,cl_sortkey FROM
428 -cur,categorylinks WHERE cl_to='$t' AND cl_from=cur_id ORDER BY
 427+ $sql = "SELECT DISTINCT cur_title,cur_namespace,cl_sortkey FROM
 428+cur,categorylinks WHERE cl_to='$t' AND cl_from=cur_id ORDER BY
429429 cl_sortkey" ;
430430 $res = wfQuery ( $sql, DB_READ ) ;
431431 while ( $x = wfFetchObject ( $res ) )
@@ -432,7 +432,7 @@
433433 $t = $ns = $wgLang->getNsText ( $x->cur_namespace ) ;
434434 if ( $t != '' ) $t .= ':' ;
435435 $t .= $x->cur_title ;
436 -
 436+
437437 if ( $x->cur_namespace == $cns ) {
438438 $ctitle = str_replace( '_',' ',$x->cur_title );
439439 array_push ( $children, $sk->makeKnownLink ( $t, $ctitle ) ) ; # Subcategory
@@ -462,22 +462,22 @@
463463 $r .= '<h2>' . wfMsg( 'subcategories' ) . "</h2>\n"
464464 . wfMsg( 'subcategorycount', count( $children ) );
465465 if ( count ( $children ) > 6 ) {
466 -
 466+
467467 // divide list into three equal chunks
468468 $chunk = (int) (count ( $children ) / 3);
469469
470470 // get and display header
471471 $r .= '<table width="100%"><tr valign="top">';
472 -
 472+
473473 $startChunk = 0;
474474 $endChunk = $chunk;
475 -
 475+
476476 // loop through the chunks
477 - for($startChunk = 0, $endChunk = $chunk, $chunkIndex = 0;
 477+ for($startChunk = 0, $endChunk = $chunk, $chunkIndex = 0;
478478 $chunkIndex < 3;
479479 $chunkIndex++, $startChunk = $endChunk, $endChunk += $chunk + 1)
480480 {
481 -
 481+
482482 $r .= '<td><ul>';
483483 // output all subcategories to category
484484 for ($index = $startChunk ;
@@ -490,17 +490,17 @@
491491 {
492492 $r .= "</ul><h3>{$children_start_char[$index]}</h3>\n<ul>";
493493 }
494 -
 494+
495495 $r .= "<li>{$children[$index]}</li>";
496496 }
497497 $r .= '</ul></td>';
498 -
499 -
 498+
 499+
500500 }
501501 $r .= '</tr></table>';
502502 } else {
503503 // for short lists of subcategories to category.
504 -
 504+
505505 $r .= "<h3>{$children_start_char[0]}</h3>\n";
506506 $r .= '<ul><li>'.$children[0].'</li>';
507507 for ($index = 1; $index < count($children); $index++ )
@@ -509,7 +509,7 @@
510510 {
511511 $r .= "</ul><h3>{$children_start_char[$index]}</h3>\n<ul>";
512512 }
513 -
 513+
514514 $r .= "<li>{$children[$index]}</li>";
515515 }
516516 $r .= '</ul>';
@@ -522,21 +522,21 @@
523523 # Showing articles in this category
524524 if ( count ( $articles ) > 6) {
525525 $ti = $this->mTitle->getText() ;
526 -
 526+
527527 // divide list into three equal chunks
528528 $chunk = (int) (count ( $articles ) / 3);
529 -
 529+
530530 // get and display header
531531 $r .= '<table width="100%"><tr valign="top">';
532 -
 532+
533533 // loop through the chunks
534 - for($startChunk = 0, $endChunk = $chunk, $chunkIndex = 0;
 534+ for($startChunk = 0, $endChunk = $chunk, $chunkIndex = 0;
535535 $chunkIndex < 3;
536536 $chunkIndex++, $startChunk = $endChunk, $endChunk += $chunk + 1)
537537 {
538 -
 538+
539539 $r .= '<td><ul>';
540 -
 540+
541541 // output all articles in category
542542 for ($index = $startChunk ;
543543 $index < $endChunk && $index < count($articles);
@@ -548,18 +548,18 @@
549549 {
550550 $r .= "</ul><h3>{$articles_start_char[$index]}</h3>\n<ul>";
551551 }
552 -
 552+
553553 $r .= "<li>{$articles[$index]}</li>";
554554 }
555555 $r .= '</ul></td>';
556 -
557 -
 556+
 557+
558558 }
559559 $r .= '</tr></table>';
560560 } elseif ( count ( $articles ) > 0) {
561561 // for short lists of articles in categories.
562562 $ti = $this->mTitle->getText() ;
563 -
 563+
564564 $r .= '<h3>'.$articles_start_char[0]."</h3>\n";
565565 $r .= '<ul><li>'.$articles[0].'</li>';
566566 for ($index = 1; $index < count($articles); $index++ )
@@ -568,7 +568,7 @@
569569 {
570570 $r .= "</ul><h3>{$articles_start_char[$index]}</h3>\n<ul>";
571571 }
572 -
 572+
573573 $r .= "<li>{$articles[$index]}</li>";
574574 }
575575 $r .= '</ul>';
@@ -624,7 +624,7 @@
625625 global $wgInputEncoding, $wgOutputEncoding;
626626 $fname = 'Parser::tidy';
627627 wfProfileIn( $fname );
628 -
 628+
629629 $cleansource = '';
630630 switch(strtoupper($wgOutputEncoding)) {
631631 case 'ISO-8859-1':
@@ -657,7 +657,7 @@
658658 }
659659
660660 wfProfileOut( $fname );
661 -
 661+
662662 if( $cleansource == '' && $text != '') {
663663 wfDebug( "Tidy error detected!\n" );
664664 return $text . "\n<!-- Tidy found serious XHTML errors -->\n";
@@ -768,13 +768,13 @@
769769
770770 # Parses the text and adds the result to the strip state
771771 # Returns the strip tag
772 - function stripParse( $text, $newline, $args )
 772+ function stripParse( $text, $newline, $args )
773773 {
774774 $text = $this->strip( $text, $this->mStripState );
775775 $text = $this->internalParse( $text, (bool)$newline, $args, false );
776776 return $newline.$this->insertStripItem( $text, $this->mStripState );
777777 }
778 -
 778+
779779 function internalParse( $text, $linestart, $args = array(), $isMain=true ) {
780780 $fname = 'Parser::internalParse';
781781 wfProfileIn( $fname );
@@ -809,7 +809,7 @@
810810 wfProfileOut( $fname );
811811 return $text;
812812 }
813 -
 813+
814814 # Parse ^^ tokens and return html
815815 /* private */ function doExponent ( $text )
816816 {
@@ -845,7 +845,7 @@
846846 wfProfileOut( $fname );
847847 return $outtext;
848848 }
849 -
 849+
850850 /* private */ function &doMagicLinks( &$text ) {
851851 $text = $this->magicISBN( $text );
852852 $text = $this->magicRFC( $text );
@@ -884,8 +884,9 @@
885885 }
886886 # Count the number of occurrences of bold and italics mark-ups.
887887 # We are not counting sequences of five apostrophes.
888 - if (strlen ($arr[$i]) == 2) $numitalics++; else
889 - if (strlen ($arr[$i]) == 3) $numbold++;
 888+ if (strlen ($arr[$i]) == 2) $numitalics++; else
 889+ if (strlen ($arr[$i]) == 3) $numbold++; else
 890+ if (strlen ($arr[$i]) == 5) { $numitalics++; $numbold++; }
890891 }
891892 $i++;
892893 }
@@ -910,7 +911,7 @@
911912 if ($firstspace == -1) $firstspace = $i;
912913 } else if ($x2 == " ") {
913914 if ($firstsingleletterword == -1) $firstsingleletterword = $i;
914 - } else {
 915+ } else {
915916 if ($firstmultiletterword == -1) $firstmultiletterword = $i;
916917 }
917918 }
@@ -922,7 +923,7 @@
923924 {
924925 $arr [ $firstsingleletterword ] = "''";
925926 $arr [ $firstsingleletterword-1 ] .= "'";
926 - }
 927+ }
927928 # If not, but there's a multi-letter word, use that one.
928929 else if ($firstmultiletterword > -1)
929930 {
@@ -930,7 +931,9 @@
931932 $arr [ $firstmultiletterword-1 ] .= "'";
932933 }
933934 # ... otherwise use the first one that has neither.
934 - else
 935+ # (notice that it is possible for all three to be -1 if, for example,
 936+ # there is only one pentuple-apostrophe in the line)
 937+ else if ($firstspace > -1)
935938 {
936939 $arr [ $firstspace ] = "''";
937940 $arr [ $firstspace-1 ] .= "'";
@@ -1160,7 +1163,7 @@
11611164 }
11621165 }
11631166 wfProfileOut( $fname.'-prefixhandling' );
1164 -
 1167+
11651168 if ( preg_match( $e1, $line, $m ) ) { # page with normal text or alt
11661169 $text = $m[2];
11671170 # fix up urlencoded title texts
@@ -1428,7 +1431,7 @@
14291432 $paragraphStack = false;
14301433 $output .= $this->closeParagraph();
14311434 if($preOpenMatch and !$preCloseMatch) {
1432 - $this->mInPre = true;
 1435+ $this->mInPre = true;
14331436 }
14341437 if ( $closematch ) {
14351438 $inBlockElem = false;
@@ -1552,12 +1555,12 @@
15531556
15541557 # PHP global rebinding syntax is a bit weird, need to use the GLOBALS array
15551558 $GLOBALS['wgCurParser'] =& $this;
1556 -
15571559
 1560+
15581561 if ( $this->mOutputType == OT_HTML ) {
15591562 # Variable substitution
15601563 $text = preg_replace_callback( "/{{([$nonBraceChars]*?)}}/", 'wfVariableSubstitution', $text );
1561 -
 1564+
15621565 # Argument substitution
15631566 $text = preg_replace_callback( "/(\\n?){{{([$titleChars]*?)}}}/", 'wfArgSubstitution', $text );
15641567 }
@@ -1612,7 +1615,7 @@
16131616 $found = false;
16141617 $nowiki = false;
16151618 $noparse = false;
1616 -
 1619+
16171620 $title = NULL;
16181621
16191622 # $newline is an optional newline character before the braces
@@ -1625,7 +1628,7 @@
16261629
16271630 $args = $this->getTemplateArgs($matches[3]);
16281631 $argc = count( $args );
1629 -
 1632+
16301633 # {{{}}}
16311634 if ( strpos( $matches[0], '{{{' ) !== false ) {
16321635 $text = $matches[0];
@@ -1811,7 +1814,7 @@
18121815 if ( array_key_exists( $arg, $inputArgs ) ) {
18131816 $text = $this->stripParse( $inputArgs[$arg], $newline, array() );
18141817 }
1815 -
 1818+
18161819 return $text;
18171820 }
18181821
@@ -1833,7 +1836,7 @@
18341837 global $wgUseTidy, $wgUserHtml;
18351838 $fname = 'Parser::removeHTMLtags';
18361839 wfProfileIn( $fname );
1837 -
 1840+
18381841 if( $wgUserHtml ) {
18391842 $htmlpairs = array( # Tags that must be closed
18401843 'b', 'del', 'i', 'ins', 'u', 'font', 'big', 'small', 'sub', 'sup', 'h1',
@@ -1938,7 +1941,7 @@
19391942 } else {
19401943 $text .= '&lt;' . str_replace( '>', '&gt;', $x);
19411944 }
1942 - }
 1945+ }
19431946 }
19441947 wfProfileOut( $fname );
19451948 return $text;
@@ -1960,7 +1963,7 @@
19611964
19621965 /* private */ function formatHeadings( $text, $isMain=true ) {
19631966 global $wgInputEncoding, $wgMaxTocLevel;
1964 -
 1967+
19651968 $doNumberHeadings = $this->mOptions->getNumberHeadings();
19661969 $doShowToc = $this->mOptions->getShowToc();
19671970 $forceTocHere = false;
@@ -2013,9 +2016,9 @@
20142017 $doShowToc = 1;
20152018 }
20162019 }
2017 -
20182020
20192021
 2022+
20202023 # We need this to perform operations on the HTML
20212024 $sk =& $this->mOptions->getSkin();
20222025
@@ -2195,7 +2198,7 @@
21962199 }
21972200 return $text;
21982201 }
2199 -
 2202+
22002203 # Return an HTML link for the "RFC 1234" text
22012204 /* private */ function magicRFC( $text ) {
22022205 global $wgLang;

Follow-up revisions

RevisionCommit summaryAuthorDate
r4747Fixes to the bold/italics rendering problems [Bug 40]...timwi08:32, 14 August 2004

Status & tagging log