*** wikiPage.old Wed May 1 18:56:22 2002 --- wikiPage.php Wed May 1 18:52:26 2002 *************** *** 12,18 **** var $timestamp ; # Time and date of last edit var $cache ; # For cached pages var $canBeCached ; ! #### Database management functions # This loads an article from the database, or calls a special function instead (all pages with "special:" namespace) --- 12,21 ---- var $timestamp ; # Time and date of last edit var $cache ; # For cached pages var $canBeCached ; ! ! var $dtOpen; # Used for handling DLs ! var $lastSection; # Used for p/pre sections ! #### Database management functions # This loads an article from the database, or calls a special function instead (all pages with "special:" namespace) *************** *** 403,409 **** # This function replaces wiki-style image links with the HTML code to display them function parseImages ( $s ) { ! $s = ereg_replace ( "([^[])http://([a-zA-Z0-9_/:.~\%\-]*)\.(png|jpg|jpeg|tif|tiff|gif)" , "\\1" , $s ) ; return $s ; } --- 406,412 ---- # This function replaces wiki-style image links with the HTML code to display them function parseImages ( $s ) { ! $s = ereg_replace ( "([^[])http://([a-zA-Z0-9_/:.~\%\-]*)\.(png|PNG|jpg|JPG|jpeg|JPEG|gif|GIF)" , "\\1" , $s ) ; return $s ; } *************** *** 696,702 **** # I don't *think* these are dangerous "id", "class" , "name" , "style" ); ! # Yeah, it seems kinda ugly. $bits = explode ( "<" , $s ) ; $s = array_shift ( $bits ) ; $tagstack = array() ; $tablestack = array () ; --- 699,707 ---- # I don't *think* these are dangerous "id", "class" , "name" , "style" ); ! # Delete comments right up front ! $s = preg_replace( "//", "", $s ); ! $bits = explode ( "<" , $s ) ; $s = array_shift ( $bits ) ; $tagstack = array() ; $tablestack = array () ; *************** *** 844,849 **** --- 849,939 ---- return $s ; } + # Some functions here useful for processing */#/: lines: + # + # Regrettably, the fact that we allow miscellaneous HTML in + # in wiki text as well as our own markup makes it almost impossible + # to parse a full DOM and output nicely-balanced and checked + # XHTML, so we settle for HTML 4.0 and never close

