X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/a65d312467c5ab179ecf4aa715790f371a46634a..7390a7a0721d9985c88efec1fd0e3a19d0368c82:/IkiWiki/Plugin/inline.pm diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index 5517e3c94..536d7cd02 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -15,6 +15,7 @@ my $nested=0; sub import { #{{{ hook(type => "getopt", id => "inline", call => \&getopt); + hook(type => "getsetup", id => "inline", call => \&getsetup); hook(type => "checkconfig", id => "inline", call => \&checkconfig); hook(type => "sessioncgi", id => "inline", call => \&sessioncgi); hook(type => "preprocess", id => "inline", @@ -27,7 +28,6 @@ sub import { #{{{ # pings interrupting page builds. hook(type => "change", id => "inline", call => \&IkiWiki::pingurl); - } # }}} sub getopt () { #{{{ @@ -39,8 +39,54 @@ sub getopt () { #{{{ "atom!" => \$config{atom}, "allowrss!" => \$config{allowrss}, "allowatom!" => \$config{allowatom}, + "pingurl=s" => sub { + push @{$config{pingurl}}, $_[1]; + }, ); -} +} #}}} + +sub getsetup () { #{{{ + return + plugin => { + safe => 1, + rebuild => undef, + }, + rss => { + type => "boolean", + example => 0, + description => "enable rss feeds by default?", + safe => 1, + rebuild => 1, + }, + atom => { + type => "boolean", + example => 0, + description => "enable atom feeds by default?", + safe => 1, + rebuild => 1, + }, + allowrss => { + type => "boolean", + example => 0, + description => "allow rss feeds to be used?", + safe => 1, + rebuild => 1, + }, + allowatom => { + type => "boolean", + example => 0, + description => "allow atom feeds to be used?", + safe => 1, + rebuild => 1, + }, + pingurl => { + type => "string", + example => "http://rpc.technorati.com/rpc/ping", + description => "urls to ping (using XML-RPC) on feed update", + safe => 1, + rebuild => 0, + }, +} #}}} sub checkconfig () { #{{{ if (($config{rss} || $config{atom}) && ! length $config{url}) { @@ -52,6 +98,9 @@ sub checkconfig () { #{{{ if ($config{atom}) { push @{$config{wiki_file_prune_regexps}}, qr/\.atom$/; } + if (! exists $config{pingurl}) { + $config{pingurl}=[]; + } } #}}} sub format (@) { #{{{ @@ -65,12 +114,12 @@ sub format (@) { #{{{ return $params{content}; } #}}} -sub sessioncgi () { #{{{ +sub sessioncgi ($$) { #{{{ my $q=shift; my $session=shift; if ($q->param('do') eq 'blog') { - my $page=IkiWiki::titlepage(decode_utf8($q->param('title'))); + my $page=titlepage(decode_utf8($q->param('title'))); $page=~s/(\/)/"__".ord($1)."__"/eg; # don't create subdirs # if the page already exists, munge it to be unique my $from=$q->param('from'); @@ -82,7 +131,13 @@ sub sessioncgi () { #{{{ $q->param('page', $page.$add); # now go create the page $q->param('do', 'create'); - IkiWiki::cgi_editpage($q, $session); + # make sure the editpage plugin in loaded + if (IkiWiki->can("cgi_editpage")) { + IkiWiki::cgi_editpage($q, $session); + } + else { + error(gettext("page editing not allowed")); + } exit; } } @@ -137,7 +192,7 @@ sub preprocess_inline (@) { #{{{ } if (exists $params{sort} && $params{sort} eq 'title') { - @list=sort @list; + @list=sort { pagetitle(basename($a)) cmp pagetitle(basename($b)) } @list; } elsif (exists $params{sort} && $params{sort} eq 'mtime') { @list=sort { $pagemtime{$b} <=> $pagemtime{$a} } @list; @@ -202,13 +257,23 @@ sub preprocess_inline (@) { #{{{ my $atomurl=basename(atompage($params{destpage}).$feednum) if $feeds && $atom; my $ret=""; - if ($config{cgiurl} && ! $params{preview} && (exists $params{rootpage} || - (exists $params{postform} && yesno($params{postform})))) { + if (length $config{cgiurl} && ! $params{preview} && (exists $params{rootpage} || + (exists $params{postform} && yesno($params{postform}))) && + IkiWiki->can("cgi_editpage")) { # Add a blog post form, with feed buttons. my $formtemplate=template("blogpost.tmpl", blind_cache => 1); $formtemplate->param(cgiurl => $config{cgiurl}); - $formtemplate->param(rootpage => - exists $params{rootpage} ? $params{rootpage} : $params{page}); + my $rootpage; + if (exists $params{rootpage}) { + $rootpage=bestlink($params{page}, $params{rootpage}); + if (!length $rootpage) { + $rootpage=$params{rootpage}; + } + } + else { + $rootpage=$params{page}; + } + $formtemplate->param(rootpage => $rootpage); $formtemplate->param(rssurl => $rssurl) if $feeds && $rss; $formtemplate->param(atomurl => $atomurl) if $feeds && $atom; if (exists $params{postformtext}) { @@ -251,6 +316,9 @@ sub preprocess_inline (@) { #{{{ $template->param(pageurl => urlto(bestlink($params{page}, $page), $params{destpage})); $template->param(title => pagetitle(basename($page))); $template->param(ctime => displaytime($pagectime{$page}, $params{timeformat})); + $template->param(ctime_raw => scalar localtime($pagectime{$page})); + $template->param(mtime => displaytime($pagemtime{$page}, $params{timeformat})); + $template->param(mtime_raw => scalar localtime($pagemtime{$page})); $template->param(first => 1) if $page eq $list[0]; $template->param(last => 1) if $page eq $list[$#list]; @@ -308,9 +376,9 @@ sub preprocess_inline (@) { #{{{ if (! $params{preview}) { writefile($rssp, $config{destdir}, genfeed("rss", - $config{url}."/".rsspage($params{destpage}).$feednum, $desc, $params{guid}, $params{destpage}, @feedlist)); + $config{url}."/".$rssp, $desc, $params{guid}, $params{destpage}, @feedlist)); $toping{$params{destpage}}=1 unless $config{rebuild}; - $feedlinks{$params{destpage}}=qq{}; + $feedlinks{$params{destpage}}=qq{}; } } if ($atom) { @@ -318,9 +386,9 @@ sub preprocess_inline (@) { #{{{ will_render($params{destpage}, $atomp); if (! $params{preview}) { writefile($atomp, $config{destdir}, - genfeed("atom", $config{url}."/".atompage($params{destpage}).$feednum, $desc, $params{guid}, $params{destpage}, @feedlist)); + genfeed("atom", $config{url}."/".$atomp, $desc, $params{guid}, $params{destpage}, @feedlist)); $toping{$params{destpage}}=1 unless $config{rebuild}; - $feedlinks{$params{destpage}}=qq{}; + $feedlinks{$params{destpage}}=qq{}; } } } @@ -419,13 +487,13 @@ sub genfeed ($$$$$@) { #{{{ my $page=shift; my @pages=@_; - my $url=URI->new(encode_utf8($config{url}."/".urlto($page,""))); + my $url=URI->new(encode_utf8(urlto($page,"",1))); my $itemtemplate=template($feedtype."item.tmpl", blind_cache => 1); my $content=""; my $lasttime = 0; foreach my $p (@pages) { - my $u=URI->new(encode_utf8($config{url}."/".urlto($p, ""))); + my $u=URI->new(encode_utf8(urlto($p, "", 1))); my $pcontent = absolute_urls(get_inline_content($p, $page), $url); $itemtemplate->param( @@ -521,7 +589,7 @@ sub pingurl (@) { #{{{ foreach my $page (keys %toping) { my $title=pagetitle(basename($page), 0); - my $url="$config{url}/".urlto($page, ""); + my $url=urlto($page, "", 1); foreach my $pingurl (@{$config{pingurl}}) { debug("Pinging $pingurl for $page"); eval { @@ -530,15 +598,15 @@ sub pingurl (@) { #{{{ $title, $url); my $res = $client->send_request($req); if (! ref $res) { - debug("Did not receive response to ping"); + error("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]")); + error("Ping rejected: ".(exists $r->{message} ? $r->{message} : "[unknown reason]")); } }; if ($@) { - debug "Ping failed: $@"; + error "Ping failed: $@"; } } }