r2950 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r2949‎ | r2950 | r2951 >
Date:01:45, 4 April 2004
Author:gabrielwicke
Status:old
Tags:
Comment:
xhtml tweaks, please review!

fixed problems:
* surplus closing p's
* invalid nesting of table / div (floated images) / hr in <p>'s
* generation of multiple empty p's
* invalid nesting of section editing spans
* invalid anchor names- attention! this might break links! Replacing [^a-z0-9] -> '_' now

known issues:
* needs a space at the beginning of the first line in the wikisource to parse leading ''', * and similar
Modified paths:
  • /trunk/phase3/includes/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Parser.php
@@ -317,7 +317,7 @@
318318 $fc = substr ( $x , 0 , 1 ) ;
319319 if ( "{|" == substr ( $x , 0 , 2 ) )
320320 {
321 - $t[$k] = "<table " . $this->fixTagAttributes ( substr ( $x , 3 ) ) . ">" ;
 321+ $t[$k] = "\n<table " . $this->fixTagAttributes ( substr ( $x , 3 ) ) . ">" ;
322322 array_push ( $td , false ) ;
323323 array_push ( $ltd , "" ) ;
324324 array_push ( $tr , false ) ;
@@ -420,7 +420,6 @@
421421 $text = str_replace ( "<HR>", "<hr />", $text );
422422
423423 $text = $this->doHeadings( $text );
424 - $text = $this->doBlockLevels( $text, $linestart );
425424
426425 if($this->mOptions->getUseDynamicDates()) {
427426 global $wgDateFormatter;
@@ -435,6 +434,7 @@
436435
437436 $sk =& $this->mOptions->getSkin();
438437 $text = $sk->transformContent( $text );
 438+ $text = $this->doBlockLevels( $text, $linestart );
439439 $text .= $this->categoryMagic () ;
440440
441441 wfProfileOut( $fname );
@@ -887,7 +887,7 @@
888888 /* private */ function closeParagraph()
889889 {
890890 $result = "";
891 - if ( 0 != strcmp( "", $this->mLastSection ) ) {
 891+ if ( '' != $this->mLastSection ) {
892892 $result = "</" . $this->mLastSection . ">";
893893 }
894894 $this->mLastSection = "";
@@ -968,8 +968,8 @@
969969 # and making lists from lines starting with * # : etc.
970970 #
971971 $a = explode( "\n", $text );
972 - $text = "<p>"; # ??
973 - $lastPref = "";
 972+ $a[0] = "\n".$a[0];
 973+ $lastPref = $text = '';
974974 $this->mDTopen = $inBlockElem = false;
975975
976976 if ( ! $linestart ) { $text .= array_shift( $a ); }
@@ -1022,32 +1022,36 @@
10231023 }
10241024 if ( 0 == $npl ) { # No prefix--go to paragraph mode
10251025 if ( preg_match(
1026 - "/(<table|<blockquote|<h1|<h2|<h3|<h4|<h5|<h6|<p)/i", $t ) ) {
 1026+ "/(<table|<blockquote|<h1|<h2|<h3|<h4|<h5|<h6|<div|<pre)/i", $t ) ) {
10271027 $text .= $this->closeParagraph();
10281028 $inBlockElem = true;
 1029+ } else if ( preg_match("/(<hr)/i", $t ) ) {
 1030+ $text .= $this->closeParagraph();
 1031+ $inBlockElem = false;
10291032 }
10301033 if ( ! $inBlockElem ) {
10311034 if ( " " == $t{0} ) {
10321035 $newSection = "pre";
10331036 # $t = wfEscapeHTML( $t );
1034 - } else {
1035 - $newSection = "p";
10361037 }
 1038+ else { $newSection = "p"; }
10371039
1038 - if ( 0 == strcmp( "", trim( $oLine ) ) ) {
1039 - $text .= $this->closeParagraph();
1040 - $text .= "<" . $newSection . ">";
1041 - } else if ( 0 != strcmp( $this->mLastSection,
1042 - $newSection ) ) {
1043 - $text .= $this->closeParagraph();
1044 - if ( 0 != strcmp( "p", $newSection ) ) {
 1040+ if ( '' == trim( $oLine ) ) {
 1041+ if ( $this->mLastSection != 'p') {
 1042+ $text .= $this->closeParagraph();
10451043 $text .= "<" . $newSection . ">";
 1044+ $this->mLastSection = $newSection;
 1045+ } else if ( $this->mLastSection == 'p') {
 1046+ $text .= '<br />';
10461047 }
 1048+ } else if ( $this->mLastSection == $newSection and $newSection != 'p' ) {
 1049+ $text .= $this->closeParagraph();
 1050+ $text .= "<" . $newSection . ">";
 1051+ $this->mLastSection = $newSection;
10471052 }
1048 - $this->mLastSection = $newSection;
10491053 }
10501054 if ( $inBlockElem &&
1051 - preg_match( "/(<\\/table|<\\/blockquote|<\\/h1|<\\/h2|<\\/h3|<\\/h4|<\\/h5|<\\/h6|<\\/p)/i", $t ) ) {
 1055+ preg_match( "/(<\\/table|<\\/blockquote|<\\/h1|<\\/h2|<\\/h3|<\\/h4|<\\/h5|<\\/h6|<\\/p<\\/div|<\\/pre)/i", $t ) ) {
10521056 $inBlockElem = false;
10531057 }
10541058 }
@@ -1269,7 +1273,7 @@
12701274 "ruby", "rt" , "rb" , "rp", "p"
12711275 );
12721276 $htmlsingle = array(
1273 - "br", "hr", "li", "dt", "dd", "hr/"
 1277+ "br", "hr", "li", "dt", "dd"
12741278 );
12751279 $htmlnest = array( # Tags that can be nested--??
12761280 "table", "tr", "td", "th", "div", "blockquote", "ol", "ul",
@@ -1465,8 +1469,7 @@
14661470 $canonized_headline = preg_replace( "/<.*?" . ">/","",$canonized_headline );
14671471
14681472 $tocline = trim( $canonized_headline );
1469 - $canonized_headline = str_replace( '"', "", $canonized_headline );
1470 - $canonized_headline = str_replace( " ", "_", trim( $canonized_headline) );
 1473+ $canonized_headline = preg_replace( "/[^a-z0-9]/i", "_", trim( $canonized_headline ) );
14711474 $refer[$headlineCount] = $canonized_headline;
14721475
14731476 # count how many in assoc. array so we can track dupes in anchors
@@ -1499,25 +1502,14 @@
15001503 }
15011504 $head[$headlineCount] .= $sk->editSectionLink($headlineCount+1);
15021505 }
1503 -
1504 -
1505 - # the headline might have a link
1506 - if( preg_match( "/(.*)<a(.*)/", $headline, $headlinematches ) ) {
1507 - # if so give an anchor name to the already existent link
1508 - $headline = $headlinematches[1]
1509 - . "<a name=\"$anchor\" " . $headlinematches[2];
1510 - } else {
1511 - # else create an anchor link for the headline
1512 - $headline = "<a name=\"$anchor\">$headline</a>";
1513 - }
15141506
1515 - # give headline the correct <h#> tag
1516 - @$head[$headlineCount] .= "<h".$level.$matches[2][$headlineCount] .$headline."</h".$level.">";
1517 -
1518 - # Add the edit section link
 1507+ # Add the edit section span
15191508 if( $rightClickHack ) {
1520 - $head[$headlineCount] = $sk->editSectionScript($headlineCount+1,$head[$headlineCount]);
 1509+ $headline = $sk->editSectionScript($headlineCount+1,$headline);
15211510 }
 1511+
 1512+ # give headline the correct <h#> tag
 1513+ @$head[$headlineCount] .= "<a name=\"$anchor\"></a><h".$level.$matches[2][$headlineCount] .$headline."</h".$level.">";
15221514
15231515 $headlineCount++;
15241516 }

Status & tagging log