diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 2f4724f38..1aaff4071 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -95,7 +95,12 @@ class WikiController < ApplicationController # edit an existing page or a new one def edit return render_403 unless editable? - @page.content = WikiContent.new(:page => @page) if @page.new_record? + if @page.new_record? + @page.content = WikiContent.new(:page => @page) + if params[:parent].present? + @page.parent = @page.wiki.find_page(params[:parent].to_s) + end + end @content = @page.content_for_version(params[:version]) @content.text = initial_page_content(@page) if @content.text.blank? @@ -143,6 +148,9 @@ class WikiController < ApplicationController @content.text = @text end @content.author = User.current + if @page.new_record? && params[:page] + @page.parent_id = params[:page][:parent_id] + 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) attachments = Attachment.attach_files(@page, params[:attachments]) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1232a8126..84c7678d1 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -596,7 +596,9 @@ module ApplicationHelper when :anchor; "##{page.present? ? Wiki.titleize(page) : title}" + (anchor.present? ? "_#{anchor}" : '') # used for single-file wiki export else wiki_page_id = page.present? ? Wiki.titleize(page) : nil - url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project, :id => wiki_page_id, :anchor => anchor) + parent = wiki_page.nil? && obj.is_a?(WikiContent) && obj.page && project == link_project ? obj.page.title : nil + url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project, + :id => wiki_page_id, :anchor => anchor, :parent => parent) end end link_to(title.present? ? title.html_safe : h(page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new'))) diff --git a/app/views/wiki/edit.html.erb b/app/views/wiki/edit.html.erb index d7c97c177..8c20e264d 100644 --- a/app/views/wiki/edit.html.erb +++ b/app/views/wiki/edit.html.erb @@ -13,6 +13,10 @@
<%= text_area_tag 'content[text]', @text, :cols => 100, :rows => 25, :class => 'wiki-edit', :accesskey => accesskey(:edit) %> +<% if @page.new_record? && @page.parent %> +

<%=h @page.parent.pretty_title %>

+<% end %> +

<%= f.text_field :comments, :size => 120 %>

<%= render :partial => 'attachments/form' %>

diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 70dc20668..80a0311f6 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -81,11 +81,6 @@ class WikiControllerTest < ActionController::TestCase assert_tag :tag => 'div', :attributes => {:id => 'sidebar'}, :content => /Side bar content for test_show_with_sidebar/ end - - def test_show_unexistent_page_without_edit_right - get :show, :project_id => 1, :id => 'Unexistent page' - assert_response 404 - end def test_show_should_display_section_edit_links @request.session[:user_id] = 2 @@ -119,11 +114,25 @@ class WikiControllerTest < ActionController::TestCase } end + def test_show_unexistent_page_without_edit_right + get :show, :project_id => 1, :id => 'Unexistent page' + assert_response 404 + end + def test_show_unexistent_page_with_edit_right @request.session[:user_id] = 2 get :show, :project_id => 1, :id => 'Unexistent page' assert_response :success assert_template 'edit' + assert_no_tag 'input', :attributes => {:name => 'page[parent_id]'} + end + + def test_show_unexistent_page_with_parent + @request.session[:user_id] = 2 + get :show, :project_id => 1, :id => 'Unexistent page', :parent => 'Another_page' + assert_response :success + assert_template 'edit' + assert_tag 'input', :attributes => {:name => 'page[parent_id]', :value => '2'} end def test_show_should_not_show_history_without_permission @@ -135,15 +144,20 @@ class WikiControllerTest < ActionController::TestCase def test_create_page @request.session[:user_id] = 2 - put :update, :project_id => 1, - :id => 'New page', - :content => {:comments => 'Created the page', - :text => "h1. New page\n\nThis is a new page", - :version => 0} + assert_difference 'WikiPage.count' do + assert_difference 'WikiContent.count' do + put :update, :project_id => 1, + :id => 'New page', + :content => {:comments => 'Created the page', + :text => "h1. New page\n\nThis is a new page", + :version => 0} + end + end assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page' page = Project.find(1).wiki.find_page('New page') assert !page.new_record? assert_not_nil page.content + assert_nil page.parent assert_equal 'Created the page', page.content.comments end @@ -164,6 +178,17 @@ class WikiControllerTest < ActionController::TestCase assert_equal 'testfile.txt', page.attachments.first.filename end + def test_create_page_with_parent + @request.session[:user_id] = 2 + assert_difference 'WikiPage.count' do + put :update, :project_id => 1, :id => 'New page', + :content => {:text => "h1. New page\n\nThis is a new page", :version => 0}, + :page => {:parent_id => 2} + end + page = Project.find(1).wiki.find_page('New page') + assert_equal WikiPage.find(2), page.parent + end + def test_edit_page @request.session[:user_id] = 2 get :edit, :project_id => 'ecookbook', :id => 'Another_page' diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index 07038567a..2b9d3848d 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -502,10 +502,10 @@ RAW '[[Another page#anchor]]' => 'Another page', '[[Another page#anchor|Page]]' => 'Page', # page that doesn't exist - '[[Unknown page]]' => 'Unknown page', - '[[Unknown page|404]]' => '404', - '[[Unknown page#anchor]]' => 'Unknown page', - '[[Unknown page#anchor|404]]' => '404', + '[[Unknown page]]' => 'Unknown page', + '[[Unknown page|404]]' => '404', + '[[Unknown page#anchor]]' => 'Unknown page', + '[[Unknown page#anchor|404]]' => '404', } @project = Project.find(1)