##// END OF EJS Templates
remove trailing white-space from app/controllers/wiki_controller.rb...
remove trailing white-space from app/controllers/wiki_controller.rb git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10246 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r10063:564de36c0879
r10063:564de36c0879
Show More
wiki_controller.rb
318 lines | 10.9 KiB | text/x-ruby | RubyLexer
Jean-Philippe Lang
Moved wiki page updated_on eager load to a scope and fixed timestamp titles on wiki page index (#7818)....
r4978 # Redmine - project management software
Jean-Philippe Lang
Copyright update....
r9453 # Copyright (C) 2006-2012 Jean-Philippe Lang
Jean-Philippe Lang
wiki branch merged into trunk...
r320 #
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
Toshi MARUYAMA
remove trailing white-spaces from wiki controller source....
r5704 #
Jean-Philippe Lang
wiki branch merged into trunk...
r320 # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
Toshi MARUYAMA
remove trailing white-spaces from wiki controller source....
r5704 #
Jean-Philippe Lang
wiki branch merged into trunk...
r320 # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Jean-Philippe Lang
Added wiki diff....
r580 require 'diff'
Eric Davis
Refactor: Rename WikiController#page_index to #index...
r4176 # The WikiController follows the Rails REST controller pattern but with
# a few differences
#
# * index - shows a list of WikiPages grouped by page or date
# * new - not used
# * create - not used
# * show - will also show the form for creating a new wiki page
# * edit - used to edit an existing or new page
# * update - used to save a wiki page update to the database, including new pages
# * destroy - normal
#
# Other member and collection methods are also used
#
# TODO: still being worked on
Jean-Philippe Lang
wiki branch merged into trunk...
r320 class WikiController < ApplicationController
Jean-Philippe Lang
Contextual quick search (#3263)....
r2829 default_search_scope :wiki_pages
Jean-Philippe Lang
Merged 0.6 branch into trunk....
r663 before_filter :find_wiki, :authorize
Jean-Philippe Lang
Code cleanup....
r5302 before_filter :find_existing_or_new_page, :only => [:show, :edit, :update]
Jean-Philippe Lang
Check that wiki page exists before processing (#2360)....
r2143 before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy]
Toshi MARUYAMA
remove trailing white-spaces from wiki controller source....
r5704
Jean-Philippe Lang
Attachments can now be added to wiki pages (original patch by Pavol Murin). Only authorized users can add/delete attachments....
r538 helper :attachments
Toshi MARUYAMA
remove trailing white-spaces from wiki controller source....
r5704 include AttachmentsHelper
Jean-Philippe Lang
Ability to watch a wiki or a single wiki page (#413)....
r2666 helper :watchers
Toshi MARUYAMA
pdf: add a new feature to export wiki pdf (#401)...
r7621 include Redmine::Export::PDF
Eric Davis
Refactor: rename WikiController#index to #show, it's a single resource action...
r4152
Eric Davis
Refactor: Rename WikiController#page_index to #index...
r4176 # List of pages, sorted alphabetically and by parent (hierarchy)
def index
Jean-Philippe Lang
Moved wiki page updated_on eager load to a scope and fixed timestamp titles on wiki page index (#7818)....
r4978 load_pages_for_index
@pages_by_parent_id = @pages.group_by(&:parent_id)
end
Toshi MARUYAMA
remove trailing white-spaces from wiki controller source....
r5704
Jean-Philippe Lang
Moved wiki page updated_on eager load to a scope and fixed timestamp titles on wiki page index (#7818)....
r4978 # List of page, by last update
def date_index
load_pages_for_index
@pages_by_date = @pages.group_by {|p| p.updated_on.to_date}
Eric Davis
Refactor: Rename WikiController#page_index to #index...
r4176 end
Jean-Philippe Lang
wiki branch merged into trunk...
r320 # display a page (in editing mode if it doesn't exist)
Eric Davis
Refactor: rename WikiController#index to #show, it's a single resource action...
r4152 def show
Jean-Philippe Lang
wiki branch merged into trunk...
r320 if @page.new_record?
Jean-Philippe Lang
Makes the wiki sidebar editable (#5208)....
r3518 if User.current.allowed_to?(:edit_wiki_pages, @project) && editable?
Jean-Philippe Lang
Fixed: a user not authorized to edit wiki pages gets the edit form if the page doesn't exist. He now gets a 404....
r812 edit
render :action => 'edit'
else
render_404
end
return
Jean-Philippe Lang
wiki branch merged into trunk...
r320 end
Jean-Philippe Lang
Adds a permission 'view wiki edits' so that wiki history can be hidden to certain users (#1154)....
r1813 if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project)
# Redirects user to the current version if he's not allowed to view previous versions
redirect_to :version => nil
return
end
Jean-Philippe Lang
Added the ability to easily rollback to a previous version of a wiki page....
r421 @content = @page.content_for_version(params[:version])
Jean-Philippe Lang
Adds a permission for exporting wiki pages....
r3257 if User.current.allowed_to?(:export_wiki_pages, @project)
Toshi MARUYAMA
pdf: add a new feature to export wiki pdf (#401)...
r7621 if params[:format] == 'pdf'
Jean-Philippe Lang
Adds export of all wiki pages to a PDF file (#3463)....
r8614 send_data(wiki_page_to_pdf(@page, @project), :type => 'application/pdf', :filename => "#{@page.title}.pdf")
Toshi MARUYAMA
pdf: add a new feature to export wiki pdf (#401)...
r7621 return
elsif params[:format] == 'html'
Jean-Philippe Lang
Adds a permission for exporting wiki pages....
r3257 export = render_to_string :action => 'export', :layout => false
send_data(export, :type => 'text/html', :filename => "#{@page.title}.html")
return
elsif params[:format] == 'txt'
send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt")
return
end
Jean-Philippe Lang
wiki branch merged into trunk...
r320 end
Jean-Philippe Lang
Adds a permission for exporting wiki pages....
r3257 @editable = editable?
Jean-Philippe Lang
Handle the case of a text formatter that doesn't support section edit (#2222)....
r7711 @sections_editable = @editable && User.current.allowed_to?(:edit_wiki_pages, @page.project) &&
Jean-Philippe Lang
Adds #current_version? method to wiki content....
r7852 @content.current_version? &&
Jean-Philippe Lang
Handle the case of a text formatter that doesn't support section edit (#2222)....
r7711 Redmine::WikiFormatting.supports_section_edit?
Jean-Philippe Lang
wiki branch merged into trunk...
r320 render :action => 'show'
end
Toshi MARUYAMA
remove trailing white-spaces from wiki controller source....
r5704
Jean-Philippe Lang
wiki branch merged into trunk...
r320 # edit an existing page or a new one
def edit
Jean-Philippe Lang
Wiki page protection (#851, patch #1146 by Mateo Murphy with slight changes)....
r1400 return render_403 unless editable?
Jean-Philippe Lang
Option to set parent automatically for new wiki pages (#3108)....
r8135 if @page.new_record?
@page.content = WikiContent.new(:page => @page)
if params[:parent].present?
@page.parent = @page.wiki.find_page(params[:parent].to_s)
end
end
Toshi MARUYAMA
remove trailing white-spaces from wiki controller source....
r5704
Jean-Philippe Lang
Added the ability to easily rollback to a previous version of a wiki page....
r421 @content = @page.content_for_version(params[:version])
Jean-Philippe Lang
Makes wiki text formatter pluggable....
r1953 @content.text = initial_page_content(@page) if @content.text.blank?
Jean-Philippe Lang
wiki branch merged into trunk...
r320 # don't keep previous comment
Jean-Philippe Lang
Fixed: 10342 Creation of Schema in Oracle...
r476 @content.comments = nil
Eric Davis
Refactor: split WikiController#edit into #update...
r4158
# To prevent StaleObjectError exception when reverting to a previous version
@content.version = @page.content.version
Toshi MARUYAMA
remove trailing white-space from app/controllers/wiki_controller.rb...
r10063
Jean-Philippe Lang
Wiki: allows single section edit (#2222)....
r7709 @text = @content.text
Jean-Philippe Lang
Handle the case of a text formatter that doesn't support section edit (#2222)....
r7711 if params[:section].present? && Redmine::WikiFormatting.supports_section_edit?
Jean-Philippe Lang
Wiki: allows single section edit (#2222)....
r7709 @section = params[:section].to_i
@text, @section_hash = Redmine::WikiFormatting.formatter.new(@text).get_section(@section)
render_404 if @text.blank?
end
Eric Davis
Refactor: split WikiController#edit into #update...
r4158 end
# Creates a new page or updates an existing one
def update
return render_403 unless editable?
@page.content = WikiContent.new(:page => @page) if @page.new_record?
Jean-Philippe Lang
Ability to edit a wiki page's parent on the edit page (#6449)....
r8667 @page.safe_attributes = params[:wiki_page]
Toshi MARUYAMA
remove trailing white-spaces from wiki controller source....
r5704
Eric Davis
Refactor: split WikiController#edit into #update...
r4158 @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)
Jean-Philippe Lang
Ability to edit a wiki page's parent on the edit page (#6449)....
r8667 # don't save content if text wasn't changed
@page.save
Eric Davis
Refactor: use :id instead of :page when linking to Wiki Pages...
r4182 redirect_to :action => 'show', :project_id => @project, :id => @page.title
Eric Davis
Refactor: split WikiController#edit into #update...
r4158 return
end
Jean-Philippe Lang
Ability to edit a wiki page's parent on the edit page (#6449)....
r8667
Jean-Philippe Lang
Wiki: allows single section edit (#2222)....
r7709 @content.comments = params[:content][:comments]
@text = params[:content][:text]
Jean-Philippe Lang
Handle the case of a text formatter that doesn't support section edit (#2222)....
r7711 if params[:section].present? && Redmine::WikiFormatting.supports_section_edit?
Jean-Philippe Lang
Wiki: allows single section edit (#2222)....
r7709 @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.text = @text
end
Eric Davis
Refactor: split WikiController#edit into #update...
r4158 @content.author = User.current
Jean-Philippe Lang
Ability to edit a wiki page's parent on the edit page (#6449)....
r8667 @page.content = @content
if @page.save
Eric Davis
Refactor: split WikiController#edit into #update...
r4158 attachments = Attachment.attach_files(@page, params[:attachments])
render_attachment_warning_if_needed(@page)
call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})
Eric Davis
Refactor: use :id instead of :page when linking to Wiki Pages...
r4182 redirect_to :action => 'show', :project_id => @project, :id => @page.title
Jean-Philippe Lang
Fixed: Missing template wiki/update.erb error introduced in r4272 (#6987)....
r4315 else
render :action => 'edit'
Jean-Philippe Lang
wiki branch merged into trunk...
r320 end
Eric Davis
Refactor: split WikiController#edit into #update...
r4158
Jean-Philippe Lang
Wiki: allows single section edit (#2222)....
r7709 rescue ActiveRecord::StaleObjectError, Redmine::WikiFormatting::StaleSectionError
Jean-Philippe Lang
Optimistic locking added for wiki edits....
r542 # Optimistic locking exception
Jean-Philippe Lang
Fixed: Simultaneous wiki updates cause internal error (#7939)....
r5065 flash.now[:error] = l(:notice_locking_conflict)
render :action => 'edit'
Jean-Philippe Lang
Merged rails-3.2 branch....
r9346 rescue ActiveRecord::RecordNotSaved
render :action => 'edit'
Jean-Philippe Lang
wiki branch merged into trunk...
r320 end
Eric Davis
Refactor: split WikiController#edit into #update...
r4158
Jean-Philippe Lang
Added the ability to rename wiki pages (specific permission required)....
r709 # rename a page
def rename
Jean-Philippe Lang
Check that wiki page exists before processing (#2360)....
r2143 return render_403 unless editable?
Jean-Philippe Lang
Added the ability to rename wiki pages (specific permission required)....
r709 @page.redirect_existing_links = true
# used to display the *original* title if some AR validation errors occur
@original_title = @page.pretty_title
if request.post? && @page.update_attributes(params[:wiki_page])
flash[:notice] = l(:notice_successful_update)
Eric Davis
Refactor: use :id instead of :page when linking to Wiki Pages...
r4182 redirect_to :action => 'show', :project_id => @project, :id => @page.title
Jean-Philippe Lang
Added the ability to rename wiki pages (specific permission required)....
r709 end
end
Toshi MARUYAMA
remove trailing white-spaces from wiki controller source....
r5704
Jean-Philippe Lang
Wiki page protection (#851, patch #1146 by Mateo Murphy with slight changes)....
r1400 def protect
Jean-Philippe Lang
Check that wiki page exists before processing (#2360)....
r2143 @page.update_attribute :protected, params[:protected]
Eric Davis
Refactor: use :id instead of :page when linking to Wiki Pages...
r4182 redirect_to :action => 'show', :project_id => @project, :id => @page.title
Jean-Philippe Lang
Wiki page protection (#851, patch #1146 by Mateo Murphy with slight changes)....
r1400 end
Jean-Philippe Lang
wiki branch merged into trunk...
r320 # show page history
def history
Jean-Philippe Lang
Added pagination on wiki page history....
r568 @version_count = @page.content.versions.count
Jean-Philippe Lang
New setting added to specify how many objects should be displayed on most paginated lists....
r1013 @version_pages = Paginator.new self, @version_count, per_page_option, params['p']
Toshi MARUYAMA
remove trailing white-spaces from wiki controller source....
r5704 # don't load text
@versions = @page.content.versions.find :all,
Jean-Philippe Lang
Fixed: 10342 Creation of Schema in Oracle...
r476 :select => "id, author_id, comments, updated_on, version",
Jean-Philippe Lang
Added pagination on wiki page history....
r568 :order => 'version DESC',
Jean-Philippe Lang
Added wiki diff....
r580 :limit => @version_pages.items_per_page + 1,
Jean-Philippe Lang
Added pagination on wiki page history....
r568 :offset => @version_pages.current.offset
render :layout => false if request.xhr?
Jean-Philippe Lang
wiki branch merged into trunk...
r320 end
Toshi MARUYAMA
remove trailing white-spaces from wiki controller source....
r5704
Jean-Philippe Lang
Added wiki diff....
r580 def diff
@diff = @page.diff(params[:version], params[:version_from])
render_404 unless @diff
end
Toshi MARUYAMA
remove trailing white-spaces from wiki controller source....
r5704
Jean-Philippe Lang
Added wiki annotate view. It's accessible for each version from the page history view. ...
r1007 def annotate
@annotate = @page.annotate(params[:version])
Jean-Philippe Lang
Check that wiki page exists before processing (#2360)....
r2143 render_404 unless @annotate
Jean-Philippe Lang
Added wiki annotate view. It's accessible for each version from the page history view. ...
r1007 end
Eric Davis
Refactor: convert WikiController#destroy to use HTTP DELETE...
r4181
Jean-Philippe Lang
Ask user what to do with child pages when deleting a parent wiki page (#3202)....
r2584 # Removes a wiki page and its history
# Children can be either set as root pages, removed or reassigned to another parent page
Jean-Philippe Lang
Added the ability to destroy wiki pages (content and its history are deleted from the database)....
r537 def destroy
Jean-Philippe Lang
Check that wiki page exists before processing (#2360)....
r2143 return render_403 unless editable?
Toshi MARUYAMA
remove trailing white-spaces from wiki controller source....
r5704
Jean-Philippe Lang
Ask user what to do with child pages when deleting a parent wiki page (#3202)....
r2584 @descendants_count = @page.descendants.size
if @descendants_count > 0
case params[:todo]
when 'nullify'
# Nothing to do
when 'destroy'
# Removes all its descendants
@page.descendants.each(&:destroy)
when 'reassign'
# Reassign children to another parent page
reassign_to = @wiki.pages.find_by_id(params[:reassign_to_id].to_i)
return unless reassign_to
@page.children.each do |child|
child.update_attribute(:parent, reassign_to)
end
else
@reassignable_to = @wiki.pages - @page.self_and_descendants
return
end
end
Jean-Philippe Lang
Check that wiki page exists before processing (#2360)....
r2143 @page.destroy
Eric Davis
Refactor: Rename WikiController#page_index to #index...
r4176 redirect_to :action => 'index', :project_id => @project
Jean-Philippe Lang
Added the ability to destroy wiki pages (content and its history are deleted from the database)....
r537 end
Jean-Philippe Lang
wiki branch merged into trunk...
r320
Jean-Philippe Lang
Adds export of all wiki pages to a PDF file (#3463)....
r8614 # Export wiki to a single pdf or html file
Eric Davis
Refactor: extract method in WikiController#special to create a new #export method...
r4137 def export
Jean-Philippe Lang
Adds export of all wiki pages to a PDF file (#3463)....
r8614 @pages = @wiki.pages.all(:order => 'title', :include => [:content, :attachments], :limit => 75)
respond_to do |format|
format.html {
export = render_to_string :action => 'export_multiple', :layout => false
send_data(export, :type => 'text/html', :filename => "wiki.html")
}
format.pdf {
send_data(wiki_pages_to_pdf(@pages, @project), :type => 'application/pdf', :filename => "#{@project.identifier}.pdf")
}
Eric Davis
Refactor: extract method in WikiController#special to create a new #export method...
r4137 end
end
Toshi MARUYAMA
remove trailing white-spaces from wiki controller source....
r5704
Jean-Philippe Lang
wiki branch merged into trunk...
r320 def preview
Eric Davis
Refactor: use :id instead of :page when linking to Wiki Pages...
r4182 page = @wiki.find_page(params[:id])
Jean-Philippe Lang
Fixed: error when previewing a new wiki page (#1292) introduced in r1415....
r1431 # page is nil when previewing a new page
return render_403 unless page.nil? || editable?(page)
Jean-Philippe Lang
Adds child_pages macro for wiki pages (#528)....
r1690 if page
@attachements = page.attachments
@previewed = page.content
end
Jean-Philippe Lang
wiki branch merged into trunk...
r320 @text = params[:content][:text]
Jean-Philippe Lang
Added preview on add/edit issue form....
r801 render :partial => 'common/preview'
Jean-Philippe Lang
wiki branch merged into trunk...
r320 end
Jean-Philippe Lang
Attachments can now be added to wiki pages (original patch by Pavol Murin). Only authorized users can add/delete attachments....
r538 def add_attachment
Jean-Philippe Lang
Wiki page protection (#851, patch #1146 by Mateo Murphy with slight changes)....
r1400 return render_403 unless editable?
Eric Davis
Refactor: Moved ApplicationController#attach_files to the Attachment model...
r3409 attachments = Attachment.attach_files(@page, params[:attachments])
Eric Davis
Refactor: Decouple failed attachments and the flash messages...
r3414 render_attachment_warning_if_needed(@page)
Eric Davis
Refactor: convert WikiController to a REST resource...
r4189 redirect_to :action => 'show', :id => @page.title, :project_id => @project
Jean-Philippe Lang
Attachments can now be added to wiki pages (original patch by Pavol Murin). Only authorized users can add/delete attachments....
r538 end
Jean-Philippe Lang
wiki branch merged into trunk...
r320 private
Toshi MARUYAMA
remove trailing white-spaces from wiki controller source....
r5704
Jean-Philippe Lang
wiki branch merged into trunk...
r320 def find_wiki
Eric Davis
Refactor: change :id on WikiController to use :project_id...
r4151 @project = Project.find(params[:project_id])
Jean-Philippe Lang
wiki branch merged into trunk...
r320 @wiki = @project.wiki
Jean-Philippe Lang
A wiki page can now be attached to each version....
r561 render_404 unless @wiki
Jean-Philippe Lang
wiki branch merged into trunk...
r320 rescue ActiveRecord::RecordNotFound
render_404
end
Toshi MARUYAMA
remove trailing white-spaces from wiki controller source....
r5704
Jean-Philippe Lang
Code cleanup....
r5302 # Finds the requested page or a new page if it doesn't exist
def find_existing_or_new_page
@page = @wiki.find_or_new_page(params[:id])
Jean-Philippe Lang
Do a redirect when accessing a renamed wiki page....
r5303 if @wiki.page_found_with_redirect?
redirect_to params.update(:id => @page.title)
end
Jean-Philippe Lang
Code cleanup....
r5302 end
Toshi MARUYAMA
remove trailing white-spaces from wiki controller source....
r5704
Jean-Philippe Lang
Check that wiki page exists before processing (#2360)....
r2143 # Finds the requested page and returns a 404 error if it doesn't exist
def find_existing_page
Eric Davis
Refactor: use :id instead of :page when linking to Wiki Pages...
r4182 @page = @wiki.find_page(params[:id])
Jean-Philippe Lang
Do a redirect when accessing a renamed wiki page....
r5303 if @page.nil?
render_404
return
end
if @wiki.page_found_with_redirect?
redirect_to params.update(:id => @page.title)
end
Jean-Philippe Lang
Check that wiki page exists before processing (#2360)....
r2143 end
Toshi MARUYAMA
remove trailing white-spaces from wiki controller source....
r5704
Jean-Philippe Lang
Wiki page protection (#851, patch #1146 by Mateo Murphy with slight changes)....
r1400 # Returns true if the current user is allowed to edit the page, otherwise false
def editable?(page = @page)
page.editable_by?(User.current)
end
Jean-Philippe Lang
Makes wiki text formatter pluggable....
r1953
# Returns the default content of a new wiki page
def initial_page_content(page)
helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting)
extend helper unless self.instance_of?(helper)
helper.instance_method(:initial_page_content).bind(self).call(page)
end
Toshi MARUYAMA
remove trailing white-spaces from wiki controller source....
r5704
Jean-Philippe Lang
Moved wiki page updated_on eager load to a scope and fixed timestamp titles on wiki page index (#7818)....
r4978 def load_pages_for_index
@pages = @wiki.pages.with_updated_on.all(:order => 'title', :include => {:wiki => :project})
end
Jean-Philippe Lang
wiki branch merged into trunk...
r320 end