PrettyRecentChanges Action


This gentle rewrite of the RecentChanges which ships with WikkaWiki 1.1.6.4 was created for use in a translucent website, where I want to make it possible to show a short list of changed pages while hiding much of the wiki guts.

It creates short unordered lists for each day's changes, up to a total specified by the constant MAX_REVISION_NUMBER_PRETTY which is set (here) at 6. The days retain the essential formatting provided by the original code, including references to the same CSS formatting. Most of the work done here was with the delete key, and a little work to generate the unordered lists.

The other change is the addition of an uncamel function which splits up CamelCase into constituent words and numbers. I have many pages which are listed as Readings4June2008 which this code presents as Readings 4 June 2008.

Installation


Place the following code in the actions directory as prettyrecentchanges.php
prettyrecentchanges.php (line 1)
  1. <?php
  2.  
  3. /**
  4.  * Display a simple list of recently changed pages.
  5.  *
  6.  * @package     Actions
  7.  * @name        PrettyRecentChanges
  8.  *
  9.  * @author      {@link http://www.mornography.de/ Hendrik Mans} (wakka code)
  10.  * @author      {@link http://wikkawiki.org/DarTar Dario Taraborelli} (preliminary code cleanup)
  11.  * @author      {@link http://wikkawiki.org/RichardMartinNielsen Richard Martin-Nielsen} (slight modifications to simplify for easy inclusion in homepages)
  12.  * @todo            - make datetime format configurable;
  13.  *              - add configurable option for non-accessible pages {@link http://wush.net/trac/wikka/ticket/178 #178};
  14.  *              - added extensive logging of events such as page deletion, cloning, ACL change {@link http://wush.net/trac/wikka/ticket/143 #143};
  15.  */
  16.  
  17. //defaults
  18. if(!defined('REVISION_DATE_FORMAT')) define('REVISION_DATE_FORMAT', 'D, d M Y');
  19. if(!defined('REVISION_TIME_FORMAT')) define('REVISION_TIME_FORMAT', 'H:i T');
  20. if (!defined('PAGE_EDITOR_DIVIDER')) define ('PAGE_EDITOR_DIVIDER', '&#8594;');
  21. if (!defined('MAX_REVISION_NUMBER')) define ('MAX_REVISION_NUMBER', '50');
  22. if (!defined('MAX_REVISION_NUMBER_PRETTY')) define ('MAX_REVISION_NUMBER_PRETTY', '6');
  23.  
  24. //i18n
  25. if (!defined('RECENT_CHANGES_HEADING')) define('RECENT_CHANGES_HEADING', '**Recently changed pages**');
  26. if (!defined('UNREGISTERED_USER')) define('UNREGISTERED_USER', 'unregistered user');
  27. if (!defined('LABEL_HISTORY')) define('LABEL_HISTORY', 'history');
  28. if (!defined('TITLE_REVISION_LINK')) define('TITLE_REVISION_LINK', 'View recent revisions list for %s');
  29. if (!defined('TITLE_HISTORY_LINK')) define('TITLE_HISTORY_LINK', 'View edit history of %s');
  30. if (!defined('WIKIPING_ENABLED')) define('WIKIPING_ENABLED', 'WikiPing enabled: Changes on this wiki are broadcast to <a href="http://%1$s">http://%1$s</a>');
  31. if (!defined('NO_RECENTLY_CHANGED_PAGES')) define ('NO_RECENTLY_CHANGED_PAGES', 'There are no recently changed pages.');
  32. if (!defined('NO_READABLE_RECENTLY_CHANGED_PAGES')) define ('NO_READABLE_RECENTLY_CHANGED_PAGES', 'There are no recently changed pages you have access to.');
  33.  
  34. //initialization
  35. $max = 0;
  36. $readable = 0;
  37.  
  38. if ( !function_exists('uncamel'))
  39.   {
  40.     function uncamel($intext)
  41.     {
  42.       // Following codes based on a blog posting by Trenton Davies
  43.       // at http://ad.hominem.org/log/2004/12/camelcase.php
  44.       $text = join( ' ', preg_split("{(?<=[a-z])(?=[A-Z0-9])}x", $intext ) );
  45.       // Following line breaks out numbers as separate words as well
  46.       $text = join( ' ', preg_split("{(?<=[0-9])(?=[A-Z])}x", $text ) );
  47.       return "$text";
  48.     }
  49.   }
  50.  
  51. if ($pages = $this->LoadRecentlyChanged())
  52. {
  53.     $curday = '';
  54.  
  55.     $max = MAX_REVISION_NUMBER_PRETTY;
  56.  
  57.     foreach ($pages as $i => $page)
  58.     {
  59.         if (($i < $max) && $this->HasAccess('read', $page['tag']))
  60.         {
  61.             $readable++;
  62.             // day header
  63.             list($day, $time) = explode(' ', $page['time']);
  64.             if ($day != $curday)
  65.             {
  66.                 $dateformatted = date(REVISION_DATE_FORMAT, strtotime($day));
  67.  
  68.                 if ($curday)
  69.                 {
  70.                     echo '</ul></span>'."\n";
  71.                 }
  72.                 echo $dateformatted.':<br />'."\n".'<span class="recentchanges"><ul>'."\n";
  73.                 $curday = $day;
  74.             }
  75.  
  76.             echo '<li>'.$this->Link($page['tag'], '', uncamel($page['tag']), 0).'</li>'."\n";
  77.         }
  78.     }
  79.     if ($readable == 0)
  80.     {
  81.         echo '<em class="error">'.NO_READABLE_RECENTLY_CHANGED_PAGES.'</em>';
  82.     }
  83.     echo '</ul></span>'."\n";
  84.  
  85.     //wikiping instructions
  86.     $wikipingserver = $this->config['wikiping_server'];
  87.     if (!$wikipingserver == '')
  88.     {
  89.         $wikipingserver_url_parsed = parse_url($wikipingserver);
  90.         $wikipingserver_host = $wikipingserver_url_parsed['host'];
  91.         printf('<br /><br />['.WIKIPING_ENABLED.']', $wikipingserver_host);
  92.     }
  93. }
  94. else
  95. {
  96.     echo '<em class="error">'.NO_RECENTLY_CHANGED_PAGES.'</em>';
  97. }
  98.  
  99.  
  100. ?>


Usage

This code was originally conceived to be used in a >> section. I apply a title by hand:

>>**Latest News and Updates**{{PrettyRecentChanges}}>>


It needn't be used this way, of course.

Possible criticisms


This could have just been another option passed to recent changes. I'm building a site to be edited and updated by novice users. They would much prefer to be told to just type {{PrettyRecentChanges}} than to try to get a series of parameters correct.

CategoryUserContributions
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki