Howdy all, I've attached a patch that basically moves a bit of code out of the PrintDiff() function in /scripts/pagerev.php to it's own function. Originally, the rendering of the diff code from page histories was handled within PrintDiff() function. However, this limits the rendering of that code to only History pages (?action=diff) which means that recipes can't utilize this the same rendering without basically duplicating the internal code (bad for upgrades, security, size, etc.). So I removed the diff rendering part and put it in it's own function called RenderDiff(). Unfortunately, I couldn't just create a new recipe that adds the function because PrintDiff() wouldn't utilize it. I've attached the new php file and a diff file.
Avast! Daniel Roesler diaf...@gmail.com
<<attachment: pagerev_with_renderdiff.php>>
85,126c85 < $difflines = explode("\n",$v."\n"); < $in=array(); $out=array(); $dtype=''; < foreach($difflines as $d) { < if ($d>'') { < if ($d[0]=='-' || $d[0]=='\\') continue; < if ($d[0]=='<') { $out[]=substr($d,2); continue; } < if ($d[0]=='>') { $in[]=substr($d,2); continue; } < } < if (preg_match("/^(\\d+)(,(\\d+))?([adc])(\\d+)(,(\\d+))?/", < $dtype,$match)) { < if (@$match[7]>'') { < $lines='lines'; < $count=$match[1].'-'.($match[1]+$match[7]-$match[5]); < } elseif ($match[3]>'') { < $lines='lines'; $count=$match[1].'-'.$match[3]; < } else { $lines='line'; $count=$match[1]; } < if ($match[4]=='a' || $match[4]=='c') { < $txt = str_replace('line',$lines,$DiffDelFmt[$match[4]]); < $FmtV['$DiffLines'] = $count; < echo FmtPageName($txt,$pagename); < if ($DiffShow['source']=='y') < echo "<div class='diffmarkup'>", < str_replace("\n","<br />",htmlspecialchars(join("\n",$in))), < "</div>"; < else echo MarkupToHTML($pagename, < preg_replace('/\\(:.*?:\\)/e',"Keep(PSS('$0'))",join("\n",$in))); < } < if ($match[4]=='d' || $match[4]=='c') { < $txt = str_replace('line',$lines,$DiffAddFmt[$match[4]]); < $FmtV['$DiffLines'] = $count; < echo FmtPageName($txt,$pagename); < if ($DiffShow['source']=='y') < echo "<div class='diffmarkup'>", < str_replace("\n","<br />",htmlspecialchars(join("\n",$out))), < "</div>"; < else echo MarkupToHTML($pagename, < preg_replace('/\\(:.*?:\\)/e',"Keep(PSS('$0'))",join("\n",$out))); < } < echo FmtPageName($DiffEndDelAddFmt,$pagename); < } < $in=array(); $out=array(); $dtype=$d; < } --- > echo RenderDiff($pagename, $v); 143a103,153 > ## Takes a diff string and returns an html rendering > ## for that diff string. > function RenderDiff($pagename, $diff, $restorelink = 1) { > global $FmtV, $DiffDelFmt, $DiffAddFmt, $DiffShow, > $DiffEndDelAddFmt; > > $htmlout = ""; > $difflines = explode("\n",$diff."\n"); > $in=array(); $out=array(); $dtype=''; > foreach($difflines as $d) { > if ($d>'') { > if ($d[0]=='-' || $d[0]=='\\') continue; > if ($d[0]=='<') { $out[]=substr($d,2); continue; } > if ($d[0]=='>') { $in[]=substr($d,2); continue; } > } > if (preg_match("/^(\\d+)(,(\\d+))?([adc])(\\d+)(,(\\d+))?/", > $dtype,$match)) { > if (@$match[7]>'') { > $lines='lines'; > $count=$match[1].'-'.($match[1]+$match[7]-$match[5]); > } elseif ($match[3]>'') { > $lines='lines'; $count=$match[1].'-'.$match[3]; > } else { $lines='line'; $count=$match[1]; } > if ($match[4]=='a' || $match[4]=='c') { > $txt = str_replace('line',$lines,$DiffDelFmt[$match[4]]); > $FmtV['$DiffLines'] = $count; > $htmlout .= FmtPageName($txt,$pagename); > if ($DiffShow['source']=='y') > $htmlout .= "<div class='diffmarkup'>". > str_replace("\n","<br />",htmlspecialchars(join("\n",$in))). > "</div>"; > else $htmlout .= MarkupToHTML($pagename, > preg_replace('/\\(:.*?:\\)/e',"Keep(PSS('$0'))",join("\n",$in))); > } > if ($match[4]=='d' || $match[4]=='c') { > $txt = str_replace('line',$lines,$DiffAddFmt[$match[4]]); > $FmtV['$DiffLines'] = $count; > $htmlout .= FmtPageName($txt,$pagename); > if ($DiffShow['source']=='y') > $htmlout .= "<div class='diffmarkup'>". > str_replace("\n","<br />",htmlspecialchars(join("\n",$out))). > "</div>"; > else $htmlout .= MarkupToHTML($pagename, > preg_replace('/\\(:.*?:\\)/e',"Keep(PSS('$0'))",join("\n",$out))); > } > $htmlout .= FmtPageName($DiffEndDelAddFmt,$pagename); > } > $in=array(); $out=array(); $dtype=$d; > } > return $htmlout; > }
_______________________________________________ pmwiki-devel mailing list pmwiki-devel@pmichaud.com http://www.pmichaud.com/mailman/listinfo/pmwiki-devel