2005-01-28 02:24:31 +01:00
|
|
|
require 'application'
|
|
|
|
|
|
|
|
class AdminController < ApplicationController
|
|
|
|
|
|
|
|
layout 'default'
|
2006-04-02 08:17:05 +02:00
|
|
|
cache_sweeper :web_sweeper
|
2005-01-28 02:24:31 +01:00
|
|
|
|
|
|
|
def create_system
|
2005-01-28 04:44:36 +01:00
|
|
|
if @wiki.setup?
|
2005-05-29 20:40:25 +02:00
|
|
|
flash[:error] =
|
|
|
|
"Wiki has already been created in '#{@wiki.storage_path}'. " +
|
|
|
|
"Shut down Instiki and delete this directory if you want to recreate it from scratch." +
|
|
|
|
"\n\n" +
|
|
|
|
"(WARNING: this will destroy content of your current wiki)."
|
2005-04-29 01:07:42 +02:00
|
|
|
redirect_home(@wiki.webs.keys.first)
|
2007-05-08 00:46:00 +02:00
|
|
|
elsif params['web_name']
|
2005-01-28 03:35:59 +01:00
|
|
|
# form submitted -> create a wiki
|
2007-05-08 00:46:00 +02:00
|
|
|
@wiki.setup(params['password'], params['web_name'], params['web_address'])
|
|
|
|
flash[:info] = "Your new wiki '#{params['web_name']}' is created!\n" +
|
2005-05-29 20:40:25 +02:00
|
|
|
"Please edit its home page and press Submit when finished."
|
2007-05-08 00:46:00 +02:00
|
|
|
redirect_to :web => params['web_address'], :controller => 'wiki', :action => 'new',
|
2005-01-28 03:57:25 +01:00
|
|
|
:id => 'HomePage'
|
2005-01-28 03:35:59 +01:00
|
|
|
else
|
|
|
|
# no form submitted -> go to template
|
|
|
|
end
|
2005-01-28 02:24:31 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_web
|
2007-05-08 00:46:00 +02:00
|
|
|
if params['address']
|
2007-10-07 19:59:20 +02:00
|
|
|
unless (request.post? || ENV["RAILS_ENV"] == "test")
|
|
|
|
headers['Allow'] = 'POST'
|
|
|
|
render(:status => 405, :text => 'You must use an HTTP POST')
|
|
|
|
return
|
|
|
|
end
|
2005-01-28 04:44:36 +01:00
|
|
|
# form submitted
|
2007-05-08 00:46:00 +02:00
|
|
|
if @wiki.authenticate(params['system_password'])
|
2005-03-26 01:09:41 +01:00
|
|
|
begin
|
2007-05-08 00:46:00 +02:00
|
|
|
@wiki.create_web(params['name'], params['address'])
|
|
|
|
flash[:info] = "New web '#{params['name']}' successfully created."
|
|
|
|
redirect_to :web => params['address'], :controller => 'wiki', :action => 'new',
|
2005-03-26 01:09:41 +01:00
|
|
|
:id => 'HomePage'
|
|
|
|
rescue Instiki::ValidationError => e
|
2005-05-09 05:41:00 +02:00
|
|
|
@error = e.message
|
2005-03-26 01:15:04 +01:00
|
|
|
# and re-render the form again
|
2005-03-26 01:09:41 +01:00
|
|
|
end
|
2005-01-28 04:44:36 +01:00
|
|
|
else
|
2005-02-15 23:41:58 +01:00
|
|
|
redirect_to :controller => 'wiki', :action => 'index'
|
2005-01-28 04:44:36 +01:00
|
|
|
end
|
|
|
|
else
|
|
|
|
# no form submitted -> render template
|
2005-01-28 02:24:31 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit_web
|
2007-05-08 00:46:00 +02:00
|
|
|
system_password = params['system_password']
|
2005-02-05 14:34:12 +01:00
|
|
|
if system_password
|
2007-10-07 19:59:20 +02:00
|
|
|
unless (request.post? || ENV["RAILS_ENV"] == "test")
|
|
|
|
headers['Allow'] = 'POST'
|
|
|
|
render(:status => 405, :text => 'You must use an HTTP POST')
|
|
|
|
return
|
|
|
|
end
|
2005-02-05 14:04:55 +01:00
|
|
|
# form submitted
|
2005-02-05 14:34:12 +01:00
|
|
|
if wiki.authenticate(system_password)
|
2005-02-10 23:05:30 +01:00
|
|
|
begin
|
|
|
|
wiki.edit_web(
|
2007-05-08 00:46:00 +02:00
|
|
|
@web.address, params['address'], params['name'],
|
|
|
|
params['markup'].intern,
|
|
|
|
params['color'], params['additional_style'],
|
|
|
|
params['safe_mode'] ? true : false,
|
|
|
|
params['password'].empty? ? nil : params['password'],
|
|
|
|
params['published'] ? true : false,
|
|
|
|
params['brackets_only'] ? true : false,
|
|
|
|
params['count_pages'] ? true : false,
|
|
|
|
params['allow_uploads'] ? true : false,
|
|
|
|
params['max_upload_size']
|
2005-02-10 23:05:30 +01:00
|
|
|
)
|
2007-05-08 00:46:00 +02:00
|
|
|
flash[:info] = "Web '#{params['address']}' was successfully updated"
|
|
|
|
redirect_home(params['address'])
|
2005-02-10 23:05:30 +01:00
|
|
|
rescue Instiki::ValidationError => e
|
2005-08-09 04:20:28 +02:00
|
|
|
logger.warn e.message
|
2005-05-09 05:41:00 +02:00
|
|
|
@error = e.message
|
2005-02-10 23:05:30 +01:00
|
|
|
# and re-render the same template again
|
|
|
|
end
|
2005-02-05 14:04:55 +01:00
|
|
|
else
|
2005-05-09 05:41:00 +02:00
|
|
|
@error = password_error(system_password)
|
2005-02-05 14:04:55 +01:00
|
|
|
# and re-render the same template again
|
|
|
|
end
|
2005-01-28 02:24:31 +01:00
|
|
|
else
|
2005-02-05 14:04:55 +01:00
|
|
|
# no form submitted - go to template
|
2005-01-28 02:24:31 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-02-13 15:58:03 +01:00
|
|
|
def remove_orphaned_pages
|
2007-10-07 19:59:20 +02:00
|
|
|
unless (request.post? || ENV["RAILS_ENV"] == "test")
|
|
|
|
headers['Allow'] = 'POST'
|
|
|
|
render(:status => 405, :text => 'You must use an HTTP POST')
|
|
|
|
return
|
|
|
|
end
|
2007-05-08 00:46:00 +02:00
|
|
|
if wiki.authenticate(params['system_password_orphaned'])
|
2005-02-13 15:58:03 +01:00
|
|
|
wiki.remove_orphaned_pages(@web_name)
|
|
|
|
flash[:info] = 'Orphaned pages removed'
|
2005-02-15 23:41:58 +01:00
|
|
|
redirect_to :controller => 'wiki', :web => @web_name, :action => 'list'
|
2005-02-13 15:58:03 +01:00
|
|
|
else
|
2007-05-08 00:46:00 +02:00
|
|
|
flash[:error] = password_error(params['system_password_orphaned'])
|
2005-05-09 05:52:43 +02:00
|
|
|
redirect_to :controller => 'admin', :web => @web_name, :action => 'edit_web'
|
2005-02-13 15:58:03 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-01-28 02:24:31 +01:00
|
|
|
end
|