Skip to content

Commit 98ba84b

Browse files
committed
Merge branch 'bzr/golem' of /Users/distler/Sites/code/instiki
2 parents f6f9ef6 + b300022 commit 98ba84b

File tree

894 files changed

+71805
-28336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

894 files changed

+71805
-28336
lines changed

app/controllers/application.rb app/controllers/application_controller.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,15 @@ def redirect_to_page(page_name = @page_name, web = @web_name)
107107

108108
def remember_location
109109
if request.method == :get and
110-
response.headers['Status'] == '200 OK' and not \
110+
@status == '200' and not \
111111
%w(locked save back file pic import).include?(action_name)
112112
session[:return_to] = request.request_uri
113113
logger.debug "Session ##{session.object_id}: remembered URL '#{session[:return_to]}'"
114114
end
115115
end
116116

117117
def rescue_action_in_public(exception)
118-
if exception.instance_of?(CGI::Session::CookieStore::TamperedWithCookie)
118+
if exception.instance_of?(ActiveController::Session::CookieStore::TamperedWithCookie)
119119
render :text => 'Stale session. Please reload the page.', :status =>500, :layout => 'error'
120120
else
121121
render :status => 500, :text => <<-EOL
@@ -241,7 +241,7 @@ module Instiki
241241
module VERSION #:nodoc:
242242
MAJOR = 0
243243
MINOR = 16
244-
TINY = 2
244+
TINY = 3
245245
SUFFIX = '(MML+)'
246246
PRERELEASE = false
247247
if PRERELEASE

app/views/layouts/error.html.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html xmlns="http://www.w3.org/1999/xhtml">
33
<head>
44
<title>
5-
<%= h headers['Status'] %>
5+
<%= h("#{@status} #{@status_message}") %>
66
</title>
77

88
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
@@ -27,7 +27,7 @@
2727

2828
<div id="Error-Container">
2929
<h1>
30-
<%= h headers['Status'] %>
30+
<%= h("#{@status} #{@status_message}") %>
3131
</h1>
3232

3333
<div id="Error-Content">

config/environment.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
####
44

