summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin
diff options
context:
space:
mode:
Diffstat (limited to 'IkiWiki/Plugin')
-rw-r--r--IkiWiki/Plugin/aggregate.pm12
-rw-r--r--IkiWiki/Plugin/attachment.pm2
-rw-r--r--IkiWiki/Plugin/blogspam.pm14
-rw-r--r--IkiWiki/Plugin/bzr.pm10
-rw-r--r--IkiWiki/Plugin/comments.pm16
-rw-r--r--IkiWiki/Plugin/cvs.pm3
-rw-r--r--IkiWiki/Plugin/darcs.pm4
-rw-r--r--IkiWiki/Plugin/editpage.pm17
-rw-r--r--IkiWiki/Plugin/getsource.pm4
-rw-r--r--IkiWiki/Plugin/git.pm44
-rw-r--r--IkiWiki/Plugin/goto.pm2
-rw-r--r--IkiWiki/Plugin/highlight.pm51
-rw-r--r--IkiWiki/Plugin/htmltidy.pm2
-rw-r--r--IkiWiki/Plugin/inline.pm39
-rw-r--r--IkiWiki/Plugin/mercurial.pm2
-rw-r--r--IkiWiki/Plugin/meta.pm5
-rw-r--r--IkiWiki/Plugin/monotone.pm11
-rw-r--r--IkiWiki/Plugin/norcs.pm2
-rw-r--r--IkiWiki/Plugin/openid.pm2
-rw-r--r--IkiWiki/Plugin/po.pm3
-rw-r--r--IkiWiki/Plugin/recentchanges.pm5
-rw-r--r--IkiWiki/Plugin/recentchangesdiff.pm3
-rw-r--r--IkiWiki/Plugin/rename.pm1
-rw-r--r--IkiWiki/Plugin/search.pm11
-rw-r--r--IkiWiki/Plugin/svn.pm3
-rw-r--r--IkiWiki/Plugin/tag.pm18
-rw-r--r--IkiWiki/Plugin/transient.pm49
-rw-r--r--IkiWiki/Plugin/websetup.pm4
28 files changed, 245 insertions, 94 deletions
diff --git a/IkiWiki/Plugin/aggregate.pm b/IkiWiki/Plugin/aggregate.pm
index 9b70e5df0..59185e97f 100644
--- a/IkiWiki/Plugin/aggregate.pm
+++ b/IkiWiki/Plugin/aggregate.pm
@@ -8,7 +8,6 @@ use IkiWiki 3.00;
use HTML::Parser;
use HTML::Tagset;
use HTML::Entities;
-use URI;
use open qw{:utf8 :std};
my %feeds;
@@ -660,7 +659,7 @@ sub add_page (@) {
$template->param(url => $feed->{url});
$template->param(copyright => $params{copyright})
if defined $params{copyright} && length $params{copyright};
- $template->param(permalink => urlabs($params{link}, $feed->{feedurl}))
+ $template->param(permalink => IkiWiki::urlabs($params{link}, $feed->{feedurl}))
if defined $params{link};
if (ref $feed->{tags}) {
$template->param(tags => [map { tag => $_ }, @{$feed->{tags}}]);
@@ -688,13 +687,6 @@ sub wikiescape ($) {
return encode_entities(shift, '\[\]');
}
-sub urlabs ($$) {
- my $url=shift;
- my $urlbase=shift;
-
- URI->new_abs($url, $urlbase)->as_string;
-}
-
sub htmlabs ($$) {
# Convert links in html from relative to absolute.
# Note that this is a heuristic, which is not specified by the rss
@@ -720,7 +712,7 @@ sub htmlabs ($$) {
next unless $v_offset; # 0 v_offset means no value
my $v = substr($text, $v_offset, $v_len);
$v =~ s/^([\'\"])(.*)\1$/$2/;
- my $new_v=urlabs($v, $urlbase);
+ my $new_v=IkiWiki::urlabs($v, $urlbase);
$new_v =~ s/\"/"/g; # since we quote with ""
substr($text, $v_offset, $v_len) = qq("$new_v");
}
diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm
index bd93d3718..647a671a5 100644
--- a/IkiWiki/Plugin/attachment.pm
+++ b/IkiWiki/Plugin/attachment.pm
@@ -92,7 +92,7 @@ sub formbuilder_setup (@) {
# Add the toggle javascript; the attachments interface uses
# it to toggle visibility.
require IkiWiki::Plugin::toggle;
- $form->tmpl_param("javascript" => IkiWiki::Plugin::toggle::include_javascript($params{page}, 1));
+ $form->tmpl_param("javascript" => IkiWiki::Plugin::toggle::include_javascript($params{page}));
# Start with the attachments interface toggled invisible,
# but if it was used, keep it open.
if ($form->submitted ne "Upload Attachment" &&
diff --git a/IkiWiki/Plugin/blogspam.pm b/IkiWiki/Plugin/blogspam.pm
index f0b6cb2a2..d32c2f169 100644
--- a/IkiWiki/Plugin/blogspam.pm
+++ b/IkiWiki/Plugin/blogspam.pm
@@ -61,12 +61,18 @@ sub checkcontent (@) {
my %params=@_;
my $session=$params{session};
- if (exists $config{blogspam_pagespec}) {
- return undef
- if ! pagespec_match($params{page}, $config{blogspam_pagespec},
- location => $params{page});
+ my $spec='!admin()';
+ if (exists $config{blogspam_pagespec} &&
+ length $config{blogspam_pagespec}) {
+ $spec.=" and (".$config{blogspam_pagespec}.")";
}
+ my $user=$session->param("name");
+ return undef unless pagespec_match($params{page}, $spec,
+ (defined $user ? (user => $user) : ()),
+ (defined $session->remote_addr() ? (ip => $session->remote_addr()) : ()),
+ location => $params{page});
+
my $url=$defaulturl;
$url = $config{blogspam_server} if exists $config{blogspam_server};
diff --git a/IkiWiki/Plugin/bzr.pm b/IkiWiki/Plugin/bzr.pm
index 562d5d389..3bc4ea8dd 100644
--- a/IkiWiki/Plugin/bzr.pm
+++ b/IkiWiki/Plugin/bzr.pm
@@ -271,8 +271,9 @@ sub rcs_recentchanges ($) {
return @ret;
}
-sub rcs_diff ($) {
+sub rcs_diff ($;$) {
my $taintedrev=shift;
+ my $maxlines=shift;
my ($rev) = $taintedrev =~ /^(\d+(\.\d+)*)$/; # untaint
my $prevspec = "before:" . $rev;
@@ -281,8 +282,11 @@ sub rcs_diff ($) {
"--new", $config{srcdir},
"-r", $prevspec . ".." . $revspec);
open (my $out, "@cmdline |");
-
- my @lines = <$out>;
+ my @lines;
+ while (my $line=<$out>) {
+ last if defined $maxlines && @lines == $maxlines;
+ push @lines, $line;
+ }
if (wantarray) {
return @lines;
}
diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm
index 63e9ab499..6691dbafa 100644
--- a/IkiWiki/Plugin/comments.pm
+++ b/IkiWiki/Plugin/comments.pm
@@ -364,16 +364,14 @@ sub editcomment ($$) {
}
# The untaint is OK (as in editpage) because we're about to pass
- # it to file_pruned anyway
- my $page = $form->field('page');
+ # it to file_pruned and wiki_file_regexp anyway.
+ my ($page) = $form->field('page')=~/$config{wiki_file_regexp}/;
$page = IkiWiki::possibly_foolish_untaint($page);
if (! defined $page || ! length $page ||
IkiWiki::file_pruned($page)) {
error(gettext("bad page name"));
}
- my $baseurl = urlto($page);
-
$form->title(sprintf(gettext("commenting on %s"),
IkiWiki::pagetitle(IkiWiki::basename($page))));
@@ -385,7 +383,7 @@ sub editcomment ($$) {
if ($form->submitted eq CANCEL) {
# bounce back to the page they wanted to comment on, and exit.
- IkiWiki::redirect($cgi, $baseurl);
+ IkiWiki::redirect($cgi, urlto($page));
exit;
}
@@ -506,7 +504,7 @@ sub editcomment ($$) {
IkiWiki::saveindex();
IkiWiki::printheader($session);
- print IkiWiki::misctemplate(gettext(gettext("comment stored for moderation")),
+ print IkiWiki::cgitemplate($cgi, gettext(gettext("comment stored for moderation")),
"<p>".
gettext("Your comment will be posted after moderator review").
"</p>");
@@ -556,8 +554,8 @@ sub editcomment ($$) {
}
else {
- IkiWiki::showform ($form, \@buttons, $session, $cgi,
- forcebaseurl => $baseurl, page => $page);
+ IkiWiki::showform($form, \@buttons, $session, $cgi,
+ page => $page);
}
exit;
@@ -662,7 +660,7 @@ sub commentmoderation ($$) {
IkiWiki::run_hooks(format => sub {
$out = shift->(page => "", content => $out);
});
- print IkiWiki::misctemplate(gettext("comment moderation"), $out);
+ print IkiWiki::cgitemplate($cgi, gettext("comment moderation"), $out);
exit;
}
diff --git a/IkiWiki/Plugin/cvs.pm b/IkiWiki/Plugin/cvs.pm
index 4972efb58..71566d212 100644
--- a/IkiWiki/Plugin/cvs.pm
+++ b/IkiWiki/Plugin/cvs.pm
@@ -436,8 +436,9 @@ sub rcs_recentchanges ($) {
return @ret;
}
-sub rcs_diff ($) {
+sub rcs_diff ($;$) {
my $rev=IkiWiki::possibly_foolish_untaint(int(shift));
+ my $maxlines=shift;
local $CWD = $config{srcdir};
diff --git a/IkiWiki/Plugin/darcs.pm b/IkiWiki/Plugin/darcs.pm
index 0f63b8807..cd4fcd0ff 100644
--- a/IkiWiki/Plugin/darcs.pm
+++ b/IkiWiki/Plugin/darcs.pm
@@ -373,11 +373,13 @@ sub rcs_recentchanges ($) {
return @ret;
}
-sub rcs_diff ($) {
+sub rcs_diff ($;$) {
my $rev=shift;
+ my $maxlines=shift;
my @lines;
foreach my $line (silentsystem("darcs", "diff", "--match", "hash ".$rev)) {
if (@lines || $line=~/^diff/) {
+ last if defined $maxlines && @lines == $maxlines;
push @lines, $line."\n";
}
}
diff --git a/IkiWiki/Plugin/editpage.pm b/IkiWiki/Plugin/editpage.pm
index 537b86ad1..3d094c263 100644
--- a/IkiWiki/Plugin/editpage.pm
+++ b/IkiWiki/Plugin/editpage.pm
@@ -91,6 +91,9 @@ sub cgi_editpage ($$) {
# This untaint is safe because we check file_pruned and
# wiki_file_regexp.
my ($page)=$form->field('page')=~/$config{wiki_file_regexp}/;
+ if (! defined $page) {
+ error(gettext("bad page name"));
+ }
$page=possibly_foolish_untaint($page);
my $absolute=($page =~ s#^/+##); # absolute name used to force location
if (! defined $page || ! length $page ||
@@ -128,7 +131,8 @@ sub cgi_editpage ($$) {
# favor the type of linking page
$type=pagetype($pagesources{$from});
}
- $type=$config{default_pageext} unless defined $type;
+ $type=$config{default_pageext}
+ if ! defined $type || $type=~/^_/; # not internal type
$file=newpagefile($page, $type);
if (! $form->submitted) {
$form->field(name => "rcsinfo", value => "", force => 1);
@@ -312,8 +316,7 @@ sub cgi_editpage ($$) {
$form->title(sprintf(gettext("editing %s"), pagetitle(basename($page))));
}
- showform($form, \@buttons, $session, $q,
- forcebaseurl => $baseurl, page => $page);
+ showform($form, \@buttons, $session, $q, page => $page);
}
else {
# save page
@@ -331,7 +334,7 @@ sub cgi_editpage ($$) {
$form->field(name => "type", type => 'hidden');
$form->title(sprintf(gettext("editing %s"), $page));
showform($form, \@buttons, $session, $q,
- forcebaseurl => $baseurl, page => $page);
+ page => $page);
exit;
}
elsif ($form->field("do") eq "create" && $exists) {
@@ -346,7 +349,7 @@ sub cgi_editpage ($$) {
"\n\n\n".$form->field("editcontent"),
force => 1);
showform($form, \@buttons, $session, $q,
- forcebaseurl => $baseurl, page => $page);
+ page => $page);
exit;
}
@@ -387,7 +390,7 @@ sub cgi_editpage ($$) {
$form->field(name => "type", type => 'hidden');
$form->title(sprintf(gettext("editing %s"), $page));
showform($form, \@buttons, $session, $q,
- forcebaseurl => $baseurl, page => $page);
+ page => $page);
exit;
}
@@ -429,7 +432,7 @@ sub cgi_editpage ($$) {
$form->field(name => "type", type => 'hidden');
$form->title(sprintf(gettext("editing %s"), $page));
showform($form, \@buttons, $session, $q,
- forcebaseurl => $baseurl, page => $page);
+ page => $page);
}
else {
# The trailing question mark tries to avoid broken
diff --git a/IkiWiki/Plugin/getsource.pm b/IkiWiki/Plugin/getsource.pm
index b362de726..0a21413bd 100644
--- a/IkiWiki/Plugin/getsource.pm
+++ b/IkiWiki/Plugin/getsource.pm
@@ -61,7 +61,7 @@ sub cgi_getsource ($) {
IkiWiki::cgi_custom_failure(
$cgi,
"404 Not Found",
- IkiWiki::misctemplate(gettext("missing page"),
+ IkiWiki::cgitemplate($cgi, gettext("missing page"),
"<p>".
sprintf(gettext("The page %s does not exist."),
htmllink("", "", $page)).
@@ -72,7 +72,7 @@ sub cgi_getsource ($) {
if (! defined pagetype($pagesources{$page})) {
IkiWiki::cgi_custom_failure(
$cgi->header(-status => "403 Forbidden"),
- IkiWiki::misctemplate(gettext("not a page"),
+ IkiWiki::cgitemplate($cgi, gettext("not a page"),
"<p>".
sprintf(gettext("%s is an attachment, not a page."),
htmllink("", "", $page)).
diff --git a/IkiWiki/Plugin/git.pm b/IkiWiki/Plugin/git.pm
index 3db4af729..cf7fbe9b7 100644
--- a/IkiWiki/Plugin/git.pm
+++ b/IkiWiki/Plugin/git.pm
@@ -152,10 +152,11 @@ sub genwrapper {
}
sub safe_git (&@) {
- # Start a child process safely without resorting /bin/sh.
- # Return command output or success state (in scalar context).
+ # Start a child process safely without resorting to /bin/sh.
+ # Returns command output (in list content) or success state
+ # (in scalar context), or runs the specified data handler.
- my ($error_handler, @cmdline) = @_;
+ my ($error_handler, $data_handler, @cmdline) = @_;
my $pid = open my $OUT, "-|";
@@ -187,7 +188,12 @@ sub safe_git (&@) {
chomp;
- push @lines, $_;
+ if (! defined $data_handler) {
+ push @lines, $_;
+ }
+ else {
+ last unless $data_handler->($_);
+ }
}
close $OUT;
@@ -197,9 +203,9 @@ sub safe_git (&@) {
return wantarray ? @lines : ($? == 0);
}
# Convenient wrappers.
-sub run_or_die ($@) { safe_git(\&error, @_) }
-sub run_or_cry ($@) { safe_git(sub { warn @_ }, @_) }
-sub run_or_non ($@) { safe_git(undef, @_) }
+sub run_or_die ($@) { safe_git(\&error, undef, @_) }
+sub run_or_cry ($@) { safe_git(sub { warn @_ }, undef, @_) }
+sub run_or_non ($@) { safe_git(undef, undef, @_) }
sub merge_past ($$$) {
@@ -663,15 +669,19 @@ sub rcs_recentchanges ($) {
return @rets;
}
-sub rcs_diff ($) {
+sub rcs_diff ($;$) {
my $rev=shift;
+ my $maxlines=shift;
my ($sha1) = $rev =~ /^($sha1_pattern)$/; # untaint
my @lines;
- foreach my $line (run_or_non("git", "show", $sha1)) {
- if (@lines || $line=~/^diff --git/) {
- push @lines, $line."\n";
- }
- }
+ my $addlines=sub {
+ my $line=shift;
+ return if defined $maxlines && @lines == $maxlines;
+ push @lines, $line."\n"
+ if (@lines || $line=~/^diff --git/);
+ return 1;
+ };
+ safe_git(undef, $addlines, "git", "show", $sha1);
if (wantarray) {
return @lines;
}
@@ -850,9 +860,8 @@ sub rcs_preprevert ($) {
# in order to see all changes.
my ($subdir, $rootdir) = git_find_root();
$git_dir=$rootdir;
- my @commits=git_commit_info($sha1, 1);
- $git_dir=undef;
+ my @commits=git_commit_info($sha1, 1);
if (! @commits) {
error "unknown commit"; # just in case
}
@@ -863,7 +872,10 @@ sub rcs_preprevert ($) {
error gettext("you are not allowed to revert a merge");
}
- return git_parse_changes(@commits);
+ my @ret=git_parse_changes(@commits);
+
+ $git_dir=undef;
+ return @ret;
}
sub rcs_revert ($) {
diff --git a/IkiWiki/Plugin/goto.pm b/IkiWiki/Plugin/goto.pm
index 0eb83fc20..6b596ac8b 100644
--- a/IkiWiki/Plugin/goto.pm
+++ b/IkiWiki/Plugin/goto.pm
@@ -56,7 +56,7 @@ sub cgi_goto ($;$) {
IkiWiki::cgi_custom_failure(
$q,
"404 Not Found",
- IkiWiki::misctemplate(gettext("missing page"),
+ IkiWiki::cgitemplate($q, gettext("missing page"),
"<p>".
sprintf(gettext("The page %s does not exist."),
htmllink("", "", $page)).
diff --git a/IkiWiki/Plugin/highlight.pm b/IkiWiki/Plugin/highlight.pm
index 9d05e9fcf..65e372db1 100644
--- a/IkiWiki/Plugin/highlight.pm
+++ b/IkiWiki/Plugin/highlight.pm
@@ -1,11 +1,17 @@
#!/usr/bin/perl
package IkiWiki::Plugin::highlight;
+# This has been tested with highlight 2.16 and highlight 3.2+svn19.
+# In particular version 3.2 won't work. It detects the different
+# versions by the presence of the the highlight::DataDir class.
+
use warnings;
use strict;
use IkiWiki 3.00;
use Encode;
+my $data_dir;
+
sub import {
hook(type => "getsetup", id => "highlight", call => \&getsetup);
hook(type => "checkconfig", id => "highlight", call => \&checkconfig);
@@ -45,13 +51,31 @@ sub getsetup () {
}
sub checkconfig () {
+
+ eval q{use highlight};
+ if ($@) {
+ print STDERR "Failed to load highlight. Configuring anyway.\n";
+ };
+
+ if (highlight::DataDir->can('new')){
+ $data_dir=new highlight::DataDir();
+ $data_dir->searchDataDir("");
+ } else {
+ $data_dir=undef;
+ }
+
if (! exists $config{filetypes_conf}) {
- $config{filetypes_conf}="/etc/highlight/filetypes.conf";
+ $config{filetypes_conf}=
+ ($data_dir ? $data_dir->getConfDir() : "/etc/highlight/")
+ . "filetypes.conf";
}
if (! exists $config{langdefdir}) {
- $config{langdefdir}="/usr/share/highlight/langDefs";
+ $config{langdefdir}=
+ ($data_dir ? $data_dir->getLangPath("")
+ : "/usr/share/highlight/langDefs");
+
}
- if (exists $config{tohighlight}) {
+ if (exists $config{tohighlight} && read_filetypes()) {
foreach my $file (split ' ', $config{tohighlight}) {
my @opts = $file=~s/^\.// ?
(keepextension => 1) :
@@ -96,7 +120,12 @@ my %highlighters;
# Parse highlight's config file to get extension => language mappings.
sub read_filetypes () {
- open (my $f, $config{filetypes_conf}) || error("$config{filetypes_conf}: $!");
+ my $f;
+ if (!open($f, $config{filetypes_conf})) {
+ warn($config{filetypes_conf}.": ".$!);
+ return 0;
+ };
+
local $/=undef;
my $config=<$f>;
close $f;
@@ -119,7 +148,7 @@ sub read_filetypes () {
}
}
- $filetypes_read=1;
+ return $filetypes_read=1;
}
@@ -158,11 +187,17 @@ sub highlight ($$) {
my $gen;
if (! exists $highlighters{$langfile}) {
- $gen = highlightc::CodeGenerator_getInstance($highlightc::XHTML);
+ $gen = highlight::CodeGenerator::getInstance($highlight::XHTML);
$gen->setFragmentCode(1); # generate html fragment
$gen->setHTMLEnclosePreTag(1); # include stylish <pre>
- $gen->initTheme("/dev/null"); # theme is not needed because CSS is not emitted
- $gen->initLanguage($langfile); # must come after initTheme
+ if ($data_dir){
+ # new style, requires a real theme, but has no effect
+ $gen->initTheme($data_dir->getThemePath("seashell.theme"));
+ } else {
+ # old style, anything works.
+ $gen->initTheme("/dev/null");
+ }
+ $gen->loadLanguage($langfile); # must come after initTheme
$gen->setEncoding("utf-8");
$highlighters{$langfile}=$gen;
}
diff --git a/IkiWiki/Plugin/htmltidy.pm b/IkiWiki/Plugin/htmltidy.pm
index 1108aeb89..da77e60f1 100644
--- a/IkiWiki/Plugin/htmltidy.pm
+++ b/IkiWiki/Plugin/htmltidy.pm
@@ -41,6 +41,8 @@ sub checkconfig () {
sub sanitize (@) {
my %params=@_;
+ return $params{content} unless defined $config{htmltidy};
+
my $pid;
my $sigpipe=0;
$SIG{PIPE}=sub { $sigpipe=1 };
diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm
index 7c5da7343..285077204 100644
--- a/IkiWiki/Plugin/inline.pm
+++ b/IkiWiki/Plugin/inline.pm
@@ -290,8 +290,17 @@ sub preprocess_inline (@) {
}
}
- my $rssurl=abs2rel($feedbase."rss".$feednum, dirname(htmlpage($params{destpage}))) if $feeds && $rss;
- my $atomurl=abs2rel($feedbase."atom".$feednum, dirname(htmlpage($params{destpage}))) if $feeds && $atom;
+ my ($rssurl, $atomurl, $rssdesc, $atomdesc);
+ if ($feeds) {
+ if ($rss) {
+ $rssurl=abs2rel($feedbase."rss".$feednum, dirname(htmlpage($params{destpage})));
+ $rssdesc = sprintf(gettext("%s (RSS feed)"), $desc);
+ }
+ if ($atom) {
+ $atomurl=abs2rel($feedbase."atom".$feednum, dirname(htmlpage($params{destpage})));
+ $atomdesc = sprintf(gettext("%s (Atom feed)"), $desc);
+ }
+ }
my $ret="";
@@ -302,8 +311,16 @@ sub preprocess_inline (@) {
my $formtemplate=template_depends("blogpost.tmpl", $params{page}, blind_cache => 1);
$formtemplate->param(cgiurl => IkiWiki::cgiurl());
$formtemplate->param(rootpage => rootpage(%params));
- $formtemplate->param(rssurl => $rssurl) if $feeds && $rss;
- $formtemplate->param(atomurl => $atomurl) if $feeds && $atom;
+ if ($feeds) {
+ if ($rss) {
+ $formtemplate->param(rssurl => $rssurl);
+ $formtemplate->param(rssdesc => $rssdesc);
+ }
+ if ($atom) {
+ $formtemplate->param(atomurl => $atomurl);
+ $formtemplate->param(atomdesc => $atomdesc);
+ }
+ }
if (exists $params{postformtext}) {
$formtemplate->param(postformtext =>
$params{postformtext});
@@ -321,8 +338,14 @@ sub preprocess_inline (@) {
elsif ($feeds && !$params{preview} && ($emptyfeeds || @feedlist)) {
# Add feed buttons.
my $linktemplate=template_depends("feedlink.tmpl", $params{page}, blind_cache => 1);
- $linktemplate->param(rssurl => $rssurl) if $rss;
- $linktemplate->param(atomurl => $atomurl) if $atom;
+ if ($rss) {
+ $linktemplate->param(rssurl => $rssurl);
+ $linktemplate->param(rssdesc => $rssdesc);
+ }
+ if ($atom) {
+ $linktemplate->param(atomurl => $atomurl);
+ $linktemplate->param(atomdesc => $atomdesc);
+ }
$ret.=$linktemplate->output;
}
@@ -419,7 +442,7 @@ sub preprocess_inline (@) {
genfeed("rss",
$config{url}."/".$rssp, $desc, $params{guid}, $params{destpage}, @feedlist));
$toping{$params{destpage}}=1 unless $config{rebuild};
- $feedlinks{$params{destpage}}.=qq{<link rel="alternate" type="application/rss+xml" title="$desc (RSS)" href="$rssurl" />};
+ $feedlinks{$params{destpage}}.=qq{<link rel="alternate" type="application/rss+xml" title="$rssdesc" href="$rssurl" />};
}
}
if ($atom) {
@@ -429,7 +452,7 @@ sub preprocess_inline (@) {
writefile($atomp, $config{destdir},
genfeed("atom", $config{url}."/".$atomp, $desc, $params{guid}, $params{destpage}, @feedlist));
$toping{$params{destpage}}=1 unless $config{rebuild};
- $feedlinks{$params{destpage}}.=qq{<link rel="alternate" type="application/atom+xml" title="$desc (Atom)" href="$atomurl" />};
+ $feedlinks{$params{destpage}}.=qq{<link rel="alternate" type="application/atom+xml" title="$atomdesc" href="$atomurl" />};
}
}
}
diff --git a/IkiWiki/Plugin/mercurial.pm b/IkiWiki/Plugin/mercurial.pm
index 59dc63b4e..d7399eaf0 100644
--- a/IkiWiki/Plugin/mercurial.pm
+++ b/IkiWiki/Plugin/mercurial.pm
@@ -229,7 +229,7 @@ sub rcs_recentchanges ($) {
return @ret;
}
-sub rcs_diff ($) {
+sub rcs_diff ($;$) {
# TODO
}
diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm
index abc8f1b1a..ad6d1a8e3 100644
--- a/IkiWiki/Plugin/meta.pm
+++ b/IkiWiki/Plugin/meta.pm
@@ -298,6 +298,11 @@ sub pagetemplate (@) {
if exists $pagestate{$page}{meta}{$field} && $template->query(name => $field);
}
+ foreach my $field (qw{permalink}) {
+ $template->param($field => IkiWiki::urlabs($pagestate{$page}{meta}{$field}, $config{url}))
+ if exists $pagestate{$page}{meta}{$field} && $template->query(name => $field);
+ }
+
foreach my $field (qw{description}) {
$template->param($field => HTML::Entities::encode_numeric($pagestate{$page}{meta}{$field}))
if exists $pagestate{$page}{meta}{$field} && $template->query(name => $field);
diff --git a/IkiWiki/Plugin/monotone.pm b/IkiWiki/Plugin/monotone.pm
index 75bf2f458..38313a542 100644
--- a/IkiWiki/Plugin/monotone.pm
+++ b/IkiWiki/Plugin/monotone.pm
@@ -42,7 +42,7 @@ sub checkconfig () {
my $version=undef;
while (<MTN>) {
- if (/^monotone (\d+\.\d+) /) {
+ if (/^monotone (\d+\.\d+)(?:(?:\.\d+){0,2}|dev)? /) {
$version=$1;
}
}
@@ -621,8 +621,9 @@ sub rcs_recentchanges ($) {
return @ret;
}
-sub rcs_diff ($) {
+sub rcs_diff ($;$) {
my $rev=shift;
+ my $maxlines=shift;
my ($sha1) = $rev =~ /^($sha1_pattern)$/; # untaint
chdir $config{srcdir}
@@ -633,7 +634,11 @@ sub rcs_diff ($) {
exec("mtn", "diff", "--root=$config{mtnrootdir}", "-r", "p:".$sha1, "-r", $sha1) || error("mtn diff $sha1 failed to run");
}
- my (@lines) = <MTNDIFF>;
+ my @lines;
+ while (my $line=<MTNDIFF>) {
+ last if defined $maxlines && @lines == $maxlines;
+ push @lines, $line;
+ }
close MTNDIFF || debug("mtn diff $sha1 exited $?");
diff --git a/IkiWiki/Plugin/norcs.pm b/IkiWiki/Plugin/norcs.pm
index a3bb6240e..6fa8bfa3a 100644
--- a/IkiWiki/Plugin/norcs.pm
+++ b/IkiWiki/Plugin/norcs.pm
@@ -58,7 +58,7 @@ sub rcs_rename ($$) {
sub rcs_recentchanges ($) {
}
-sub rcs_diff ($) {
+sub rcs_diff ($;$) {
}
sub rcs_getctime ($) {
diff --git a/IkiWiki/Plugin/openid.pm b/IkiWiki/Plugin/openid.pm
index ce0990e40..bd67384f2 100644
--- a/IkiWiki/Plugin/openid.pm
+++ b/IkiWiki/Plugin/openid.pm
@@ -84,7 +84,7 @@ sub openid_selector {
);
IkiWiki::printheader($session);
- print IkiWiki::misctemplate("signin", $template->output);
+ print IkiWiki::cgitemplate($q, "signin", $template->output);
exit;
}
diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm
index 9ed4a1adb..4f8d5036e 100644
--- a/IkiWiki/Plugin/po.pm
+++ b/IkiWiki/Plugin/po.pm
@@ -38,7 +38,8 @@ memoize("percenttranslated");
sub import {
hook(type => "getsetup", id => "po", call => \&getsetup);
- hook(type => "checkconfig", id => "po", call => \&checkconfig);
+ hook(type => "checkconfig", id => "po", call => \&checkconfig,
+ last => 1);
hook(type => "needsbuild", id => "po", call => \&needsbuild);
hook(type => "scan", id => "po", call => \&scan, last => 1);
hook(type => "filter", id => "po", call => \&filter);
diff --git a/IkiWiki/Plugin/recentchanges.pm b/IkiWiki/Plugin/recentchanges.pm
index 6fccd16f6..d6292c3f2 100644
--- a/IkiWiki/Plugin/recentchanges.pm
+++ b/IkiWiki/Plugin/recentchanges.pm
@@ -121,7 +121,7 @@ sub sessioncgi ($$) {
}
elsif ($form->submitted ne 'Cancel') {
$form->title(sprintf(gettext("confirm reversion of %s"), $rev));
- $form->tmpl_param(diff => encode_entities(scalar IkiWiki::rcs_diff($rev)));
+ $form->tmpl_param(diff => encode_entities(scalar IkiWiki::rcs_diff($rev, 200)));
$form->field(name => "rev", type => "hidden", value => $rev, force => 1);
IkiWiki::showform($form, $buttons, $session, $q);
exit 0;
@@ -178,7 +178,6 @@ sub store ($$$) {
else {
$_->{link} = pagetitle($_->{page});
}
- $_->{baseurl}=IkiWiki::baseurl(undef) if length $config{url};
$_;
} @{$change->{pages}}
@@ -226,7 +225,7 @@ sub store ($$$) {
wikiname => $config{wikiname},
);
- $template->param(permalink => urlto($config{recentchangespage}, undef)."#change-".titlepage($change->{rev}))
+ $template->param(permalink => urlto($config{recentchangespage})."#change-".titlepage($change->{rev}))
if exists $config{url};
IkiWiki::run_hooks(pagetemplate => sub {
diff --git a/IkiWiki/Plugin/recentchangesdiff.pm b/IkiWiki/Plugin/recentchangesdiff.pm
index e3ba9b8d8..71297572d 100644
--- a/IkiWiki/Plugin/recentchangesdiff.pm
+++ b/IkiWiki/Plugin/recentchangesdiff.pm
@@ -28,11 +28,10 @@ sub pagetemplate (@) {
my $template=$params{template};
if ($config{rcs} && exists $params{rev} && length $params{rev} &&
$template->query(name => "diff")) {
- my @lines=IkiWiki::rcs_diff($params{rev});
+ my @lines=IkiWiki::rcs_diff($params{rev}, $maxlines+1);
if (@lines) {
my $diff;
if (@lines > $maxlines) {
- # only include so many lines of diff
$diff=join("", @lines[0..($maxlines-1)])."\n".
gettext("(Diff truncated)");
}
diff --git a/IkiWiki/Plugin/rename.pm b/IkiWiki/Plugin/rename.pm
index 57747d3c9..e871b815d 100644
--- a/IkiWiki/Plugin/rename.pm
+++ b/IkiWiki/Plugin/rename.pm
@@ -567,6 +567,7 @@ sub fixlinks ($$$) {
}
if ($needfix) {
my $file=$pagesources{$page};
+ next unless -e $config{srcdir}."/".$file;
my $oldcontent=readfile($config{srcdir}."/".$file);
my $content=renamepage_hook($page, $rename->{src}, $rename->{dest}, $oldcontent);
if ($oldcontent ne $content) {
diff --git a/IkiWiki/Plugin/search.pm b/IkiWiki/Plugin/search.pm
index 78eb750b5..3f0b7c9ad 100644
--- a/IkiWiki/Plugin/search.pm
+++ b/IkiWiki/Plugin/search.pm
@@ -227,20 +227,21 @@ sub setupfiles () {
"database_dir .\n".
"template_dir ./templates\n");
- # Avoid omega interpreting anything in the misctemplate
+ # Avoid omega interpreting anything in the cgitemplate
# as an omegascript command.
- my $misctemplate=IkiWiki::misctemplate(gettext("search"), "\0",
+ eval q{use IkiWiki::CGI};
+ my $template=IkiWiki::cgitemplate(undef, gettext("search"), "\0",
searchform => "", # avoid showing the small search form
);
eval q{use HTML::Entities};
error $@ if $@;
- $misctemplate=encode_entities($misctemplate, '\$');
+ $template=encode_entities($template, '\$');
my $querytemplate=readfile(IkiWiki::template_file("searchquery.tmpl"));
- $misctemplate=~s/\0/$querytemplate/;
+ $template=~s/\0/$querytemplate/;
writefile("query", $config{wikistatedir}."/xapian/templates",
- $misctemplate);
+ $template);
$setup=1;
}
}
diff --git a/IkiWiki/Plugin/svn.pm b/IkiWiki/Plugin/svn.pm
index 9cf82b5db..faaf567d5 100644
--- a/IkiWiki/Plugin/svn.pm
+++ b/IkiWiki/Plugin/svn.pm
@@ -345,8 +345,9 @@ sub rcs_recentchanges ($) {
return @ret;
}
-sub rcs_diff ($) {
+sub rcs_diff ($;$) {
my $rev=IkiWiki::possibly_foolish_untaint(int(shift));
+ my $maxlines=shift;
return `svnlook diff $config{svnrepo} -r$rev --no-diff-deleted`;
}
diff --git a/IkiWiki/Plugin/tag.pm b/IkiWiki/Plugin/tag.pm
index 55064a9a3..fd5ce1e8a 100644
--- a/IkiWiki/Plugin/tag.pm
+++ b/IkiWiki/Plugin/tag.pm
@@ -55,6 +55,17 @@ sub taglink ($) {
return $tag;
}
+# Returns a tag name from a tag link
+sub tagname ($) {
+ my $tag=shift;
+ if (defined $config{tagbase}) {
+ $tag =~ s!^/\Q$config{tagbase}\E/!!;
+ } else {
+ $tag =~ s!^\.?/!!;
+ }
+ return pagetitle($tag, 1);
+}
+
sub htmllink_tag ($$$;@) {
my $page=shift;
my $destpage=shift;
@@ -84,7 +95,7 @@ sub gentag ($) {
debug($message);
my $template=template("autotag.tmpl");
- $template->param(tagname => IkiWiki::basename($tag));
+ $template->param(tagname => tagname($tag));
$template->param(tag => $tag);
writefile($tagfile, $config{srcdir}, $template->output);
if ($config{rcs}) {
@@ -154,14 +165,15 @@ sub pagetemplate (@) {
$template->param(tags => [
map {
- link => htmllink_tag($page, $destpage, $_, rel => "tag")
+ link => htmllink_tag($page, $destpage, $_,
+ rel => "tag", linktext => tagname($_))
}, sort keys %$tags
]) if defined $tags && %$tags && $template->query(name => "tags");
if ($template->query(name => "categories")) {
# It's an rss/atom template. Add any categories.
if (defined $tags && %$tags) {
- $template->param(categories => [map { category => $_ },
+ $template->param(categories => [map { category => tagname($_) },
sort keys %$tags]);
}
}
diff --git a/IkiWiki/Plugin/transient.pm b/IkiWiki/Plugin/transient.pm
new file mode 100644
index 000000000..9811aa010
--- /dev/null
+++ b/IkiWiki/Plugin/transient.pm
@@ -0,0 +1,49 @@
+#!/usr/bin/perl
+package IkiWiki::Plugin::transient;
+
+use warnings;
+use strict;
+use IkiWiki 3.00;
+
+sub import {
+ hook(type => "getsetup", id => "transient", call => \&getsetup);
+ hook(type => "checkconfig", id => "transient", call => \&checkconfig);
+ hook(type => "change", id => "transient", call => \&change);
+}
+
+sub getsetup () {
+ return
+ plugin => {
+ # this plugin is safe but only makes sense as a
+ # dependency; similarly, it needs a rebuild but
+ # only if something else does
+ safe => 0,
+ rebuild => 0,
+ },
+}
+
+our $transientdir;
+
+sub checkconfig () {
+ $transientdir = $config{wikistatedir}."/transient";
+ # add_underlay treats relative underlays as relative to the installed
+ # location, not the cwd. That's not what we want here.
+ IkiWiki::add_literal_underlay($transientdir);
+}
+
+sub change (@) {
+ foreach my $file (@_) {
+ # If the corresponding file exists in the transient underlay
+ # and isn't actually being used, we can get rid of it.
+ # Assume that the file that just changed has the same extension
+ # as the obsolete transient version: this'll be true for web
+ # edits, and avoids invoking File::Find.
+ my $casualty = "$transientdir/$file";
+ if (srcfile($file) ne $casualty && -e $casualty) {
+ debug(sprintf(gettext("removing transient version of %s"), $file));
+ IkiWiki::prune($casualty);
+ }
+ }
+}
+
+1;
diff --git a/IkiWiki/Plugin/websetup.pm b/IkiWiki/Plugin/websetup.pm
index 6a5190301..0a3d90aec 100644
--- a/IkiWiki/Plugin/websetup.pm
+++ b/IkiWiki/Plugin/websetup.pm
@@ -447,10 +447,10 @@ sub showform ($$) {
IkiWiki::saveindex();
IkiWiki::unlockwiki();
- # Print the top part of a standard misctemplate,
+ # Print the top part of a standard cgitemplate,
# then show the rebuild or refresh, live.
my $divider="\0";
- my $html=IkiWiki::misctemplate("setup", $divider);
+ my $html=IkiWiki::cgitemplate($cgi, "setup", $divider);
IkiWiki::printheader($session);
my ($head, $tail)=split($divider, $html, 2);
print $head."<pre>\n";