2005-01-15 21:26:54 +01:00
|
|
|
require 'url_rewriting_hack'
|
|
|
|
|
|
|
|
# The filters added to this controller will be run for all controllers in the application.
|
|
|
|
# Likewise will all the methods added be available for all controllers.
|
|
|
|
class ApplicationController < ActionController::Base
|
|
|
|
|
|
|
|
# implements Instiki's legacy URLs
|
|
|
|
require 'url_rewriting_hack'
|
|
|
|
|
2005-01-21 20:41:46 +01:00
|
|
|
before_filter :set_utf8_http_header
|
2005-01-18 00:17:28 +01:00
|
|
|
after_filter :remember_location
|
|
|
|
|
2005-01-15 21:26:54 +01:00
|
|
|
# For injecting a different wiki model implementation. Intended for use in tests
|
|
|
|
def self.wiki=(the_wiki)
|
|
|
|
# a global variable is used here because Rails reloads controller and model classes in the
|
|
|
|
# development environment; therefore, storing it as a class variable does not work
|
|
|
|
# class variable is, anyway, not much different from a global variable
|
|
|
|
$instiki_wiki_service = the_wiki
|
|
|
|
logger.debug("Wiki service: #{the_wiki.to_s}")
|
|
|
|
end
|
2005-01-18 00:17:28 +01:00
|
|
|
|
2005-01-15 21:26:54 +01:00
|
|
|
def self.wiki
|
|
|
|
$instiki_wiki_service
|
|
|
|
end
|
2005-01-18 00:17:28 +01:00
|
|
|
|
|
|
|
protected
|
2005-01-15 21:26:54 +01:00
|
|
|
|
|
|
|
def wiki
|
|
|
|
$instiki_wiki_service
|
|
|
|
end
|
2005-01-18 00:17:28 +01:00
|
|
|
|
2005-01-18 01:36:43 +01:00
|
|
|
@@REMEMBER_NOT = ['locked', 'save']
|
2005-01-15 21:26:54 +01:00
|
|
|
|
2005-01-18 00:17:28 +01:00
|
|
|
def remember_location
|
|
|
|
if @response.headers['Status'] == '200 OK'
|
2005-01-18 01:36:43 +01:00
|
|
|
unless @@REMEMBER_NOT.include? action_name or @request.method != :get
|
|
|
|
@session[:return_to] = url_for
|
|
|
|
logger.debug("Session ##{session.object_id}: remembered URL '#{@session[:return_to]}'")
|
|
|
|
end
|
2005-01-18 00:17:28 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def return_to_last_remembered
|
|
|
|
# Forget the redirect location
|
|
|
|
redirect_target, @session[:return_to] = @session[:return_to], nil
|
|
|
|
# then try to redirect to it
|
|
|
|
if redirect_target.nil?
|
2005-01-18 01:36:43 +01:00
|
|
|
logger.debug("Session ##{session.object_id}: no remembered redirect location, trying /")
|
2005-01-18 00:17:28 +01:00
|
|
|
redirect_to_url '/'
|
|
|
|
else
|
2005-01-18 01:36:43 +01:00
|
|
|
logger.debug("Session ##{session.object_id}: " +
|
|
|
|
"redirect to the last remembered URL #{redirect_target}")
|
2005-01-18 00:17:28 +01:00
|
|
|
redirect_to_url(redirect_target)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-01-21 20:41:46 +01:00
|
|
|
def set_utf8_http_header
|
|
|
|
@response.headers['Content-Type'] = 'text/html; charset=UTF-8'
|
|
|
|
end
|
|
|
|
|
2005-01-15 21:26:54 +01:00
|
|
|
end
|