Index: test/unit/wiki_page_test.rb =================================================================== --- test/unit/wiki_page_test.rb (revisão 1930) +++ test/unit/wiki_page_test.rb (cópia de trabalho) @@ -53,8 +53,16 @@ assert_nil page.parent_title page = WikiPage.find_by_title('Page_with_an_inline_image') - assert_equal 'CookBook documentation', page.parent_title + assert_equal 'CookBook_documentation', page.parent_title end + + def test_parent_pretty_title + page = WikiPage.find_by_title('Another_page') + assert_nil page.parent_title + + page = WikiPage.find_by_title('Page_with_an_inline_image') + assert_equal 'CookBook documentation', page.parent_pretty_title + end def test_assign_parent page = WikiPage.find_by_title('Another_page') Index: app/helpers/application_helper.rb =================================================================== --- app/helpers/application_helper.rb (revisão 1930) +++ app/helpers/application_helper.rb (cópia de trabalho) @@ -197,7 +197,8 @@ def breadcrumb(*args) elements = args.flatten - elements.any? ? content_tag('p', args.join(' » ') + ' » ', :class => 'breadcrumb') : nil + last_element = elements.pop + last_element.nil? ? nil : content_tag('p', elements.join(' » ') + ' » ' + last_element, :class => 'breadcrumb') end def html_title(*args) @@ -260,7 +261,6 @@ text = (Setting.text_formatting == 'textile') ? Redmine::WikiFormatting.to_html(text) { |macro, args| exec_macro(macro, obj, args) } : simple_format(auto_link(h(text))) - # different methods for formatting wiki links case options[:wiki_links] when :local @@ -270,7 +270,7 @@ # used for single-file wiki export format_wiki_link = Proc.new {|project, title, anchor| "##{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 && parent.title) } end project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil) @@ -303,7 +303,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), + link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page), anchor, obj && obj.page), :class => ('wiki-page' + (wiki_page ? '' : ' new'))) else # project or wiki doesn't exist Index: app/models/wiki_page.rb =================================================================== --- app/models/wiki_page.rb (revisão 1930) +++ app/models/wiki_page.rb (cópia de trabalho) @@ -113,14 +113,19 @@ end def parent_title - @parent_title || (self.parent && self.parent.pretty_title) + @parent_title || (self.parent && self.parent.title) end def parent_title=(t) + return self.parent if (self.parent && (self.parent.title == t)) @parent_title = t parent_page = t.blank? ? nil : self.wiki.find_page(t) self.parent = parent_page end + + def parent_pretty_title + @parent_pretty_title || (self.parent && self.parent.pretty_title) + end protected Index: app/controllers/wiki_controller.rb =================================================================== --- app/controllers/wiki_controller.rb (revisão 1930) +++ app/controllers/wiki_controller.rb (cópia de trabalho) @@ -52,14 +52,16 @@ send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt") return end - @editable = editable? + @editable = editable? render :action => 'show' end # edit an existing page or a new one def edit - @page = @wiki.find_or_new_page(params[:page]) + @page = @wiki.find_or_new_page(params[:page]) + @page.parent_title = params[:parent] if params[:parent] return render_403 unless editable? + @page.content = WikiContent.new(:page => @page) if @page.new_record? @content = @page.content_for_version(params[:version]) @@ -70,19 +72,11 @@ # To prevent StaleObjectError exception when reverting to a previous version @content.version = @page.content.version else - if !@page.new_record? && @content.text == params[:content][:text] - # don't save if text wasn't changed - redirect_to :action => 'index', :id => @project, :page => @page.title - return - end - #@content.text = params[:content][:text] - #@content.comments = params[:content][:comments] @content.attributes = params[:content] @content.author = User.current - # 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 - end + @page.save if @page.changed? + @content.save if @content.changed? + redirect_to :action => 'index', :id => @project, :page => @page.title end rescue ActiveRecord::StaleObjectError # Optimistic locking exception Index: app/views/wiki/show.rhtml =================================================================== --- app/views/wiki/show.rhtml (revisão 1930) +++ app/views/wiki/show.rhtml (cópia de trabalho) @@ -10,7 +10,7 @@ <%= link_to_if_authorized(l(:label_history), {:action => 'history', :page => @page.title}, :class => 'icon icon-history') %> -<%= breadcrumb(@page.ancestors.reverse.collect {|parent| link_to h(parent.pretty_title), {:page => parent.title}}) %> +<%= breadcrumb(@page.ancestors.reverse.push(@page).collect {|parent| link_to h(parent.pretty_title), {:page => parent.title}}) %> <% if @content.version != @page.content.version %>
Index: app/views/wiki/edit.rhtml =================================================================== --- app/views/wiki/edit.rhtml (revisão 1930) +++ app/views/wiki/edit.rhtml (cópia de trabalho) @@ -1,3 +1,5 @@ +<%= breadcrumb(@page.ancestors.reverse.push(@page).collect {|parent| link_to h(parent.pretty_title), {:page => parent.title}}) %> +
<%= f.text_area :text, :cols => 100, :rows => 25, :class => 'wiki-edit', :accesskey => accesskey(:edit) %>
<%= f.text_field :comments, :size => 120 %>
<%= select_tag 'parent', options_for_select(@wiki.pages.collect{|page| [page.pretty_title,page.title]}, @page.parent_title) %>
<%= submit_tag l(:button_save) %> <%= link_to_remote l(:label_preview), { :url => { :controller => 'wiki', :action => 'preview', :id => @project, :page => @page.title }, Index: app/views/wiki/rename.rhtml =================================================================== --- app/views/wiki/rename.rhtml (revisão 1930) +++ app/views/wiki/rename.rhtml (cópia de trabalho) @@ -6,7 +6,7 @@
<%= f.text_field :title, :required => true, :size => 100 %>
<%= f.check_box :redirect_existing_links %>
-<%= f.text_field :parent_title, :size => 100 %>
+<%= f.select :parent_title, @wiki.pages.collect{|page| [page.pretty_title,page.title]} %>