summaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/CGI.pm109
-rw-r--r--IkiWiki/Plugin/aggregate.pm197
-rw-r--r--IkiWiki/Plugin/calendar.pm3
-rw-r--r--IkiWiki/Plugin/ddate.pm6
-rw-r--r--IkiWiki/Plugin/edittemplate.pm3
-rw-r--r--IkiWiki/Plugin/inline.pm33
-rw-r--r--IkiWiki/Plugin/meta.pm125
-rw-r--r--IkiWiki/Plugin/openid.pm27
-rw-r--r--IkiWiki/Plugin/poll.pm6
-rw-r--r--IkiWiki/Plugin/prettydate.pm5
-rw-r--r--IkiWiki/Plugin/recentchanges.pm169
-rw-r--r--IkiWiki/Plugin/teximg.pm4
-rw-r--r--IkiWiki/Plugin/version.pm3
-rw-r--r--IkiWiki/Rcs/Stub.pm8
-rw-r--r--IkiWiki/Rcs/bzr.pm166
-rw-r--r--IkiWiki/Rcs/git.pm48
-rw-r--r--IkiWiki/Rcs/mercurial.pm6
-rw-r--r--IkiWiki/Rcs/monotone.pm79
-rw-r--r--IkiWiki/Rcs/svn.pm43
-rw-r--r--IkiWiki/Rcs/tla.pm50
-rw-r--r--IkiWiki/Render.pm59
-rw-r--r--IkiWiki/UserInfo.pm87
-rw-r--r--IkiWiki/Wrapper.pm16
23 files changed, 713 insertions, 539 deletions
diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm
index 65a1d7fa0..4d4464c28 100644
--- a/IkiWiki/CGI.pm
+++ b/IkiWiki/CGI.pm
@@ -84,53 +84,6 @@ sub decode_cgi_utf8 ($) { #{{{
}
} #}}}
-sub cgi_recentchanges ($) { #{{{
- my $q=shift;
-
- # Optimisation: building recentchanges means calculating lots of
- # links. Memoizing htmllink speeds it up a lot (can't be memoized
- # during page builds as the return values may change, but they
- # won't here.)
- eval q{use Memoize};
- error($@) if $@;
- memoize("htmllink");
-
- eval q{use Time::Duration};
- error($@) if $@;
-
- my $changelog=[rcs_recentchanges(100)];
- foreach my $change (@$changelog) {
- $change->{when} = concise(ago($change->{when}));
-
- $change->{user} = userlink($change->{user});
-
- my $is_excess = exists $change->{pages}[10]; # limit pages to first 10
- delete @{$change->{pages}}[10 .. @{$change->{pages}}] if $is_excess;
- $change->{pages} = [
- map {
- $_->{link} = htmllink("", "", $_->{page},
- noimageinline => 1,
- linktext => pagetitle($_->{page}));
- $_;
- } @{$change->{pages}}
- ];
- push @{$change->{pages}}, { link => '...' } if $is_excess;
- }
-
- my $template=template("recentchanges.tmpl");
- $template->param(
- title => "RecentChanges",
- indexlink => indexlink(),
- wikiname => $config{wikiname},
- changelog => $changelog,
- baseurl => baseurl(),
- );
- run_hooks(pagetemplate => sub {
- shift->(page => "", destpage => "", template => $template);
- });
- print $q->header(-charset => 'utf-8'), $template->output;
-} #}}}
-
# Check if the user is signed in. If not, redirect to the signin form and
# save their place to return to later.
sub needsignin ($$) { #{{{
@@ -242,9 +195,6 @@ sub cgi_prefs ($$) { #{{{
$form->field(name => "do", type => "hidden");
$form->field(name => "email", size => 50, fieldset => "preferences");
- $form->field(name => "subscriptions", size => 50,
- fieldset => "preferences",
- comment => "(".htmllink("", "", "ikiwiki/PageSpec", noimageinline => 1).")");
$form->field(name => "banned_users", size => 50,
fieldset => "admin");
@@ -256,8 +206,6 @@ sub cgi_prefs ($$) { #{{{
if (! $form->submitted) {
$form->field(name => "email", force => 1,
value => userinfo_get($user_name, "email"));
- $form->field(name => "subscriptions", force => 1,
- value => userinfo_get($user_name, "subscriptions"));
if (is_admin($user_name)) {
$form->field(name => "banned_users", force => 1,
value => join(" ", get_banned_users()));
@@ -274,11 +222,9 @@ sub cgi_prefs ($$) { #{{{
return;
}
elsif ($form->submitted eq 'Save Preferences' && $form->validate) {
- foreach my $field (qw(email subscriptions)) {
- if (defined $form->field($field)) {
- userinfo_set($user_name, $field, $form->field($field)) ||
- error("failed to set $field");
- }
+ if (defined $form->field('email')) {
+ userinfo_set($user_name, 'email', $form->field('email')) ||
+ error("failed to set email");
}
if (is_admin($user_name)) {
set_banned_users(grep { ! is_admin($_) }
@@ -341,7 +287,7 @@ sub cgi_editpage ($$) { #{{{
if (exists $pagesources{$page} && $form->field("do") ne "create") {
$file=$pagesources{$page};
$type=pagetype($file);
- if (! defined $type) {
+ if (! defined $type || $type=~/^_/) {
error(sprintf(gettext("%s is not an editable page"), $page));
}
if (! $form->submitted) {
@@ -411,6 +357,8 @@ sub cgi_editpage ($$) { #{{{
linkify($page, "",
preprocess($page, $page,
filter($page, $page, $content), 0, 1))));
+ # previewing may have created files on disk
+ saveindex();
}
elsif ($form->submitted eq "Save Page") {
$form->tmpl_param("page_preview", "");
@@ -470,7 +418,8 @@ sub cgi_editpage ($$) { #{{{
my @page_types;
if (exists $hooks{htmlize}) {
- @page_types=keys %{$hooks{htmlize}};
+ @page_types=grep { !/^_/ }
+ keys %{$hooks{htmlize}};
}
$form->tmpl_param("page_select", 1);
@@ -501,7 +450,6 @@ sub cgi_editpage ($$) { #{{{
}
showform($form, \@buttons, $session, $q);
- saveindex();
}
else {
# save page
@@ -579,7 +527,7 @@ sub cgi_editpage ($$) { #{{{
# Prevent deadlock with post-commit hook by
# signaling to it that it should not try to
- # do anything (except send commit mails).
+ # do anything.
disable_commit_hook();
$conflict=rcs_commit($file, $message,
$form->field("rcsinfo"),
@@ -592,10 +540,6 @@ sub cgi_editpage ($$) { #{{{
# may have been committed while the post-commit hook was
# disabled.
require IkiWiki::Render;
- # Reload index, since the first time it's loaded is before
- # the wiki is locked, and things may have changed in the
- # meantime.
- loadindex();
refresh();
saveindex();
@@ -667,14 +611,9 @@ sub cgi (;$$) { #{{{
}
}
- # Things that do not need a session.
- if ($do eq 'recentchanges') {
- cgi_recentchanges($q);
- return;
- }
-
# Need to lock the wiki before getting a session.
lockwiki();
+ loadindex();
if (! $session) {
$session=cgi_getsession($q);
@@ -726,32 +665,4 @@ sub cgi (;$$) { #{{{
}
} #}}}
-sub userlink ($) { #{{{
- my $user=shift;
-
- eval q{use CGI 'escapeHTML'};
- error($@) if $@;
- if ($user =~ m!^https?://! &&
- eval q{use Net::OpenID::VerifiedIdentity; 1} && !$@) {
- # Munge user-urls, as used by eg, OpenID.
- my $oid=Net::OpenID::VerifiedIdentity->new(identity => $user);
- my $display=$oid->display;
- # Convert "user.somehost.com" to "user [somehost.com]".
- if ($display !~ /\[/) {
- $display=~s/^(.*?)\.([^.]+\.[a-z]+)$/$1 [$2]/;
- }
- # Convert "http://somehost.com/user" to "user [somehost.com]".
- if ($display !~ /\[/) {
- $display=~s/^https?:\/\/(.+)\/([^\/]+)$/$2 [$1]/;
- }
- $display=~s!^https?://!!; # make sure this is removed
- return "<a href=\"$user\">".escapeHTML($display)."</a>";
- }
- else {
- return htmllink("", "", escapeHTML(
- length $config{userdir} ? $config{userdir}."/".$user : $user
- ), noimageinline => 1);
- }
-} #}}}
-
1
diff --git a/IkiWiki/Plugin/aggregate.pm b/IkiWiki/Plugin/aggregate.pm
index 71368e254..ba40ee6bc 100644
--- a/IkiWiki/Plugin/aggregate.pm
+++ b/IkiWiki/Plugin/aggregate.pm
@@ -33,43 +33,62 @@ sub getopt () { #{{{
sub checkconfig () { #{{{
if ($config{aggregate} && ! ($config{post_commit} &&
IkiWiki::commit_hook_enabled())) {
- if (! IkiWiki::lockwiki(0)) {
- debug("wiki is locked by another process, not aggregating");
- exit 1;
+ # See if any feeds need aggregation.
+ loadstate();
+ my @feeds=needsaggregate();
+ return unless @feeds;
+ if (! lockaggregate()) {
+ debug("an aggregation process is already running");
+ return;
}
-
+ # force a later rebuild of source pages
+ $IkiWiki::forcerebuild{$_->{sourcepage}}=1
+ foreach @feeds;
+
# Fork a child process to handle the aggregation.
- # The parent process will then handle building the result.
- # This avoids messy code to clear state accumulated while
- # aggregating.
+ # The parent process will then handle building the
+ # result. This avoids messy code to clear state
+ # accumulated while aggregating.
defined(my $pid = fork) or error("Can't fork: $!");
if (! $pid) {
- loadstate();
IkiWiki::loadindex();
- aggregate();
+
+ # Aggregation happens without the main wiki lock
+ # being held. This allows editing pages etc while
+ # aggregation is running.
+ aggregate(@feeds);
+
+ IkiWiki::lockwiki;
+ # Merge changes, since aggregation state may have
+ # changed on disk while the aggregation was happening.
+ mergestate();
expire();
savestate();
+ IkiWiki::unlockwiki;
exit 0;
}
waitpid($pid,0);
if ($?) {
error "aggregation failed with code $?";
}
-
- IkiWiki::unlockwiki();
+
+ clearstate();
+ unlockaggregate();
}
} #}}}
sub needsbuild (@) { #{{{
my $needsbuild=shift;
- loadstate(); # if not already loaded
+ loadstate();
foreach my $feed (values %feeds) {
- if (grep { $_ eq $pagesources{$feed->{sourcepage}} } @$needsbuild) {
- # Mark all feeds originating on this page as removable;
- # preprocess will unmark those that still exist.
- remove_feeds($feed->{sourcepage});
+ if (exists $pagesources{$feed->{sourcepage}} &&
+ grep { $_ eq $pagesources{$feed->{sourcepage}} } @$needsbuild) {
+ # Mark all feeds originating on this page as
+ # not yet seen; preprocess will unmark those that
+ # still exist.
+ markunseen($feed->{sourcepage});
}
}
} # }}}
@@ -102,8 +121,7 @@ sub preprocess (@) { #{{{
$feed->{updateinterval}=defined $params{updateinterval} ? $params{updateinterval} * 60 : 15 * 60;
$feed->{expireage}=defined $params{expireage} ? $params{expireage} : 0;
$feed->{expirecount}=defined $params{expirecount} ? $params{expirecount} : 0;
- delete $feed->{remove};
- delete $feed->{expired};
+ delete $feed->{unseen};
$feed->{lastupdate}=0 unless defined $feed->{lastupdate};
$feed->{numposts}=0 unless defined $feed->{numposts};
$feed->{newposts}=0 unless defined $feed->{newposts};
@@ -133,11 +151,22 @@ sub delete (@) { #{{{
# Remove feed data for removed pages.
foreach my $file (@files) {
my $page=pagename($file);
- remove_feeds($page);
+ markunseen($page);
+ }
+} #}}}
+
+sub markunseen ($) { #{{{
+ my $page=shift;
+
+ foreach my $id (keys %feeds) {
+ if ($feeds{$id}->{sourcepage} eq $page) {
+ $feeds{$id}->{unseen}=1;
+ }
}
} #}}}
my $state_loaded=0;
+
sub loadstate () { #{{{
return if $state_loaded;
$state_loaded=1;
@@ -176,32 +205,13 @@ sub loadstate () { #{{{
sub savestate () { #{{{
return unless $state_loaded;
+ garbage_collect();
eval q{use HTML::Entities};
error($@) if $@;
my $newfile="$config{wikistatedir}/aggregate.new";
my $cleanup = sub { unlink($newfile) };
open (OUT, ">$newfile") || error("open $newfile: $!", $cleanup);
foreach my $data (values %feeds, values %guids) {
- if ($data->{remove}) {
- if ($data->{name}) {
- foreach my $guid (values %guids) {
- if ($guid->{feed} eq $data->{name}) {
- $guid->{remove}=1;
- }
- }
- }
- else {
- unlink pagefile($data->{page})
- if exists $data->{page};
- }
- next;
- }
- elsif ($data->{expired} && exists $data->{page}) {
- unlink pagefile($data->{page});
- delete $data->{page};
- delete $data->{md5};
- }
-
my @line;
foreach my $field (keys %$data) {
if ($field eq "name" || $field eq "feed" ||
@@ -222,6 +232,69 @@ sub savestate () { #{{{
error("rename $newfile: $!", $cleanup);
} #}}}
+sub garbage_collect () { #{{{
+ foreach my $name (keys %feeds) {
+ # remove any feeds that were not seen while building the pages
+ # that used to contain them
+ if ($feeds{$name}->{unseen}) {
+ delete $feeds{$name};
+ }
+ }
+
+ foreach my $guid (values %guids) {
+ # any guid whose feed is gone should be removed
+ if (! exists $feeds{$guid->{feed}}) {
+ unlink pagefile($guid->{page})
+ if exists $guid->{page};
+ delete $guids{$guid->{guid}};
+ }
+ # handle expired guids
+ elsif ($guid->{expired} && exists $guid->{page}) {
+ unlink pagefile($guid->{page});
+ delete $guid->{page};
+ delete $guid->{md5};
+ }
+ }
+} #}}}
+
+sub mergestate () { #{{{
+ # Load the current state in from disk, and merge into it
+ # values from the state in memory that might have changed
+ # during aggregation.
+ my %myfeeds=%feeds;
+ my %myguids=%guids;
+ clearstate();
+ loadstate();
+
+ # All that can change in feed state during aggregation is a few
+ # fields.
+ foreach my $name (keys %myfeeds) {
+ if (exists $feeds{$name}) {
+ foreach my $field (qw{message lastupdate numposts
+ newposts error}) {
+ $feeds{$name}->{$field}=$myfeeds{$name}->{$field};
+ }
+ }
+ }
+
+ # New guids can be created during aggregation.
+ # It's also possible that guids were removed from the on-disk state
+ # while the aggregation was in process. That would only happen if
+ # their feed was also removed, so any removed guids added back here
+ # will be garbage collected later.
+ foreach my $guid (keys %myguids) {
+ if (! exists $guids{$guid}) {
+ $guids{$guid}=$myguids{$guid};
+ }
+ }
+} #}}}
+
+sub clearstate () { #{{{
+ %feeds=();
+ %guids=();
+ $state_loaded=0;
+} #}}}
+
sub expire () { #{{{
foreach my $feed (values %feeds) {
next unless $feed->{expireage} || $feed->{expirecount};
@@ -253,7 +326,12 @@ sub expire () { #{{{
}
} #}}}
-sub aggregate () { #{{{
+sub needsaggregate () { #{{{
+ return values %feeds if $config{rebuild};
+ return grep { time - $_->{lastupdate} >= $_->{updateinterval} } values %feeds;
+} #}}}
+
+sub aggregate (@) { #{{{
eval q{use XML::Feed};
error($@) if $@;
eval q{use URI::Fetch};
@@ -261,15 +339,12 @@ sub aggregate () { #{{{
eval q{use HTML::Entities};
error($@) if $@;
- foreach my $feed (values %feeds) {
- next unless $config{rebuild} ||
- time - $feed->{lastupdate} >= $feed->{updateinterval};
+ foreach my $feed (@_) {
$feed->{lastupdate}=time;
$feed->{newposts}=0;
$feed->{message}=sprintf(gettext("processed ok at %s"),
displaytime($feed->{lastupdate}));
$feed->{error}=0;
- $IkiWiki::forcerebuild{$feed->{sourcepage}}=1;
debug(sprintf(gettext("checking feed %s ..."), $feed->{name}));
@@ -477,18 +552,6 @@ sub htmlabs ($$) { #{{{
return $ret;
} #}}}
-sub remove_feeds () { #{{{
- my $page=shift;
-
- my %removed;
- foreach my $id (keys %feeds) {
- if ($feeds{$id}->{sourcepage} eq $page) {
- $feeds{$id}->{remove}=1;
- $removed{$id}=1;
- }
- }
-} #}}}
-
sub pagefile ($) { #{{{
my $page=shift;
@@ -499,4 +562,26 @@ sub htmlfn ($) { #{{{
return shift().".".$config{htmlext};
} #}}}
+my $aggregatelock;
+
+sub lockaggregate () { #{{{
+ # Take an exclusive lock to prevent multiple concurrent aggregators.
+ # Returns true if the lock was aquired.
+ if (! -d $config{wikistatedir}) {
+ mkdir($config{wikistatedir});
+ }
+ open($aggregatelock, '>', "$config{wikistatedir}/aggregatelock") ||
+ error ("cannot open to $config{wikistatedir}/aggregatelock: $!");
+ if (! flock($aggregatelock, 2 | 4)) { # LOCK_EX | LOCK_NB
+ close($aggregatelock) || error("failed closing aggregatelock: $!");
+ return 0;
+ }
+ return 1;
+} #}}}
+
+sub unlockaggregate () { #{{{
+ return close($aggregatelock) if $aggregatelock;
+ return;
+} #}}}
+
1
diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm
index 4bb4c2c21..aed087eed 100644
--- a/IkiWiki/Plugin/calendar.pm
+++ b/IkiWiki/Plugin/calendar.pm
@@ -390,7 +390,8 @@ sub needsbuild (@) { #{{{
# the current day
push @$needsbuild, $pagesources{$page};
}
- if (grep { $_ eq $pagesources{$page} } @$needsbuild) {
+ if (exists $pagesources{$page} &&
+ grep { $_ eq $pagesources{$page} } @$needsbuild) {
# remove state, will be re-added if
# the calendar is still there during the
# rebuild
diff --git a/IkiWiki/Plugin/ddate.pm b/IkiWiki/Plugin/ddate.pm
index 6b67f4202..d081cb509 100644
--- a/IkiWiki/Plugin/ddate.pm
+++ b/IkiWiki/Plugin/ddate.pm
@@ -18,6 +18,10 @@ sub checkconfig () { #{{{
sub IkiWiki::displaytime ($;$) { #{{{
my $time=shift;
+ my $format=shift;
+ if (! defined $format) {
+ $format=$config{timeformat};
+ }
eval q{
use DateTime;
use DateTime::Calendar::Discordian;
@@ -27,7 +31,7 @@ sub IkiWiki::displaytime ($;$) { #{{{
}
my $dt = DateTime->from_epoch(epoch => $time);
my $dd = DateTime::Calendar::Discordian->from_object(object => $dt);
- return $dd->strftime($IkiWiki::config{timeformat});
+ return $dd->strftime($format);
} #}}}
5
diff --git a/IkiWiki/Plugin/edittemplate.pm b/IkiWiki/Plugin/edittemplate.pm
index aa72b0845..b7651ce02 100644
--- a/IkiWiki/Plugin/edittemplate.pm
+++ b/IkiWiki/Plugin/edittemplate.pm
@@ -21,7 +21,8 @@ sub needsbuild (@) { #{{{
foreach my $page (keys %pagestate) {
if (exists $pagestate{$page}{edittemplate}) {
- if (grep { $_ eq $pagesources{$page} } @$needsbuild) {
+ if (exists $pagesources{$page} &&
+ grep { $_ eq $pagesources{$page} } @$needsbuild) {
# remove state, it will be re-added
# if the preprocessor directive is still
# there during the rebuild
diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm
index 59eabb606..b40303078 100644
--- a/IkiWiki/Plugin/inline.pm
+++ b/IkiWiki/Plugin/inline.pm
@@ -34,6 +34,8 @@ sub getopt () { #{{{
GetOptions(
"rss!" => \$config{rss},
"atom!" => \$config{atom},
+ "allowrss!" => \$config{allowrss},
+ "allowatom!" => \$config{allowatom},
);
}
@@ -91,11 +93,10 @@ sub preprocess_inline (@) { #{{{
}
my $raw=yesno($params{raw});
my $archive=yesno($params{archive});
- my $rss=($config{rss} && exists $params{rss}) ? yesno($params{rss}) : $config{rss};
- my $atom=($config{atom} && exists $params{atom}) ? yesno($params{atom}) : $config{atom};
+ my $rss=(($config{rss} || $config{allowrss}) && exists $params{rss}) ? yesno($params{rss}) : $config{rss};
+ my $atom=(($config{atom} || $config{allowatom}) && exists $params{atom}) ? yesno($params{atom}) : $config{atom};
my $quick=exists $params{quick} ? yesno($params{quick}) : 0;
my $feeds=exists $params{feeds} ? yesno($params{feeds}) : !$quick;
- $feeds=0 if $params{preview};
my $feedonly=yesno($params{feedonly});
if (! exists $params{show} && ! $archive) {
$params{show}=10;
@@ -182,7 +183,7 @@ sub preprocess_inline (@) { #{{{
my $atomurl=basename(atompage($params{destpage}).$feednum) if $feeds && $atom;
my $ret="";
- if ($config{cgiurl} && (exists $params{rootpage} ||
+ if ($config{cgiurl} && ! $params{preview} && (exists $params{rootpage} ||
(exists $params{postform} && yesno($params{postform})))) {
# Add a blog post form, with feed buttons.
my $formtemplate=template("blogpost.tmpl", blind_cache => 1);
@@ -201,7 +202,7 @@ sub preprocess_inline (@) { #{{{
}
$ret.=$formtemplate->output;
}
- elsif ($feeds) {
+ elsif ($feeds && !$params{preview}) {
# Add feed buttons.
my $linktemplate=template("feedlink.tmpl", blind_cache => 1);
$linktemplate->param(rssurl => $rssurl) if $rss;
@@ -231,6 +232,8 @@ sub preprocess_inline (@) { #{{{
$template->param(pageurl => urlto(bestlink($params{page}, $page), $params{destpage}));
$template->param(title => pagetitle(basename($page)));
$template->param(ctime => displaytime($pagectime{$page}, $params{timeformat}));
+ $template->param(first => 1) if $page eq $list[0];
+ $template->param(last => 1) if $page eq $list[$#list];
if ($actions) {
my $file = $pagesources{$page};
@@ -286,18 +289,22 @@ sub preprocess_inline (@) { #{{{
if ($rss) {
my $rssp=rsspage($params{destpage}).$feednum;
will_render($params{destpage}, $rssp);
- writefile($rssp, $config{destdir},
- genfeed("rss", $rssurl, $desc, $params{destpage}, @list));
- $toping{$params{destpage}}=1 unless $config{rebuild};
- $feedlinks{$params{destpage}}=qq{<link rel="alternate" type="application/rss+xml" title="RSS" href="$rssurl" />};
+ if (! $params{preview}) {
+ writefile($rssp, $config{destdir},
+ genfeed("rss", $rssurl, $desc, $params{destpage}, @list));
+ $toping{$params{destpage}}=1 unless $config{rebuild};
+ $feedlinks{$params{destpage}}=qq{<link rel="alternate" type="application/rss+xml" title="RSS" href="$rssurl" />};
+ }
}
if ($atom) {
my $atomp=atompage($params{destpage}).$feednum;
will_render($params{destpage}, $atomp);
- writefile($atomp, $config{destdir},
- genfeed("atom", $atomurl, $desc, $params{destpage}, @list));
- $toping{$params{destpage}}=1 unless $config{rebuild};
- $feedlinks{$params{destpage}}=qq{<link rel="alternate" type="application/atom+xml" title="Atom" href="$atomurl" />};
+ if (! $params{preview}) {
+ writefile($atomp, $config{destdir},
+ genfeed("atom", $atomurl, $desc, $params{destpage}, @list));
+ $toping{$params{destpage}}=1 unless $config{rebuild};
+ $feedlinks{$params{destpage}}=qq{<link rel="alternate" type="application/atom+xml" title="Atom" href="$atomurl" />};
+ }
}
}
diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm
index d2c6e7f8b..621e87674 100644
--- a/IkiWiki/Plugin/meta.pm
+++ b/IkiWiki/Plugin/meta.pm
@@ -6,13 +6,7 @@ use warnings;
use strict;
use IkiWiki 2.00;
-my %meta;
-my %title;
-my %permalink;
-my %author;
-my %authorurl;
-my %license;
-my %copyright;
+my %metaheaders;
sub import { #{{{
hook(type => "needsbuild", id => "meta", call => \&needsbuild);
@@ -24,7 +18,8 @@ sub needsbuild (@) { #{{{
my $needsbuild=shift;
foreach my $page (keys %pagestate) {
if (exists $pagestate{$page}{meta}) {
- if (grep { $_ eq $pagesources{$page} } @$needsbuild) {
+ if (exists $pagesources{$page} &&
+ grep { $_ eq $pagesources{$page} } @$needsbuild) {
# remove state, it will be re-added
# if the preprocessor directive is still
# there during the rebuild
@@ -71,16 +66,16 @@ sub preprocess (@) { #{{{
# Metadata collection that needs to happen during the scan pass.
if ($key eq 'title') {
- $title{$page}=HTML::Entities::encode_numeric($value);
+ $pagestate{$page}{meta}{title}=HTML::Entities::encode_numeric($value);
}
elsif ($key eq 'license') {
- push @{$meta{$page}}, '<link rel="license" href="#page_license" />';
- $license{$page}=$value;
+ push @{$metaheaders{$page}}, '<link rel="license" href="#page_license" />';
+ $pagestate{$page}{meta}{license}=$value;
return "";
}
elsif ($key eq 'copyright') {
- push @{$meta{$page}}, '<link rel="copyright" href="#page_copyright" />';
- $copyright{$page}=$value;
+ push @{$metaheaders{$page}}, '<link rel="copyright" href="#page_copyright" />';
+ $pagestate{$page}{meta}{copyright}=$value;
return "";
}
elsif ($key eq 'link' && ! %params) {
@@ -89,11 +84,11 @@ sub preprocess (@) { #{{{
return "";
}
elsif ($key eq 'author') {
- $author{$page}=$value;
+ $pagestate{$page}{meta}{author}=$value;
# fallthorough
}
elsif ($key eq 'authorurl') {
- $authorurl{$page}=$value;
+ $pagestate{$page}{meta}{authorurl}=$value;
# fallthrough
}
@@ -111,8 +106,8 @@ sub preprocess (@) { #{{{
}
}
elsif ($key eq 'permalink') {
- $permalink{$page}=$value;
- push @{$meta{$page}}, scrub('<link rel="bookmark" href="'.encode_entities($value).'" />');
+ $pagestate{$page}{meta}{permalink}=$value;
+ push @{$metaheaders{$page}}, scrub('<link rel="bookmark" href="'.encode_entities($value).'" />');
}
elsif ($key eq 'stylesheet') {
my $rel=exists $params{rel} ? $params{rel} : "alternate stylesheet";
@@ -123,17 +118,17 @@ sub preprocess (@) { #{{{
if (! length $stylesheet) {
return "[[meta ".gettext("stylesheet not found")."]]";
}
- push @{$meta{$page}}, '<link href="'.urlto($stylesheet, $page).
+ push @{$metaheaders{$page}}, '<link href="'.urlto($stylesheet, $page).
'" rel="'.encode_entities($rel).
'" title="'.encode_entities($title).
"\" type=\"text/css\" />";
}
elsif ($key eq 'openid') {
if (exists $params{server}) {
- push @{$meta{$page}}, '<link href="'.encode_entities($params{server}).
+ push @{$metaheaders{$page}}, '<link href="'.encode_entities($params{server}).
'" rel="openid.server" />';
}
- push @{$meta{$page}}, '<link href="'.encode_entities($value).
+ push @{$metaheaders{$page}}, '<link href="'.encode_entities($value).
'" rel="openid.delegate" />';
}
elsif ($key eq 'redir') {
@@ -172,11 +167,11 @@ sub preprocess (@) { #{{{
if (! $safe) {
$redir=scrub($redir);
}
- push @{$meta{$page}}, $redir;
+ push @{$metaheaders{$page}}, $redir;
}
elsif ($key eq 'link') {
if (%params) {
- push @{$meta{$page}}, scrub("<link href=\"".encode_entities($value)."\" ".
+ push @{$metaheaders{$page}}, scrub("<link href=\"".encode_entities($value)."\" ".
join(" ", map {
encode_entities($_)."=\"".encode_entities(decode_entities($params{$_}))."\""
} keys %params).
@@ -184,7 +179,7 @@ sub preprocess (@) { #{{{
}
}
else {
- push @{$meta{$page}}, scrub('<meta name="'.encode_entities($key).
+ push @{$metaheaders{$page}}, scrub('<meta name="'.encode_entities($key).
'" content="'.encode_entities($value).'" />');
}
@@ -197,32 +192,80 @@ sub pagetemplate (@) { #{{{
my $destpage=$params{destpage};
my $template=$params{template};
- if (exists $meta{$page} && $template->query(name => "meta")) {
+ if (exists $metaheaders{$page} && $template->query(name => "meta")) {
# avoid duplicate meta lines
my %seen;
- $template->param(meta => join("\n", grep { (! $seen{$_}) && ($seen{$_}=1) } @{$meta{$page}}));
+ $template->param(meta => join("\n", grep { (! $seen{$_}) && ($seen{$_}=1) } @{$metaheaders{$page}}));
}
- if (exists $title{$page} && $template->query(name => "title")) {
- $template->param(title => $title{$page});
+ if (exists $pagestate{$page}{meta}{title} && $template->query(name => "title")) {
+ $template->param(title => $pagestate{$page}{meta}{title});
$template->param(title_overridden => 1);
}
- $template->param(permalink => $permalink{$page})
- if exists $permalink{$page} && $template->query(name => "permalink");
- $template->param(author => $author{$page})
- if exists $author{$page} && $template->query(name => "author");
- $template->param(authorurl => $authorurl{$page})
- if exists $authorurl{$page} && $template->query(name => "authorurl");
- if (exists $license{$page} && $template->query(name => "license") &&
- ($page eq $destpage || ! exists $license{$destpage} ||
- $license{$page} ne $license{$destpage})) {
- $template->param(license => htmlize($page, $destpage, $license{$page}));
+ foreach my $field (qw{author authorurl permalink}) {
+ $template->param($field => $pagestate{$page}{meta}{$field})
+ if exists $pagestate{$page}{meta}{$field} && $template->query(name => $field);
}
- if (exists $copyright{$page} && $template->query(name => "copyright") &&
- ($page eq $destpage || ! exists $copyright{$destpage} ||
- $copyright{$page} ne $copyright{$destpage})) {
- $template->param(copyright => htmlize($page, $destpage, $copyright{$page}));
+
+ foreach my $field (qw{license copyright}) {
+ if (exists $pagestate{$page}{meta}{$field} && $template->query(name => $field) &&
+ ($page eq $destpage || ! exists $pagestate{$destpage}{meta}{$field} ||
+ $pagestate{$page}{meta}{$field} ne $pagestate{$destpage}{meta}{$field})) {
+ $template->param($field => htmlize($page, $destpage, $pagestate{$page}{meta}{$field}));
+ }
}
} # }}}
+sub match { #{{{
+ my $field=shift;
+ my $page=shift;
+
+ # turn glob into a safe regexp
+ my $re=quotemeta(shift);
+ $re=~s/\\\*/.*/g;
+ $re=~s/\\\?/./g;
+
+ my $val;
+ if (exists $pagestate{$page}{meta}{$field}) {
+ $val=$pagestate{$page}{meta}{$field};
+ }
+ elsif ($field eq 'title') {
+ $val=pagetitle($page);
+ }
+
+ if (defined $val) {
+ if ($val=~/^$re$/i) {
+ return IkiWiki::SuccessReason->new("$re matches $field of $page");
+ }
+ else {
+ return IkiWiki::FailReason->new("$re does not match $field of $page");
+ }
+ }
+ else {
+ return IkiWiki::FailReason->new("$page does not have a $field");
+ }
+} #}}}
+
+package IkiWiki::PageSpec;
+
+sub match_title ($$;@) { #{{{
+ IkiWiki::Plugin::meta::match("title", @_);
+} #}}}
+
+sub match_author ($$;@) { #{{{
+ IkiWiki::Plugin::meta::match("author", @_);
+} #}}}
+
+sub match_authorurl ($$;@) { #{{{
+ IkiWiki::Plugin::meta::match("authorurl", @_);
+} #}}}
+
+sub match_license ($$;@) { #{{{
+ IkiWiki::Plugin::meta::match("license", @_);
+} #}}}
+
+sub match_copyright ($$;@) { #{{{
+ IkiWiki::Plugin::meta::match("copyright", @_);
+} #}}}
+
1
diff --git a/IkiWiki/Plugin/openid.pm b/IkiWiki/Plugin/openid.pm
index e8dbe964f..de31f38ee 100644
--- a/IkiWiki/Plugin/openid.pm
+++ b/IkiWiki/Plugin/openid.pm
@@ -164,4 +164,31 @@ sub getobj ($$) { #{{{
);
} #}}}
+package IkiWiki;
+
+# This is not used by this plugin, but this seems the best place to put it.
+# Used elsewhere to pretty-display the name of an openid user.
+sub openiduser ($) { #{{{
+ my $user=shift;
+
+ if ($user =~ m!^https?://! &&
+ eval q{use Net::OpenID::VerifiedIdentity; 1} && !$@) {
+ my $oid=Net::OpenID::VerifiedIdentity->new(identity => $user);
+ my $display=$oid->display;
+ # Convert "user.somehost.com" to "user [somehost.com]".
+ if ($display !~ /\[/) {
+ $display=~s/^(.*?)\.([^.]+\.[a-z]+)$/$1 [$2]/;
+ }
+ # Convert "http://somehost.com/user" to "user [somehost.com]".
+ if ($display !~ /\[/) {
+ $display=~s/^https?:\/\/(.+)\/([^\/]+)$/$2 [$1]/;
+ }
+ $display=~s!^https?://!!; # make sure this is removed
+ eval q{use CGI 'escapeHTML'};
+ error($@) if $@;
+ return escapeHTML($display);
+ }
+ return;
+}
+
1
diff --git a/IkiWiki/Plugin/poll.pm b/IkiWiki/Plugin/poll.pm
index 63c93c62d..41ebd74a0 100644
--- a/IkiWiki/Plugin/poll.pm
+++ b/IkiWiki/Plugin/poll.pm
@@ -7,7 +7,7 @@ use IkiWiki 2.00;
sub import { #{{{
hook(type => "preprocess", id => "poll", call => \&preprocess);
- hook(type => "cgi", id => "poll", call => \&cgi);
+ hook(type => "sessioncgi", id => "poll", call => \&sessioncgi);
} # }}}
sub yesno ($) { #{{{
@@ -74,8 +74,9 @@ sub preprocess (@) { #{{{
return "<div class=poll>$ret</div>";
} # }}}
-sub cgi ($) { #{{{
+sub sessioncgi ($$) { #{{{
my $cgi=shift;
+ my $session=shift;
if (defined $cgi->param('do') && $cgi->param('do') eq "poll") {
my $choice=$cgi->param('choice');
if (! defined $choice) {
@@ -92,7 +93,6 @@ sub cgi ($) { #{{{
# Did they vote before? If so, let them change their vote,
# and check for dups.
- my $session=IkiWiki::cgi_getsession();
my $choice_param="poll_choice_${page}_$num";
my $oldchoice=$session->param($choice_param);
if (defined $oldchoice && $oldchoice eq $choice) {
diff --git a/IkiWiki/Plugin/prettydate.pm b/IkiWiki/Plugin/prettydate.pm
index b6110e427..745e6a1de 100644
--- a/IkiWiki/Plugin/prettydate.pm
+++ b/IkiWiki/Plugin/prettydate.pm
@@ -63,6 +63,10 @@ sub checkconfig () { #{{{
sub IkiWiki::displaytime ($;$) { #{{{
my $time=shift;
+ my $format=shift;
+ if (! defined $format) {
+ $format=$config{prettydateformat};
+ }
eval q{use Date::Format};
error($@) if $@;
@@ -93,7 +97,6 @@ sub IkiWiki::displaytime ($;$) { #{{{
$t=~s{\%A-}{my @yest=@t; $yest[6]--; strftime("%A", \@yest)}eg;
- my $format=$config{prettydateformat};
$format=~s/\%X/$t/g;
return strftime($format, \@t);
} #}}}
diff --git a/IkiWiki/Plugin/recentchanges.pm b/IkiWiki/Plugin/recentchanges.pm
new file mode 100644
index 000000000..22f934f2e
--- /dev/null
+++ b/IkiWiki/Plugin/recentchanges.pm
@@ -0,0 +1,169 @@
+#!/usr/bin/perl
+package IkiWiki::Plugin::recentchanges;
+
+use warnings;
+use strict;
+use IkiWiki 2.00;
+
+sub import { #{{{
+ hook(type => "checkconfig", id => "recentchanges", call => \&checkconfig);
+ hook(type => "refresh", id => "recentchanges", call => \&refresh);
+ hook(type => "pagetemplate", id => "recentchanges", call => \&pagetemplate);
+ hook(type => "htmlize", id => "_change", call => \&htmlize);
+ hook(type => "cgi", id => "recentchanges", call => \&cgi);
+} #}}}
+
+sub checkconfig () { #{{{
+ $config{recentchangespage}='recentchanges' unless defined $config{recentchangespage};
+ $config{recentchangesnum}=100 unless defined $config{recentchangesnum};
+} #}}}
+
+sub refresh ($) { #{{{
+ my %seen;
+
+ # 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 =~ /\._change$/ && ! $seen{$page}) {
+ unlink($config{srcdir}.'/'.$pagesources{$page});
+ }
+ }
+} #}}}
+
+# Enable the recentchanges link on wiki pages.
+sub pagetemplate (@) { #{{{
+ my %params=@_;
+ my $template=$params{template};
+ my $page=$params{page};
+ if ($config{rcs} && $page ne $config{recentchangespage} &&
+ $template->query(name => "recentchangesurl")) {
+ $template->param(recentchangesurl => urlto($config{recentchangespage}, $page));
+ $template->param(have_actions => 1);
+ }
+} #}}}
+
+# Pages with extension _change have plain html markup, pass through.
+sub htmlize (@) { #{{{
+ my %params=@_;
+ return $params{content};
+} #}}}
+
+sub cgi ($) { #{{{
+ my $cgi=shift;
+ if (defined $cgi->param('do') && $cgi->param('do') eq "recentchanges_link") {
+ # This is a link from a change page to some
+ # other page. Since the change pages are only generated
+ # once, statically, links on them won't be updated if the
+ # page they link to is deleted, or newly created, or
+ # changes for whatever reason. So this CGI handles that
+ # dynamic linking stuff.
+ my $page=$cgi->param("page");
+ if (!defined $page) {
+ error("missing page parameter");
+ }
+
+ IkiWiki::loadindex();
+
+ my $link=bestlink("", $page);
+ if (! length $link) {
+ print "Content-type: text/html\n\n";
+ print IkiWiki::misctemplate(gettext(gettext("missing page")),
+ "<p>".
+ sprintf(gettext("The page %s does not exist."),
+ htmllink("", "", $page)).
+ "</p>");
+ }
+ else {
+ IkiWiki::redirect($cgi, $config{url}."/".htmlpage($link));
+ }
+
+ exit;
+ }
+}
+
+sub store ($$$) { #{{{
+ my $change=shift;
+
+ 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).
+ return $page if exists $pagesources{$page} && ! $config{rebuild};
+
+ # Limit pages to first 10, and add links to the changed pages.
+ my $is_excess = exists $change->{pages}[10];
+ delete @{$change->{pages}}[10 .. @{$change->{pages}}] if $is_excess;
+ $change->{pages} = [
+ map {
+ if (length $config{cgiurl}) {
+ $_->{link} = "<a href=\"".
+ IkiWiki::cgiurl(
+ do => "recentchanges_link",
+ page => $_->{page}
+ ).
+ "\">".
+ IkiWiki::pagetitle($_->{page}).
+ "</a>"
+ }
+ else {
+ $_->{link} = IkiWiki::pagetitle($_->{page});
+ }
+ $_->{baseurl}="$config{url}/" if length $config{url};
+
+ $_;
+ } @{$change->{pages}}
+ ];
+ push @{$change->{pages}}, { link => '...' } if $is_excess;
+
+ # See if the committer is an openid.
+ $change->{author}=$change->{user};
+ my $oiduser=eval { IkiWiki::openiduser($change->{user}) };
+ if (defined $oiduser) {
+ $change->{authorurl}=$change->{user};
+ $change->{user}=$oiduser;
+ }
+ elsif (length $config{cgiurl}) {
+ $change->{authorurl} = IkiWiki::cgiurl(
+ do => "recentchanges_link",
+ page => (length $config{userdir} ? "$config{userdir}/" : "").$change->{author},
+ );
+ }
+
+ # escape wikilinks and preprocessor stuff in commit messages
+ if (ref $change->{message}) {
+ foreach my $field (@{$change->{message}}) {
+ if (exists $field->{line}) {
+ $field->{line} =~ s/(?<!\\)\[\[/\\\[\[/g;
+ }
+ }
+ }
+
+ # Fill out a template with the change info.
+ my $template=template("change.tmpl", blind_cache => 1);
+ $template->param(
+ %$change,
+ commitdate => displaytime($change->{when}, "%X %x"),
+ wikiname => $config{wikiname},
+ );
+ IkiWiki::run_hooks(pagetemplate => sub {
+ shift->(page => $page, destpage => $page, template => $template);
+ });
+
+ my $file=$page."._change";
+ writefile($file, $config{srcdir}, $template->output);
+ utime $change->{when}, $change->{when}, "$config{srcdir}/$file";
+
+ return $page;
+} #}}}
+
+sub updatechanges ($$) { #{{{
+ my $subdir=shift;
+ my @changes=@{shift()};
+
+} #}}}
+
+1
diff --git a/IkiWiki/Plugin/teximg.pm b/IkiWiki/Plugin/teximg.pm
index 5f9589fdd..5dff5feef 100644
--- a/IkiWiki/Plugin/teximg.pm
+++ b/IkiWiki/Plugin/teximg.pm
@@ -82,8 +82,8 @@ sub create ($$$) { #{{{
$logurl = urlto($imglog, $params->{destpage});
}
else {
- $imgurl="$params->{page}/$digest.png";
- $logurl="$params->{page}/$digest.log";
+ $imgurl=$params->{page}."/$digest.png";
+ $logurl=$params->{page}."/$digest.log";
}
if (-e "$config{destdir}/$imglink" ||
diff --git a/IkiWiki/Plugin/version.pm b/IkiWiki/Plugin/version.pm
index d39fd9419..f96d2df06 100644
--- a/IkiWiki/Plugin/version.pm
+++ b/IkiWiki/Plugin/version.pm
@@ -18,7 +18,8 @@ sub needsbuild (@) { #{{{
if ($pagestate{$page}{version}{shown} ne $IkiWiki::version) {
push @$needsbuild, $pagesources{$page};
}
- if (grep { $_ eq $pagesources{$page} } @$needsbuild) {
+ if (exists $pagesources{$page} &&
+ grep { $_ eq $pagesources{$page} } @$needsbuild) {
# remove state, will be re-added if
# the version is still shown during the
# rebuild
diff --git a/IkiWiki/Rcs/Stub.pm b/IkiWiki/Rcs/Stub.pm
index 19ecfa88d..df347f6a9 100644
--- a/IkiWiki/Rcs/Stub.pm
+++ b/IkiWiki/Rcs/Stub.pm
@@ -37,6 +37,7 @@ sub rcs_recentchanges ($) {
# Examine the RCS history and generate a list of recent changes.
# The data structure returned for each change is:
# {
+ # rev => # the RCSs id for this commit
# user => # name of user who made the change,
# committype => # either "web" or the name of the rcs,
# when => # time when the change was made,
@@ -56,13 +57,6 @@ sub rcs_recentchanges ($) {
# }
}
-sub rcs_notify () {
- # This function is called when a change is committed to the wiki,
- # and ikiwiki is running as a post-commit hook from the RCS.
- # It should examine the repository to somehow determine what pages
- # changed, and then send emails to users subscribed to those pages.
-}
-
sub rcs_getctime ($) {
# Optional, used to get the page creation time from the RCS.
error gettext("getctime not implemented");
diff --git a/IkiWiki/Rcs/bzr.pm b/IkiWiki/Rcs/bzr.pm
new file mode 100644
index 000000000..a04bfe1cb
--- /dev/null
+++ b/IkiWiki/Rcs/bzr.pm
@@ -0,0 +1,166 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+use IkiWiki;
+use Encode;
+use open qw{:utf8 :std};
+
+package IkiWiki;
+
+sub bzr_log ($) { #{{{
+ my $out = shift;
+ my @infos = ();
+ my $key = undef;
+
+ while (<$out>) {
+ my $line = $_;
+ my ($value);
+ if ($line =~ /^message:/) {
+ $key = "message";
+ $infos[$#infos]{$key} = "";
+ }
+ elsif ($line =~ /^(modified|added|renamed|renamed and modified|removed):/) {
+ $key = "files";
+ unless (defined($infos[$#infos]{$key})) { $infos[$#infos]{$key} = ""; }
+ }
+ elsif (defined($key) and $line =~ /^ (.*)/) {
+ $infos[$#infos]{$key} .= $1;
+ }
+ elsif ($line eq "------------------------------------------------------------\n") {
+ $key = undef;
+ push (@infos, {});
+ }
+ else {
+ chomp $line;
+ ($key, $value) = split /: +/, $line, 2;
+ $infos[$#infos]{$key} = $value;
+ }
+ }
+ close $out;
+
+ return @infos;
+} #}}}
+
+sub rcs_update () { #{{{
+ my @cmdline = ("bzr", $config{srcdir}, "update");
+ if (system(@cmdline) != 0) {
+ warn "'@cmdline' failed: $!";
+ }
+} #}}}
+
+sub rcs_prepedit ($) { #{{{
+ return "";
+} #}}}
+
+sub rcs_commit ($$$;$$) { #{{{
+ my ($file, $message, $rcstoken, $user, $ipaddr) = @_;
+
+ if (defined $user) {
+ $user = possibly_foolish_untaint($user);
+ }
+ elsif (defined $ipaddr) {
+ $user = "Anonymous from ".possibly_foolish_untaint($ipaddr);
+ }
+ else {
+ $user = "Anonymous";
+ }
+
+ $message = possibly_foolish_untaint($message);
+ if (! length $message) {
+ $message = "no message given";
+ }
+
+ my @cmdline = ("bzr", "commit", "-m", $message, "--author", $user,
+ $config{srcdir}."/".$file);
+ if (system(@cmdline) != 0) {
+ warn "'@cmdline' failed: $!";
+ }
+
+ return undef; # success
+} #}}}
+
+sub rcs_add ($) { # {{{
+ my ($file) = @_;
+
+ my @cmdline = ("bzr", "add", "$config{srcdir}/$file");
+ if (system(@cmdline) != 0) {
+ warn "'@cmdline' failed: $!";
+ }
+} #}}}
+
+sub rcs_recentchanges ($) { #{{{
+ my ($num) = @_;
+
+ eval q{use CGI 'escapeHTML'};
+ error($@) if $@;
+
+ my @cmdline = ("bzr", "log", "-v", "--show-ids", "--limit", $num,
+ $config{srcdir});
+ open (my $out, "@cmdline |");
+
+ eval q{use Date::Parse};
+ error($@) if $@;
+
+ my @ret;
+ foreach my $info (bzr_log($out)) {
+ my @pages = ();
+ my @message = ();
+
+ foreach my $msgline (split(/\n/, $info->{message})) {
+ push @message, { line => $msgline };
+ }
+
+ foreach my $file (split(/\n/, $info->{files})) {
+ my ($filename, $fileid) = split(/[ \t]+/, $file);
+ my $diffurl = $config{'diffurl'};
+ $diffurl =~ s/\[\[file\]\]/$filename/go;
+ $diffurl =~ s/\[\[file-id\]\]/$fileid/go;
+ $diffurl =~ s/\[\[r2\]\]/$info->{revno}/go;
+
+ push @pages, {
+ page => pagename($filename),
+ diffurl => $diffurl,
+ };
+ }
+
+ my $user = $info->{"committer"};
+ if (defined($info->{"author"})) { $user = $info->{"author"}; }
+ $user =~ s/\s*<.*>\s*$//;
+ $user =~ s/^\s*//;
+
+ push @ret, {
+ rev => $info->{"revno"},
+ user => $user,
+ committype => "bzr",
+ when => time - str2time($info->{"timestamp"}),
+ message => [@message],
+ pages => [@pages],
+ };
+ }
+
+ return @ret;
+} #}}}
+
+sub rcs_getctime ($) { #{{{
+ my ($file) = @_;
+
+ # XXX filename passes through the shell here, should try to avoid
+ # that just in case
+ my @cmdline = ("bzr", "log", "--limit", '1', "$config{srcdir}/$file");
+ open (my $out, "@cmdline |");
+
+ my @log = bzr_log($out);
+
+ if (length @log < 1) {
+ return 0;
+ }
+
+ eval q{use Date::Parse};
+ error($@) if $@;
+
+ my $ctime = str2time($log[0]->{"timestamp"});
+ return $ctime;
+} #}}}
+
+1
diff --git a/IkiWiki/Rcs/git.pm b/IkiWiki/Rcs/git.pm
index fea1c11eb..26a6f4266 100644
--- a/IkiWiki/Rcs/git.pm
+++ b/IkiWiki/Rcs/git.pm
@@ -247,8 +247,6 @@ sub _parse_diff_tree ($@) { #{{{
last;
}
- debug("No detail in diff-tree output") if !defined $ci{'details'};
-
return \%ci;
} #}}}
@@ -374,7 +372,7 @@ sub rcs_recentchanges ($) { #{{{
my ($sha1, $when) = (
$ci->{'sha1'},
- time - $ci->{'author_epoch'}
+ $ci->{'author_epoch'}
);
my (@pages, @messages);
@@ -421,50 +419,6 @@ sub rcs_recentchanges ($) { #{{{
return @rets;
} #}}}
-sub rcs_notify () { #{{{
- # Send notification mail to subscribed users.
- #
- # In usual Git usage, hooks/update script is presumed to send
- # notification mails (see git-receive-pack(1)). But we prefer
- # hooks/post-update to support IkiWiki commits coming from a
- # cloned repository (through command line) because post-update
- # is called _after_ each ref in repository is updated (update
- # hook is called _before_ the repository is updated). Since
- # post-update hook does not accept command line arguments, we
- # don't have an $ENV variable in this function.
- #
- # Here, we rely on a simple fact: we can extract all parts of the
- # notification content by parsing the "HEAD" commit (which also
- # triggers a refresh of IkiWiki pages).
-
- my $ci = git_commit_info('HEAD');
- return if !defined $ci;
-
- my @changed_pages = map { $_->{'file'} } @{ $ci->{'details'} };
-
- my ($user, $message);
- if (@{ $ci->{'comment'} }[0] =~ m/$config{web_commit_regexp}/) {
- $user = defined $2 ? "$2" : "$3";
- $message = $4;
- }
- else {
- $user = $ci->{'author_username'};
- $message = join "\n", @{ $ci->{'comment'} };
- }
-
- my $sha1 = $ci->{'sha1'};
-
- require IkiWiki::UserInfo;
- send_commit_mails(
- sub {
- $message;
- },
- sub {
- join "\n", run_or_die('git', 'diff', "${sha1}^", $sha1);
- }, $user, @changed_pages
- );
-} #}}}
-
sub rcs_getctime ($) { #{{{
my $file=shift;
# Remove srcdir prefix
diff --git a/IkiWiki/Rcs/mercurial.pm b/IkiWiki/Rcs/mercurial.pm
index 15edb3245..db6a396ac 100644
--- a/IkiWiki/Rcs/mercurial.pm
+++ b/IkiWiki/Rcs/mercurial.pm
@@ -142,7 +142,7 @@ sub rcs_recentchanges ($) { #{{{
rev => $info->{"changeset"},
user => $user,
committype => "mercurial",
- when => time - str2time($info->{"date"}),
+ when => str2time($info->{"date"}),
message => [@message],
pages => [@pages],
};
@@ -151,10 +151,6 @@ sub rcs_recentchanges ($) { #{{{
return @ret;
} #}}}
-sub rcs_notify () { #{{{
- # TODO
-} #}}}
-
sub rcs_getctime ($) { #{{{
my ($file) = @_;
diff --git a/IkiWiki/Rcs/monotone.pm b/IkiWiki/Rcs/monotone.pm
index 5717e0043..c4a6d9864 100644
--- a/IkiWiki/Rcs/monotone.pm
+++ b/IkiWiki/Rcs/monotone.pm
@@ -342,10 +342,10 @@ sub rcs_commit ($$$;$$) { #{{{
return $conflict;
}
if (defined($config{mtnsync}) && $config{mtnsync}) {
- if (system("mtn", "--root=$config{mtnrootdir}", "sync",
+ if (system("mtn", "--root=$config{mtnrootdir}", "push",
"--quiet", "--ticker=none", "--key",
$config{mtnkey}) != 0) {
- debug("monotone sync failed");
+ debug("monotone push failed");
}
}
@@ -416,7 +416,7 @@ sub rcs_recentchanges ($) { #{{{
$committype = "monotone";
}
} elsif ($cert->{name} eq "date") {
- $when = time - str2time($cert->{value}, 'UTC');
+ $when = str2time($cert->{value}, 'UTC');
} elsif ($cert->{name} eq "changelog") {
my $messageText = $cert->{value};
# split the changelog into multiple
@@ -431,10 +431,28 @@ sub rcs_recentchanges ($) { #{{{
my @changed_files = get_changed_files($automator, $rev);
my $file;
+ my ($out, $err) = $automator->call("parents", $rev);
+ my @parents = ($out =~ m/^($sha1_pattern)$/);
+ my $parent = $parents[0];
+
foreach $file (@changed_files) {
- push @pages, {
- page => pagename($file),
- } if length $file;
+ next unless length $file;
+
+ if (defined $config{diffurl} and (@parents == 1)) {
+ my $diffurl=$config{diffurl};
+ $diffurl=~s/\[\[r1\]\]/$parent/g;
+ $diffurl=~s/\[\[r2\]\]/$rev/g;
+ $diffurl=~s/\[\[file\]\]/$file/g;
+ push @pages, {
+ page => pagename($file),
+ diffurl => $diffurl,
+ };
+ }
+ else {
+ push @pages, {
+ page => pagename($file),
+ }
+ }
}
push @ret, {
@@ -452,54 +470,6 @@ sub rcs_recentchanges ($) { #{{{
return @ret;
} #}}}
-sub rcs_notify () { #{{{
- debug("The monotone rcs_notify function is currently untested. Use at own risk!");
-
- if (! exists $ENV{REV}) {
- error(gettext("REV is not set, not running from mtn post-commit hook, cannot send notifications"));
- }
- if ($ENV{REV} !~ m/($sha1_pattern)/) { # sha1 is untainted now
- error(gettext("REV is not a valid revision identifier, cannot send notifications"));
- }
- my $rev = $1;
-
- check_config();
-
- my $automator = Monotone->new();
- $automator->open(undef, $config{mtnrootdir});
-
- my $certs = [read_certs($automator, $rev)];
- my $user;
- my $message;
- my $when;
-
- foreach my $cert (@$certs) {
- if ($cert->{signature} eq "ok" && $cert->{trust} eq "trusted") {
- if ($cert->{name} eq "author") {
- $user = $cert->{value};
- } elsif ($cert->{name} eq "date") {
- $when = $cert->{value};
- } elsif ($cert->{name} eq "changelog") {
- $message = $cert->{value};
- }
- }
- }
-
- my @changed_pages = get_changed_files($automator, $rev);
-
- $automator->close();
-
- require IkiWiki::UserInfo;
- send_commit_mails(
- sub {
- return $message;
- },
- sub {
- `mtn --root=$config{mtnrootdir} au content_diff -r $rev`;
- },
- $user, @changed_pages);
-} #}}}
-
sub rcs_getctime ($) { #{{{
my $file=shift;
@@ -604,4 +574,3 @@ __DATA__
return true
end
}
-EOF
diff --git a/IkiWiki/Rcs/svn.pm b/IkiWiki/Rcs/svn.pm
index 987469ba0..f7d2242f0 100644
--- a/IkiWiki/Rcs/svn.pm
+++ b/IkiWiki/Rcs/svn.pm
@@ -171,7 +171,7 @@ sub rcs_recentchanges ($) { #{{{
my $rev = $logentry->{revision};
my $user = $logentry->{author};
- my $when=time - str2time($logentry->{date}, 'UTC');
+ my $when=str2time($logentry->{date}, 'UTC');
foreach my $msgline (split(/\n/, $logentry->{msg})) {
push @message, { line => $msgline };
@@ -203,7 +203,8 @@ sub rcs_recentchanges ($) { #{{{
diffurl => $diffurl,
} if length $file;
}
- push @ret, { rev => $rev,
+ push @ret, {
+ rev => $rev,
user => $user,
committype => $committype,
when => $when,
@@ -216,44 +217,6 @@ sub rcs_recentchanges ($) { #{{{
return @ret;
} #}}}
-sub rcs_notify () { #{{{
- if (! exists $ENV{REV}) {
- error(gettext("REV is not set, not running from svn post-commit hook, cannot send notifications"));
- }
- my $rev=int(possibly_foolish_untaint($ENV{REV}));
-
- my $user=`svnlook author $config{svnrepo} -r $rev`;
- chomp $user;
-
- my $message=`svnlook log $config{svnrepo} -r $rev`;
- if ($message=~/$config{web_commit_regexp}/) {
- $user=defined $2 ? "$2" : "$3";
- $message=$4;
- }
-
- my @changed_pages;
- foreach my $change (`svnlook changed $config{svnrepo} -r $rev`) {
- chomp $change;
- if (length $config{svnpath}) {
- if ($change =~ /^[A-Z]+\s+\Q$config{svnpath}\E\/(.*)/) {
- push @changed_pages, $1;
- }
- }
- else {
- push @changed_pages, $change;
- }
- }
-
- require IkiWiki::UserInfo;
- send_commit_mails(
- sub {
- return $message;
- },
- sub {
- `svnlook diff $config{svnrepo} -r $rev --no-diff-deleted`;
- }, $user, @changed_pages);
-} #}}}
-
sub rcs_getctime ($) { #{{{
my $file=shift;
diff --git a/IkiWiki/Rcs/tla.pm b/IkiWiki/Rcs/tla.pm
index 1dbc006c1..ecc561bde 100644
--- a/IkiWiki/Rcs/tla.pm
+++ b/IkiWiki/Rcs/tla.pm
@@ -120,7 +120,7 @@ sub rcs_recentchanges ($) {
split(/ /, "$newfiles $modfiles .arch-ids/fake.id");
my $sdate = $head->get("Standard-date");
- my $when = time - str2time($sdate, 'UTC');
+ my $when = str2time($sdate, 'UTC');
my $committype = "web";
if (defined $summ && $summ =~ /$config{web_commit_regexp}/) {
@@ -145,7 +145,8 @@ sub rcs_recentchanges ($) {
diffurl => $diffurl,
} if length $file;
}
- push @ret, { rev => $change,
+ push @ret, {
+ rev => $change,
user => $user,
committype => $committype,
when => $when,
@@ -159,51 +160,6 @@ sub rcs_recentchanges ($) {
return @ret;
}
-sub rcs_notify () { #{{{
- # FIXME: Not set
- if (! exists $ENV{ARCH_VERSION}) {
- error("ARCH_VERSION is not set, not running from tla post-commit hook, cannot send notifications");
- }
- my $rev=int(possibly_foolish_untaint($ENV{REV}));
-
- eval q{use Mail::Header};
- error($@) if $@;
- open(LOG, $ENV{"ARCH_LOG"});
- my $head = Mail::Header->new(\*LOG);
- close(LOG);
-
- my $user = $head->get("Creator");
-
- my $newfiles = $head->get("New-files");
- my $modfiles = $head->get("Modified-files");
- my $remfiles = $head->get("Removed-files");
-
- my @changed_pages = grep { !/(^.*\/)?\.arch-ids\/.*\.id$/ }
- split(/ /, "$newfiles $modfiles $remfiles .arch-ids/fake.id");
-
- require IkiWiki::UserInfo;
- send_commit_mails(
- sub {
- my $message = $head->get("Summary");
- if ($message =~ /$config{web_commit_regexp}/) {
- $user=defined $2 ? "$2" : "$3";
- $message=$4;
- }
- },
- sub {
- my $logs = `tla logs -d $config{srcdir}`;
- my @changesets = reverse split(/\n/, $logs);
- my $i;
-
- for($i=0;$i<$#changesets;$i++) {
- last if $changesets[$i] eq $rev;
- }
-
- my $revminusone = $changesets[$i+1];
- `tla diff -d $ENV{ARCH_TREE_ROOT} $revminusone`;
- }, $user, @changed_pages);
-} #}}}
-
sub rcs_getctime ($) { #{{{
my $file=shift;
eval q{use Date::Parse};
diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm
index 4fefadf09..17b60ee94 100644
--- a/IkiWiki/Render.pm
+++ b/IkiWiki/Render.pm
@@ -82,12 +82,9 @@ sub genpage ($$) { #{{{
if (length $config{cgiurl}) {
$template->param(editurl => cgiurl(do => "edit", page => pagetitle($page, 1)));
$template->param(prefsurl => cgiurl(do => "prefs"));
- if ($config{rcs}) {
- $template->param(recentchangesurl => cgiurl(do => "recentchanges"));
- }
$actions++;
}
-
+
if (length $config{historyurl}) {
my $u=$config{historyurl};
$u=~s/\[\[file\]\]/$pagesources{$page}/g;
@@ -196,6 +193,7 @@ sub render ($) { #{{{
my $page=pagename($file);
delete $depends{$page};
will_render($page, htmlpage($page), 1);
+ return if $type=~/^_/;
my $content=htmlize($page, $type,
linkify($page, $page,
@@ -205,7 +203,6 @@ sub render ($) { #{{{
my $output=htmlpage($page);
writefile($output, $config{destdir}, genpage($page, $content));
- utime($pagemtime{$page}, $pagemtime{$page}, $config{destdir}."/".$output);
}
else {
my $srcfd=readfile($srcfile, 1, 1);
@@ -231,7 +228,6 @@ sub render ($) { #{{{
}
}
});
- utime($pagemtime{$file}, $pagemtime{$file}, $config{destdir}."/".$file);
}
} #}}}
@@ -256,6 +252,8 @@ sub refresh () { #{{{
$test=dirname($test);
}
}
+
+ run_hooks(refresh => sub { shift->() });
# find existing pages
my %exists;
@@ -314,15 +312,19 @@ sub refresh () { #{{{
}, $dir);
};
- my %rendered;
+ my (%rendered, @add, @del, @internal);
# check for added or removed pages
- my @add;
foreach my $file (@files) {
my $page=pagename($file);
$pagesources{$page}=$file;
if (! $pagemtime{$page}) {
- push @add, $file;
+ if (isinternal($page)) {
+ push @internal, $file;
+ }
+ else {
+ push @add, $file;
+ }
$pagecase{lc $page}=$page;
if ($config{getctime} && -e "$config{srcdir}/$file") {
$pagectime{$page}=rcs_getctime("$config{srcdir}/$file");
@@ -332,11 +334,15 @@ sub refresh () { #{{{
}
}
}
- my @del;
foreach my $page (keys %pagemtime) {
if (! $exists{$page}) {
- debug(sprintf(gettext("removing old page %s"), $page));
- push @del, $pagesources{$page};
+ if (isinternal($page)) {
+ push @internal, $pagesources{$page};
+ }
+ else {
+ debug(sprintf(gettext("removing old page %s"), $page));
+ push @del, $pagesources{$page};
+ }
$links{$page}=[];
$renderedfiles{$page}=[];
$pagemtime{$page}=0;
@@ -361,7 +367,14 @@ sub refresh () { #{{{
$mtime > $pagemtime{$page} ||
$forcerebuild{$page}) {
$pagemtime{$page}=$mtime;
- push @needsbuild, $file;
+ if (isinternal($page)) {
+ push @internal, $file;
+ # Preprocess internal page in scan-only mode.
+ preprocess($page, $page, readfile(srcfile($file)), 1);
+ }
+ else {
+ push @needsbuild, $file;
+ }
}
}
run_hooks(needsbuild => sub { shift->(\@needsbuild) });
@@ -377,6 +390,15 @@ sub refresh () { #{{{
render($file);
$rendered{$file}=1;
}
+ foreach my $file (@internal) {
+ # internal pages are not rendered
+ my $page=pagename($file);
+ delete $depends{$page};
+ foreach my $old (@{$renderedfiles{$page}}) {
+ delete $destsources{$old};
+ }
+ $renderedfiles{$page}=[];
+ }
# rebuild pages that link to added or removed pages
if (@add || @del) {
@@ -392,13 +414,17 @@ sub refresh () { #{{{
}
}
- if (%rendered || @del) {
+ if (%rendered || @del || @internal) {
+ my @changed=(keys %rendered, @del);
+
# rebuild dependant pages
foreach my $f (@files) {
next if $rendered{$f};
my $p=pagename($f);
if (exists $depends{$p}) {
- foreach my $file (keys %rendered, @del) {
+ # only consider internal files
+ # if the page explicitly depends on such files
+ foreach my $file (@changed, $depends{$p}=~/internal\(/ ? @internal : ()) {
next if $f eq $file;
my $page=pagename($file);
if (pagespec_match($page, $depends{$p}, location => $p)) {
@@ -414,7 +440,7 @@ sub refresh () { #{{{
# handle backlinks; if a page has added/removed links,
# update the pages it links to
my %linkchanged;
- foreach my $file (keys %rendered, @del) {
+ foreach my $file (@changed) {
my $page=pagename($file);
if (exists $links{$page}) {
@@ -436,6 +462,7 @@ sub refresh () { #{{{
}
}
}
+
foreach my $link (keys %linkchanged) {
my $linkfile=$pagesources{$link};
if (defined $linkfile) {
diff --git a/IkiWiki/UserInfo.pm b/IkiWiki/UserInfo.pm
index cfc27609d..2ffc51c55 100644
--- a/IkiWiki/UserInfo.pm
+++ b/IkiWiki/UserInfo.pm
@@ -92,91 +92,4 @@ sub set_banned_users (@) { #{{{
return userinfo_store($userinfo);
} #}}}
-sub commit_notify_list ($@) { #{{{
- my $committer=shift;
- my @pages = map pagename($_), @_;
-
- my @ret;
- my $userinfo=userinfo_retrieve();
- foreach my $user (keys %{$userinfo}) {
- next if $user eq $committer;
- if (exists $userinfo->{$user}->{subscriptions} &&
- length $userinfo->{$user}->{subscriptions} &&
- exists $userinfo->{$user}->{email} &&
- length $userinfo->{$user}->{email} &&
- grep { pagespec_match($_,
- $userinfo->{$user}->{subscriptions},
- user => $committer) }
- map pagename($_), @_) {
- push @ret, $userinfo->{$user}->{email};
- }
- }
- return @ret;
-} #}}}
-
-sub send_commit_mails ($$$@) { #{{{
- my $messagesub=shift;
- my $diffsub=shift;
- my $user=shift;
- my @changed_pages=@_;
-
- return unless @changed_pages;
-
- my @email_recipients=commit_notify_list($user, @changed_pages);
- if (@email_recipients) {
- # TODO: if a commit spans multiple pages, this will send
- # subscribers a diff that might contain pages they did not
- # sign up for. Should separate the diff per page and
- # reassemble into one mail with just the pages subscribed to.
- my $diff=$diffsub->();
- my $message=$messagesub->();
-
- my $pagelist;
- if (@changed_pages > 2) {
- $pagelist="$changed_pages[0] $changed_pages[1] ...";
- }
- else {
- $pagelist.=join(" ", @changed_pages);
- }
- #translators: The three variables are the name of the wiki,
- #translators: A list of one or more pages that were changed,
- #translators: And the name of the user making the change.
- #translators: This is used as the subject of a commit email.
- my $subject=sprintf(gettext("update of %s's %s by %s"),
- $config{wikiname}, $pagelist, $user);
-
- my $template=template("notifymail.tmpl");
- $template->param(
- wikiname => $config{wikiname},
- diff => $diff,
- user => $user,
- message => $message,
- );
-
- # Daemonize, in case the mail sending takes a while.
- defined(my $pid = fork) or error("Can't fork: $!");
- return if $pid;
- setsid() or error("Can't start a new session: $!");
- chdir '/';
- open STDIN, '/dev/null';
- open STDOUT, '>/dev/null';
- open STDERR, '>&STDOUT' or error("Can't dup stdout: $!");
-
- unlockwiki(); # don't need to keep a lock on the wiki
-
- eval q{use Mail::Sendmail};
- error($@) if $@;
- foreach my $email (@email_recipients) {
- sendmail(
- To => $email,
- From => "$config{wikiname} <$config{adminemail}>",
- Subject => $subject,
- Message => $template->output,
- );
- }
-
- exit 0; # daemon process done
- }
-} #}}}
-
1
diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm
index 2103ea53a..90a4c46c7 100644
--- a/IkiWiki/Wrapper.pm
+++ b/IkiWiki/Wrapper.pm
@@ -36,22 +36,6 @@ sub gen_wrapper () { #{{{
addenv("$var", s);
EOF
}
- if ($config{rcs} eq "svn" && $config{notify}) {
- # Support running directly as hooks/post-commit by passing
- # $2 in REV in the environment.
- $envsave.=<<"EOF"
- if (argc == 3)
- addenv("REV", argv[2]);
- else if ((s=getenv("REV")))
- addenv("REV", s);
-EOF
- }
- if ($config{rcs} eq "tla" && $config{notify}) {
- $envsave.=<<"EOF"
- if ((s=getenv("ARCH_VERSION")))
- addenv("ARCH_VERSION", s);
-EOF
- }
$Data::Dumper::Indent=0; # no newlines
my $configstring=Data::Dumper->Dump([\%config], ['*config']);