summaryrefslogtreecommitdiffstats
path: root/app/controllers/wiki_controller.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-10-25 20:38:29 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-10-25 20:38:29 +0000
commiteff874b29a908e85e80d8bcd6a20fd85165e59cd (patch)
tree914366bfb252d98ef35bde6e738e880e98e9483d /app/controllers/wiki_controller.rb
parent9e313087205721ed3c6239be7cde55598d29f9e6 (diff)
downloadredmine-eff874b29a908e85e80d8bcd6a20fd85165e59cd.tar.gz
redmine-eff874b29a908e85e80d8bcd6a20fd85165e59cd.zip
REST API for creating/updating wiki pages (#7082).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10717 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/wiki_controller.rb')
-rw-r--r--app/controllers/wiki_controller.rb52
1 files changed, 38 insertions, 14 deletions
diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb
index e8f6ef35d..51e2ef367 100644
--- a/app/controllers/wiki_controller.rb
+++ b/app/controllers/wiki_controller.rb
@@ -36,7 +36,7 @@ class WikiController < ApplicationController
before_filter :find_wiki, :authorize
before_filter :find_existing_or_new_page, :only => [:show, :edit, :update]
before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy, :destroy_version]
- accept_api_auth :index, :show
+ accept_api_auth :index, :show, :update
helper :attachments
include AttachmentsHelper
@@ -130,15 +130,18 @@ class WikiController < ApplicationController
# Creates a new page or updates an existing one
def update
return render_403 unless editable?
+ was_new_page = @page.new_record?
@page.content = WikiContent.new(:page => @page) if @page.new_record?
@page.safe_attributes = params[:wiki_page]
- @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
+ @content = @page.content
+ content_params = params[:content]
+ if content_params.nil? && params[:wiki_page].is_a?(Hash)
+ content_params = params[:wiki_page].slice(:text, :comments, :version)
+ end
+ content_params ||= {}
- if !@page.new_record? && params[:content].present? && @content.text == params[:content][:text]
+ if !@page.new_record? && content_params.present? && @content.text == content_params[:text]
attachments = Attachment.attach_files(@page, params[:attachments])
render_attachment_warning_if_needed(@page)
# don't save content if text wasn't changed
@@ -147,14 +150,14 @@ class WikiController < ApplicationController
return
end
- @content.comments = params[:content][:comments]
- @text = params[:content][:text]
+ @content.comments = content_params[:comments]
+ @text = content_params[:text]
if params[:section].present? && Redmine::WikiFormatting.supports_section_edit?
@section = params[:section].to_i
@section_hash = params[:section_hash]
@content.text = Redmine::WikiFormatting.formatter.new(@content.text).update_section(params[:section].to_i, @text, @section_hash)
else
- @content.version = params[:content][:version]
+ @content.version = content_params[:version] if content_params[:version]
@content.text = @text
end
@content.author = User.current
@@ -163,17 +166,38 @@ class WikiController < ApplicationController
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, :id => @page.title
+
+ respond_to do |format|
+ format.html { redirect_to :action => 'show', :project_id => @project, :id => @page.title }
+ format.api {
+ if was_new_page
+ render :action => 'show', :status => :created, :location => url_for(:controller => 'wiki', :action => 'show', :project_id => @project, :id => @page.title)
+ else
+ render_api_ok
+ end
+ }
+ end
else
- render :action => 'edit'
+ respond_to do |format|
+ format.html { render :action => 'edit' }
+ format.api { render_validation_errors(@content) }
+ end
end
rescue ActiveRecord::StaleObjectError, Redmine::WikiFormatting::StaleSectionError
# Optimistic locking exception
- flash.now[:error] = l(:notice_locking_conflict)
- render :action => 'edit'
+ respond_to do |format|
+ format.html {
+ flash.now[:error] = l(:notice_locking_conflict)
+ render :action => 'edit'
+ }
+ format.api { render_api_head :conflict }
+ end
rescue ActiveRecord::RecordNotSaved
- render :action => 'edit'
+ respond_to do |format|
+ format.html { render :action => 'edit' }
+ format.api { render_validation_errors(@content) }
+ end
end
# rename a page