Delta Bytes in Recent Changes

Summary: Display the number of bytes (characters) added or deleted to a page in RecentChanges.
Version: 24 February 2007
Prerequisites:
Status:
Maintainer: Petko
License: PD

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?

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:

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

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.

Array
(
    [post_max_size] => 64M
    [$_POST keys] => 
    [$_REQUEST keys] => n
    [$_SERVER] => Array
        (
            [CONTEXT_DOCUMENT_ROOT] => /home/pmwiki/public_html
            [CONTEXT_PREFIX] => 
            [DOCUMENT_ROOT] => /home/pmwiki/public_html
            [GATEWAY_INTERFACE] => CGI/1.1
            [HTTPS] => on
            [HTTP_ACCEPT] => */*
            [HTTP_ACCEPT_ENCODING] => gzip, br, zstd, deflate
            [HTTP_COOKIE] => PHPSESSID=kkfupq4vk3m6ppb1fn2mnunh25
            [HTTP_HOST] => www.pmwiki.org
            [HTTP_REFERER] => https://www.pmwiki.org/wiki/Cookbook/Delta%20Bytes%20Recent%20Changes
            [HTTP_USER_AGENT] => Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
            [HTTP_X_HTTPS] => 1
            [PATH] => /bin:/usr/bin
            [PHP_INI_SCAN_DIR] => /opt/cpanel/ea-php70/root/etc:/opt/cpanel/ea-php70/root/etc/php.d:.
            [QUERY_STRING] => n=Cookbook%2fDeltaBytesRecentChanges
            [REDIRECT_HTTPS] => on
            [REDIRECT_QUERY_STRING] => n=Cookbook%2fDeltaBytesRecentChanges
            [REDIRECT_SCRIPT_URI] => https://www.pmwiki.org/wiki/Cookbook/DeltaBytesRecentChanges
            [REDIRECT_SCRIPT_URL] => /wiki/Cookbook/DeltaBytesRecentChanges
            [REDIRECT_SSL_TLS_SNI] => www.pmwiki.org
            [REDIRECT_STATUS] => 200
            [REDIRECT_UNIQUE_ID] => afSepep7fEfwjP_WmMLHXQAAAUE
            [REDIRECT_URL] => /wiki/Cookbook/DeltaBytesRecentChanges
            [REMOTE_ADDR] => 216.73.216.25
            [REMOTE_PORT] => 65037
            [REQUEST_METHOD] => GET
            [REQUEST_SCHEME] => https
            [REQUEST_URI] => /wiki/Cookbook/DeltaBytesRecentChanges
            [SCRIPT_FILENAME] => /home/pmwiki/public_html/index.php
            [SCRIPT_NAME] => /index.php
            [SCRIPT_URI] => https://www.pmwiki.org/wiki/Cookbook/DeltaBytesRecentChanges
            [SCRIPT_URL] => /wiki/Cookbook/DeltaBytesRecentChanges
            [SERVER_ADDR] => 23.254.203.248
            [SERVER_ADMIN] => webmaster@pmwiki.org
            [SERVER_NAME] => www.pmwiki.org
            [SERVER_PORT] => 443
            [SERVER_PROTOCOL] => HTTP/1.1
            [SERVER_SIGNATURE] => 
            [SERVER_SOFTWARE] => Apache
            [SSL_TLS_SNI] => www.pmwiki.org
            [TZ] => America/Los_Angeles
            [UNIQUE_ID] => afSepep7fEfwjP_WmMLHXQAAAUE
            [PHP_SELF] => /index.php
            [REQUEST_TIME_FLOAT] => 1777639077.4078
            [REQUEST_TIME] => 1777639077
            [argv] => Array
                (
                    [0] => n=Cookbook%2fDeltaBytesRecentChanges
                )

            [argc] => 1
        )

)