class WikiController < ApplicationController
before_filter :find_wiki, :authorize
+ before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy]
verify :method => :post, :only => [:destroy, :protect], :redirect_to => { :action => :index }
# rename a page
def rename
- @page = @wiki.find_page(params[:page])
- return render_403 unless editable?
+ return render_403 unless editable?
@page.redirect_existing_links = true
# used to display the *original* title if some AR validation errors occur
@original_title = @page.pretty_title
end
def protect
- page = @wiki.find_page(params[:page])
- page.update_attribute :protected, params[:protected]
- redirect_to :action => 'index', :id => @project, :page => page.title
+ @page.update_attribute :protected, params[:protected]
+ redirect_to :action => 'index', :id => @project, :page => @page.title
end
# show page history
def history
- @page = @wiki.find_page(params[:page])
-
@version_count = @page.content.versions.count
@version_pages = Paginator.new self, @version_count, per_page_option, params['p']
# don't load text
end
def diff
- @page = @wiki.find_page(params[:page])
@diff = @page.diff(params[:version], params[:version_from])
render_404 unless @diff
end
def annotate
- @page = @wiki.find_page(params[:page])
@annotate = @page.annotate(params[:version])
+ render_404 unless @annotate
end
# remove a wiki page and its history
def destroy
- @page = @wiki.find_page(params[:page])
- return render_403 unless editable?
- @page.destroy if @page
+ return render_403 unless editable?
+ @page.destroy
redirect_to :action => 'special', :id => @project, :page => 'Page_index'
end
end
def add_attachment
- @page = @wiki.find_page(params[:page])
return render_403 unless editable?
attach_files(@page, params[:attachments])
redirect_to :action => 'index', :page => @page.title
render_404
end
+ # 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
+
# Returns true if the current user is allowed to edit the page, otherwise false
def editable?(page = @page)
page.editable_by?(User.current)