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

@ -13,30 +13,63 @@ class Itex
end
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)
@params = Rack::Request.new(env).params
tex = (@params['tex'] || '').purify
case @params['display']
params = Rack::Request.new(env).params
tex = (params['tex'] || '').purify.strip
case params['display']
when 'block'
filter = :block_filter
else
filter = :inline_filter
end
return "<math xmlns='http://www.w3.org/1998/Math/MathML' display='" +
filter.to_s[/(.*?)_filter/] + "'/>" if tex.strip == ''
estart = "<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><merror><mtext>"
eend = "</mtext></merror></math>"
filter.to_s[/(.*?)_filter/] + "'/>" if tex == ''
begin
require 'itextomml'
@itex2mml_parser ||= Itex2MML::Parser.new
@itex2mml_parser.send(filter, tex).to_utf8
rescue LoadError
estart + "Please install the itex2MML Ruby bindings." + eend
doc = parse_itex(tex, filter)
# make sure the result is well-formed, before sending it off
begin
xmlparse(doc)
rescue
return error("Ill-formed XML.")
end
return doc
rescue Itex2MML::Error => e
estart + e.to_s + eend
error(e.to_s)
rescue
estart + "Unknown Error" + eend
error("Unknown Error")
end
end
end

View file

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

View file

@ -765,6 +765,11 @@ class WikiControllerTest < ActionController::TestCase
'author' => 'AuthorOfNewPage'
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
def test_dnsbl_filter_allow_action

View file

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