2012-09-27 20:59:42 +02:00
|
|
|
class WikisController < ProjectResourceController
|
2012-02-20 19:16:55 +01:00
|
|
|
before_filter :authorize_read_wiki!
|
2012-08-11 00:07:50 +02:00
|
|
|
before_filter :authorize_write_wiki!, only: [:edit, :create, :history]
|
|
|
|
before_filter :authorize_admin_wiki!, only: :destroy
|
2013-03-04 04:43:52 +01:00
|
|
|
before_filter :load_gollum_wiki
|
2013-01-11 20:04:14 +01:00
|
|
|
|
2012-08-09 06:34:29 +02:00
|
|
|
def pages
|
2013-03-04 04:43:52 +01:00
|
|
|
@wiki_pages = @gollum_wiki.pages
|
2012-08-09 06:34:29 +02:00
|
|
|
end
|
|
|
|
|
2012-02-19 15:35:31 +01:00
|
|
|
def show
|
2013-03-04 04:43:52 +01:00
|
|
|
@wiki = @gollum_wiki.find_page(params[:id], params[:version_id])
|
2012-02-21 23:31:18 +01:00
|
|
|
|
2012-07-26 13:45:17 +02:00
|
|
|
if @wiki
|
|
|
|
render 'show'
|
|
|
|
else
|
2013-03-04 04:43:52 +01:00
|
|
|
return render('empty') unless can?(current_user, :write_wiki, @project)
|
|
|
|
@wiki = WikiPage.new(@gollum_wiki)
|
|
|
|
@wiki.title = params[:id]
|
|
|
|
|
|
|
|
render 'edit'
|
2012-02-19 15:35:31 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2013-03-04 04:43:52 +01:00
|
|
|
@wiki = @gollum_wiki.find_page(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@wiki = @gollum_wiki.find_page(params[:id])
|
|
|
|
|
|
|
|
return render('empty') unless can?(current_user, :write_wiki, @project)
|
|
|
|
|
|
|
|
if @wiki.update(content, format, message)
|
|
|
|
redirect_to [@project, @wiki], notice: 'Wiki was successfully updated.'
|
|
|
|
else
|
|
|
|
render 'edit'
|
|
|
|
end
|
2012-02-19 15:35:31 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2013-03-04 04:43:52 +01:00
|
|
|
@wiki = WikiPage.new(@gollum_wiki)
|
|
|
|
|
|
|
|
if @wiki.create(wiki_params)
|
|
|
|
redirect_to project_wiki_path(@project, @wiki), notice: 'Wiki was successfully updated.'
|
|
|
|
else
|
|
|
|
render action: "edit"
|
2012-02-19 15:35:31 +01:00
|
|
|
end
|
|
|
|
end
|
2012-02-19 20:52:05 +01:00
|
|
|
|
|
|
|
def history
|
2013-03-04 04:43:52 +01:00
|
|
|
unless @wiki = @gollum_wiki.find_page(params[:id])
|
|
|
|
redirect_to project_wiki_path(@project, :home), notice: "Page not found"
|
|
|
|
end
|
2012-02-19 20:52:05 +01:00
|
|
|
end
|
2013-01-11 20:04:14 +01:00
|
|
|
|
2012-02-19 15:35:31 +01:00
|
|
|
def destroy
|
2013-03-04 04:43:52 +01:00
|
|
|
@wiki = @gollum_wiki.find_page(params[:id])
|
|
|
|
@wiki.delete if @wiki
|
|
|
|
redirect_to project_wiki_path(@project, :home), notice: "Page was successfully deleted"
|
|
|
|
end
|
2012-02-19 15:35:31 +01:00
|
|
|
|
2013-03-04 04:43:52 +01:00
|
|
|
def git_access
|
2012-02-19 15:35:31 +01:00
|
|
|
end
|
2013-03-04 04:43:52 +01:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def load_gollum_wiki
|
|
|
|
@gollum_wiki = GollumWiki.new(@project, current_user)
|
|
|
|
|
|
|
|
# Call #wiki to make sure the Wiki Repo is initialized
|
|
|
|
@gollum_wiki.wiki
|
|
|
|
rescue GollumWiki::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 15:35:31 +01:00
|
|
|
end
|