X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/774a5f86b2fa8dcbc561c50901cf655711e836dc..50a5ab3c4e1db5beb18d86873143e7715fd5b27e:/IkiWiki/Plugin/aggregate.pm diff --git a/IkiWiki/Plugin/aggregate.pm b/IkiWiki/Plugin/aggregate.pm index e44c26f74..9da619375 100644 --- a/IkiWiki/Plugin/aggregate.pm +++ b/IkiWiki/Plugin/aggregate.pm @@ -30,7 +30,10 @@ sub getopt () { #{{{ eval q{use Getopt::Long}; error($@) if $@; Getopt::Long::Configure('pass_through'); - GetOptions("aggregate" => \$config{aggregate}); + GetOptions( + "aggregate" => \$config{aggregate}, + "aggregateinternal!" => \$config{aggregateinternal}, + ); } #}}} sub checkconfig () { #{{{ @@ -110,6 +113,49 @@ sub launchaggregation () { #{{{ return 1; } #}}} +sub migrate_to_internal { #{{{ + + if (! lockaggregate()) { + error("an aggregation process is already running"); + return; + } + + IkiWiki::lockwiki(); + loadstate(); + + foreach my $data (values %guids) { + next unless $data->{page}; + + $config{aggregateinternal} = 0; + my $oldname = pagefile($data->{page}); + + $config{aggregateinternal} = 1; + my $newname = pagefile($data->{page}); + + print "I: $oldname -> $newname\n"; + if (-e $newname) { + if (-e $oldname) { + error("$newname already exists"); + } + else { + print STDERR + "W: already renamed to $newname?\n"; + } + } + elsif (-e $oldname) { + rename($oldname, $newname) || error("$!"); + } + else { + print "W: $oldname not found\n"; + } + } + + savestate(); + IkiWiki::unlockwiki; + + unlockaggregate(); +} #}}} + sub needsbuild (@) { #{{{ my $needsbuild=shift; @@ -131,7 +177,7 @@ sub preprocess (@) { #{{{ foreach my $required (qw{name url}) { if (! exists $params{$required}) { - return "[[aggregate ".sprintf(gettext("missing %s parameter"), $required)."]]"; + error sprintf(gettext("missing %s parameter"), $required) } } @@ -154,6 +200,13 @@ sub preprocess (@) { #{{{ $feed->{updateinterval}=defined $params{updateinterval} ? $params{updateinterval} * 60 : 15 * 60; $feed->{expireage}=defined $params{expireage} ? $params{expireage} : 0; $feed->{expirecount}=defined $params{expirecount} ? $params{expirecount} : 0; + if (exists $params{template}) { + $params{template}=~s/[^-_a-zA-Z0-9]+//g; + } + else { + $params{template} = "aggregatepost" + } + $feed->{template}=$params{template} . ".tmpl"; delete $feed->{unseen}; $feed->{lastupdate}=0 unless defined $feed->{lastupdate}; $feed->{numposts}=0 unless defined $feed->{numposts}; @@ -507,7 +560,7 @@ sub add_page (@) { #{{{ $guid->{md5}=$digest; # Create the page. - my $template=template("aggregatepost.tmpl", blind_cache => 1); + my $template=template($feed->{template}, blind_cache => 1); $template->param(title => $params{title}) if defined $params{title} && length($params{title}); $template->param(content => htmlescape(htmlabs($params{content}, $feed->{feedurl}))); @@ -588,7 +641,7 @@ sub pagefile ($) { #{{{ } #}}} sub htmlfn ($) { #{{{ - return shift().".".$config{htmlext}; + return shift().".".($config{aggregateinternal} ? "_" : "").$config{htmlext}; } #}}} my $aggregatelock;