gitlabhq/app/controllers/wikis_controller.rb
Dan Knox ea9b3687db Replace current Wiki system with Gollum Wikis.
This commit replaces the old database backed Wiki system with the
excellent Gollum git based Wiki system.

The UI has been updated to allow for utilizing the extra features
that Gollum provides. Specifically:

* Edit page now allows you to choose the content format.
* Edit page allows you to provide a commit message for the change.
* History page now shows Format, Commit Message, and Commit Hash.
* A new Git Access page has been added with the Wiki Repo URL.
* The default page has been changed to Home from Index to match
the Gollum standard.

The old Wiki model has been left in tact to provide for the
development of a migration script that will move all content stored
in the old Wiki system into new Gollum Wikis.
2013-03-09 16:39:51 -08:00

96 lines
2.1 KiB
Ruby

class WikisController < ProjectResourceController
before_filter :authorize_read_wiki!
before_filter :authorize_write_wiki!, only: [:edit, :create, :history]
before_filter :authorize_admin_wiki!, only: :destroy
before_filter :load_gollum_wiki
def pages
@wiki_pages = @gollum_wiki.pages
end
def show
@wiki = @gollum_wiki.find_page(params[:id], params[:version_id])
if @wiki
render 'show'
else
return render('empty') unless can?(current_user, :write_wiki, @project)
@wiki = WikiPage.new(@gollum_wiki)
@wiki.title = params[:id]
render 'edit'
end
end
def edit
@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
end
def create
@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"
end
end
def history
unless @wiki = @gollum_wiki.find_page(params[:id])
redirect_to project_wiki_path(@project, :home), notice: "Page not found"
end
end
def destroy
@wiki = @gollum_wiki.find_page(params[:id])
@wiki.delete if @wiki
redirect_to project_wiki_path(@project, :home), notice: "Page was successfully deleted"
end
def git_access
end
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
end