diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 5652e3a362..a3478c69bb 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -72,6 +72,10 @@ class WikiController < ApplicationController controller.current_menu_item_sym :related_page end + current_menu_item :new_child do |controller| + controller.current_menu_item_sym :parent_page + end + current_menu_item do |controller| controller.current_menu_item_sym :page end @@ -368,7 +372,8 @@ class WikiController < ApplicationController end def current_menu_item_sym(page) - page = send(page) + page = page_for_menu_item(page) + menu_item = page.try(:menu_item) if menu_item.present? @@ -382,18 +387,12 @@ class WikiController < ApplicationController protected def parse_preview_data - page = @wiki.find_page(wiki_page_title) + page = @wiki.find_page(wiki_page_title.presence || params[:id]) # page is nil when previewing a new page return render_403 unless page.nil? || editable?(page) - attachments = page && page.attachments - previewed = - if page - page.content - else - build_wiki_page_and_content - @content - end + attachments = page.try(:attachments) + previewed = content_to_preview(page) text = { WikiPage.human_attribute_name(:content) => params[:content][:text] } @@ -402,8 +401,25 @@ class WikiController < ApplicationController private + def content_to_preview(page) + return page.content if page + + build_wiki_page_and_content + @content + end + + def page_for_menu_item(page) + if page == :parent_page + page = send(:page) + page = page.parent if page && page.parent + else + page = send(page) + end + page + end + def wiki_page_title - params[:title] || params[:id] + params[:title] || action_name == 'new_child' ? '' : params[:id].to_s.capitalize.tr('-', ' ') end def find_wiki @@ -416,12 +432,12 @@ class WikiController < ApplicationController # Finds the requested page and returns a 404 error if it doesn't exist def find_existing_page - @page = @wiki.find_page(wiki_page_title) + @page = @wiki.find_page(wiki_page_title.presence || params[:id]) render_404 if @page.nil? end def build_wiki_page_and_content - @page = WikiPage.new wiki: @wiki, title: wiki_page_title.presence || I18n.t(:label_wiki_page) + @page = WikiPage.new wiki: @wiki, title: wiki_page_title.presence @page.content = WikiContent.new page: @page @content = @page.content_for_version nil diff --git a/app/views/wiki/new.html.erb b/app/views/wiki/new.html.erb index 339478aac2..fb457c845a 100644 --- a/app/views/wiki/new.html.erb +++ b/app/views/wiki/new.html.erb @@ -44,7 +44,7 @@ See docs/COPYRIGHT.rdoc for more details.
<%= f.fields_for :page, @page do |page_fields| %> <%= page_fields.hidden_field :parent_id %> - <%= page_fields.text_field :title, required: true, size: 120 %> + <%= page_fields.text_field :title, required: true, size: 120, placeholder: t('label_page_title') %> <% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 15765b2fe4..e0b9677d0d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1351,6 +1351,7 @@ en: label_overall_activity: "Overall activity" label_overall_spent_time: "Overall spent time" label_overview: "Overview" + label_page_title: "Page title" label_part_of: "part of" label_password_lost: "Forgot your password?" label_password_rule_lowercase: "Lowercase" diff --git a/spec/features/wiki/wiki_textile_links_spec.rb b/spec/features/wiki/wiki_textile_links_spec.rb index cc74cd54e2..4ceb951fce 100644 --- a/spec/features/wiki/wiki_textile_links_spec.rb +++ b/spec/features/wiki/wiki_textile_links_spec.rb @@ -70,7 +70,7 @@ describe 'Wiki unicode title spec', type: :feature, js: true do find('#content_text').set(wiki_body) click_button 'Save' - expect(page).to have_selector('.title-container h2', text: 'wiki') + expect(page).to have_selector('.title-container h2', text: 'Wiki') end it 'renders correct links' do diff --git a/spec/features/wiki/wiki_unicode_spec.rb b/spec/features/wiki/wiki_unicode_spec.rb index 0d91ad1434..ec970c8eb0 100644 --- a/spec/features/wiki/wiki_unicode_spec.rb +++ b/spec/features/wiki/wiki_unicode_spec.rb @@ -94,7 +94,7 @@ describe 'Wiki unicode title spec', type: :feature, js: true do find('#content_text').set(wiki_body) click_button 'Save' - expect(page).to have_selector('.title-container h2', text: 'wiki') + expect(page).to have_selector('.title-container h2', text: 'Wiki') expect(page).to have_selector('a.wiki-page', count: 5) end