55
# Make sure we are using the latest rexml
6-
rexml_versions = ['', 'vendor/plugins/rexml/lib/'].collect { |v|
6+
rexml_versions = ['', File.dirname(__FILE__) + '/../vendor/plugins/rexml/lib/'].collect { |v|
77
`ruby -r #{v + 'rexml/rexml'} -e 'p REXML::VERSION'`.split('.').collect {|n| n.to_i} }
8-
$:.unshift('vendor/plugins/rexml/lib') if (rexml_versions[0] <=> rexml_versions[1]) == -1
8+
$:.unshift(File.dirname(__FILE__) + '/../vendor/plugins/rexml/lib') if (rexml_versions[0] <=> rexml_versions[1]) == -1
99

10+
$:.unshift(File.dirname(__FILE__) + '/../vendor/plugins/rack/lib')
1011
require File.join(File.dirname(__FILE__), 'boot')
1112

1213
require 'active_support/secure_random'

instiki

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env ruby
22

3+
$:.unshift(File.dirname(__FILE__) + '/vendor/plugins/rack/lib')
34
# Executable file for a gem
45
# must be same as ./instiki.rb
56

lib/sanitizer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Sanitizer
55
#
66
# Based heavily on Sam Ruby's code in the Universal FeedParser.
77

8-
require 'html/tokenizer'
8+
require 'action_controller/vendor/html-scanner/html/tokenizer'
99
require 'node'
1010
require 'stringsupport'
1111

lib/url_generator.rb

+11-3
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,22 @@ def page_link(mode, name, text, web_address, known_page)
8585
end
8686
when :publish
8787
if known_page
88-
web = Web.find_by_address(web_address)
89-
action = web.published? ? 'published' : 'show'
90-
href = @controller.url_for :controller => 'wiki', :web => web_address, :action => action,
88+
href = @controller.url_for :controller => 'wiki', :web => web_address, :action => 'published',
9189
:id => name
9290
%{<a class="existingWikiWord" href="#{href}">#{text}</a>}
9391
else
9492
%{<span class="newWikiWord">#{text}</span>}
9593
end
94+
when :show
95+
if known_page
96+
href = @controller.url_for :controller => 'wiki', :web => web_address, :action => 'show',
97+
:id => name
98+
%{<a class="existingWikiWord" href="#{href}">#{text}</a>}
99+
else
100+
href = @controller.url_for :controller => 'wiki', :web => web_address, :action => 'new',
101+
:id => name
102+
%{<span class="newWikiWord">#{text}<a href="#{href}">?</a></span>}
103+
end
96104
else
97105
if known_page
98106
web = Web.find_by_address(web_address)

script/server

+89-46
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,108 @@
11
#!/usr/bin/env ruby
2+
require File.dirname(__FILE__) + '/../config/boot'
3+
# Don't do this. Instead, put it here, where we can customize it.
4+
#require 'commands/server'
25

3-
require 'webrick'
4-
require 'optparse'
6+
require 'active_support'
7+
require 'action_controller'
58

6-
OPTIONS = {
7-
:port => 2500,
8-
:ip => "0.0.0.0",
9-
:environment => "production",
10-
:server_root => File.expand_path(File.dirname(__FILE__) + "/../public/"),
11-
:server_type => WEBrick::SimpleServer,
12-
:mime_types => WEBrick::HTTPUtils::DefaultMimeTypes.merge({
13-
'avi' => 'video/x-msvideo',
14-
'gz' => 'application/x-gzip',
15-
'js' => 'application/x-javascript',
16-
'nb' => 'application/mathematica',
17-
'pdf' => 'application/pdf',
18-
'svg' => 'application/svg+xml',
19-
'tar' => 'application/x-tar',
20-
'tex' => 'application/x-tex',
21-
'xhtml' => 'application/xhtml+xml',
22-
'xml' => 'application/xml',
23-
'xslt' => 'application/xslt+xml'
24-
})
25-
}
9+
require 'fileutils'
10+
require 'optparse'
2611

27-
ARGV.options do |opts|
28-
script_name = File.basename($0)
29-
opts.banner = "Usage: ruby #{script_name} [options]"
12+
# TODO: Push Thin adapter upstream so we don't need worry about requiring it
13+
begin
14+
require_library_or_gem 'thin'
15+
rescue Exception
16+
# Thin not available
17+
end
3018

31-
opts.separator ""
19+
options = {
20+
:Port => 2500,
21+
:Host => "0.0.0.0",
22+
:environment => (ENV['RAILS_ENV'] || "production").dup,
23+
:config => RAILS_ROOT + "/config.ru",
24+
:detach => false,
25+
:debugger => false
26+
}
3227

28+
ARGV.clone.options do |opts|
3329
opts.on("-p", "--port=port", Integer,
34-
"Runs Instiki on the specified port.",
35-
"Default: 2500") { }
36-
# "Default: 2500") { |OPTIONS[:port]| }
30+
"Runs Instiki on the specified port.", "Default: 2500") { |v| options[:Port] = v }
3731
opts.on("-b", "--binding=ip", String,
38-
"Binds Instiki to the specified ip.",
39-
"Default: 0.0.0.0") { }
40-
# "Default: 0.0.0.0") { |OPTIONS[:ip]| }
32+
"Binds Instiki to the specified ip.", "Default: 0.0.0.0") { |v| options[:Host] = v }
33+
opts.on("-c", "--config=file", String,
34+
"Use custom rackup configuration file") { |v| options[:config] = v }
35+
opts.on("-d", "--daemon", "Make server run as a Daemon.") { options[:detach] = true }
36+
opts.on("-u", "--debugger", "Enable ruby-debugging for the server.") { options[:debugger] = true }
4137
opts.on("-e", "--environment=name", String,
4238
"Specifies the environment to run this server under (test/development/production).",
43-
"Default: development") { }
44-
# "Default: development") { |OPTIONS[:environment]| }
45-
opts.on("-d", "--daemon",
46-
"Make Instiki run as a Daemon (only works if fork is available -- meaning on *nix)."
47-
) { OPTIONS[:server_type] = WEBrick::Daemon }
39+
"Default: production") { |v| options[:environment] = v }
4840

4941
opts.separator ""
5042

51-
opts.on("-h", "--help",
52-
"Show this help message.") { puts opts; exit }
43+
opts.on("-h", "--help", "Show this help message.") { puts opts; exit }
5344

5445
opts.parse!
5546
end
5647

57-
ENV["RAILS_ENV"] = OPTIONS[:environment]
58-
require File.dirname(__FILE__) + "/../config/environment"
59-
require 'webrick_server'
48+
server = Rack::Handler.get(ARGV.first) rescue nil
49+
unless server
50+
begin
51+
server = Rack::Handler::Mongrel
52+
rescue LoadError => e
53+
server = Rack::Handler::WEBrick
54+
end
55+
end
6056

61-
OPTIONS['working_directory'] = File.expand_path(RAILS_ROOT)
57+
puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
58+
puts "=> Rails #{Rails.version} application starting on http://#{options[:Host]}:#{options[:Port]}"
6259

63-
puts "=> Instiki started on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
64-
puts "=> Ctrl-C to shutdown; call with --help for options" if OPTIONS[:server_type] == WEBrick::SimpleServer
65-
DispatchServlet.dispatch(OPTIONS)
60+
%w(cache pids sessions sockets).each do |dir_to_make|
61+
FileUtils.mkdir_p(File.join(RAILS_ROOT, 'tmp', dir_to_make))
62+
end
63+
64+
if options[:detach]
65+
Process.daemon
66+
pid = "#{RAILS_ROOT}/tmp/pids/server.pid"
67+
File.open(pid, 'w'){ |f| f.write(Process.pid) }
68+
at_exit { File.delete(pid) if File.exist?(pid) }
69+
end
70+
71+
ENV["RAILS_ENV"] = options[:environment]
72+
RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV)
73+
74+
if File.exist?(options[:config])
75+
config = options[:config]
76+
if config =~ /\.ru$/
77+
cfgfile = File.read(config)
78+
if cfgfile[/^#\\(.*)/]
79+
opts.parse!($1.split(/\s+/))
80+
end
81+
inner_app = eval("Rack::Builder.new {( " + cfgfile + "\n )}.to_app", nil, config)
82+
else
83+
require config
84+
inner_app = Object.const_get(File.basename(config, '.rb').capitalize)
85+
end
86+
else
87+
require RAILS_ROOT + "/config/environment"
88+
inner_app = ActionController::Dispatcher.new
89+
end
90+
91+
app = Rack::Builder.new {
92+
use Rails::Rack::LogTailer unless options[:detach]
93+
use Rails::Rack::Static
94+
use Rails::Rack::Debugger if options[:debugger]
95+
run inner_app
96+
}.to_app
97+
98+
puts "=> Call with -d to detach"
99+
100+
trap(:INT) { exit }
101+
102+
puts "=> Ctrl-C to shutdown server"
103+
104+
begin
105+
server.run(app, options.merge(:AccessLog => []))
106+
ensure
107+
puts 'Exiting'
108+
end

test/functional/admin_controller_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Raise errors beyond the default web-based presentation
77
class AdminController; def rescue_action(e) logger.error(e); raise e end; end
88

9-
class AdminControllerTest < Test::Unit::TestCase
9+
class AdminControllerTest < ActionController::TestCase
1010
fixtures :webs, :pages, :revisions, :system, :wiki_references
1111

1212
def setup

test/functional/application_test.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Need some concrete class to test the abstract class features
77
class WikiController; def rescue_action(e) logger.error(e); raise e end; end
88

9-
class ApplicationTest < Test::Unit::TestCase
9+
class ApplicationTest < ActionController::TestCase
1010
fixtures :webs, :pages, :revisions, :system
1111

1212
Mime::LOOKUP["text/html"] = HTML
@@ -20,43 +20,43 @@ def setup
2020

2121
def test_utf8_header
2222
get :show, :web => 'wiki1', :id => 'HomePage'
23-
assert_equal 'text/html; charset=utf-8', @response.headers['type']
23+
assert_equal 'text/html; charset=utf-8', @response.headers['Content-Type']
2424
end
2525

2626
def test_mathplayer_mime_type
2727
@request.user_agent = 'MathPlayer'
2828
get :show, :web => 'wiki1', :id => 'HomePage'
29-
assert_equal 'application/xhtml+xml', @response.headers['type']
29+
assert_equal 'application/xhtml+xml', @response.headers['Content-Type']
3030
end
3131

3232
def test_validator_mime_type
3333
@request.user_agent = 'Validator'
3434
get :show, :web => 'wiki1', :id => 'HomePage'
35-
assert_equal 'application/xhtml+xml; charset=utf-8', @response.headers['type']
35+
assert_equal 'application/xhtml+xml; charset=utf-8', @response.headers['Content-Type']
3636
end
3737

3838
def test_accept_header_xhtml
3939
@request.user_agent = 'Mozilla/5.0'
4040
@request.env.update({'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' })
4141
get :show, :web => 'wiki1', :id => 'HomePage'
42-
assert_equal 'application/xhtml+xml; charset=utf-8', @response.headers['type']
42+
assert_equal 'application/xhtml+xml; charset=utf-8', @response.headers['Content-Type']
4343
end
4444

4545
def test_accept_header_html
4646
@request.user_agent = 'Foo'
4747
@request.env.update({'HTTP_ACCEPT' => 'text/html,application/xml;q=0.9,*/*;q=0.8' })
4848
get :show, :web => 'wiki1', :id => 'HomePage'
49-
assert_equal 'text/html; charset=utf-8', @response.headers['type']
49+
assert_equal 'text/html; charset=utf-8', @response.headers['Content-Type']
5050
end
5151

5252
def test_tex_mime_type
5353
get :tex, :web => 'wiki1', :id => 'HomePage'
54-
assert_equal 'text/plain; charset=utf-8', @response.headers['type']
54+
assert_equal 'text/plain; charset=utf-8', @response.headers['Content-Type']
5555
end
5656

5757
def test_atom_mime_type
5858
get :atom_with_content, :web => 'wiki1'
59-
assert_equal 'application/atom+xml; charset=utf-8', @response.headers['type']
59+
assert_equal 'application/atom+xml; charset=utf-8', @response.headers['Content-Type']
6060
end
6161

6262
def test_connect_to_model_unknown_wiki

test/functional/file_controller_test.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# Raise errors beyond the default web-based presentation
99
class FileController; def rescue_action(e) logger.error(e); raise e end; end
1010

11-
class FileControllerTest < Test::Unit::TestCase
11+
class FileControllerTest < ActionController::TestCase
1212
fixtures :webs, :pages, :revisions, :system
1313

1414
def setup
@@ -41,7 +41,7 @@ def test_file_download_text_file
4141

4242
assert_response(:success, bypass_body_parsing = true)
4343
assert_equal "Contents of the file", r.body
44-
assert_equal 'text/plain', r.headers['type']
44+
assert_equal 'text/plain', r.headers['Content-Type']
4545
assert_equal 'inline; filename="foo.txt"', r.headers['Content-Disposition']
4646
end
4747

@@ -53,7 +53,7 @@ def test_file_download_html_file
5353

5454
assert_response(:success, bypass_body_parsing = true)
5555
assert_equal "Contents of the file", r.body
56-
assert_equal 'application/octet-stream', r.headers['type']
56+
assert_equal 'application/octet-stream', r.headers['Content-Type']
5757
assert_equal 'attachment; filename="foo.html"', r.headers['Content-Disposition']
5858
end
5959

@@ -65,7 +65,7 @@ def test_file_download_pdf_file
6565

6666
assert_response(:success, bypass_body_parsing = true)
6767
assert_equal "aaa\nbbb\n", r.body
68-
assert_equal 'application/pdf', r.headers['type']
68+
assert_equal 'application/pdf', r.headers['Content-Type']
6969
end
7070

7171
def test_pic_download_gif
@@ -75,7 +75,7 @@ def test_pic_download_gif
7575
r = get :file, :web => 'wiki1', :id => 'rails.gif'
7676

7777
assert_response(:success, bypass_body_parsing = true)
78-
assert_equal 'image/gif', r.headers['type']
78+
assert_equal 'image/gif', r.headers['Content-Type']
7979
assert_equal pic.size, r.body.size
8080
assert_equal pic, r.body
8181
assert_equal 'inline; filename="rails.gif"', r.headers['Content-Disposition']

test/functional/routes_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
require 'action_controller/routing'
66

7-
class RoutesTest < Test::Unit::TestCase
7+
class RoutesTest < ActionController::TestCase
88

99
def test_parse_uri
1010
assert_routing('', :controller => 'wiki', :action => 'index')

0 commit comments

Comments
 (0)