2014-04-09 11:35:01 +00:00
|
|
|
require 'project_wiki'
|
|
|
|
|
2013-06-23 16:47:22 +00:00
|
|
|
class Projects::WikisController < Projects::ApplicationController
|
2012-02-20 18:16:55 +00:00
|
|
|
before_filter :authorize_read_wiki!
|
2012-08-10 22:07:50 +00:00
|
|
|
before_filter :authorize_write_wiki!, only: [:edit, :create, :history]
|
|
|
|
before_filter :authorize_admin_wiki!, only: :destroy
|
2014-04-09 11:35:01 +00:00
|
|
|
before_filter :load_project_wiki
|
2013-01-11 19:04:14 +00:00
|
|
|
|
2012-08-09 04:34:29 +00:00
|
|
|
def pages
|
2014-04-11 08:02:52 +00:00
|
|
|
@wiki_pages = Kaminari.paginate_array(@project_wiki.pages).page(params[:page]).per(30)
|
2012-08-09 04:34:29 +00:00
|
|
|
end
|
|
|
|
|
2012-02-19 14:35:31 +00:00
|
|
|
def show
|
2014-04-09 11:35:01 +00:00
|
|
|
@page = @project_wiki.find_page(params[:id], params[:version_id])
|
2012-02-21 22:31:18 +00:00
|
|
|
|
2014-04-09 11:35:01 +00:00
|
|
|
if @page
|
2012-07-26 11:45:17 +00:00
|
|
|
render 'show'
|
2014-04-24 13:00:18 +00:00
|
|
|
elsif file = @project_wiki.wiki.file(params[:id], @project_wiki.wiki.ref, true)
|
|
|
|
if file.on_disk?
|
|
|
|
send_file file.on_disk_path, :disposition => 'inline'
|
|
|
|
else
|
|
|
|
send_data(
|
|
|
|
file.raw_data,
|
|
|
|
type: file.mime_type,
|
|
|
|
disposition: 'inline',
|
|
|
|
filename: file.name
|
|
|
|
)
|
|
|
|
end
|
2012-07-26 11:45:17 +00:00
|
|
|
else
|
2013-03-04 03:43:52 +00:00
|
|
|
return render('empty') unless can?(current_user, :write_wiki, @project)
|
2014-04-09 11:35:01 +00:00
|
|
|
@page = WikiPage.new(@project_wiki)
|
|
|
|
@page.title = params[:id]
|
2013-03-04 03:43:52 +00:00
|
|
|
|
|
|
|
render 'edit'
|
2012-02-19 14:35:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2014-04-09 11:35:01 +00:00
|
|
|
@page = @project_wiki.find_page(params[:id])
|
2013-03-04 03:43:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2014-04-09 11:35:01 +00:00
|
|
|
@page = @project_wiki.find_page(params[:id])
|
2013-03-04 03:43:52 +00:00
|
|
|
|
|
|
|
return render('empty') unless can?(current_user, :write_wiki, @project)
|
|
|
|
|
2014-04-09 11:35:01 +00:00
|
|
|
if @page.update(content, format, message)
|
|
|
|
redirect_to [@project, @page], notice: 'Wiki was successfully updated.'
|
2013-03-04 03:43:52 +00:00
|
|
|
else
|
|
|
|
render 'edit'
|
|
|
|
end
|
2012-02-19 14:35:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2014-04-09 11:35:01 +00:00
|
|
|
@page = WikiPage.new(@project_wiki)
|
2013-03-04 03:43:52 +00:00
|
|
|
|
2014-04-09 11:35:01 +00:00
|
|
|
if @page.create(wiki_params)
|
|
|
|
redirect_to project_wiki_path(@project, @page), notice: 'Wiki was successfully updated.'
|
2013-03-04 03:43:52 +00:00
|
|
|
else
|
|
|
|
render action: "edit"
|
2012-02-19 14:35:31 +00:00
|
|
|
end
|
|
|
|
end
|
2012-02-19 19:52:05 +00:00
|
|
|
|
|
|
|
def history
|
2014-04-09 11:35:01 +00:00
|
|
|
@page = @project_wiki.find_page(params[:id])
|
2013-04-03 18:05:10 +00:00
|
|
|
|
2014-04-09 11:35:01 +00:00
|
|
|
unless @page
|
|
|
|
redirect_to(project_wiki_path(@project, :home), notice: "Page not found")
|
|
|
|
end
|
2012-02-19 19:52:05 +00:00
|
|
|
end
|
2013-01-11 19:04:14 +00:00
|
|
|
|
2012-02-19 14:35:31 +00:00
|
|
|
def destroy
|
2014-04-09 11:35:01 +00:00
|
|
|
@page = @project_wiki.find_page(params[:id])
|
|
|
|
@page.delete if @page
|
|
|
|
|
2013-03-04 03:43:52 +00:00
|
|
|
redirect_to project_wiki_path(@project, :home), notice: "Page was successfully deleted"
|
|
|
|
end
|
2012-02-19 14:35:31 +00:00
|
|
|
|
2013-03-04 03:43:52 +00:00
|
|
|
def git_access
|
2012-02-19 14:35:31 +00:00
|
|
|
end
|
2013-03-04 03:43:52 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2014-04-09 11:35:01 +00:00
|
|
|
def load_project_wiki
|
|
|
|
@project_wiki = ProjectWiki.new(@project, current_user)
|
2013-03-04 03:43:52 +00:00
|
|
|
|
|
|
|
# Call #wiki to make sure the Wiki Repo is initialized
|
2014-04-09 11:35:01 +00:00
|
|
|
@project_wiki.wiki
|
|
|
|
rescue ProjectWiki::CouldNotCreateWikiError => ex
|
2013-03-04 03:43:52 +00:00
|
|
|
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 14:35:31 +00:00
|
|
|
end
|