Atom Feeds

Replaced Instiki's RSS 2.0 feeds with Atom 1.0 feeds.
This commit is contained in:
Jacques Distler 2007-04-13 17:04:03 -05:00
parent 81d71854c0
commit 3a57d3aade
6 changed files with 54 additions and 41 deletions

View file

@ -145,8 +145,8 @@ class ApplicationController < ActionController::Base
end end
def set_content_type_header def set_content_type_header
if %w(rss_with_content rss_with_headlines).include?(action_name) if %w(atom_with_content atom_with_headlines).include?(action_name)
@response.headers['Content-Type'] = 'text/xml; charset=UTF-8' @response.headers['Content-Type'] = 'application/atom+xml; charset=UTF-8'
elsif %w(tex).include?(action_name) elsif %w(tex).include?(action_name)
@response.headers['Content-Type'] = 'text/plain; charset=UTF-8' @response.headers['Content-Type'] = 'text/plain; charset=UTF-8'
elsif @request.env['HTTP_USER_AGENT'] =~ /MathPlayer|Validator/ or @request.env.include?('HTTP_ACCEPT') && elsif @request.env['HTTP_USER_AGENT'] =~ /MathPlayer|Validator/ or @request.env.include?('HTTP_ACCEPT') &&
@ -185,7 +185,7 @@ class ApplicationController < ActionController::Base
end end
def authorization_needed? def authorization_needed?
not %w( login authenticate published rss_with_content rss_with_headlines ).include?(action_name) not %w( login authenticate published atom_with_headlines atom_with_content).include?(action_name)
end end
def authorized? def authorized?

View file

@ -16,7 +16,9 @@ module CacheSweepingHelper
end end
end end
expire_action :controller => 'wiki', :web => web.address, :action => 'authors' %w(authors atom_with_content atom_with_headlines).each do |action|
expire_action :controller => 'wiki', :web => web.address, :action => action
end
expire_fragment :controller => 'wiki', :web => web.address, :action => %w(rss_with_headlines rss_with_content) expire_fragment :controller => 'wiki', :web => web.address, :action => %w(rss_with_headlines rss_with_content)
end end

View file

@ -8,10 +8,10 @@ require 'string_utils'
class WikiController < ApplicationController class WikiController < ApplicationController
before_filter :load_page before_filter :load_page
caches_action :show, :published, :authors, :tex, :s5, :print, :recently_revised, :list caches_action :show, :published, :authors, :tex, :s5, :print, :recently_revised, :list, :atom_with_content, :atom_with_headlines
cache_sweeper :revision_sweeper cache_sweeper :revision_sweeper
layout 'default', :except => [:rss_feed, :rss_with_content, :rss_with_headlines, :tex, :pdf, :s5, :export_tex, :export_html] layout 'default', :except => [:atom_with_content, :atom_with_headlines, :atom, :tex, :pdf, :s5, :export_tex, :export_html]
include Sanitize include Sanitize
@ -132,17 +132,17 @@ class WikiController < ApplicationController
end end
end end
def rss_with_content def atom_with_content
if rss_with_content_allowed? if rss_with_content_allowed?
render_rss(hide_description = false, *parse_rss_params) render_atom(hide_description = false)
else else
render_text 'RSS feed with content for this web is blocked for security reasons. ' + render_text 'Atom feed with content for this web is blocked for security reasons. ' +
'The web is password-protected and not published', '403 Forbidden' 'The web is password-protected and not published', '403 Forbidden'
end end
end end
def rss_with_headlines def atom_with_headlines
render_rss(hide_description = true, *parse_rss_params) render_atom(hide_description = true)
end end
def search def search
@ -393,37 +393,17 @@ class WikiController < ApplicationController
end end
end end
def parse_rss_params
if @params.include? 'limit'
limit = @params['limit'].to_i rescue nil
limit = nil if limit == 0
else
limit = 15
end
start_date = Time.local(*ParseDate::parsedate(@params['start'])) rescue nil
end_date = Time.local(*ParseDate::parsedate(@params['end'])) rescue nil
[ limit, start_date, end_date ]
end
def remote_ip def remote_ip
ip = @request.remote_ip ip = @request.remote_ip
logger.info(ip) logger.info(ip)
ip ip
end end
def render_rss(hide_description = false, limit = 15, start_date = nil, end_date = nil) def render_atom(hide_description = false, limit = 15)
if limit && !start_date && !end_date @pages_by_revision = @web.select.by_revision.first(limit)
@pages_by_revision = @web.select.by_revision.first(limit)
else
@pages_by_revision = @web.select.by_revision
@pages_by_revision.reject! { |page| page.revised_at < start_date } if start_date
@pages_by_revision.reject! { |page| page.revised_at > end_date } if end_date
end
@hide_description = hide_description @hide_description = hide_description
@link_action = @web.password ? 'published' : 'show' @link_action = @web.password ? 'published' : 'show'
render :action => 'atom'
render :action => 'rss_feed'
end end
def render_tex_web def render_tex_web

