Delta Bytes in Recent Changes
Note: A feature like the one described in this page will be included in PmWiki 2.2.119. To enable it, see $EnableRCDiffBytes
.
How can the RecentChanges pages display the amount of bytes (characters) added or deleted to a page? Like it is done in Wikipedia?
Contents
Description
Display the number of bytes (characters) added or deleted to a page in RecentChanges.
You can use such a function (add it in your (farm)config.php):
# before 2.3.24:
# array_unshift($EditFunctions, "DeltaPageSize");
# since 2.3.24:
InsertEditFunction("DeltaPageSize", '>SaveChangeSummary');
function DeltaPageSize($pagename,&$page,&$new)
{
global $EnablePost, $ChangeSummary, $Now;
if (!$EnablePost) return;
$delta = strlen($new['text']) - strlen($page['text']);
if($delta>0) $delta = "+$delta";
$new['csum'] .= " ($delta)";
$new["csum:$Now"] .= " ($delta)";
$ChangeSummary .= " ($delta)";
}
A sample output of this recipe would be:
- Cookbook.ThumbList . . . 2007-02-24 15:13:51 by Petko: comma (+1)
- PmWiki.WikiSandbox . . . 2007-02-24 15:13:24 by Petko: Testing the new "DeltaPageSize" recipe... (-673)
- PmWiki.PmWiki . . . 2007-02-24 15:10:11 by Petko: Reverting (+1234)
Variant with colored delta numbers
This variant displays important deletions in red, important additions in green and in bold.
# before 2.3.24:
# array_unshift($EditFunctions, "DeltaPageSize");
# since 2.3.24:
InsertEditFunction("DeltaPageSize", '>SaveChangeSummary');
function DeltaPageSize($pagename,&$page,&$new)
{
global $EnablePost, $ChangeSummary, $Now;
if (!$EnablePost) return;
$delta = strlen($new['text']) - strlen($page['text']);
$span = $_span = $bold = '';
if(abs($delta) > 500 )$bold = "'''";
if($delta<-500) $span="purple";
elseif($delta<-100)$span="red";
elseif($delta==0) $span="gray";
elseif($delta>100)$span="green";
if($span){$span="=]%$span%"; $_span="%%[=";}
if($delta>0) $delta = "+$delta";
$new['csum'] .= " ($delta)";
$new["csum:$Now"] .= " ($delta)";
$ChangeSummary .= " ($span$bold$delta$bold$_span)";
}
Notes
- This will append (±Number) to the $ChangeSummary variable. That is, no additional page variables, but the change summary will always be modified (and exist).
Release Notes
- Drafted on 2007-02-24
See Also
- Recent Uploads Log List all uploaded files in RecentUploads pages
- Cookbook.PageDiffSize Add an accurate count of characters added & removed to each edit summary
Contributors
Comments
See discussion at DeltaBytesRecentChanges-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.