diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-09-09 17:05:38 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-09-09 17:05:38 +0000 |
commit | b4d9ca8875898500ca198bff501dfc7d1c28bd71 (patch) | |
tree | 8d9ebcf80cd56b427211b6b769514ab8d66f33a2 /app/models/wiki.rb | |
parent | f6fe15716e4714c5f6d4d88149927b7dfa5c6fce (diff) | |
download | redmine-b4d9ca8875898500ca198bff501dfc7d1c28bd71.tar.gz redmine-b4d9ca8875898500ca198bff501dfc7d1c28bd71.zip |
Added the ability to rename wiki pages (specific permission required).
Existing links that point to the old page are preserved and automatically redirected to the new page (this behaviour can be disabled when renaming the page).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@720 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/wiki.rb')
-rw-r--r-- | app/models/wiki.rb | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/app/models/wiki.rb b/app/models/wiki.rb index ed473c7c0..b6cd661ff 100644 --- a/app/models/wiki.rb +++ b/app/models/wiki.rb @@ -18,6 +18,7 @@ class Wiki < ActiveRecord::Base belongs_to :project has_many :pages, :class_name => 'WikiPage', :dependent => :destroy + has_many :redirects, :class_name => 'WikiRedirect', :dependent => :delete_all validates_presence_of :start_page validates_format_of :start_page, :with => /^[^,\.\/\?\;\|\:]*$/ @@ -25,14 +26,20 @@ class Wiki < ActiveRecord::Base # find the page with the given title # if page doesn't exist, return a new page def find_or_new_page(title) - title = Wiki.titleize(title || start_page) - find_page(title) || WikiPage.new(:wiki => self, :title => title) + find_page(title) || WikiPage.new(:wiki => self, :title => Wiki.titleize(title)) end # find the page with the given title - def find_page(title) + def find_page(title, options = {}) title = start_page if title.blank? - pages.find_by_title(Wiki.titleize(title)) + title = Wiki.titleize(title) + page = pages.find_by_title(title) + if !page && !(options[:with_redirect] == false) + # search for a redirect + redirect = redirects.find_by_title(title) + page = find_page(redirect.redirects_to, :with_redirect => false) if redirect + end + page end # turn a string into a valid page title |