View file

@ -32,8 +32,8 @@
</style> </style>
<%= javascript_include_tag :defaults %> <%= javascript_include_tag :defaults %>
<% if @web %> <% if @web %>
<%= auto_discovery_link_tag(:rss, :controller => 'wiki', :web => @web.address, :action => 'rss_with_headlines') %> <%= auto_discovery_link_tag(:atom, :controller => 'wiki', :web => @web.address, :action => 'atom_with_headlines') %>
<%= auto_discovery_link_tag(:rss, :controller => 'wiki', :web => @web.address, :action => 'rss_with_content') %> <%= auto_discovery_link_tag(:atom, :controller => 'wiki', :web => @web.address, :action => 'atom_with_content') %>
<% end %> <% end %>
</head> </head>

31
app/views/wiki/atom.rxml Normal file
View file

@ -0,0 +1,31 @@
xml.feed('xmlns' => "http://www.w3.org/2005/Atom", "xml:lang" => 'en') do
xml.title(@web.name)
xml.link( 'rel' => 'alternate', 'type' => "application/xhtml+xml", 'href' => url_for(:only_path => false, :web => @web_name, :action => @link_action, :id => 'HomePage') )
xml.link( 'rel' => 'self', 'href' => url_for(:only_path => false, :web => @web_name, :action => @hide_description? :atom_with_headlines : :atom_with_content ) )
xml.updated(@web.updated_at.getgm.strftime("%Y-%m-%dT%H:%M:%SZ") )
xml.id('tag:' + url_for(:only_path => false, :web => @web_name).split('/')[2].split(':')[0] + ',' + @web.created_at.getgm.strftime("%Y-%m-%d") + ':' + CGI.escape(@web.name) )
xml.subtitle('An Instiki Wiki')
xml.generator('Instiki', 'uri' => "http://golem.ph.utexas.edu/instiki/show/HomePage", 'version' => Instiki::VERSION::STRING)
for page in @pages_by_revision
xml.entry do
xml.title(page.plain_name, 'type' => "html")
xml.link('rel' => 'alternate', 'type' => 'application/xhtml+xml', 'href' => url_for(:only_path => false, :web => @web_name, :action => @link_action, :id => page.name) )
xml.updated(page.updated_at.getgm.strftime("%Y-%m-%dT%H:%M:%SZ") )
xml.published(page.created_at.getgm.strftime("%Y-%m-%dT%H:%M:%SZ") )
xml.id('tag:' +url_for(:only_path => false, :web => @web_name).split('/')[2].split(':')[0] + ',' + page.created_at.getgm.strftime("%Y-%m-%d") + ":" + @web.name + ',' + CGI.escape(page.name))
xml.author do
xml.name(page.author)
end
if @hide_description
xml.summary('Content suppressed.', 'type' => 'text')
else
xml.content('type' => 'xhtml', 'xml:base' => url_for(:only_path => false, :web => @web_name, :action => @link_action, :id => page.name) ) do
xml.div('xmlns' => 'http://www.w3.org/1999/xhtml' ) do
|x| x << rendered_content(page)
end
end
end
end
end
end

View file

@ -1,14 +1,14 @@
<% @title = "Feeds" %> <% @title = "Feeds" %>
<p>You can subscribe to this wiki by RSS and get either just the headlines of the pages that change or the entire page.</p> <p>You can subscribe to this wiki's Atom feed and get either just the headlines of the pages that change or the entire page.</p>
<ul id="feedsList"> <ul id="feedsList">
<li> <li>
<% if @rss_with_content_allowed %> <% if @rss_with_content_allowed %>
<%= link_to 'Full content (RSS 2.0)', :web => @web.address, :action => :rss_with_content %> <%= link_to 'Full content (Atom 1.0)', :web => @web.address, :action => :atom_with_content %>
<% end %> <% end %>
</li> </li>
<li> <li>
<%= link_to 'Headlines (RSS 2.0)', :web => @web.address, :action => :rss_with_headlines %> <%= link_to 'Headlines (Atom 1.0)', :web => @web.address, :action => :atom_with_headlines %>
</li> </li>
</ul> </ul>