]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/rename.pm
avoid keeping running if a DOS attack is possible
[git.ikiwiki.info.git] / IkiWiki / Plugin / rename.pm
index 54c7faf137c1c87d5e90156b74be3e1139ef04d3..f793495612c2d360dd2df480c33913f0ad801b7b 100644 (file)
@@ -87,6 +87,27 @@ sub check_canrename ($$$$$$) {
                        IkiWiki::Plugin::attachment::check_canattach($session, $dest, $srcfile);
                }
        }
+
+       my $canrename;
+       IkiWiki::run_hooks(canrename => sub {
+               return if defined $canrename;
+               my $ret=shift->($q, $session, src => $src, srcfile => $srcfile,
+                               dest => $dest, destfile => $destfile);
+               if (defined $ret) {
+                       if ($ret eq "") {
+                               $canrename=1;
+                       }
+                       elsif (ref $ret eq 'CODE') {
+                               $ret->();
+                               $canrename=0;
+                       }
+                       elsif (defined $ret) {
+                               error($ret);
+                               $canrename=0;
+                       }
+               }
+       });
+       return $canrename;
 }
 
 sub rename_form ($$$) {
@@ -195,7 +216,7 @@ sub postrename ($;$$$) {
                # Update edit form content to fix any links present
                # on it.
                $postrename->param("editcontent",
-                       renamepage_hook($dest, $src, $dest,
+                       renamelink_hook($dest, $src, $dest,
                                 $postrename->param("editcontent")));
 
                # Get a new edit token; old was likely invalidated.
@@ -291,6 +312,8 @@ sub sessioncgi ($$) {
                                required => 1,
                        };
 
+                       IkiWiki::run_hooks(rename => sub { shift->(\@torename, $q, $session); });
+
                        # See if any subpages need to be renamed.
                        if ($q->param("subpages") && $src ne $dest) {
                                foreach my $p (keys %pagesources) {
@@ -390,22 +413,8 @@ sub sessioncgi ($$) {
                                $template->param(error => $rename->{error});
                                if ($rename->{src} ne $rename->{dest}) {
                                        $template->param(brokenlinks_checked => 1);
-                                       $template->param(brokenlinks => [
-                                               map {
-                                                       {
-                                                               page => htmllink($rename->{dest}, $rename->{dest}, $_,
-                                                                               noimageinline => 1)
-                                                       }
-                                               } @{$rename->{brokenlinks}}
-                                       ]);
-                                       $template->param(fixedlinks => [
-                                               map {
-                                                       {
-                                                               page => htmllink($rename->{dest}, $rename->{dest}, $_,
-                                                                               noimageinline => 1)
-                                                       }
-                                               } @{$rename->{fixedlinks}}
-                                       ]);
+                                       $template->param(brokenlinks => linklist($rename->{dest}, $rename->{brokenlinks}));
+                                       $template->param(fixedlinks => linklist($rename->{dest}, $rename->{fixedlinks}));
                                }
                                $renamesummary.=$template->output;
                        }
@@ -419,11 +428,28 @@ sub sessioncgi ($$) {
                exit 0;
        }
 }
+                                               
+sub linklist {
+       # generates a list of links in a form suitable for FormBuilder
+       my $dest=shift;
+       my $list=shift;
+       # converts a list of pages into a list of links
+       # in a form suitable for FormBuilder.
+
+       [map {
+               {
+                       page => htmllink($dest, $dest, $_,
+                                       noimageinline => 1,
+                                       linktext => pagetitle($_),
+                               )
+               }
+       } @{$list}]
+}
 
-sub renamepage_hook ($$$$) {
+sub renamelink_hook ($$$$) {
        my ($page, $src, $dest, $content)=@_;
 
-       IkiWiki::run_hooks(renamepage => sub {
+       IkiWiki::run_hooks(renamelink => sub {
                $content=shift->(
                        page => $page,
                        oldpage => $src,
@@ -480,7 +506,7 @@ sub fixlinks ($$$) {
                if ($needfix) {
                        my $file=$pagesources{$page};
                        my $oldcontent=readfile($config{srcdir}."/".$file);
-                       my $content=renamepage_hook($page, $rename->{src}, $rename->{dest}, $oldcontent);
+                       my $content=renamelink_hook($page, $rename->{src}, $rename->{dest}, $oldcontent);
                        if ($oldcontent ne $content) {
                                my $token=IkiWiki::rcs_prepedit($file);
                                eval { writefile($file, $config{srcdir}, $content) };