tags (if + # we tried we'd have headings inside paragraphs and such muck). + # Someday... + + # getCommon() returns the length of the longest common substring + # + function closeParagraph( ) + { + $result = ""; + if ( 0 != strcmp( "p", $this->lastSection ) && + 0 != strcmp( "", $this->lastSection ) ) { + $result = "lastSection . ">"; + } + $this->lastSection = ""; + return $result; + } + # of both arguments, starting at the beginning of both. + # + function getCommon( $st1, $st2 ) + { + $fl = strlen( $st1 ); + $shorter = strlen( $st2 ); + if ($fl < $shorter) { $shorter = $fl; } + + for ( $i = 0; $i < $shorter; ++$i ) { + if ( 0 != strcmp( substr( $st1, $i, 1 ), substr( $st2, $i, 1 ) ) ) { + break; + } + } + return $i; + } + + # These next three functions open, continue, and close the list + # element appropriate to the prefix character passed into them. + # + function openList( $char ) + { + $result = $this->closeParagraph(); + + if ( "*" == $char ) { $result .= "

"; } + else if ( "#" == $char ) { return ""; } + else if ( ":" == $char ) { + if ( $this->dtOpen ) { + $this->dtOpen = false; + return ""; + } else { + return ""; + } + } + return ""; + } + # This function does the actual parsing of the wiki parts of the article, for regions NOT marked with function subParseContents ( $s ) { global $user ; *************** *** 874,945 **** # Parsing through the text line by line # The main thing happening here is handling of lines starting with * # : etc. $a = explode ( "\n" , $s ) ; ! $s = "" ; ! $obegin = "" ; foreach ( $a as $t ) { ! $pre = "" ; ! $post = "" ; ! $ppre = "" ; ! $ppost = "" ; ! if ( trim ( $t ) == "" ) $post .= "

" ; ! ! if ( substr($t,0,1) == " " ) { $ppre = "

\n " ; $ppost = "
".$ppost ; $t = substr ( $t , 1 ) ; } ! if ( substr($t,0,1) == "*" ) { $ppre .= "
  • " ; $ppost .= "
  • " ; } ! if ( substr($t,0,1) == "#" ) { $ppre .= "
  • " ; $ppost .= "
  • " ; } ! if ( substr($t,0,1) == ":" ) { $ppre .= "
    " ; } ! if ( substr($t,0,1) == ";" ) { ! $ppre = "
    \n
    " ; ! $t = str_replace ( ":" , "
    " , $t ) ; ! $ppost = "
    ".$ppost ; ! $t = substr ( $t , 1 ) ; ! } ! ! $nbegin = "" ; ! while ( $t != "" and $obegin != "" and substr($obegin,0,1)==substr($t,0,1) ) { ! $nbegin .= substr($obegin,0,1) ; ! $t = substr ( $t , 1 ) ; ! $obegin = substr ( $obegin , 1 ) ; ! } ! ! $obegin = str_replace ( "*" , "" , $obegin ) ; ! $obegin = str_replace ( "#" , "" , $obegin ) ; ! $obegin = str_replace ( ":" , "" , $obegin ) ; ! $pre .= $obegin ; ! $obegin = $nbegin ; ! ! while ( substr ( $t , 0 , 1 ) == "*" ) { ! $pre .= "
      " ; ! $t = substr ( $t , 1 ) ; ! $obegin .= "*" ; ! } ! ! while ( substr ( $t , 0 , 1 ) == "#" ) { ! $pre .= "
        " ; ! $t = substr ( $t , 1 ) ; ! $obegin .= "#" ; ! } ! ! while ( substr ( $t , 0 , 1 ) == ":" ) { ! $pre .= "
        " ; ! $t = substr ( $t , 1 ) ; ! $obegin .= ":" ; ! } ! ! $t = str_replace ( " " , "  " , $t ) ; ! ! $t = $pre.$ppre.$t.$ppost.$post ; ! $s .= $t."\n" ; ! } ! $s .= "

        " ; ! ! $s = str_replace ( "\n 
      1. " , "
      2. \n
      3. " , $s ) ; ! $s = str_replace ( "\n
        " , "" , $s ) ;
        !         $s = str_replace ( "
      4. \n
        " , "" , $s ) ; ! ! # Removing artefact empty paragraphs like

        ! $this->replaceAll ( "

        \n

        " , "

        " , $s ) ; ! $this->replaceAll ( "

        " , "" , $s ) ; ! $this->replaceAll ( "

        " , "

        " , $s ) ; # Stuff for the skins if ( $user->options["textTableBackground"] != "" ) { --- 964,1050 ---- # Parsing through the text line by line # The main thing happening here is handling of lines starting with * # : etc. $a = explode ( "\n" , $s ) ; ! $s = "

        " ; ! $lastPref = ""; ! $lastSection = ""; ! $this->dtOpen = false; ! $inBlockElem = false; ! foreach ( $a as $t ) { ! $oLine = $t; ! $opl = strlen( $lastPref ); ! $npl = strspn( $t, "*#:;" ); ! $pref = substr( $t, 0, $npl ); ! $pref2 = str_replace( ";", ":", $pref ); ! $t = substr( $t, $npl ); ! ! if ( 0 != $npl && 0 == strcmp( $lastPref, $pref2 ) ) { ! $s .= $this->nextItem( substr( $pref, -1 ) ); ! ! if ( ";" == substr( $pref, -1 ) ) { ! $cpos = strpos( $t, ":" ); ! if ( false === $cpos ) { ! # PHP weirdness: need empty block here. ! } else { ! $term = substr( $t, 0, $cpos ); ! $s .= $term . "

        "; ! $t = substr( $t, $cpos + 1 ); ! } ! } ! } else if (0 != $npl || 0 != $opl) { ! $cpl = $this->getCommon( $pref, $lastPref ); ! ! while ( $cpl < $opl ) { ! $s .= $this->closeList( substr( $lastPref, ($opl - 1), 1 ) ); ! --$opl; ! } ! while ( $npl > $cpl ) { ! $char = substr( $pref, $cpl, 1 ); ! $s .= $this->openList( $char ); ! ! if ( ";" == $char ) { ! $cpos = strpos( $t, ":" ); ! if ( false === $cpos ) { ! } else { ! $term = substr( $t, 0, $cpos ); ! $s .= $term . "
        "; ! $t = substr( $t, $cpos + 1 ); ! } ! } ! ++$cpl; ! } ! $lastPref = $pref2; ! } ! if ( 0 == $npl ) { # No prefix--go to paragraph mode ! if ( preg_match( "/(closeParagraph(); ! $inBlockElem = true; ! } ! if ( ! $inBlockElem ) { ! if ( 0 == strcmp( " ", substr( $t, 0, 1 ) ) ) { ! $newSection = "pre"; ! } else { ! $newSection = "p"; ! } ! if ( 0 == strcmp( "", trim( $oLine ) ) ) { ! $s .= $this->closeParagraph(); ! $s .= "<" . $newSection . ">"; ! } else if ( 0 != strcmp( $this->lastSection, $newSection ) ) { ! $s .= $this->closeParagraph(); ! if ( 0 != strcmp( "p", $newSection ) ) { ! $s .= "<" . $newSection . ">"; ! } ! } ! $this->lastSection = $newSection; ! } ! if ( $inBlockElem && ! preg_match( "/(<\/table|<\/blockquote|<\/h1|<\/h2|<\/h3|<\/h4|<\/h5|<\/h6)/i", $t ) ) { ! $inBlockElem = false; ! } ! } ! $s .= $t . "\n"; ! } ! $s .= $this->closeParagraph(); # Stuff for the skins if ( $user->options["textTableBackground"] != "" ) {