Mercurial > hg > soundsoftware-site
comparison app/controllers/wiki_controller.rb @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | cbce1fd3b1b7 |
children | 433d4f72a19b |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
38 before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy] | 38 before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy] |
39 | 39 |
40 helper :attachments | 40 helper :attachments |
41 include AttachmentsHelper | 41 include AttachmentsHelper |
42 helper :watchers | 42 helper :watchers |
43 include Redmine::Export::PDF | |
43 | 44 |
44 # List of pages, sorted alphabetically and by parent (hierarchy) | 45 # List of pages, sorted alphabetically and by parent (hierarchy) |
45 def index | 46 def index |
46 load_pages_for_index | 47 load_pages_for_index |
47 @pages_by_parent_id = @pages.group_by(&:parent_id) | 48 @pages_by_parent_id = @pages.group_by(&:parent_id) |
69 redirect_to :version => nil | 70 redirect_to :version => nil |
70 return | 71 return |
71 end | 72 end |
72 @content = @page.content_for_version(params[:version]) | 73 @content = @page.content_for_version(params[:version]) |
73 if User.current.allowed_to?(:export_wiki_pages, @project) | 74 if User.current.allowed_to?(:export_wiki_pages, @project) |
74 if params[:format] == 'html' | 75 if params[:format] == 'pdf' |
76 send_data(wiki_to_pdf(@page, @project), :type => 'application/pdf', :filename => "#{@page.title}.pdf") | |
77 return | |
78 elsif params[:format] == 'html' | |
75 export = render_to_string :action => 'export', :layout => false | 79 export = render_to_string :action => 'export', :layout => false |
76 send_data(export, :type => 'text/html', :filename => "#{@page.title}.html") | 80 send_data(export, :type => 'text/html', :filename => "#{@page.title}.html") |
77 return | 81 return |
78 elsif params[:format] == 'txt' | 82 elsif params[:format] == 'txt' |
79 send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt") | 83 send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt") |
80 return | 84 return |
81 end | 85 end |
82 end | 86 end |
83 @editable = editable? | 87 @editable = editable? |
88 @sections_editable = @editable && User.current.allowed_to?(:edit_wiki_pages, @page.project) && | |
89 @content.current_version? && | |
90 Redmine::WikiFormatting.supports_section_edit? | |
91 | |
84 render :action => 'show' | 92 render :action => 'show' |
85 end | 93 end |
86 | 94 |
87 # edit an existing page or a new one | 95 # edit an existing page or a new one |
88 def edit | 96 def edit |
94 # don't keep previous comment | 102 # don't keep previous comment |
95 @content.comments = nil | 103 @content.comments = nil |
96 | 104 |
97 # To prevent StaleObjectError exception when reverting to a previous version | 105 # To prevent StaleObjectError exception when reverting to a previous version |
98 @content.version = @page.content.version | 106 @content.version = @page.content.version |
107 | |
108 @text = @content.text | |
109 if params[:section].present? && Redmine::WikiFormatting.supports_section_edit? | |
110 @section = params[:section].to_i | |
111 @text, @section_hash = Redmine::WikiFormatting.formatter.new(@text).get_section(@section) | |
112 render_404 if @text.blank? | |
113 end | |
99 end | 114 end |
100 | 115 |
101 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } | 116 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } |
102 # Creates a new page or updates an existing one | 117 # Creates a new page or updates an existing one |
103 def update | 118 def update |
114 render_attachment_warning_if_needed(@page) | 129 render_attachment_warning_if_needed(@page) |
115 # don't save if text wasn't changed | 130 # don't save if text wasn't changed |
116 redirect_to :action => 'show', :project_id => @project, :id => @page.title | 131 redirect_to :action => 'show', :project_id => @project, :id => @page.title |
117 return | 132 return |
118 end | 133 end |
119 @content.attributes = params[:content] | 134 |
135 @content.comments = params[:content][:comments] | |
136 @text = params[:content][:text] | |
137 if params[:section].present? && Redmine::WikiFormatting.supports_section_edit? | |
138 @section = params[:section].to_i | |
139 @section_hash = params[:section_hash] | |
140 @content.text = Redmine::WikiFormatting.formatter.new(@content.text).update_section(params[:section].to_i, @text, @section_hash) | |
141 else | |
142 @content.version = params[:content][:version] | |
143 @content.text = @text | |
144 end | |
120 @content.author = User.current | 145 @content.author = User.current |
121 # if page is new @page.save will also save content, but not if page isn't a new record | 146 # if page is new @page.save will also save content, but not if page isn't a new record |
122 if (@page.new_record? ? @page.save : @content.save) | 147 if (@page.new_record? ? @page.save : @content.save) |
123 attachments = Attachment.attach_files(@page, params[:attachments]) | 148 attachments = Attachment.attach_files(@page, params[:attachments]) |
124 render_attachment_warning_if_needed(@page) | 149 render_attachment_warning_if_needed(@page) |
126 redirect_to :action => 'show', :project_id => @project, :id => @page.title | 151 redirect_to :action => 'show', :project_id => @project, :id => @page.title |
127 else | 152 else |
128 render :action => 'edit' | 153 render :action => 'edit' |
129 end | 154 end |
130 | 155 |
131 rescue ActiveRecord::StaleObjectError | 156 rescue ActiveRecord::StaleObjectError, Redmine::WikiFormatting::StaleSectionError |
132 # Optimistic locking exception | 157 # Optimistic locking exception |
133 flash.now[:error] = l(:notice_locking_conflict) | 158 flash.now[:error] = l(:notice_locking_conflict) |
134 render :action => 'edit' | 159 render :action => 'edit' |
135 end | 160 end |
136 | 161 |