AutomaticChangeSummary
Description
This recipe automatically generates "change-summaries" Sometimes the user forgets to fill in the "Change summary" box when editing. Or maybe you've removed that box entirely by going to Site/EditForm?action=edit. And you'd like some change summary to appear. It's especially useful to have a change summary for rss feeds.
The change-summaries generated by this recipe consist of the first ten lines or so of changes to the document.
To do it, add the following to local/config.php
:
array_unshift($EditFunctions, 'ProvideDefaultSummary'); function ProvideDefaultSummary($pagename,&$page,&$new) { global $ChangeSummary, $DiffFunction; if ($ChangeSummary || !function_exists(@$DiffFunction)) return; $diff = $DiffFunction((array_key_exists ('text', $new) ? $new['text'] : ''), (array_key_exists ('text', $page) ? $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." ";} $ChangeSummary=str_replace(array("<",">","\n"),array("<",">"," "),$diff2); $new['csum']=$ChangeSummary; }
ProvideDefaultSummary
function. This provides a change summary (if one wasn't already there). It calls DiffFunction
to find what's new, in figures out which lines have been added and which have been removed, and it tries to make a useful summary out of it. The summary is plain text so as to work fine on RSS feeds.Notes
You'll likely want to have the change-summary appear in an rss feed of your site.
Add this to local/config.php
:
if ($action == 'rss') include_once("$FarmD/scripts/feeds.php"); $FeedFmt['rss']['item']['description'] = '$LastModifiedSummary';
See Web Feeds for more information. The second line makes
sure that the rss feed includes your change-summary. (by default
it is absent from the feed.) Users can find your feed at
...mywiki/Site/AllRecentChanges?action=rss
I also found it nice for my "AllRecentChanges" page and my
rss feed to show all recent changes. (The default pmwiki
behaviour is just to show the single most recent change
for a given page). To do this, put this in your local/config.php
:
$RCLinesMax=50; $RecentChangesFmt['$SiteGroup.AllRecentChanges'] = '* [[{$FullName}]] . . . $CurrentTime $[by] $AuthorLink: [=$ChangeSummary=]';
(What's important here is that there's only a single space before the three dots. The default pmwiki behaviour comes from having two dots instead.)
See Also
Contributors
Lucian Wischik
Comments
See discussion at AutomaticChangeSummary-Talk
User notes +1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.