added configuration for recentchanges

I kept it to a simple global configuration, rather than using the
preprocessor directive for recentchanges, because that had chicken and egg
problems and seemed overcomplicated. This should work reasonably well,
though it would be good to add some more metadata so that more customised
recentchanges pages can be made.
master
Joey Hess 2008-01-29 15:51:32 -05:00
parent cabd5140c4
commit 8b31c53366
10 changed files with 39 additions and 58 deletions

View File

@ -6,25 +6,30 @@ use strict;
use IkiWiki 2.00;
sub import { #{{{
hook(type => "refresh", id => "recentchanges",
call => \&refresh);
hook(type => "preprocess", id => "recentchanges",
call => \&preprocess);
hook(type => "htmlize", id => "_change",
call => \&htmlize);
hook(type => "checkconfig", id => "recentchanges", call => \&checkconfig);
hook(type => "refresh", id => "recentchanges", call => \&refresh);
hook(type => "htmlize", id => "_change", call => \&htmlize);
} #}}}
sub checkconfig () { #{{{
$config{recentchangespage}='recentchanges' unless defined $config{recentchangespage};
$config{recentchangesnum}=100 unless defined $config{recentchangesnum};
} #}}}
sub refresh ($) { #{{{
my @changes=IkiWiki::rcs_recentchanges(100);
updatechanges("*", "recentchanges", \@changes);
} #}}}
my %seen;
sub preprocess (@) { #{{{
my %params=@_;
# TODO
return "";
# add new changes
foreach my $change (IkiWiki::rcs_recentchanges($config{recentchangesnum})) {
$seen{store($change, $config{recentchangespage})}=1;
}
# delete old and excess changes
foreach my $page (keys %pagesources) {
if ($page=~/^\Q$config{recentchangespage}\E\/change_/ && ! $seen{$page}) {
unlink($config{srcdir}.'/'.$pagesources{$page});
}
}
} #}}}
# Pages with extension _change have plain html markup, pass through.
@ -33,11 +38,10 @@ sub htmlize (@) { #{{{
return $params{content};
} #}}}
sub store ($$) { #{{{
sub store ($$$) { #{{{
my $change=shift;
my $subdir=shift;
my $page="$subdir/change_".IkiWiki::titlepage($change->{rev});
my $page="$config{recentchangespage}/change_".IkiWiki::titlepage($change->{rev});
# Optimisation to avoid re-writing pages. Assumes commits never
# change (or that any changes are not important).
@ -102,23 +106,9 @@ sub store ($$) { #{{{
} #}}}
sub updatechanges ($$) { #{{{
my $pagespec=shift;
my $subdir=shift;
my @changes=@{shift()};
my %seen;
# add new changes
foreach my $change (@changes) {
$seen{store($change, $subdir)}=1;
}
# delete old and excess changes
foreach my $page (keys %pagesources) {
if ($page=~/^\Q$subdir\E\/change_/ && ! $seen{$page}) {
unlink($config{srcdir}.'/'.$pagesources{$page});
}
}
} #}}}
1

View File

@ -85,8 +85,8 @@ sub genpage ($$) { #{{{
$actions++;
}
if ($config{rcs}) {
$template->param(recentchangesurl => urlto("recentchanges", $page));
if ($config{rcs} && exists $config{recentchangespage}) {
$template->param(recentchangesurl => urlto($config{recentchangespage}, $page));
$actions++;
}

View File

@ -1,3 +1,5 @@
While ikiwiki is primarily a wiki compiler, which generates static html pages, it does use CGI for two important wiki features, online page editing and the [[RecentChanges]] display.
While ikiwiki is primarily a wiki compiler, which generates static html
pages, it does use CGI for online page editing.
To enable CGI, you need to create and install an ikiwiki.cgi wrapper. [[Setup]] explains how to do this.
To enable CGI, you need to create and install an ikiwiki.cgi wrapper.
[[Setup]] explains how to do this.

View File

@ -115,6 +115,9 @@ use IkiWiki::Setup::Standard {
#account_creation_password => "example",
# Uncomment to force ikiwiki to run with a particular umask.
#umask => 022,
# Default settings for the recentchanges page.
#recentchangespage => "recentchanges",
#recentchangesnum => 100,
# To add plugins, list them here.
#add_plugins => [qw{goodstuff search wikitext camelcase

View File

@ -5,12 +5,8 @@ generates a page describing each recent change made to the wiki. These
pages can be joined together with [[inline]] to generate the
[[RecentChanges]] page.
Typically only the RecentChanges page will use the plugin, but you can
use it elsewhere too if you like. It's used like this:
Typically only the RecentChanges page will use the pages generated by this
plugin, but you can use it elsewhere too if you like. It's used like this:
\[[recentchanges pages="*" num=100 template=change]]
\[[inline pages="internal(recentchanges/change_*)"
template=recentchanges show=0]]
The pages describing recent changes will be created as [[subpages|subpage]]
of the page where the `recentchanges` directive is placed.

View File

@ -1,5 +1,4 @@
Recent changes to this wiki:
[[recentchanges pages="*" num=100 template=change]]
[[inline pages="internal(recentchanges/change_*) and !*/Discussion"
template=recentchanges show=0]]

View File

@ -33,8 +33,7 @@ These options control the mode that ikiwiki operates in.
* --cgi
Enable [[CGI]] mode. In cgi mode ikiwiki runs as a cgi script, and
supports editing pages, signing in, registration, and displaying
[[RecentChanges]].
supports editing pages, signing in, and registration.
To use ikiwiki as a [[CGI]] program you need to use --wrapper or --setup
to generate a wrapper. The wrapper will generally need to run suid 6755 to
@ -141,8 +140,7 @@ configuration options of their own.
whatever the revision control system you select uses.
In [[CGI]] mode, with a revision control system enabled, pages edited via
the web will be committed. Also, the [[RecentChanges]] link will be placed
on pages.
the web will be committed.
No revision control is enabled by default.

View File

@ -15,10 +15,6 @@ use IkiWiki::Setup::Standard {
syslog => 0,
userdir => "users",
usedirs => 0,
rcs => 'git',
rss => 1,
cgiurl => "http://ikiwiki.info/ikiwiki.cgi",
url => "http://ikiwiki.info",
add_plugins => [qw{goodstuff version haiku polygen fortune
recentchanges }],
add_plugins => [qw{goodstuff version haiku polygen fortune}],
disable_plugins => [qw{recentchanges}],
}

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2008-01-29 15:21-0500\n"
"POT-Creation-Date: 2008-01-29 15:46-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"

View File

@ -67,9 +67,6 @@ ok(! pagespec_match("foo", "creation_day(3)"), "other day");
ok(! pagespec_match("foo", "no_such_function(foo)"), "foo");
ok(pagespec_match("foo", "foo and user(bar)", user => "bar"), "user");
ok(! pagespec_match("foo", "foo and user(bar)", user => "baz"), "user fail");
my $ret=pagespec_match("foo", "(invalid");
ok(! $ret, "syntax error");
ok($ret eq "syntax error", "error message");