Wiki source for PrettyRecentChanges


Show raw source

=====PrettyRecentChanges Action=====

This gentle rewrite of the [[RecentChangesActionInfo | 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
%%(php;1;prettyrecentchanges.php)
<?php

/**
* Display a simple list of recently changed pages.
*
* @package Actions
* @name PrettyRecentChanges
*
* @author {@link http://www.mornography.de/ Hendrik Mans} (wakka code)
* @author {@link http://wikkawiki.org/DarTar Dario Taraborelli} (preliminary code cleanup)
* @author {@link http://wikkawiki.org/RichardMartinNielsen Richard Martin-Nielsen} (slight modifications to simplify for easy inclusion in homepages)
* @todo - make datetime format configurable;
* - add configurable option for non-accessible pages {@link http://wush.net/trac/wikka/ticket/178 #178};
* - added extensive logging of events such as page deletion, cloning, ACL change {@link http://wush.net/trac/wikka/ticket/143 #143};
*/

//defaults
if(!defined('REVISION_DATE_FORMAT')) define('REVISION_DATE_FORMAT', 'D, d M Y');
if(!defined('REVISION_TIME_FORMAT')) define('REVISION_TIME_FORMAT', 'H:i T');
if (!defined('PAGE_EDITOR_DIVIDER')) define ('PAGE_EDITOR_DIVIDER', '→');
if (!defined('MAX_REVISION_NUMBER')) define ('MAX_REVISION_NUMBER', '50');
if (!defined('MAX_REVISION_NUMBER_PRETTY')) define ('MAX_REVISION_NUMBER_PRETTY', '6');

//i18n
if (!defined('RECENT_CHANGES_HEADING')) define('RECENT_CHANGES_HEADING', '**Recently changed pages**');
if (!defined('UNREGISTERED_USER')) define('UNREGISTERED_USER', 'unregistered user');
if (!defined('LABEL_HISTORY')) define('LABEL_HISTORY', 'history');
if (!defined('TITLE_REVISION_LINK')) define('TITLE_REVISION_LINK', 'View recent revisions list for %s');
if (!defined('TITLE_HISTORY_LINK')) define('TITLE_HISTORY_LINK', 'View edit history of %s');
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>');
if (!defined('NO_RECENTLY_CHANGED_PAGES')) define ('NO_RECENTLY_CHANGED_PAGES', 'There are no recently changed pages.');
if (!defined('NO_READABLE_RECENTLY_CHANGED_PAGES')) define ('NO_READABLE_RECENTLY_CHANGED_PAGES', 'There are no recently changed pages you have access to.');

//initialization
$max = 0;
$readable = 0;

if ( !function_exists('uncamel'))
{
function uncamel($intext)
{
// Following codes based on a blog posting by Trenton Davies
// at http://ad.hominem.org/log/2004/12/camelcase.php
$text = join( ' ', preg_split("{(?<=[a-z])(?=[A-Z0-9])}x", $intext ) );
// Following line breaks out numbers as separate words as well
$text = join( ' ', preg_split("{(?<=[0-9])(?=[A-Z])}x", $text ) );
return "$text";
}
}

if ($pages = $this->LoadRecentlyChanged())
{
$curday = '';

$max = MAX_REVISION_NUMBER_PRETTY;

foreach ($pages as $i => $page)
{
if (($i < $max) && $this->HasAccess('read', $page['tag']))
{
$readable++;
// day header
list($day, $time) = explode(' ', $page['time']);
if ($day != $curday)
{
$dateformatted = date(REVISION_DATE_FORMAT, strtotime($day));

if ($curday)
{
echo '</ul></span>'."\n";
}
echo $dateformatted.':<br />'."\n".'<span class="recentchanges"><ul>'."\n";
$curday = $day;
}

echo '<li>'.$this->Link($page['tag'], '', uncamel($page['tag']), 0).'</li>'."\n";
}
}
if ($readable == 0)
{
echo '<em class="error">'.NO_READABLE_RECENTLY_CHANGED_PAGES.'</em>';
}
echo '</ul></span>'."\n";

//wikiping instructions
$wikipingserver = $this->config['wikiping_server'];
if (!$wikipingserver == '')
{
$wikipingserver_url_parsed = parse_url($wikipingserver);
$wikipingserver_host = $wikipingserver_url_parsed['host'];
printf('<br /><br />['.WIKIPING_ENABLED.']', $wikipingserver_host);
}
}
else
{
echo '<em class="error">'.NO_RECENTLY_CHANGED_PAGES.'</em>';
}


?>
%%

====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
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki