*** 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 = "" . $this->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 .= "
" ; ! $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 .= "
" , "" , $s ) ; ! $s = str_replace ( "\n
\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 . "