summaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/CGI.pm44
-rw-r--r--IkiWiki/Plugin/aggregate.pm12
-rw-r--r--IkiWiki/Plugin/attachment.pm2
-rw-r--r--IkiWiki/Plugin/bzr.pm10
-rw-r--r--IkiWiki/Plugin/comments.pm12
-rw-r--r--IkiWiki/Plugin/cvs.pm3
-rw-r--r--IkiWiki/Plugin/darcs.pm4
-rw-r--r--IkiWiki/Plugin/editpage.pm11
-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/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/recentchanges.pm5
-rw-r--r--IkiWiki/Plugin/recentchangesdiff.pm3
-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
-rw-r--r--IkiWiki/Wrapper.pm1
25 files changed, 234 insertions, 81 deletions
diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm
index ede194ff9..f8617bfc6 100644
--- a/IkiWiki/CGI.pm
+++ b/IkiWiki/CGI.pm
@@ -46,13 +46,51 @@ sub showform ($$$$;@) {
my $cgi=shift;
printheader($session);
- print misctemplate($form->title, $form->render(submit => $buttons), @_);
+ print cgitemplate($cgi, $form->title,
+ $form->render(submit => $buttons), @_);
+}
+
+sub cgitemplate ($$$;@) {
+ my $cgi=shift;
+ my $title=shift;
+ my $content=shift;
+ my %params=@_;
+
+ my $template=template("page.tmpl");
+
+ my $topurl = defined $cgi ? $cgi->url : $config{url};
+
+ my $page="";
+ if (exists $params{page}) {
+ $page=delete $params{page};
+ $params{forcebaseurl}=urlabs(urlto($page), $topurl);
+ }
+ run_hooks(pagetemplate => sub {
+ shift->(
+ page => $page,
+ destpage => $page,
+ template => $template,
+ );
+ });
+ templateactions($template, "");
+
+ $template->param(
+ dynamic => 1,
+ title => $title,
+ wikiname => $config{wikiname},
+ content => $content,
+ baseurl => urlabs(urlto(""), $topurl),
+ html5 => $config{html5},
+ %params,
+ );
+
+ return $template->output;
}
sub redirect ($$) {
my $q=shift;
eval q{use URI};
- my $url=URI->new(shift);
+ my $url=URI->new(urlabs(shift, $q->url));
if (! $config{w3mmode}) {
print $q->redirect($url);
}
@@ -423,7 +461,7 @@ sub cgierror ($) {
my $message=shift;
print "Content-type: text/html\n\n";
- print misctemplate(gettext("Error"),
+ print cgitemplate(undef, gettext("Error"),
"<p class=\"error\">".gettext("Error").": $message</p>");
die $@;
}
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/\"/&quot;/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/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..1287590a7 100644
--- a/IkiWiki/Plugin/comments.pm
+++ b/IkiWiki/Plugin/comments.pm
@@ -372,8 +372,6 @@ sub editcomment ($$) {
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..df29bcc98 100644
--- a/IkiWiki/Plugin/editpage.pm
+++ b/IkiWiki/Plugin/editpage.pm
@@ -312,8 +312,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 +330,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 +345,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 +386,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 +428,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/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/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/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..c482b8552
--- /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 () {
+ eval q{use Cwd 'abs_path'};
+ error($@) if $@;
+ $transientdir = abs_path($config{wikistatedir})."/transient";
+ add_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";
diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm
index 5eb96f4ae..84cc7540b 100644
--- a/IkiWiki/Wrapper.pm
+++ b/IkiWiki/Wrapper.pm
@@ -49,6 +49,7 @@ sub gen_wrapper () {
push @envsave, qw{REMOTE_ADDR QUERY_STRING REQUEST_METHOD REQUEST_URI
CONTENT_TYPE CONTENT_LENGTH GATEWAY_INTERFACE
HTTP_COOKIE REMOTE_USER HTTPS REDIRECT_STATUS
+ HTTP_HOST SERVER_PORT HTTPS
REDIRECT_URL} if $config{cgi};
my $envsave="";
foreach my $var (@envsave) {