]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/rename.pm
po: actually use pofiles() function, to enhance code clarity
[git.ikiwiki.info.git] / IkiWiki / Plugin / rename.pm
index b2c3eedfe075a20b98c57b7e2cd812fcbb7bc276..7e55e271cbe6a403115fb38eff1f5655fbc626d6 100644 (file)
@@ -210,11 +210,12 @@ sub formbuilder (@) { #{{{
        my %params=@_;
        my $form=$params{form};
 
-       if (defined $form->field("do") && $form->field("do") eq "edit") {
+       if (defined $form->field("do") && ($form->field("do") eq "edit" ||
+           $form->field("do") eq "create")) {
                my $q=$params{cgi};
                my $session=$params{session};
 
-               if ($form->submitted eq "Rename") {
+               if ($form->submitted eq "Rename" && $form->field("do") eq "edit") {
                        rename_start($q, $session, 0, $form->field("page"));
                }
                elsif ($form->submitted eq "Rename Attachment") {
@@ -237,9 +238,10 @@ sub formbuilder_setup (@) { #{{{
        my $form=$params{form};
        my $q=$params{cgi};
 
-       if (defined $form->field("do") && $form->field("do") eq "edit") {
+       if (defined $form->field("do") && ($form->field("do") eq "edit" ||
+           $form->field("do") eq "create")) {
                # Rename button for the page, and also for attachments.
-               push @{$params{buttons}}, "Rename";
+               push @{$params{buttons}}, "Rename" if $form->field("do") eq "edit";
                $form->tmpl_param("field-rename" => '<input name="_submit" type="submit" value="Rename Attachment" />');
 
                if (defined $renamesummary) {
@@ -279,12 +281,7 @@ sub sessioncgi ($$) { #{{{
                                        $type=$ext;
                                }
                                
-                               if (! $config{indexpages}) {
-                                       $destfile.=".".$type;
-                               }
-                               else {
-                                       $destfile.="/index.".$type;
-                               }
+                               $destfile=newpagefile($dest, $type);
                        }
                        push @torename, {
                                src => $src,
@@ -297,17 +294,21 @@ sub sessioncgi ($$) { #{{{
                        # See if any subpages need to be renamed.
                        if ($q->param("subpages") && $src ne $dest) {
                                foreach my $p (keys %pagesources) {
-                                       if ($pagesources{$p}=~m/^\Q$src\E\//) {
-                                               my $d=$pagesources{$p};
-                                               $d=~s/^\Q$src\E\//$dest\//;
-                                               push @torename, {
-                                                       src => $p,
-                                                       srcfile => $pagesources{$p},
-                                                       dest => pagename($d),
-                                                       destfile => $d,
-                                                       required => 0,
-                                               };
-                                       }
+                                       next unless $pagesources{$p}=~m/^\Q$src\E\//;
+                                       # If indexpages is enabled, the
+                                       # srcfile should not be confused
+                                       # with a subpage.
+                                       next if $pagesources{$p} eq $srcfile;
+
+                                       my $d=$pagesources{$p};
+                                       $d=~s/^\Q$src\E\//$dest\//;
+                                       push @torename, {
+                                               src => $p,
+                                               srcfile => $pagesources{$p},
+                                               dest => pagename($d),
+                                               destfile => $d,
+                                               required => 0,
+                                       };
                                }
                        }