[pmwiki-users] Get history/diff in Site.AllRecentChanges ?

Lucian Wischik lu.gmane at wischik.com
Wed Nov 15 20:36:52 CST 2006


Lucian Wischik <lu.gmane <at> wischik.com> writes:
> At the moment, AllRecentChanges shows the change summary of each
> change, [=$ChangeSummary=]
> What I'd like instead is to display the "diff" associated with this change,
> like it does in the ?action=diff page.

Add this to your local/config.php

array_unshift($EditFunctions, 'ProvideDefaultSummary');
function ProvideDefaultSummary($pagename,&$page,&$new)
{ global $ChangeSummary, $DiffFunction;
  if ($ChangeSummary || !function_exists(@$DiffFunction)) return;
  $diff = $DiffFunction($new['text'],@$page['text']);
  $difflines = explode("\n",$diff."\n");
  $in=array(); $out=array();
  foreach ($difflines as $d)
  { if ($d=='' || $d[0]=='-' || $d[0]=='\\') continue;
    if ($d[0]=='<' && count($out)<10) {$out[]=substr($d,2); continue;}
    if ($d[0]=='>' && count($in)<10) {$in[]=substr($d,2); continue;}
  }
  $diff2=''; if (count($out)==0) {$out=$in; $diff2="[deleted] ";}
  foreach ($out as $s) {$diff2 .= $s." ";}
  $diff2=str_replace(array("<",">"),array("&lt;","&gt;"),$diff2);
  $ChangeSummary=$diff2;
}

How it works: $EditFunctions is an ordered list of functions
that get called by pmwiki when a user has submitted a change.
We add our own function 'ProvideDefaultSummary' to the head
of the list. What it does is invoke the standard DiffFunction
(as used e.g. by ?action=diff). We parse it into a summary
and put that into $ChangeSummary. Note: we only do this if
$ChangeSummary was empty. In formatting our default
change summary, we're careful to use formatting that will
be compatible with Site/AllRecentChanges?action=rss, ie.
the rss feed of recent changes. That's why we stick to
plain text, we remove the < and >, and we only include
up to ten lines of change.



> (Also: when there is a change, I want Site.AllRecentChanges to do a
> transformation on the page. When there has been a change to
> Comments.GroupPage, I want it to show the diff for Comments.GroupPage
> but the title and link of this change should instead point to
> Group.Page. Is this possible?)

Put this in local/config.php

$BaseNamePatterns['/^Comments\.(.*?)-(.*)/'] = '\1/\2';
$RecentChangesFmt['$SiteGroup.AllRecentChanges'] =
 '* [[{$BaseName}]]  . . . $CurrentTime $[by] '.
 '$AuthorLink: [=$ChangeSummary=]';

How it works: BaseNamePatterns is a set of patterns that are
applied somewhere or other useful. It does a regexp search-replace
on the string $Group.Name. In this case it detects "Comments"
and strips it out. So we use this $BasName in our $RecentChangesFmt.


-- 
Lucian






More information about the pmwiki-users mailing list