2006-05-02 04:34:33 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# Page inlining and blogging.
|
|
|
|
package IkiWiki::Plugin::inline;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2007-08-06 00:07:32 +02:00
|
|
|
use Encode;
|
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
|
|
|
|
2007-10-25 11:43:43 +02:00
|
|
|
my %knownfeeds;
|
|
|
|
my %page_numfeeds;
|
|
|
|
|
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);
|
2008-01-07 21:28:53 +01:00
|
|
|
hook(type => "sessioncgi", id => "inline", call => \&sessioncgi);
|
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);
|
2007-08-06 00:07:32 +02:00
|
|
|
|
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},
|
2008-02-05 00:36:50 +01:00
|
|
|
"allowrss!" => \$config{allowrss},
|
|
|
|
"allowatom!" => \$config{allowatom},
|
2006-12-21 20:36:15 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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$/;
|
|
|
|
}
|
|
|
|
} #}}}
|
|
|
|
|
2007-08-06 00:07:32 +02:00
|
|
|
sub sessioncgi () { #{{{
|
|
|
|
my $q=shift;
|
|
|
|
my $session=shift;
|
|
|
|
|
|
|
|
if ($q->param('do') eq 'blog') {
|
|
|
|
my $page=decode_utf8($q->param('title'));
|
|
|
|
$page=~s/\///g; # no slashes in blog posts
|
|
|
|
# if the page already exists, munge it to be unique
|
|
|
|
my $from=$q->param('from');
|
|
|
|
my $add="";
|
|
|
|
while (exists $IkiWiki::pagecase{lc($from."/".IkiWiki::titlepage($page).$add)}) {
|
|
|
|
$add=1 unless length $add;
|
|
|
|
$add++;
|
|
|
|
}
|
|
|
|
$q->param('page', $page.$add);
|
|
|
|
# now go create the page
|
|
|
|
$q->param('do', 'create');
|
|
|
|
IkiWiki::cgi_editpage($q, $session);
|
2007-08-26 19:32:15 +02:00
|
|
|
exit;
|
2007-08-06 00:07:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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});
|
2008-02-05 00:36:50 +01:00
|
|
|
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};
|
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-09-14 00:23:32 +02:00
|
|
|
my $feedonly=yesno($params{feedonly});
|
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));
|
2008-01-09 08:38:43 +01:00
|
|
|
|
2007-10-25 11:43:43 +02:00
|
|
|
my $feednum="";
|
|
|
|
|
2007-10-25 12:20:32 +02:00
|
|
|
my $feedid=join("\0", map { $_."\0".$params{$_} } sort keys %params);
|
2007-10-25 11:43:43 +02:00
|
|
|
if (exists $knownfeeds{$feedid}) {
|
|
|
|
$feednum=$knownfeeds{$feedid};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (exists $page_numfeeds{$params{destpage}}) {
|
2007-12-13 09:56:59 +01:00
|
|
|
if ($feeds) {
|
|
|
|
$feednum=$knownfeeds{$feedid}=++$page_numfeeds{$params{destpage}};
|
|
|
|
}
|
2007-10-25 11:43:43 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$feednum=$knownfeeds{$feedid}="";
|
2007-12-06 13:06:21 +01:00
|
|
|
if ($feeds) {
|
|
|
|
$page_numfeeds{$params{destpage}}=1;
|
|
|
|
}
|
2007-10-25 11:43:43 +02:00
|
|
|
}
|
|
|
|
}
|
2006-05-02 04:34:33 +02:00
|
|
|
|
2007-12-16 22:07:52 +01:00
|
|
|
my $rssurl=basename(rsspage($params{destpage}).$feednum) if $feeds && $rss;
|
|
|
|
my $atomurl=basename(atompage($params{destpage}).$feednum) if $feeds && $atom;
|
2006-05-02 04:34:33 +02:00
|
|
|
my $ret="";
|
2006-09-06 23:03:39 +02:00
|
|
|
|
2008-02-05 00:44:54 +01:00
|
|
|
if ($config{cgiurl} && ! $params{preview} && (exists $params{rootpage} ||
|
2007-03-22 00:11:09 +01:00
|
|
|
(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;
|
|
|
|
}
|
2008-02-05 00:44:54 +01:00
|
|
|
elsif ($feeds && !$params{preview}) {
|
2006-10-09 01:57:37 +02:00
|
|
|
# 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-09-14 00:23:32 +02:00
|
|
|
if (! $feedonly) {
|
|
|
|
require HTML::Template;
|
|
|
|
my @params=IkiWiki::template_params($params{template}.".tmpl", blind_cache => 1);
|
|
|
|
if (! @params) {
|
|
|
|
return sprintf(gettext("nonexistant template %s"), $params{template});
|
|
|
|
}
|
|
|
|
my $template=HTML::Template->new(@params) unless $raw;
|
2006-05-02 04:34:33 +02:00
|
|
|
|
2007-09-14 00:23:32 +02:00
|
|
|
foreach my $page (@list) {
|
|
|
|
my $file = $pagesources{$page};
|
|
|
|
my $type = pagetype($file);
|
|
|
|
if (! $raw || ($raw && ! defined $type)) {
|
|
|
|
unless ($archive && $quick) {
|
|
|
|
# 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);
|
|
|
|
}
|
|
|
|
$template->param(pageurl => urlto(bestlink($params{page}, $page), $params{destpage}));
|
|
|
|
$template->param(title => pagetitle(basename($page)));
|
2007-11-13 22:14:48 +01:00
|
|
|
$template->param(ctime => displaytime($pagectime{$page}, $params{timeformat}));
|
2008-01-29 03:22:04 +01:00
|
|
|
$template->param(first => 1) if $page eq $list[0];
|
|
|
|
$template->param(last => 1) if $page eq $list[$#list];
|
2007-09-14 00:23:32 +02:00
|
|
|
|
|
|
|
if ($actions) {
|
|
|
|
my $file = $pagesources{$page};
|
|
|
|
my $type = pagetype($file);
|
|
|
|
if ($config{discussion}) {
|
|
|
|
my $discussionlink=gettext("discussion");
|
|
|
|
if ($page !~ /.*\/\Q$discussionlink\E$/ &&
|
|
|
|
(length $config{cgiurl} ||
|
|
|
|
exists $links{$page."/".$discussionlink})) {
|
|
|
|
$template->param(have_actions => 1);
|
|
|
|
$template->param(discussionlink =>
|
|
|
|
htmllink($page,
|
2007-10-25 11:43:43 +02:00
|
|
|
$params{destpage},
|
2007-09-14 00:23:32 +02:00
|
|
|
gettext("Discussion"),
|
|
|
|
noimageinline => 1,
|
|
|
|
forcesubpage => 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (length $config{cgiurl} && defined $type) {
|
2007-01-18 16:06:57 +01:00
|
|
|
$template->param(have_actions => 1);
|
2007-09-14 00:23:32 +02:00
|
|
|
$template->param(editurl => cgiurl(do => "edit", page => pagetitle($page, 1)));
|
2007-01-18 16:06:57 +01:00
|
|
|
}
|
2006-08-28 21:43:07 +02:00
|
|
|
}
|
2007-09-14 00:23:32 +02:00
|
|
|
|
|
|
|
run_hooks(pagetemplate => sub {
|
2007-10-25 11:43:43 +02:00
|
|
|
shift->(page => $page, destpage => $params{destpage},
|
2007-09-14 00:23:32 +02:00
|
|
|
template => $template,);
|
|
|
|
});
|
|
|
|
|
|
|
|
$ret.=$template->output;
|
|
|
|
$template->clear_params;
|
2006-08-28 21:43:07 +02:00
|
|
|
}
|
2007-09-14 00:23:32 +02:00
|
|
|
else {
|
|
|
|
if (defined $type) {
|
|
|
|
$ret.="\n".
|
2007-10-25 11:43:43 +02:00
|
|
|
linkify($page, $params{destpage},
|
|
|
|
preprocess($page, $params{destpage},
|
|
|
|
filter($page, $params{destpage},
|
2007-09-14 00:23:32 +02:00
|
|
|
readfile(srcfile($file)))));
|
|
|
|
}
|
2006-08-18 05:56:18 +02:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2008-02-05 00:46:34 +01:00
|
|
|
if ($rss) {
|
2007-10-25 11:43:43 +02:00
|
|
|
my $rssp=rsspage($params{destpage}).$feednum;
|
|
|
|
will_render($params{destpage}, $rssp);
|
2008-02-05 00:46:34 +01:00
|
|
|
if (! $params{preview}) {
|
|
|
|
writefile($rssp, $config{destdir},
|
2008-03-12 23:49:41 +01:00
|
|
|
genfeed("rss",
|
|
|
|
$config{url}."/".rsspage($params{destpage}).$feednum, $desc, $params{destpage}, @list));
|
2008-02-05 00:46:34 +01:00
|
|
|
$toping{$params{destpage}}=1 unless $config{rebuild};
|
|
|
|
$feedlinks{$params{destpage}}=qq{<link rel="alternate" type="application/rss+xml" title="RSS" href="$rssurl" />};
|
|
|
|
}
|
2007-02-05 22:54:36 +01:00
|
|
|
}
|
2008-02-05 00:46:34 +01:00
|
|
|
if ($atom) {
|
2007-10-25 11:43:43 +02:00
|
|
|
my $atomp=atompage($params{destpage}).$feednum;
|
|
|
|
will_render($params{destpage}, $atomp);
|
2008-02-05 00:46:34 +01:00
|
|
|
if (! $params{preview}) {
|
|
|
|
writefile($atomp, $config{destdir},
|
2008-03-12 23:49:41 +01:00
|
|
|
genfeed("atom", $config{url}."/".atompage($params{destpage}).$feednum, $desc, $params{destpage}, @list));
|
2008-02-05 00:46:34 +01:00
|
|
|
$toping{$params{destpage}}=1 unless $config{rebuild};
|
|
|
|
$feedlinks{$params{destpage}}=qq{<link rel="alternate" type="application/atom+xml" title="Atom" href="$atomurl" />};
|
|
|
|
}
|
2007-02-05 22:54:36 +01:00
|
|
|
}
|
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");
|
2007-09-02 21:29:40 +02:00
|
|
|
my $ret=POSIX::strftime("%Y-%m-%dT%H:%M:%SZ", gmtime($time));
|
2006-10-09 01:57:37 +02:00
|
|
|
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/[^\/]+$//;
|
|
|
|
|
2007-06-03 19:10:32 +02:00
|
|
|
$content=~s/(<a(?:\s+(?:class|id)\s*="?\w+"?)?)\s+href=\s*"(#[^"]+)"/$1 href="$baseurl$2"/mig;
|
2008-02-24 23:07:56 +01:00
|
|
|
$content=~s/(<a(?:\s+(?:class|id)\s*="?\w+"?)?)\s+href=\s*"(?!\w+:)([^"]+)"/$1 href="$url$2"/mig;
|
|
|
|
$content=~s/(<img(?:\s+(?:class|id|width|height)\s*="?\w+"?)*)\s+src=\s*"(?!\w+:)([^"]+)"/$1 src="$url$2"/mig;
|
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,
|
2007-08-12 01:15:08 +02:00
|
|
|
cdate_822 => date_822($pagectime{$p}),
|
|
|
|
mdate_822 => date_822($pagemtime{$p}),
|
|
|
|
cdate_3339 => date_3339($pagectime{$p}),
|
|
|
|
mdate_3339 => date_3339($pagemtime{$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
|
|
|
|
2007-08-12 01:15:08 +02:00
|
|
|
$lasttime = $pagemtime{$p} if $pagemtime{$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
|