2006-05-02 04:34:33 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# Page inlining and blogging.
|
|
|
|
package IkiWiki::Plugin::inline;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2007-04-27 04:55:52 +02:00
|
|
|
use IkiWiki 2.00;
|
2006-08-04 04:22:16 +02:00
|
|
|
use URI;
|
2006-05-02 04:34:33 +02:00
|
|
|
|
|
|
|
sub import { #{{{
|
2006-12-21 20:36:15 +01:00
|
|
|
hook(type => "getopt", id => "inline", call => \&getopt);
|
|
|
|
hook(type => "checkconfig", id => "inline", call => \&checkconfig);
|
2006-09-10 00:50:27 +02:00
|
|
|
hook(type => "preprocess", id => "inline",
|
2006-05-03 21:58:58 +02:00
|
|
|
call => \&IkiWiki::preprocess_inline);
|
2006-09-10 00:50:27 +02:00
|
|
|
hook(type => "pagetemplate", id => "inline",
|
2006-09-06 23:03:39 +02:00
|
|
|
call => \&IkiWiki::pagetemplate_inline);
|
2006-06-27 03:13:03 +02:00
|
|
|
# Hook to change to do pinging since it's called late.
|
|
|
|
# This ensures each page only pings once and prevents slow
|
|
|
|
# pings interrupting page builds.
|
2006-09-10 00:50:27 +02:00
|
|
|
hook(type => "change", id => "inline",
|
2006-06-27 03:13:03 +02:00
|
|
|
call => \&IkiWiki::pingurl);
|
2006-05-02 04:34:33 +02:00
|
|
|
} # }}}
|
|
|
|
|
2006-12-21 20:36:15 +01:00
|
|
|
sub getopt () { #{{{
|
|
|
|
eval q{use Getopt::Long};
|
|
|
|
error($@) if $@;
|
|
|
|
Getopt::Long::Configure('pass_through');
|
|
|
|
GetOptions(
|
|
|
|
"rss!" => \$config{rss},
|
|
|
|
"atom!" => \$config{atom},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub checkconfig () { #{{{
|
|
|
|
if (($config{rss} || $config{atom}) && ! length $config{url}) {
|
2006-12-29 05:38:40 +01:00
|
|
|
error(gettext("Must specify url to wiki with --url when using --rss or --atom"));
|
2006-12-21 20:36:15 +01:00
|
|
|
}
|
|
|
|
if ($config{rss}) {
|
|
|
|
push @{$config{wiki_file_prune_regexps}}, qr/\.rss$/;
|
|
|
|
}
|
|
|
|
if ($config{atom}) {
|
|
|
|
push @{$config{wiki_file_prune_regexps}}, qr/\.atom$/;
|
|
|
|
}
|
|
|
|
} #}}}
|
|
|
|
|
2006-05-02 04:34:33 +02:00
|
|
|
# Back to ikiwiki namespace for the rest, this code is very much
|
|
|
|
# internal to ikiwiki even though it's separated into a plugin.
|
|
|
|
package IkiWiki;
|
2006-06-27 03:13:03 +02:00
|
|
|
|
|
|
|
my %toping;
|
2006-10-09 01:57:37 +02:00
|
|
|
my %feedlinks;
|
2006-08-18 05:56:18 +02:00
|
|
|
|
|
|
|
sub yesno ($) { #{{{
|
|
|
|
my $val=shift;
|
|
|
|
return (defined $val && lc($val) eq "yes");
|
|
|
|
} #}}}
|
2006-06-27 03:13:03 +02:00
|
|
|
|
2006-05-02 04:34:33 +02:00
|
|
|
sub preprocess_inline (@) { #{{{
|
|
|
|
my %params=@_;
|
2006-08-18 05:56:18 +02:00
|
|
|
|
2006-05-02 04:34:33 +02:00
|
|
|
if (! exists $params{pages}) {
|
|
|
|
return "";
|
|
|
|
}
|
2006-08-18 05:56:18 +02:00
|
|
|
my $raw=yesno($params{raw});
|
|
|
|
my $archive=yesno($params{archive});
|
2006-10-09 01:57:37 +02:00
|
|
|
my $rss=($config{rss} && exists $params{rss}) ? yesno($params{rss}) : $config{rss};
|
|
|
|
my $atom=($config{atom} && exists $params{atom}) ? yesno($params{atom}) : $config{atom};
|
2006-11-26 20:43:24 +01:00
|
|
|
my $quick=exists $params{quick} ? yesno($params{quick}) : 0;
|
|
|
|
my $feeds=exists $params{feeds} ? yesno($params{feeds}) : !$quick;
|
2007-03-06 23:37:05 +01:00
|
|
|
$feeds=0 if $params{preview};
|
2006-08-18 05:56:18 +02:00
|
|
|
if (! exists $params{show} && ! $archive) {
|
2006-05-02 04:34:33 +02:00
|
|
|
$params{show}=10;
|
|
|
|
}
|
2006-08-26 19:36:46 +02:00
|
|
|
my $desc;
|
|
|
|
if (exists $params{description}) {
|
|
|
|
$desc = $params{description}
|
|
|
|
} else {
|
|
|
|
$desc = $config{wikiname};
|
|
|
|
}
|
2006-08-28 21:43:07 +02:00
|
|
|
my $actions=yesno($params{actions});
|
2007-03-02 05:00:42 +01:00
|
|
|
if (exists $params{template}) {
|
|
|
|
$params{template}=~s/[^-_a-zA-Z0-9]+//g;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$params{template} = $archive ? "archivepage" : "inlinepage";
|
|
|
|
}
|
2006-07-29 23:38:50 +02:00
|
|
|
|
2006-07-02 21:44:42 +02:00
|
|
|
my @list;
|
|
|
|
foreach my $page (keys %pagesources) {
|
|
|
|
next if $page eq $params{page};
|
2007-04-27 04:55:52 +02:00
|
|
|
if (pagespec_match($page, $params{pages}, location => $params{page})) {
|
2006-07-02 21:44:42 +02:00
|
|
|
push @list, $page;
|
|
|
|
}
|
|
|
|
}
|
2006-09-25 23:13:14 +02:00
|
|
|
|
|
|
|
if (exists $params{sort} && $params{sort} eq 'title') {
|
|
|
|
@list=sort @list;
|
|
|
|
}
|
2007-03-24 16:10:58 +01:00
|
|
|
elsif (exists $params{sort} && $params{sort} eq 'mtime') {
|
|
|
|
@list=sort { $pagemtime{$b} <=> $pagemtime{$a} } @list;
|
|
|
|
}
|
2006-09-25 23:13:14 +02:00
|
|
|
elsif (! exists $params{sort} || $params{sort} eq 'age') {
|
|
|
|
@list=sort { $pagectime{$b} <=> $pagectime{$a} } @list;
|
|
|
|
}
|
|
|
|
else {
|
2006-12-29 05:38:40 +01:00
|
|
|
return sprintf(gettext("unknown sort type %s"), $params{sort});
|
2006-09-25 23:13:14 +02:00
|
|
|
}
|
|
|
|
|
2007-02-08 20:48:00 +01:00
|
|
|
if (yesno($params{reverse})) {
|
|
|
|
@list=reverse(@list);
|
|
|
|
}
|
|
|
|
|
2006-11-08 21:39:48 +01:00
|
|
|
if (exists $params{skip}) {
|
|
|
|
@list=@list[$params{skip} .. scalar @list - 1];
|
|
|
|
}
|
|
|
|
|
2006-07-02 21:44:42 +02:00
|
|
|
if ($params{show} && @list > $params{show}) {
|
|
|
|
@list=@list[0..$params{show} - 1];
|
|
|
|
}
|
|
|
|
|
2006-05-02 04:34:33 +02:00
|
|
|
add_depends($params{page}, $params{pages});
|
2007-03-24 16:10:58 +01:00
|
|
|
# Explicitly add all currently displayed pages as dependencies, so
|
|
|
|
# that if they are removed or otherwise changed, the inline will be
|
|
|
|
# sure to be updated.
|
|
|
|
add_depends($params{page}, join(" or ", @list));
|
2006-05-02 04:34:33 +02:00
|
|
|
|
2007-04-01 21:59:42 +02:00
|
|
|
my $rssurl=basename(rsspage($params{page}));
|
|
|
|
my $atomurl=basename(atompage($params{page}));
|
2006-05-02 04:34:33 +02:00
|
|
|
my $ret="";
|
2006-09-06 23:03:39 +02:00
|
|
|
|
2007-03-22 00:11:09 +01:00
|
|
|
if ($config{cgiurl} && (exists $params{rootpage} ||
|
|
|
|
(exists $params{postform} && yesno($params{postform})))) {
|
2006-10-09 01:57:37 +02:00
|
|
|
# Add a blog post form, with feed buttons.
|
2006-07-02 21:06:08 +02:00
|
|
|
my $formtemplate=template("blogpost.tmpl", blind_cache => 1);
|
2006-05-02 04:34:33 +02:00
|
|
|
$formtemplate->param(cgiurl => $config{cgiurl});
|
2007-03-22 00:11:09 +01:00
|
|
|
$formtemplate->param(rootpage =>
|
|
|
|
exists $params{rootpage} ? $params{rootpage} : $params{page});
|
2006-10-09 01:57:37 +02:00
|
|
|
$formtemplate->param(rssurl => $rssurl) if $feeds && $rss;
|
|
|
|
$formtemplate->param(atomurl => $atomurl) if $feeds && $atom;
|
2007-04-12 06:13:55 +02:00
|
|
|
if (exists $params{postformtext}) {
|
|
|
|
$formtemplate->param(postformtext =>
|
|
|
|
$params{postformtext});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$formtemplate->param(postformtext =>
|
|
|
|
gettext("Add a new post titled:"));
|
|
|
|
}
|
2006-05-02 04:34:33 +02:00
|
|
|
$ret.=$formtemplate->output;
|
|
|
|
}
|
2006-10-09 01:57:37 +02:00
|
|
|
elsif ($feeds) {
|
|
|
|
# Add feed buttons.
|
|
|
|
my $linktemplate=template("feedlink.tmpl", blind_cache => 1);
|
|
|
|
$linktemplate->param(rssurl => $rssurl) if $rss;
|
|
|
|
$linktemplate->param(atomurl => $atomurl) if $atom;
|
2006-05-02 04:34:33 +02:00
|
|
|
$ret.=$linktemplate->output;
|
|
|
|
}
|
|
|
|
|
2007-03-02 05:00:42 +01:00
|
|
|
my @params=IkiWiki::template_params($params{template}.".tmpl", blind_cache => 1);
|
|
|
|
if (! @params) {
|
2007-03-03 03:27:14 +01:00
|
|
|
return sprintf(gettext("nonexistant template %s"), $params{template});
|
2007-03-02 05:00:42 +01:00
|
|
|
}
|
|
|
|
my $template=HTML::Template->new(@params) unless $raw;
|
2006-05-02 04:34:33 +02:00
|
|
|
|
2006-07-02 21:44:42 +02:00
|
|
|
foreach my $page (@list) {
|
2006-11-01 07:45:59 +01:00
|
|
|
my $file = $pagesources{$page};
|
|
|
|
my $type = pagetype($file);
|
|
|
|
if (! $raw || ($raw && ! defined $type)) {
|
2006-11-26 21:23:23 +01:00
|
|
|
unless ($archive && $quick) {
|
2006-11-26 20:43:24 +01:00
|
|
|
# Get the content before populating the
|
|
|
|
# template, since getting the content uses
|
|
|
|
# the same template if inlines are nested.
|
|
|
|
my $content=get_inline_content($page, $params{destpage});
|
|
|
|
$template->param(content => $content);
|
|
|
|
}
|
2007-04-01 21:59:42 +02:00
|
|
|
$template->param(pageurl => urlto(bestlink($params{page}, $page), $params{destpage}));
|
2006-08-18 05:56:18 +02:00
|
|
|
$template->param(title => pagetitle(basename($page)));
|
|
|
|
$template->param(ctime => displaytime($pagectime{$page}));
|
|
|
|
|
2006-08-28 21:43:07 +02:00
|
|
|
if ($actions) {
|
|
|
|
my $file = $pagesources{$page};
|
|
|
|
my $type = pagetype($file);
|
2007-01-18 16:06:57 +01:00
|
|
|
if ($config{discussion}) {
|
|
|
|
my $discussionlink=gettext("discussion");
|
|
|
|
if ($page !~ /.*\/\Q$discussionlink\E$/ &&
|
|
|
|
(length $config{cgiurl} ||
|
|
|
|
exists $links{$page."/".$discussionlink})) {
|
|
|
|
$template->param(have_actions => 1);
|
2007-02-20 04:05:47 +01:00
|
|
|
$template->param(discussionlink =>
|
|
|
|
htmllink($page,
|
|
|
|
$params{page},
|
|
|
|
gettext("Discussion"),
|
|
|
|
noimageinline => 1,
|
|
|
|
forcesubpage => 1));
|
2007-01-18 16:06:57 +01:00
|
|
|
}
|
2006-08-28 21:43:07 +02:00
|
|
|
}
|
|
|
|
if (length $config{cgiurl} && defined $type) {
|
2006-08-28 21:46:00 +02:00
|
|
|
$template->param(have_actions => 1);
|
2007-03-08 07:03:59 +01:00
|
|
|
$template->param(editurl => cgiurl(do => "edit", page => pagetitle($page, 1)));
|
2006-08-28 21:43:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-18 05:56:18 +02:00
|
|
|
run_hooks(pagetemplate => sub {
|
|
|
|
shift->(page => $page, destpage => $params{page},
|
|
|
|
template => $template,);
|
|
|
|
});
|
|
|
|
|
|
|
|
$ret.=$template->output;
|
|
|
|
$template->clear_params;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (defined $type) {
|
|
|
|
$ret.="\n".
|
|
|
|
linkify($page, $params{page},
|
2006-08-23 22:23:57 +02:00
|
|
|
preprocess($page, $params{page},
|
2007-05-17 21:55:11 +02:00
|
|
|
filter($page, $params{page},
|
2006-08-18 05:56:18 +02:00
|
|
|
readfile(srcfile($file)))));
|
|
|
|
}
|
|
|
|
}
|
2006-05-02 04:34:33 +02:00
|
|
|
}
|
|
|
|
|
2007-02-05 22:54:36 +01:00
|
|
|
if ($feeds) {
|
|
|
|
if (exists $params{feedshow} && @list > $params{feedshow}) {
|
|
|
|
@list=@list[0..$params{feedshow} - 1];
|
|
|
|
}
|
2007-04-14 22:58:02 +02:00
|
|
|
if (exists $params{feedpages}) {
|
2007-04-27 04:55:52 +02:00
|
|
|
@list=grep { pagespec_match($_, $params{feedpages}, location => $params{page}) } @list;
|
2007-04-14 22:58:02 +02:00
|
|
|
}
|
2007-02-05 22:54:36 +01:00
|
|
|
|
|
|
|
if ($rss) {
|
2007-04-01 21:59:42 +02:00
|
|
|
my $rssp=rsspage($params{page});
|
|
|
|
will_render($params{page}, $rssp);
|
|
|
|
writefile($rssp, $config{destdir},
|
2007-02-05 22:54:36 +01:00
|
|
|
genfeed("rss", $rssurl, $desc, $params{page}, @list));
|
|
|
|
$toping{$params{page}}=1 unless $config{rebuild};
|
|
|
|
$feedlinks{$params{destpage}}=qq{<link rel="alternate" type="application/rss+xml" title="RSS" href="$rssurl" />};
|
|
|
|
}
|
|
|
|
if ($atom) {
|
2007-04-01 21:59:42 +02:00
|
|
|
my $atomp=atompage($params{page});
|
|
|
|
will_render($params{page}, $atomp);
|
|
|
|
writefile($atomp, $config{destdir},
|
2007-02-05 22:54:36 +01:00
|
|
|
genfeed("atom", $atomurl, $desc, $params{page}, @list));
|
|
|
|
$toping{$params{page}}=1 unless $config{rebuild};
|
|
|
|
$feedlinks{$params{destpage}}=qq{<link rel="alternate" type="application/atom+xml" title="Atom" href="$atomurl" />};
|
|
|
|
}
|
2006-05-02 04:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
} #}}}
|
|
|
|
|
2006-09-06 23:03:39 +02:00
|
|
|
sub pagetemplate_inline (@) { #{{{
|
|
|
|
my %params=@_;
|
|
|
|
my $page=$params{page};
|
|
|
|
my $template=$params{template};
|
|
|
|
|
2006-10-09 01:57:37 +02:00
|
|
|
$template->param(feedlinks => $feedlinks{$page})
|
|
|
|
if exists $feedlinks{$page} && $template->query(name => "feedlinks");
|
2006-09-06 23:03:39 +02:00
|
|
|
} #}}}
|
|
|
|
|
2006-05-02 04:34:33 +02:00
|
|
|
sub get_inline_content ($$) { #{{{
|
|
|
|
my $page=shift;
|
2006-07-28 01:41:58 +02:00
|
|
|
my $destpage=shift;
|
2006-05-02 04:34:33 +02:00
|
|
|
|
|
|
|
my $file=$pagesources{$page};
|
|
|
|
my $type=pagetype($file);
|
2006-07-04 00:14:52 +02:00
|
|
|
if (defined $type) {
|
2006-08-28 20:17:59 +02:00
|
|
|
return htmlize($page, $type,
|
2006-08-18 02:44:46 +02:00
|
|
|
linkify($page, $destpage,
|
2006-08-23 22:23:57 +02:00
|
|
|
preprocess($page, $destpage,
|
2007-05-17 21:55:11 +02:00
|
|
|
filter($page, $destpage,
|
2006-08-18 02:44:46 +02:00
|
|
|
readfile(srcfile($file))))));
|
2006-05-02 04:34:33 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
} #}}}
|
|
|
|
|
|
|
|
sub date_822 ($) { #{{{
|
|
|
|
my $time=shift;
|
|
|
|
|
2007-01-10 21:25:00 +01:00
|
|
|
my $lc_time=POSIX::setlocale(&POSIX::LC_TIME);
|
2006-08-05 02:45:03 +02:00
|
|
|
POSIX::setlocale(&POSIX::LC_TIME, "C");
|
|
|
|
my $ret=POSIX::strftime("%a, %d %b %Y %H:%M:%S %z", localtime($time));
|
|
|
|
POSIX::setlocale(&POSIX::LC_TIME, $lc_time);
|
|
|
|
return $ret;
|
2006-05-02 04:34:33 +02:00
|
|
|
} #}}}
|
|
|
|
|
2006-10-09 01:57:37 +02:00
|
|
|
sub date_3339 ($) { #{{{
|
|
|
|
my $time=shift;
|
|
|
|
|
2007-01-10 21:25:00 +01:00
|
|
|
my $lc_time=POSIX::setlocale(&POSIX::LC_TIME);
|
2006-10-09 01:57:37 +02:00
|
|
|
POSIX::setlocale(&POSIX::LC_TIME, "C");
|
|
|
|
my $ret=POSIX::strftime("%Y-%m-%dT%H:%M:%SZ", localtime($time));
|
|
|
|
POSIX::setlocale(&POSIX::LC_TIME, $lc_time);
|
|
|
|
return $ret;
|
|
|
|
} #}}}
|
|
|
|
|
2006-05-02 04:34:33 +02:00
|
|
|
sub absolute_urls ($$) { #{{{
|
|
|
|
# sucky sub because rss sucks
|
|
|
|
my $content=shift;
|
2006-11-28 10:10:42 +01:00
|
|
|
my $baseurl=shift;
|
2006-05-02 04:34:33 +02:00
|
|
|
|
2006-11-28 10:10:42 +01:00
|
|
|
my $url=$baseurl;
|
2006-05-02 04:34:33 +02:00
|
|
|
$url=~s/[^\/]+$//;
|
|
|
|
|
2006-11-28 10:10:42 +01:00
|
|
|
$content=~s/(<a(?:\s+(?:class|id)="?\w+"?)?)\s+href="(#[^"]+)"/$1 href="$baseurl$2"/ig;
|
2006-12-21 22:52:06 +01:00
|
|
|
$content=~s/(<a(?:\s+(?:class|id)="?\w+"?)?)\s+href="(?!\w+:\/\/)([^"]+)"/$1 href="$url$2"/ig;
|
|
|
|
$content=~s/(<img(?:\s+(?:class|id)="?\w+"?)?)\s+src="(?!\w+:\/\/)([^"]+)"/$1 src="$url$2"/ig;
|
2006-05-02 04:34:33 +02:00
|
|
|
return $content;
|
|
|
|
} #}}}
|
|
|
|
|
|
|
|
sub rsspage ($) { #{{{
|
2007-04-01 21:59:42 +02:00
|
|
|
return targetpage(shift, "rss");
|
2006-05-02 04:34:33 +02:00
|
|
|
} #}}}
|
|
|
|
|
2006-10-09 01:57:37 +02:00
|
|
|
sub atompage ($) { #{{{
|
2007-04-01 21:59:42 +02:00
|
|
|
return targetpage(shift, "atom");
|
2006-10-09 01:57:37 +02:00
|
|
|
} #}}}
|
|
|
|
|
|
|
|
sub genfeed ($$$$@) { #{{{
|
|
|
|
my $feedtype=shift;
|
|
|
|
my $feedurl=shift;
|
|
|
|
my $feeddesc=shift;
|
2006-05-02 04:34:33 +02:00
|
|
|
my $page=shift;
|
|
|
|
my @pages=@_;
|
|
|
|
|
2007-04-14 22:46:41 +02:00
|
|
|
my $url=URI->new(encode_utf8($config{url}."/".urlto($page,"")));
|
2006-05-02 04:34:33 +02:00
|
|
|
|
2006-10-09 01:57:37 +02:00
|
|
|
my $itemtemplate=template($feedtype."item.tmpl", blind_cache => 1);
|
2006-07-31 02:34:18 +02:00
|
|
|
my $content="";
|
2006-10-09 01:57:37 +02:00
|
|
|
my $lasttime = 0;
|
2006-05-02 04:34:33 +02:00
|
|
|
foreach my $p (@pages) {
|
2007-04-14 22:46:41 +02:00
|
|
|
my $u=URI->new(encode_utf8($config{url}."/".urlto($p, "")));
|
2006-12-21 14:51:50 +01:00
|
|
|
my $pcontent = absolute_urls(get_inline_content($p, $page), $url);
|
2006-08-04 03:57:32 +02:00
|
|
|
|
2006-07-31 02:34:18 +02:00
|
|
|
$itemtemplate->param(
|
2007-05-28 21:43:28 +02:00
|
|
|
title => pagetitle(basename($p)),
|
2006-08-04 03:57:32 +02:00
|
|
|
url => $u,
|
|
|
|
permalink => $u,
|
2006-10-09 01:57:37 +02:00
|
|
|
date_822 => date_822($pagectime{$p}),
|
|
|
|
date_3339 => date_3339($pagectime{$p}),
|
2006-07-31 02:34:18 +02:00
|
|
|
);
|
2006-11-01 07:45:59 +01:00
|
|
|
|
|
|
|
if ($itemtemplate->query(name => "enclosure")) {
|
|
|
|
my $file=$pagesources{$p};
|
|
|
|
my $type=pagetype($file);
|
|
|
|
if (defined $type) {
|
|
|
|
$itemtemplate->param(content => $pcontent);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
my ($a, $b, $c, $d, $e, $f, $g, $size) = stat(srcfile($file));
|
|
|
|
my $mime="unknown";
|
|
|
|
eval q{use File::MimeInfo};
|
|
|
|
if (! $@) {
|
|
|
|
$mime = mimetype($file);
|
|
|
|
}
|
|
|
|
$itemtemplate->param(
|
|
|
|
enclosure => $u,
|
|
|
|
type => $mime,
|
|
|
|
length => $size,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$itemtemplate->param(content => $pcontent);
|
|
|
|
}
|
|
|
|
|
2006-07-31 02:34:18 +02:00
|
|
|
run_hooks(pagetemplate => sub {
|
|
|
|
shift->(page => $p, destpage => $page,
|
|
|
|
template => $itemtemplate);
|
|
|
|
});
|
2006-08-04 02:01:51 +02:00
|
|
|
|
2006-07-31 02:34:18 +02:00
|
|
|
$content.=$itemtemplate->output;
|
|
|
|
$itemtemplate->clear_params;
|
2006-10-09 01:57:37 +02:00
|
|
|
|
|
|
|
$lasttime = $pagectime{$p} if $pagectime{$p} > $lasttime;
|
2006-05-02 04:34:33 +02:00
|
|
|
}
|
|
|
|
|
2006-10-09 01:57:37 +02:00
|
|
|
my $template=template($feedtype."page.tmpl", blind_cache => 1);
|
2006-05-02 04:34:33 +02:00
|
|
|
$template->param(
|
2007-05-28 21:43:28 +02:00
|
|
|
title => $page ne "index" ? pagetitle($page) : $config{wikiname},
|
2006-07-31 01:51:48 +02:00
|
|
|
wikiname => $config{wikiname},
|
2006-05-02 04:34:33 +02:00
|
|
|
pageurl => $url,
|
2006-07-31 02:34:18 +02:00
|
|
|
content => $content,
|
2006-10-09 01:57:37 +02:00
|
|
|
feeddesc => $feeddesc,
|
|
|
|
feeddate => date_3339($lasttime),
|
|
|
|
feedurl => $feedurl,
|
|
|
|
version => $IkiWiki::version,
|
2006-05-02 04:34:33 +02:00
|
|
|
);
|
2006-07-30 02:20:11 +02:00
|
|
|
run_hooks(pagetemplate => sub {
|
|
|
|
shift->(page => $page, destpage => $page,
|
|
|
|
template => $template);
|
|
|
|
});
|
2006-07-29 09:25:17 +02:00
|
|
|
|
2006-05-02 04:34:33 +02:00
|
|
|
return $template->output;
|
|
|
|
} #}}}
|
|
|
|
|
2006-06-27 03:13:03 +02:00
|
|
|
sub pingurl (@) { #{{{
|
2006-12-02 01:12:26 +01:00
|
|
|
return unless @{$config{pingurl}} && %toping;
|
2006-06-27 03:13:03 +02:00
|
|
|
|
|
|
|
eval q{require RPC::XML::Client};
|
|
|
|
if ($@) {
|
2006-12-29 05:38:40 +01:00
|
|
|
debug(gettext("RPC::XML::Client not found, not pinging"));
|
2006-06-27 03:14:46 +02:00
|
|
|
return;
|
2006-06-27 03:13:03 +02:00
|
|
|
}
|
|
|
|
|
2006-11-21 18:47:53 +01:00
|
|
|
# daemonize here so slow pings don't slow down wiki updates
|
|
|
|
defined(my $pid = fork) or error("Can't fork: $!");
|
|
|
|
return if $pid;
|
2006-12-02 01:12:26 +01:00
|
|
|
chdir '/';
|
2006-11-21 18:47:53 +01:00
|
|
|
setsid() or error("Can't start a new session: $!");
|
2006-12-02 01:12:26 +01:00
|
|
|
open STDIN, '/dev/null';
|
|
|
|
open STDOUT, '>/dev/null';
|
2006-12-29 05:38:40 +01:00
|
|
|
open STDERR, '>&STDOUT' or error("Can't dup stdout: $!");
|
2006-10-16 21:06:29 +02:00
|
|
|
|
2006-11-22 03:28:42 +01:00
|
|
|
# Don't need to keep a lock on the wiki as a daemon.
|
|
|
|
IkiWiki::unlockwiki();
|
|
|
|
|
2006-06-27 03:13:03 +02:00
|
|
|
foreach my $page (keys %toping) {
|
2006-12-21 22:52:06 +01:00
|
|
|
my $title=pagetitle(basename($page), 0);
|
2007-04-14 22:46:41 +02:00
|
|
|
my $url="$config{url}/".urlto($page, "");
|
2006-06-27 03:13:03 +02:00
|
|
|
foreach my $pingurl (@{$config{pingurl}}) {
|
|
|
|
debug("Pinging $pingurl for $page");
|
2006-10-16 21:03:33 +02:00
|
|
|
eval {
|
|
|
|
my $client = RPC::XML::Client->new($pingurl);
|
|
|
|
my $req = RPC::XML::request->new('weblogUpdates.ping',
|
2006-12-21 22:52:06 +01:00
|
|
|
$title, $url);
|
2006-10-16 21:03:33 +02:00
|
|
|
my $res = $client->send_request($req);
|
|
|
|
if (! ref $res) {
|
|
|
|
debug("Did not receive response to ping");
|
|
|
|
}
|
|
|
|
my $r=$res->value;
|
|
|
|
if (! exists $r->{flerror} || $r->{flerror}) {
|
|
|
|
debug("Ping rejected: ".(exists $r->{message} ? $r->{message} : "[unknown reason]"));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if ($@) {
|
|
|
|
debug "Ping failed: $@";
|
2006-06-27 03:13:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-11-22 03:28:42 +01:00
|
|
|
|
|
|
|
exit 0; # daemon done
|
2006-06-27 03:13:03 +02:00
|
|
|
} #}}}
|
|
|
|
|
2006-05-02 04:34:33 +02:00
|
|
|
1
|