##// END OF EJS Templates
Upgraded to Rails 2.3.4 (#3597)...
Upgraded to Rails 2.3.4 (#3597) * Ran the Rails upgrade * Upgraded to Rails Engines 2.3.2 * Added a plugin to let Engines override application views. * Converted tests to use the new classes: ** ActionController::TestCase for functional ** ActiveSupport::TestCase for units * Converted ActiveRecord::Error message to a string. * ActiveRecord grouping returns an ordered hash which doesn't have #sort! * Updated the I18n storage_units format. * Added some default initializers from a fresh rails app * Changed the order of check_box_tags and hidden_field_tags. The hidden tag needs to appear first in Rails 2.3, otherwise it will override any value in the check_box_tag. * Removed the custom handler for when the cookie store is tampered with. Rails 2.3 removed the TamperedWithCookie exception and instead Rails will not load the data from it when it's been tampered with (e.g. no user login). * Fixed mail layouts, 2.3 has problems with implicit multipart emails that use layouts. Also removed some custom Redmine mailer code. * Fixed a bug that occurred in tests where the "required" span tag would be added to the :field_status translation. This resulted in an email string of: <li>Status<span class="required"> *</span><span class="required"> *</span> Instead of: <li>Status: New</li> git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2887 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r2674:4ba83085072d
r2773:7b0cb6aba871
Show More
wiki_controller.rb
235 lines | 8.4 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
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
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 if User.current.allowed_to?(:edit_wiki_pages, @project)
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 an helper to render other formats download links....
r2331 if params[:format] == 'html'
Jean-Philippe Lang
wiki branch merged into trunk...
r320 export = render_to_string :action => 'export', :layout => false
send_data(export, :type => 'text/html', :filename => "#{@page.title}.html")
return
Jean-Philippe Lang
Adds an helper to render other formats download links....
r2331 elsif params[:format] == 'txt'
Jean-Philippe Lang
wiki branch merged into trunk...
r320 send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt")
return
end
Jean-Philippe Lang
Wiki page protection (#851, patch #1146 by Mateo Murphy with slight changes)....
r1400 @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]
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
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
Jean-Philippe Lang
Added the ability to destroy wiki pages (content and its history are deleted from the database)....
r537 redirect_to :action => 'special', :id => @project, :page => 'Page_index'
end
Jean-Philippe Lang
wiki branch merged into trunk...
r320
# display special pages
def special
page_title = params[:page].downcase
case page_title
# show pages index, sorted by title
Jean-Philippe Lang
Added wiki index by date....
r757 when 'page_index', 'date_index'
Jean-Philippe Lang
wiki branch merged into trunk...
r320 # eager load information about last updates, without loading text
Jean-Philippe Lang
fixed #9308 table_name pre/suffix support...
r334 @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",
Jean-Philippe Lang
wiki branch merged into trunk...
r320 :order => 'title'
Jean-Philippe Lang
Added wiki index by date....
r757 @pages_by_date = @pages.group_by {|p| p.updated_on.to_date}
Jean-Philippe Lang
Wiki page hierarchy (#528). Parent page can be assigned on Rename screen....
r1689 @pages_by_parent_id = @pages.group_by(&:parent_id)
Jean-Philippe Lang
wiki branch merged into trunk...
r320 # export wiki to a single html file
when 'export'
@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")
return
else
# requested special page doesn't exist, redirect to default page
redirect_to :action => 'index', :id => @project, :page => nil and return
end
render :action => "special_#{page_title}"
end
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?
Jean-Philippe Lang
Added ApplicationController#attach_files as a common method to attach files in all actions....
r977 attach_files(@page, params[:attachments])
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
Jean-Philippe Lang
wiki branch merged into trunk...
r320 end