gitlab-org--gitlab-foss/app/controllers/projects/wikis_controller.rb

111 lines
2.6 KiB
Ruby
Raw Normal View History

require 'project_wiki'
class Projects::WikisController < Projects::ApplicationController
2012-02-20 13:16:55 -05:00
before_filter :authorize_read_wiki!
before_filter :authorize_write_wiki!, only: [:edit, :create, :history]
before_filter :authorize_admin_wiki!, only: :destroy
before_filter :load_project_wiki
2013-01-11 14:04:14 -05:00
2012-08-09 00:34:29 -04:00
def pages
@wiki_pages = Kaminari.paginate_array(@project_wiki.pages).page(params[:page]).per(30)
2012-08-09 00:34:29 -04:00
end
2012-02-19 09:35:31 -05:00
def show
@page = @project_wiki.find_page(params[:id], params[:version_id])
if @page
render 'show'
elsif file = @project_wiki.find_file(params[:id], params[:version_id])
2014-04-24 09:00:18 -04:00
if file.on_disk?
2014-05-05 05:55:49 -04:00
send_file file.on_disk_path, disposition: 'inline'
2014-04-24 09:00:18 -04:00
else
2014-05-05 05:55:49 -04:00
send_data(
file.raw_data,
type: file.mime_type,
disposition: 'inline',
filename: file.name
)
2014-04-24 09:00:18 -04:00
end
else
return render('empty') unless can?(current_user, :write_wiki, @project)
@page = WikiPage.new(@project_wiki)
@page.title = params[:id]
render 'edit'
2012-02-19 09:35:31 -05:00
end
end
def edit
@page = @project_wiki.find_page(params[:id])
end
def update
@page = @project_wiki.find_page(params[:id])
return render('empty') unless can?(current_user, :write_wiki, @project)
if @page.update(content, format, message)
redirect_to [@project, @page], notice: 'Wiki was successfully updated.'
else
render 'edit'
end
2012-02-19 09:35:31 -05:00
end
def create
@page = WikiPage.new(@project_wiki)
if @page.create(wiki_params)
redirect_to project_wiki_path(@project, @page), notice: 'Wiki was successfully updated.'
else
render action: "edit"
2012-02-19 09:35:31 -05:00
end
end
2012-02-19 14:52:05 -05:00
def history
@page = @project_wiki.find_page(params[:id])
unless @page
redirect_to(project_wiki_path(@project, :home), notice: "Page not found")
end
2012-02-19 14:52:05 -05:00
end
2013-01-11 14:04:14 -05:00
2012-02-19 09:35:31 -05:00
def destroy
@page = @project_wiki.find_page(params[:id])
@page.delete if @page
redirect_to project_wiki_path(@project, :home), notice: "Page was successfully deleted"
end
2012-02-19 09:35:31 -05:00
def git_access
2012-02-19 09:35:31 -05:00
end
private
def load_project_wiki
@project_wiki = ProjectWiki.new(@project, current_user)
# Call #wiki to make sure the Wiki Repo is initialized
@project_wiki.wiki
rescue ProjectWiki::CouldNotCreateWikiError => ex
flash[:notice] = "Could not create Wiki Repository at this time. Please try again later."
redirect_to @project
return false
end
def wiki_params
params[:wiki].slice(:title, :content, :format, :message)
end
def content
params[:wiki][:content]
end
def format
params[:wiki][:format]
end
def message
params[:wiki][:message]
end
2012-02-19 09:35:31 -05:00
end