]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/rename.pm
po plugin: implement linking specification in one of the main cases
[git.ikiwiki.info.git] / IkiWiki / Plugin / rename.pm
index 4ee377b86c5b5f500eb6acd1323fa174cf4ba709..7e55e271cbe6a403115fb38eff1f5655fbc626d6 100644 (file)
@@ -29,7 +29,7 @@ sub check_canrename ($$$$$$) { #{{{
        my $q=shift;
        my $session=shift;
 
        my $q=shift;
        my $session=shift;
 
-       my $attachment=! defined IkiWiki::pagetype($pagesources{$src});
+       my $attachment=! defined pagetype($pagesources{$src});
 
        # Must be a known source file.
        if (! exists $pagesources{$src}) {
 
        # Must be a known source file.
        if (! exists $pagesources{$src}) {
@@ -98,7 +98,7 @@ sub rename_form ($$$) { #{{{
        error($@) if $@;
        my $f = CGI::FormBuilder->new(
                name => "rename",
        error($@) if $@;
        my $f = CGI::FormBuilder->new(
                name => "rename",
-               title => sprintf(gettext("rename %s"), IkiWiki::pagetitle($page)),
+               title => sprintf(gettext("rename %s"), pagetitle($page)),
                header => 0,
                charset => "utf-8",
                method => 'POST',
                header => 0,
                charset => "utf-8",
                method => 'POST',
@@ -111,7 +111,7 @@ sub rename_form ($$$) { #{{{
        
        $f->field(name => "do", type => "hidden", value => "rename", force => 1);
        $f->field(name => "page", type => "hidden", value => $page, force => 1);
        
        $f->field(name => "do", type => "hidden", value => "rename", force => 1);
        $f->field(name => "page", type => "hidden", value => $page, force => 1);
-       $f->field(name => "new_name", value => IkiWiki::pagetitle($page), size => 60);
+       $f->field(name => "new_name", value => pagetitle($page), size => 60);
        if (!$q->param("attachment")) {
                # insert the standard extensions
                my @page_types;
        if (!$q->param("attachment")) {
                # insert the standard extensions
                my @page_types;
@@ -210,11 +210,12 @@ sub formbuilder (@) { #{{{
        my %params=@_;
        my $form=$params{form};
 
        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};
 
                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") {
                        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};
 
        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.
                # 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) {
                $form->tmpl_param("field-rename" => '<input name="_submit" type="submit" value="Rename Attachment" />');
 
                if (defined $renamesummary) {
@@ -267,7 +269,7 @@ sub sessioncgi ($$) { #{{{
                        # performed in check_canrename later.
                        my $src=$q->param("page");
                        my $srcfile=IkiWiki::possibly_foolish_untaint($pagesources{$src});
                        # performed in check_canrename later.
                        my $src=$q->param("page");
                        my $srcfile=IkiWiki::possibly_foolish_untaint($pagesources{$src});
-                       my $dest=IkiWiki::possibly_foolish_untaint(IkiWiki::titlepage($q->param("new_name")));
+                       my $dest=IkiWiki::possibly_foolish_untaint(titlepage($q->param("new_name")));
                        my $destfile=$dest;
                        if (! $q->param("attachment")) {
                                my $type=$q->param('type');
                        my $destfile=$dest;
                        if (! $q->param("attachment")) {
                                my $type=$q->param('type');
@@ -279,7 +281,7 @@ sub sessioncgi ($$) { #{{{
                                        $type=$ext;
                                }
                                
                                        $type=$ext;
                                }
                                
-                               $destfile.=".".$type;
+                               $destfile=newpagefile($dest, $type);
                        }
                        push @torename, {
                                src => $src,
                        }
                        push @torename, {
                                src => $src,
@@ -292,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) {
                        # 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,
+                                       };
                                }
                        }
                        
                                }
                        }