2009-03-25 19:54:04 +01:00
|
|
|
class PagesController < ApplicationController
|
|
|
|
|
|
|
|
def index
|
2009-06-11 23:51:26 +02:00
|
|
|
@page = Page.find_by_permalink "Home"
|
2009-03-25 19:54:04 +01:00
|
|
|
|
|
|
|
if @page
|
|
|
|
render :action => 'show'
|
|
|
|
else
|
|
|
|
redirect_to all_pages_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@page = Page.find_by_permalink(params[:permalink])
|
|
|
|
|
|
|
|
if @page.nil?
|
|
|
|
redirect_to new_page_path(:title => params[:permalink])
|
2009-06-11 23:51:26 +02:00
|
|
|
elsif @page.redirect?
|
|
|
|
flash[:notice] = "Weitergeleitet von #{@page.title} ..."
|
|
|
|
redirect_to wiki_page_path(Page.find(@page.redirect).permalink)
|
2009-03-25 19:54:04 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2009-05-20 15:26:53 +02:00
|
|
|
@page = Page.new
|
2009-06-11 22:40:56 +02:00
|
|
|
@page.title = params[:title].gsub("_", " ") if params[:title]
|
2009-03-25 19:54:04 +01:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # new.html.erb
|
|
|
|
format.xml { render :xml => @page }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@page = Page.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2009-05-15 17:32:45 +02:00
|
|
|
@page = current_user.pages.build(params[:page])
|
2009-03-25 19:54:04 +01:00
|
|
|
|
2009-05-20 12:42:01 +02:00
|
|
|
if params[:preview]
|
|
|
|
render :action => 'new'
|
|
|
|
else
|
2009-03-25 19:54:04 +01:00
|
|
|
if @page.save
|
2009-05-07 18:15:14 +02:00
|
|
|
flash[:notice] = 'Seite wurde angelegt.'
|
2009-05-20 12:42:01 +02:00
|
|
|
redirect_to(wiki_page_path(@page.permalink))
|
2009-03-25 19:54:04 +01:00
|
|
|
else
|
2009-05-20 12:42:01 +02:00
|
|
|
render :action => "new"
|
2009-03-25 19:54:04 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@page = Page.find(params[:id])
|
2009-05-20 12:42:01 +02:00
|
|
|
@page.attributes = params[:page].merge({:user => current_user})
|
2009-03-25 19:54:04 +01:00
|
|
|
|
2009-05-20 12:42:01 +02:00
|
|
|
if params[:preview]
|
|
|
|
@page.attributes = params[:page]
|
|
|
|
render :action => 'edit'
|
2009-05-15 13:54:42 +02:00
|
|
|
else
|
2009-05-20 12:42:01 +02:00
|
|
|
if @page.save
|
|
|
|
flash[:notice] = 'Seite wurde aktualisiert.'
|
|
|
|
redirect_to wiki_page_path(@page.permalink)
|
|
|
|
else
|
|
|
|
render :action => "edit"
|
|
|
|
end
|
2009-03-25 19:54:04 +01:00
|
|
|
end
|
2009-05-15 13:54:42 +02:00
|
|
|
|
|
|
|
rescue ActiveRecord::StaleObjectError
|
|
|
|
flash[:error] = "Achtung, die Seite wurde gerade von jemand anderes bearbeitet. Bitte versuche es erneut."
|
|
|
|
redirect_to wiki_page_path(@page.permalink)
|
2009-03-25 19:54:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@page = Page.find(params[:id])
|
|
|
|
@page.destroy
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to(pages_url) }
|
|
|
|
format.xml { head :ok }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def all
|
2009-06-11 23:51:26 +02:00
|
|
|
@pages = Page.all :order => 'created_at', :conditions => {:redirect => nil}
|
2009-03-25 19:54:04 +01:00
|
|
|
end
|
2009-05-15 17:32:45 +02:00
|
|
|
|
|
|
|
def version
|
|
|
|
@page = Page.find(params[:id])
|
2009-05-20 15:26:53 +02:00
|
|
|
@version = Page::Version.find_by_page_id_and_lock_version params[:id], params[:version]
|
2009-05-15 17:32:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def revert
|
|
|
|
@page = Page.find(params[:id])
|
2009-05-20 15:26:53 +02:00
|
|
|
@page.revert_to!(params[:version].to_i)
|
2009-05-15 17:32:45 +02:00
|
|
|
|
2009-05-20 15:26:53 +02:00
|
|
|
redirect_to wiki_page_path(@page.permalink)
|
2009-05-15 17:32:45 +02:00
|
|
|
end
|
2009-03-25 19:54:04 +01:00
|
|
|
end
|