");
SDV($DiffDelFmt['c'],"
\$[Changed line \$DiffLines from:]
");
SDV($DiffAddFmt['d'],"
\$[Added line \$DiffLines:]
");
SDV($DiffAddFmt['c'],"
$[to:]
");
SDV($DiffEndDelAddFmt,"
");
SDV($DiffEndFmt,"
");
SDV($DiffRestoreFmt,"
");
SDV($DiffAuthorPageExistsFmt,"
\$DiffAuthor");
SDV($DiffAuthorPageMissingFmt,"\$DiffAuthor");
$HandleActions['diff']='HandleDiff';
function PrintDiff($pagename) {
global $DiffClass,$DiffId,$DiffTime,$DiffAuthor,$TimeFmt,
$DiffStartFmt,$DiffEndFmt,$DiffAddFmt,$DiffDelFmt,
$DiffEndDelAddFmt,$DiffRestoreFmt,$PatchFunction,$DiffShow,$GCount,
$DiffAuthorPage,$DiffAuthorPageExistsFmt,$DiffAuthorPageMissingFmt,
$AuthorGroup,$DiffChangeSum;
$page = ReadPage($pagename);
if (!$page) return;
Lock(0);
krsort($page); reset($page);
foreach($page as $k=>$v) {
if (!preg_match("/^diff:(\d+):(\d+):?([^:]*)/",$k,$match)) continue;
$DiffClass = $match[3];
if ($DiffClass=='minor' && $DiffShow['minor']!='y') continue;
$DiffGmt = $match[1]; $DiffTime = strftime($TimeFmt,$DiffGmt);
$DiffAuthor = @$page["author:$DiffGmt"];
if (!$DiffAuthor) @$DiffAuthor=$page["host:$DiffGmt"];
if (!$DiffAuthor) $DiffAuthor="unknown";
if ($a = FreeLink('{{'.$DiffAuthor.'}}')) {
$DiffAuthorPage="$AuthorGroup/".$a['name']; $GCount=0;
if (PageExists($DiffAuthorPage))
$DiffAuthor=FmtPageName($DiffAuthorPageExistsFmt,$pagename);
else $DiffAuthor=FmtPageName($DiffAuthorPageMissingFmt,$pagename);
}
$DiffChangeSum = @$page["csum:$DiffGmt"];
$DiffId = $k; $GCount=0;
echo FmtPageName($DiffStartFmt,$pagename);
$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/",$dtype,$match)) {
if ($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]]);
$txt = FmtPageName($txt,$pagename);
echo str_replace('$DiffLines',$count,$txt);
if ($DiffShow['source']=='y')
echo "
",
str_replace("\n","
",htmlspecialchars(join("\n",$in))),
"
";
else PrintText($pagename,join("\n",$in));
}
if ($match[4]=='d' || $match[4]=='c') {
$txt = str_replace('line',$lines,$DiffAddFmt[$match[4]]);
$txt = FmtPageName($txt,$pagename);
echo str_replace('$DiffLines',$count,$txt);
if ($DiffShow['source']=='y')
echo "
",
str_replace("\n","
",htmlspecialchars(join("\n",$out))),
"
";
else PrintText($pagename,join("\n",$out));
}
echo FmtPageName($DiffEndDelAddFmt,$pagename);
}
$in=array(); $out=array(); $dtype=$d;
}
echo FmtPageName($DiffEndFmt,$pagename);
if ($PatchFunction) echo FmtPageName($DiffRestoreFmt,$pagename);
}
}
function HandleDiff($pagename) {
global $DiffAccessLevel,$HandleDiffFmt,
$PageStartFmt,$PageDiffFmt,$PageEndFmt;
SDV($DiffAccessLevel,'read');
$page = RetrieveAuthPage($pagename,$DiffAccessLevel);
if (!$page) { Abort("?cannot diff $pagename"); }
SetPageVars($pagename,$page,"$pagename History");
SDV($HandleDiffFmt,array(&$PageStartFmt,
&$PageDiffFmt,'function:PrintDiff',
&$PageEndFmt));
PrintFmt($pagename,$HandleDiffFmt);
}