##// END OF EJS Templates
Remove the Description label from the issue view and omit the block if empty (#6677)....
Remove the Description label from the issue view and omit the block if empty (#6677). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4264 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r4148:297eb6f81bf2
r4150:c058bc224549
Show More
wiki_controller.rb
247 lines | 8.7 KiB | text/x-ruby | RubyLexer
Jean-Philippe Lang
wiki branch merged into trunk...
r320 # redMine - project management software
# Copyright (C) 2006-2007 Jean-Philippe Lang
#
# 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.
#
# 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.
#
# 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'
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
Check that wiki page exists before processing (#2360)....
r2143 before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy]
Jean-Philippe Lang
Added the ability to destroy wiki pages (content and its history are deleted from the database)....
r537
Jean-Philippe Lang
AttachmentsController now handles attachments deletion....
r2114 verify :method => :post, :only => [:destroy, :protect], :redirect_to => { :action => :index }
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
include AttachmentsHelper
Jean-Philippe Lang
Ability to watch a wiki or a single wiki page (#413)....
r2666 helper :watchers
Jean-Philippe Lang
Added the ability to destroy wiki pages (content and its history are deleted from the database)....
r537
Jean-Philippe Lang
wiki branch merged into trunk...
r320 # display a page (in editing mode if it doesn't exist)
def index
page_title = params[:page]
@page = @wiki.find_or_new_page(page_title)
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)
if params[:format] == 'html'
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
wiki branch merged into trunk...
r320 render :action => 'show'
end
# edit an existing page or a new one
def edit
@page = @wiki.find_or_new_page(params[:page])
Jean-Philippe Lang
Wiki page protection (#851, patch #1146 by Mateo Murphy with slight changes)....
r1400 return render_403 unless editable?
Jean-Philippe Lang
wiki branch merged into trunk...
r320 @page.content = WikiContent.new(:page => @page) if @page.new_record?
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
Jean-Philippe Lang
Fixed: unable to revert to a previous wiki page version....
r1819 if request.get?
# To prevent StaleObjectError exception when reverting to a previous version
@content.version = @page.content.version
else
Jean-Philippe Lang
Fixed: unable to save a new wiki page that just contains the default h1 title...
r723 if !@page.new_record? && @content.text == params[:content][:text]
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)
Jean-Philippe Lang
wiki branch merged into trunk...
r320 # don't save if text wasn't changed
redirect_to :action => 'index', :id => @project, :page => @page.title
return
end
Jean-Philippe Lang
Optimistic locking added for wiki edits....
r542 #@content.text = params[:content][:text]
#@content.comments = params[:content][:comments]
@content.attributes = params[:content]
Jean-Philippe Lang
Anonymous users can now be allowed to create, edit, comment issues, comment news and post messages in the forums....
r906 @content.author = User.current
Jean-Philippe Lang
wiki branch merged into trunk...
r320 # 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)
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
Added more plugin hooks:...
r2674 call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})
Jean-Philippe Lang
wiki branch merged into trunk...
r320 redirect_to :action => 'index', :id => @project, :page => @page.title
end
end
Jean-Philippe Lang
Optimistic locking added for wiki edits....
r542 rescue ActiveRecord::StaleObjectError
# Optimistic locking exception
Jean-Philippe Lang
Applied the flash notices patch by Matt Jones (slightly edited)....
r597 flash[:error] = l(:notice_locking_conflict)
Jean-Philippe Lang
wiki branch merged into trunk...
r320 end
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)
redirect_to :action => 'index', :id => @project, :page => @page.title
end
end
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]
redirect_to :action => 'index', :id => @project, :page => @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']
Jean-Philippe Lang
Added pagination on wiki page history....
r568 # don't load text
Jean-Philippe Lang
wiki branch merged into trunk...
r320 @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
Jean-Philippe Lang
Added the ability to destroy wiki pages (content and its history are deleted from the database)....
r537
Jean-Philippe Lang
Added wiki diff....
r580 def diff
@diff = @page.diff(params[:version], params[:version_from])
render_404 unless @diff
end
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
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?
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: extract #page_index from WikiController#special...
r4139 redirect_to :action => 'page_index', :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
Eric Davis
Refactor: extract method in WikiController#special to create a new #export method...
r4137 # Export wiki to a single html file
def export
if User.current.allowed_to?(:export_wiki_pages, @project)
@pages = @wiki.pages.find :all, :order => 'title'
export = render_to_string :action => 'export_multiple', :layout => false
send_data(export, :type => 'text/html', :filename => "wiki.html")
else
redirect_to :action => 'index', :id => @project, :page => nil
end
end
Eric Davis
Refactor: extract #page_index from WikiController#special...
r4139
def page_index
load_pages_grouped_by_date_without_content
end
Eric Davis
Refactor: extract method from WikiController#special...
r4147
def date_index
load_pages_grouped_by_date_without_content
end
Jean-Philippe Lang
wiki branch merged into trunk...
r320
def preview
Jean-Philippe Lang
Attachments can now be added to wiki pages (original patch by Pavol Murin). Only authorized users can add/delete attachments....
r538 page = @wiki.find_page(params[:page])
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)
Jean-Philippe Lang
Attachments can now be added to wiki pages (original patch by Pavol Murin). Only authorized users can add/delete attachments....
r538 redirect_to :action => 'index', :page => @page.title
end
Jean-Philippe Lang
wiki branch merged into trunk...
r320 private
def find_wiki
@project = Project.find(params[:id])
@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
Jean-Philippe Lang
Wiki page protection (#851, patch #1146 by Mateo Murphy with slight changes)....
r1400
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
@page = @wiki.find_page(params[:page])
render_404 if @page.nil?
end
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
Eric Davis
Refactor: extract finder to a utility method...
r4138
# eager load information about last updates, without loading text
def load_pages_grouped_by_date_without_content
@pages = @wiki.pages.find :all, :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on",
:joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id",
:order => 'title'
@pages_by_date = @pages.group_by {|p| p.updated_on.to_date}
@pages_by_parent_id = @pages.group_by(&:parent_id)
end
Jean-Philippe Lang
wiki branch merged into trunk...
r320 end