]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/aggregate.pm
Add aggregateinternal mode to ikiwiki-transition.
[ikiwiki.git] / IkiWiki / Plugin / aggregate.pm
index a9c7447fa8faf6a082e714b84cd203f2c4e3355d..9da619375df515ec4e8d236d10ce7b7b5b2c2130 100644 (file)
@@ -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};
@@ -407,14 +460,14 @@ sub aggregate (@) { #{{{
                        # that contains invalid UTF-8 sequences. Convert
                        # feed to ascii to try to work around.
                        $feed->{message}.=" ".sprintf(gettext("(invalid UTF-8 stripped from feed)"));
-                       $content=Encode::decode_utf8($content);
+                       $content=Encode::decode_utf8($content, 0);
                        $f=eval{XML::Feed->parse(\$content)};
                }
                if ($@) {
                        # Another possibility is badly escaped entities.
                        $feed->{message}.=" ".sprintf(gettext("(feed entities escaped)"));
                        $content=~s/\&(?!amp)(\w+);/&$1;/g;
-                       $content=Encode::decode_utf8($content);
+                       $content=Encode::decode_utf8($content, 0);
                        $f=eval{XML::Feed->parse(\$content)};
                }
                if ($@) {
@@ -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;