Index: app/controllers/wiki_controller.rb =================================================================== --- app/controllers/wiki_controller.rb (revision 1023) +++ app/controllers/wiki_controller.rb (working copy) @@ -58,11 +58,19 @@ @content = @page.content_for_version(params[:version]) @content.text = "h1. #{@page.pretty_title}" if @content.text.blank? + @page.parent_id = params[:parent_id] if params[:parent_id] + @content.parent_id = @page.parent_id + @content.page = @page # don't keep previous comment @content.comments = nil if request.post? - if !@page.new_record? && @content.text == params[:content][:text] - # don't save if text wasn't changed + #if the parent id changes we'll need to save + if @page.parent_id.to_s != params[:content][:parent_id] + @page.parent_id = params[:content][:parent_id] + @parent_changed = true + end + if !@page.new_record? && @content.text == params[:content][:text] && !@parent_changed + # don't save if text or parent wasn't changed redirect_to :action => 'index', :id => @project, :page => @page.title return end @@ -71,7 +79,7 @@ @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) + if (@page.new_record? || @parent_changed == true ? @page.save : @content.save) redirect_to :action => 'index', :id => @project, :page => @page.title end end Index: app/helpers/application_helper.rb =================================================================== --- app/helpers/application_helper.rb (revision 1023) +++ app/helpers/application_helper.rb (working copy) @@ -194,6 +194,7 @@ else format_wiki_link = Proc.new {|project, title| url_for :controller => 'wiki', :action => 'index', :id => project, :page => title } end + format_new_wiki_link = Proc.new {|project, title, parent_id| url_for :controller => 'wiki', :action => 'edit', :id => project, :page => title, :parent_id => parent_id} project = options[:project] || @project @@ -219,8 +220,14 @@ if link_project && link_project.wiki # 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)), - :class => ('wiki-page' + (wiki_page ? '' : ' new'))) + if wiki_page + link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page) + (wiki_page ? '' : '/edit/' + page_id)), + :class => ('wiki-page' + (wiki_page ? '' : ' new'))) + else + parent_id = options[:page].id.to_s if options[:page] + link_to((title || page), format_new_wiki_link.call(link_project, Wiki.titleize(page), parent_id), + :class => ('wiki-page' + (wiki_page ? '' : ' new'))) + end else # project or wiki doesn't exist title || page @@ -248,6 +255,24 @@ end leading + (link || "#{otype}#{oid}") end + + #convert {{child_pages}} tags into a table of links + #this should really be a macro but not sure how to make :page visible to it + text = text.gsub(/\{\{(>|<)?child_pages\}\}/) do |m| + if options[:page] && options[:page].children + div_class = 'toc' + div_class << ' right' if $1 == '>' + div_class << ' left' if $1 == '<' + out = "
" + l(:label_wiki_child_pages) + ":" + for page in options[:page].children + out << link_to(page.pretty_title, format_wiki_link.call(project, page.title)) + end + out << '
' + out + else + "" + end + end text end Index: app/helpers/wiki_helper.rb =================================================================== --- app/helpers/wiki_helper.rb (revision 1023) +++ app/helpers/wiki_helper.rb (working copy) @@ -17,6 +17,12 @@ module WikiHelper + def link_to_pages(pages, options = {}) + if pages.any? + render :partial => 'wiki/links', :locals => {:pages => pages, :options => options} + end + end + def html_diff(wdiff) words = wdiff.words.collect{|word| h(word)} words_add = 0 Index: app/models/wiki_content.rb =================================================================== --- app/models/wiki_content.rb (revision 1023) +++ app/models/wiki_content.rb (working copy) @@ -23,6 +23,8 @@ belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' validates_presence_of :text + attr_accessor :parent_id + acts_as_versioned class Version belongs_to :page, :class_name => '::WikiPage', :foreign_key => 'page_id' Index: app/models/wiki_page.rb =================================================================== --- app/models/wiki_page.rb (revision 1023) +++ app/models/wiki_page.rb (working copy) @@ -21,6 +21,7 @@ class WikiPage < ActiveRecord::Base belongs_to :wiki has_one :content, :class_name => 'WikiContent', :foreign_key => 'page_id', :dependent => :destroy + has_one :parent, :class_name => 'WikiPage', :foreign_key => 'page_id' has_many :attachments, :as => :container, :dependent => :destroy acts_as_event :title => Proc.new {|o| "#{l(:label_wiki)}: #{o.title}"}, @@ -32,6 +33,8 @@ :include => [:wiki, :content], :project_key => "#{Wiki.table_name}.project_id" + acts_as_tree :order => "id" + attr_accessor :redirect_existing_links validates_presence_of :title @@ -105,6 +108,17 @@ def text content.text if content end + + def parents + @parents = [] + @parent = parent + while @parent + logger.info(@parent.title) + @parents = [parent] + @parents + @parent = @parent.parent + end + @parents + end end class WikiDiff Index: app/views/wiki/_content.rhtml =================================================================== --- app/views/wiki/_content.rhtml (revision 1023) +++ app/views/wiki/_content.rhtml (working copy) @@ -1,3 +1,3 @@
- <%= textilizable content, :text, :attachments => content.page.attachments %> + <%= textilizable content, :text, :attachments => content.page.attachments, :page => @page %>
Index: app/views/wiki/_links.rhtml =================================================================== --- app/views/wiki/_links.rhtml (revision 0) +++ app/views/wiki/_links.rhtml (revision 0) @@ -0,0 +1,8 @@ +<% +@first = true +for page in pages %> + <%=" > " if !@first%><%= link_to page.pretty_title, {:controller => 'wiki', :action => 'index', :page => page.title} %> +<% + @first = false +end %> +     \ No newline at end of file Index: app/views/wiki/edit.rhtml =================================================================== --- app/views/wiki/edit.rhtml (revision 1023) +++ app/views/wiki/edit.rhtml (working copy) @@ -4,6 +4,8 @@ <%= f.hidden_field :version %> <%= error_messages_for 'content' %>
+<%= l(:label_wiki_parent_page) %>: <%= f.select :parent_id, (@page.wiki.pages.collect {|p| [p.pretty_title, p.id]}).sort, :include_blank => true %> +     <%= l(:setting_text_formatting) %>: <%= link_to l(:label_help), '/help/wiki_syntax.html', :onclick => "window.open('#{ url_for '/help/wiki_syntax.html' }', '', 'resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes'); return false;" %> Index: app/views/wiki/show.rhtml =================================================================== --- app/views/wiki/show.rhtml (revision 1023) +++ app/views/wiki/show.rhtml (working copy) @@ -1,5 +1,8 @@ +
-<%= link_to_if_authorized(l(:button_edit), {:action => 'edit', :page => @page.title}, :class => 'icon icon-edit', :accesskey => accesskey(:edit)) if @content.version == @page.content.version %> +<%= link_to_if_authorized(l(:button_edit), {:action => 'edit', :page => @page.title, :parent_id => @page.parent_id}, :class => 'icon icon-edit', :accesskey => accesskey(:edit)) if @content.version == @page.content.version %> <%= link_to_if_authorized(l(:button_rename), {:action => 'rename', :page => @page.title}, :class => 'icon icon-move') if @content.version == @page.content.version %> <%= link_to_if_authorized(l(:button_delete), {:action => 'destroy', :page => @page.title}, :method => :post, :confirm => l(:text_are_you_sure), :class => 'icon icon-del') %> <%= link_to_if_authorized(l(:button_rollback), {:action => 'edit', :page => @page.title, :version => @content.version }, :class => 'icon icon-cancel') if @content.version < @page.content.version %> Index: config/routes.rb =================================================================== --- config/routes.rb (revision 1023) +++ config/routes.rb (working copy) @@ -9,6 +9,7 @@ map.home '', :controller => 'welcome' map.connect 'wiki/:id/:page/:action', :controller => 'wiki', :page => nil + map.connect 'wiki/:id/:page/:action/:parent_id', :controller => 'wiki', :page => nil map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow' map.connect 'help/:ctrl/:page', :controller => 'help' #map.connect ':controller/:action/:id/:sort_key/:sort_order' Index: db/migrate/1001_wiki_hierarchy.rb =================================================================== --- db/migrate/1001_wiki_hierarchy.rb (revision 0) +++ db/migrate/1001_wiki_hierarchy.rb (revision 0) @@ -0,0 +1,9 @@ +class WikiHierarchy < ActiveRecord::Migration + def self.up + add_column(:wiki_pages, :parent_id, :integer) + end + + def self.down + remove_column :wiki_pages, :parent_id + end +end Index: lang/en.yml =================================================================== --- lang/en.yml (revision 1023) +++ lang/en.yml (working copy) @@ -378,6 +378,8 @@ label_wiki_edit_plural: Wiki edits label_wiki_page: Wiki page label_wiki_page_plural: Wiki pages +label_wiki_parent_page: Parent Page +label_wiki_child_pages: Child Pages label_index_by_title: Index by title label_index_by_date: Index by date label_current_version: Current version Index: public/stylesheets/application.css =================================================================== --- public/stylesheets/application.css (revision 1023) +++ public/stylesheets/application.css (working copy) @@ -109,7 +109,7 @@ overflow: hidden; width: .6em; height: .6em; } - +.breadcrumbs {white-space: nowrap; line-height:0.2em;margin-top:5px;font-size:0.9em;} .contextual {float:right; white-space: nowrap; line-height:1.4em;margin-top:5px;font-size:0.9em;} .contextual input {font-size:0.9em;}