Index: test/functional/wiki_controller_test.rb
===================================================================
--- test/functional/wiki_controller_test.rb	(revision 2761)
+++ test/functional/wiki_controller_test.rb	(working copy)
@@ -57,6 +57,9 @@
                :child => { :tag => 'li',
                            :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
                                                     :content => 'Page with an inline image' } }
+    assert_tag :a, :attributes => { :href => '/projects/ecookbook/wiki/Documentation?parent=CookBook_documentation',
+                                    :class => 'wiki-page new' },
+                   :content => 'documentation'
   end
   
   def test_show_page_with_name
@@ -106,7 +109,41 @@
     assert_not_nil page.content
     assert_equal 'Created the page', page.content.comments
   end
-  
+
+  def test_create_page_with_automatic_parent
+    @request.session[:user_id] = 2
+    post :edit, :id => 1,
+                :page => 'New page 2',
+                :content => {:comments => 'Created the page 2',
+                             :text => "h1. New page 2\n\nThis is a new page with an auto parent !",
+                             :version => 0},
+                :set_parent => 'Save and set parent page',
+                :parent => 'CookBook_documentation'
+    assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'New_page_2'
+    page = Project.find(1).wiki.find_page('New page 2')
+    assert !page.new_record?
+    assert_not_nil page.content
+    assert_equal 'Created the page 2', page.content.comments
+    assert_not_nil page.parent
+    assert_equal 'CookBook_documentation', page.parent.title
+  end
+ 
+  def test_create_page_without_automatic_parent
+    @request.session[:user_id] = 2
+    post :edit, :id => 1,
+                :page => 'New page 3',
+                :content => {:comments => 'Created the page 3',
+                             :text => "h1. New page 3\n\nThis is a new page without an auto parent :-(",
+                             :version => 0},
+                :parent => 'CookBook_documentation'
+    assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'New_page_3'
+    page = Project.find(1).wiki.find_page('New page 3')
+    assert !page.new_record?   
+    assert_not_nil page.content
+    assert_equal 'Created the page 3', page.content.comments
+    assert_nil page.parent
+  end
+ 
   def test_preview_routing
     assert_routing(
       {:method => :post, :path => '/projects/567/wiki/CookBook_documentation/preview'},
Index: app/helpers/application_helper.rb
===================================================================
--- app/helpers/application_helper.rb	(revision 2761)
+++ app/helpers/application_helper.rb	(working copy)
@@ -361,12 +361,12 @@
     case options[:wiki_links]
     when :local
       # used for local links to html files
-      format_wiki_link = Proc.new {|project, title, anchor| "#{title}.html" }
+      format_wiki_link = Proc.new {|project, title, anchor, parent| "#{title}.html" }
     when :anchor
       # used for single-file wiki export
-      format_wiki_link = Proc.new {|project, title, anchor| "##{title}" }
+      format_wiki_link = Proc.new {|project, title, anchor, parent| "##{title}" }
     else
-      format_wiki_link = Proc.new {|project, title, anchor| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title, :anchor => anchor) }
+      format_wiki_link = Proc.new {|project, title, anchor, parent| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title, :anchor => anchor, :parent => parent) }
     end
 
     project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
@@ -399,8 +399,7 @@
           end
           # check if page exists
           wiki_page = link_project.wiki.find_page(page)
-          link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page), anchor),
-                                   :class => ('wiki-page' + (wiki_page ? '' : ' new')))
+          link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page), anchor, (wiki_page || @page.nil? ? nil : @page.title)), :class => ('wiki-page' + (wiki_page ? '' : ' new')))
         else
           # project or wiki doesn't exist
           all
Index: app/controllers/wiki_controller.rb
===================================================================
--- app/controllers/wiki_controller.rb	(revision 2761)
+++ app/controllers/wiki_controller.rb	(working copy)
@@ -80,6 +80,10 @@
       #@content.comments = params[:content][:comments]
       @content.attributes = params[:content]
       @content.author = User.current
+      if params[:set_parent] && !params[:parent].blank?
+        @page.parent_title = params[:parent]
+        @page.parent_title = nil unless @page.valid?
+      end
       # if page is new @page.save will also save content, but not if page isn't a new record
       if (@page.new_record? ? @page.save : @content.save)
         redirect_to :action => 'index', :id => @project, :page => @page.title
Index: app/views/wiki/edit.rhtml
===================================================================
--- app/views/wiki/edit.rhtml	(revision 2761)
+++ app/views/wiki/edit.rhtml	(working copy)
@@ -6,7 +6,11 @@
 
 <p><%= f.text_area :text, :cols => 100, :rows => 25, :class => 'wiki-edit', :accesskey => accesskey(:edit) %></p>
 <p><label><%= l(:field_comments) %></label><br /><%= f.text_field :comments, :size => 120 %></p>
+<% if params[:parent] %>
+  <%= hidden_field_tag :parent, params[:parent] -%>
+<% end %>
 <p><%= submit_tag l(:button_save) %>
+   <%= submit_tag l(:button_save_and_set_parent), :name => 'set_parent' if params[:parent] %>
    <%= link_to_remote l(:label_preview), 
                        { :url => { :controller => 'wiki', :action => 'preview', :id => @project, :page => @page.title },
                          :method => 'post',
Index: config/locales/en.yml
===================================================================
--- config/locales/en.yml	(revision 2761)
+++ config/locales/en.yml	(working copy)
@@ -682,6 +682,7 @@
   button_login: Login
   button_submit: Submit
   button_save: Save
+  button_save_and_set_parent: Save and set parent page
   button_check_all: Check all
   button_uncheck_all: Uncheck all
   button_delete: Delete
Index: config/locales/fr.yml
===================================================================
--- config/locales/fr.yml	(revision 2761)
+++ config/locales/fr.yml	(working copy)
@@ -712,6 +712,7 @@
   button_login: Connexion
   button_submit: Soumettre
   button_save: Sauvegarder
+  button_save_and_set_parent: Sauvegarder et définir la page parent
   button_check_all: Tout cocher
   button_uncheck_all: Tout décocher
   button_delete: Supprimer

