summaryrefslogtreecommitdiffstats
path: root/app/controllers/wiki_controller.rb
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2010-10-22 16:20:20 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2010-10-22 16:20:20 +0000
commitcac3b1e5381d0756ba9bb6bcb356a4b081f3407d (patch)
tree0db0a74406411e65697abe5150d56465dcc51818 /app/controllers/wiki_controller.rb
parent2fbf7bbcf1af756c4d0de3c7de96194376d33f1d (diff)
downloadredmine-cac3b1e5381d0756ba9bb6bcb356a4b081f3407d.tar.gz
redmine-cac3b1e5381d0756ba9bb6bcb356a4b081f3407d.zip
Refactor: split WikiController#edit into #update
update will handle the saving and should be accessed via POST only. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4272 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/wiki_controller.rb')
-rw-r--r--app/controllers/wiki_controller.rb60
1 files changed, 37 insertions, 23 deletions
diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb
index 95e1943e9..1c42ab5cd 100644
--- a/app/controllers/wiki_controller.rb
+++ b/app/controllers/wiki_controller.rb
@@ -71,34 +71,48 @@ class WikiController < ApplicationController
@content.text = initial_page_content(@page) if @content.text.blank?
# don't keep previous comment
@content.comments = nil
- if request.get?
- # 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]
- attachments = Attachment.attach_files(@page, params[:attachments])
- render_attachment_warning_if_needed(@page)
- # don't save if text wasn't changed
- redirect_to :action => 'show', :project_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)
- attachments = Attachment.attach_files(@page, params[:attachments])
- render_attachment_warning_if_needed(@page)
- call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})
- redirect_to :action => 'show', :project_id => @project, :page => @page.title
- end
+
+ # To prevent StaleObjectError exception when reverting to a previous version
+ @content.version = @page.content.version
+ rescue ActiveRecord::StaleObjectError
+ # Optimistic locking exception
+ flash[:error] = l(:notice_locking_conflict)
+ end
+
+ verify :method => :post, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
+ # Creates a new page or updates an existing one
+ def update
+ @page = @wiki.find_or_new_page(params[:page])
+ return render_403 unless editable?
+ @page.content = WikiContent.new(:page => @page) if @page.new_record?
+
+ @content = @page.content_for_version(params[:version])
+ @content.text = initial_page_content(@page) if @content.text.blank?
+ # don't keep previous comment
+ @content.comments = nil
+
+ if !@page.new_record? && params[:content].present? && @content.text == params[:content][:text]
+ attachments = Attachment.attach_files(@page, params[:attachments])
+ render_attachment_warning_if_needed(@page)
+ # don't save if text wasn't changed
+ redirect_to :action => 'show', :project_id => @project, :page => @page.title
+ return
+ end
+ @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)
+ attachments = Attachment.attach_files(@page, params[:attachments])
+ render_attachment_warning_if_needed(@page)
+ call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})
+ redirect_to :action => 'show', :project_id => @project, :page => @page.title
end
+
rescue ActiveRecord::StaleObjectError
# Optimistic locking exception
flash[:error] = l(:notice_locking_conflict)
end
-
+
# rename a page
def rename
return render_403 unless editable?