Mercurial > hg > soundsoftware-site
comparison app/controllers/wiki_controller.rb @ 1295:622f24f53b42 redmine-2.3
Update to Redmine SVN revision 11972 on 2.3-stable branch
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:02:21 +0100 |
parents | 433d4f72a19b |
children |
comparison
equal
deleted
inserted
replaced
1294:3e4c3460b6ca | 1295:622f24f53b42 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | 2 # Copyright (C) 2006-2013 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
35 default_search_scope :wiki_pages | 35 default_search_scope :wiki_pages |
36 before_filter :find_wiki, :authorize | 36 before_filter :find_wiki, :authorize |
37 before_filter :find_existing_or_new_page, :only => [:show, :edit, :update] | 37 before_filter :find_existing_or_new_page, :only => [:show, :edit, :update] |
38 before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy, :destroy_version] | 38 before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy, :destroy_version] |
39 accept_api_auth :index, :show, :update, :destroy | 39 accept_api_auth :index, :show, :update, :destroy |
40 before_filter :find_attachments, :only => [:preview] | |
40 | 41 |
41 helper :attachments | 42 helper :attachments |
42 include AttachmentsHelper | 43 include AttachmentsHelper |
43 helper :watchers | 44 helper :watchers |
44 include Redmine::Export::PDF | 45 include Redmine::Export::PDF |
157 attachments = Attachment.attach_files(@page, params[:attachments]) | 158 attachments = Attachment.attach_files(@page, params[:attachments]) |
158 render_attachment_warning_if_needed(@page) | 159 render_attachment_warning_if_needed(@page) |
159 call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page}) | 160 call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page}) |
160 | 161 |
161 respond_to do |format| | 162 respond_to do |format| |
162 format.html { redirect_to :action => 'show', :project_id => @project, :id => @page.title } | 163 format.html { redirect_to project_wiki_page_path(@project, @page.title) } |
163 format.api { | 164 format.api { |
164 if was_new_page | 165 if was_new_page |
165 render :action => 'show', :status => :created, :location => url_for(:controller => 'wiki', :action => 'show', :project_id => @project, :id => @page.title) | 166 render :action => 'show', :status => :created, :location => project_wiki_page_path(@project, @page.title) |
166 else | 167 else |
167 render_api_ok | 168 render_api_ok |
168 end | 169 end |
169 } | 170 } |
170 end | 171 end |
197 @page.redirect_existing_links = true | 198 @page.redirect_existing_links = true |
198 # used to display the *original* title if some AR validation errors occur | 199 # used to display the *original* title if some AR validation errors occur |
199 @original_title = @page.pretty_title | 200 @original_title = @page.pretty_title |
200 if request.post? && @page.update_attributes(params[:wiki_page]) | 201 if request.post? && @page.update_attributes(params[:wiki_page]) |
201 flash[:notice] = l(:notice_successful_update) | 202 flash[:notice] = l(:notice_successful_update) |
202 redirect_to :action => 'show', :project_id => @project, :id => @page.title | 203 redirect_to project_wiki_page_path(@project, @page.title) |
203 end | 204 end |
204 end | 205 end |
205 | 206 |
206 def protect | 207 def protect |
207 @page.update_attribute :protected, params[:protected] | 208 @page.update_attribute :protected, params[:protected] |
208 redirect_to :action => 'show', :project_id => @project, :id => @page.title | 209 redirect_to project_wiki_page_path(@project, @page.title) |
209 end | 210 end |
210 | 211 |
211 # show page history | 212 # show page history |
212 def history | 213 def history |
213 @version_count = @page.content.versions.count | 214 @version_count = @page.content.versions.count |
214 @version_pages = Paginator.new self, @version_count, per_page_option, params['page'] | 215 @version_pages = Paginator.new @version_count, per_page_option, params['page'] |
215 # don't load text | 216 # don't load text |
216 @versions = @page.content.versions.find :all, | 217 @versions = @page.content.versions. |
217 :select => "id, author_id, comments, updated_on, version", | 218 select("id, author_id, comments, updated_on, version"). |
218 :order => 'version DESC', | 219 reorder('version DESC'). |
219 :limit => @version_pages.items_per_page + 1, | 220 limit(@version_pages.per_page + 1). |
220 :offset => @version_pages.current.offset | 221 offset(@version_pages.offset). |
222 all | |
221 | 223 |
222 render :layout => false if request.xhr? | 224 render :layout => false if request.xhr? |
223 end | 225 end |
224 | 226 |
225 def diff | 227 def diff |
258 return unless api_request? | 260 return unless api_request? |
259 end | 261 end |
260 end | 262 end |
261 @page.destroy | 263 @page.destroy |
262 respond_to do |format| | 264 respond_to do |format| |
263 format.html { redirect_to :action => 'index', :project_id => @project } | 265 format.html { redirect_to project_wiki_index_path(@project) } |
264 format.api { render_api_ok } | 266 format.api { render_api_ok } |
265 end | 267 end |
266 end | 268 end |
267 | 269 |
268 def destroy_version | 270 def destroy_version |
269 return render_403 unless editable? | 271 return render_403 unless editable? |
270 | 272 |
271 @content = @page.content_for_version(params[:version]) | 273 @content = @page.content_for_version(params[:version]) |
272 @content.destroy | 274 @content.destroy |
273 redirect_to_referer_or :action => 'history', :id => @page.title, :project_id => @project | 275 redirect_to_referer_or history_project_wiki_page_path(@project, @page.title) |
274 end | 276 end |
275 | 277 |
276 # Export wiki to a single pdf or html file | 278 # Export wiki to a single pdf or html file |
277 def export | 279 def export |
278 @pages = @wiki.pages.all(:order => 'title', :include => [:content, {:attachments => :author}]) | 280 @pages = @wiki.pages.all(:order => 'title', :include => [:content, {:attachments => :author}]) |
290 def preview | 292 def preview |
291 page = @wiki.find_page(params[:id]) | 293 page = @wiki.find_page(params[:id]) |
292 # page is nil when previewing a new page | 294 # page is nil when previewing a new page |
293 return render_403 unless page.nil? || editable?(page) | 295 return render_403 unless page.nil? || editable?(page) |
294 if page | 296 if page |
295 @attachements = page.attachments | 297 @attachments += page.attachments |
296 @previewed = page.content | 298 @previewed = page.content |
297 end | 299 end |
298 @text = params[:content][:text] | 300 @text = params[:content][:text] |
299 render :partial => 'common/preview' | 301 render :partial => 'common/preview' |
300 end | 302 end |
347 extend helper unless self.instance_of?(helper) | 349 extend helper unless self.instance_of?(helper) |
348 helper.instance_method(:initial_page_content).bind(self).call(page) | 350 helper.instance_method(:initial_page_content).bind(self).call(page) |
349 end | 351 end |
350 | 352 |
351 def load_pages_for_index | 353 def load_pages_for_index |
352 @pages = @wiki.pages.with_updated_on.order("#{WikiPage.table_name}.title").includes(:wiki => :project).includes(:parent).all | 354 @pages = @wiki.pages.with_updated_on.reorder("#{WikiPage.table_name}.title").includes(:wiki => :project).includes(:parent).all |
353 end | 355 end |
354 end | 356 end |