Deal with clients that don't send an HTTP_ACCEPT header.

Cache S5, TeX and Print views.
Temporary hack: don't cache list and recently_revised pages.
This commit is contained in:
Jacques Distler 2007-03-08 21:57:21 -06:00
parent d74116dc67
commit a656772622
5 changed files with 10 additions and 9 deletions

View file

@ -149,7 +149,7 @@ class ApplicationController < ActionController::Base
@response.headers['Content-Type'] = 'text/xml; charset=UTF-8'
elsif %w(tex).include?(action_name)
@response.headers['Content-Type'] = 'text/plain; charset=UTF-8'
elsif @request.env['HTTP_USER_AGENT'] =~ /MathPlayer|Validator/ or Mime::Type.parse(@request.env["HTTP_ACCEPT"]).include?(Mime::XHTML)
elsif @request.env['HTTP_USER_AGENT'] =~ /MathPlayer|Validator/ or @request.env.include?('HTTP_ACCEPT') && Mime::Type.parse(@request.env["HTTP_ACCEPT"]).include?(Mime::XHTML)
@response.headers['Content-Type'] = 'application/xhtml+xml; charset=UTF-8'
else
@response.headers['Content-Type'] = 'text/html; charset=UTF-8'

View file

@ -2,7 +2,7 @@ module CacheSweepingHelper
def expire_cached_page(web, page_name)
expire_action :controller => 'wiki', :web => web.address,
:action => %w(show published), :id => page_name
:action => %w(show published s5 tex print), :id => page_name
expire_action :controller => 'wiki', :web => web.address,
:action => %w(show published), :id => page_name, :mode => 'diff'
end
@ -20,4 +20,4 @@ module CacheSweepingHelper
expire_fragment :controller => 'wiki', :web => web.address, :action => %w(rss_with_headlines rss_with_content)
end
end
end

View file

@ -8,7 +8,8 @@ require 'string_utils'
class WikiController < ApplicationController
before_filter :load_page
caches_action :show, :published, :authors, :recently_revised, :list
caches_action :show, :published, :authors, :tex, :s5, :print
# caches_action :show, :published, :authors, :tex. :s5, :print, :recently_revised, :list
cache_sweeper :revision_sweeper
layout 'default', :except => [:rss_feed, :rss_with_content, :rss_with_headlines, :tex, :pdf, :s5, :export_tex, :export_html]
@ -294,7 +295,7 @@ class WikiController < ApplicationController
def s5
if @web.markup == :markdownMML or @web.markup == :markdown
@s5_content = sanitize_html(Maruku.new(@page.content.delete("\r"),
@s5_content = sanitize_html(Maruku.new(@page.content.delete("\r\x01-\x08\x0B\x0C\x0E-\x1F"),
{:math_enabled => true, :math_numbered => ['\\[','\\begin{equation}'], :content_only => true,
:author => @page.author, :title => @page.plain_name}).to_s5)
end

View file

@ -85,7 +85,7 @@ class PageSet < Array
def wiki_words
self.inject([]) { |wiki_words, page|
wiki_words + page.wiki_words
wiki_words + page.wiki_words
}.flatten.uniq.sort
end

View file

@ -40,8 +40,8 @@ class WikiReference < ActiveRecord::Base
def self.pages_in_category(category)
query =
'SELECT name FROM pages JOIN wiki_references ON pages.id = wiki_references.page_id ' +
'WHERE wiki_references.referenced_name = ? ' +
"SELECT name FROM pages JOIN wiki_references ON pages.id = wiki_references.page_id " +
"WHERE wiki_references.referenced_name = ? " +
"AND wiki_references.link_type = '#{CATEGORY}'"
names = connection.select_all(sanitize_sql([query, category])).map { |row| row['name'] }
end
@ -51,7 +51,7 @@ class WikiReference < ActiveRecord::Base
"FROM wiki_references LEFT OUTER JOIN pages " +
"ON wiki_references.page_id = pages.id " +
"WHERE wiki_references.link_type = '#{CATEGORY}' " +
"AND pages.web_id = #{web.id}"
"AND pages.web_id = '#{web.id}'"
connection.select_all(query).map { |row| row['referenced_name'] }
end