Merge branch 'bzr/golem' of /Users/distler/Sites/code/instiki

This commit is contained in:
Jacques Distler 2010-03-02 16:07:08 -06:00
commit 2df08e21d1
4 changed files with 60 additions and 18 deletions

View file

@ -14,29 +14,62 @@ class Itex
private private
# plugable XML parser; falls back to REXML
begin
require 'nokogiri'
def self.xmlparse(text)
Nokogiri::XML(text) { |config| config.options = Nokogiri::XML::ParseOptions::STRICT }
end
rescue LoadError
require 'rexml/document'
def self.xmlparse(text)
REXML::Document.new(text)
end
end
#error message to return
def self.error(str)
"<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><merror><mtext>" +
str + "</mtext></merror></math>"
end
# itex2MML parser
begin
require 'itextomml'
def self.parse_itex(tex, filter)
Itex2MML::Parser.new.send(filter, tex).to_utf8
end
rescue LoadError
def self.parse_itex(tex, filter)
error("Please install the itex2MML Ruby bindings.")
end
end
# the actual response
def self.response(env) def self.response(env)
@params = Rack::Request.new(env).params params = Rack::Request.new(env).params
tex = (@params['tex'] || '').purify tex = (params['tex'] || '').purify.strip
case @params['display'] case params['display']
when 'block' when 'block'
filter = :block_filter filter = :block_filter
else else
filter = :inline_filter filter = :inline_filter
end end
return "<math xmlns='http://www.w3.org/1998/Math/MathML' display='" + return "<math xmlns='http://www.w3.org/1998/Math/MathML' display='" +
filter.to_s[/(.*?)_filter/] + "'/>" if tex.strip == '' filter.to_s[/(.*?)_filter/] + "'/>" if tex == ''
estart = "<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><merror><mtext>"
eend = "</mtext></merror></math>"
begin begin
require 'itextomml' doc = parse_itex(tex, filter)
@itex2mml_parser ||= Itex2MML::Parser.new # make sure the result is well-formed, before sending it off
@itex2mml_parser.send(filter, tex).to_utf8 begin
rescue LoadError xmlparse(doc)
estart + "Please install the itex2MML Ruby bindings." + eend
rescue Itex2MML::Error => e
estart + e.to_s + eend
rescue rescue
estart + "Unknown Error" + eend return error("Ill-formed XML.")
end
return doc
rescue Itex2MML::Error => e
error(e.to_s)
rescue
error("Unknown Error")
end end
end end
end end

View file

@ -31,7 +31,11 @@
</h1> </h1>
<div id="Error-Content"> <div id="Error-Content">
<%= h @content_for_layout %> <%= if :raw
@content_for_layout
else
h @content_for_layout
end %>
</div> <!-- Error-Content --> </div> <!-- Error-Content -->

View file

@ -765,6 +765,11 @@ class WikiControllerTest < ActionController::TestCase
'author' => 'AuthorOfNewPage' 'author' => 'AuthorOfNewPage'
assert_equal 403, r.response_code assert_equal 403, r.response_code
resp = %{<p>Access denied. Your IP address, 127.0.0.2, was found on one or more DNSBL blocking } +
%{list(s).</p>\n<p>See <a href='http://www.spamcop.net/w3m?action=checkblock&amp;ip=127.0.0.2} +
%{'>here</a> for more information.</p>\n<p>See <a href='http://www.spamhaus.org/query/bl?ip=1} +
%{27.0.0.2'>here</a> for more information.</p>\n}
assert_match Regexp.new(Regexp.escape(resp)), r.body
end end
def test_dnsbl_filter_allow_action def test_dnsbl_filter_allow_action

View file

@ -45,7 +45,7 @@ module DNSBL_Check
addr = Resolv.getaddress("#{host}") rescue '' addr = Resolv.getaddress("#{host}") rescue ''
if addr[0,7]=="127.0.0" if addr[0,7]=="127.0.0"
logger.info("#{request.remote_addr} found using DNSBL #{host}") logger.info("#{request.remote_addr} found using DNSBL #{host}")
ban_help << " See <a href='#{DNSBLS[host]}#{request.remote_addr}'>here</a> for more information." ban_help << "\n<p>See <a href='#{DNSBLS[dnsbl]}#{request.remote_addr}'>here</a> for more information.</p>"
passed = false passed = false
end end
end end
@ -58,8 +58,8 @@ module DNSBL_Check
$dnsbl_passed.push request.remote_addr $dnsbl_passed.push request.remote_addr
logger.warn("#{request.remote_addr} added to DNSBL passed cache") logger.warn("#{request.remote_addr} added to DNSBL passed cache")
else else
render( :text => "Access denied. Your IP address, #{request.remote_addr}, was found on one or more DNSBL" + render( :text => "<p>Access denied. Your IP address, #{request.remote_addr}, was found on one or more DNSBL" +
" blocking list(s).#{ban_help}", :status => 403, :layout => 'error') " blocking list(s).</p>#{ban_help}", :status => 403, :layout => 'error', :locals => {:raw => true})
return false return false
end end
end end