diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 3fab01d0..23dd05c2 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -145,8 +145,8 @@ class ApplicationController < ActionController::Base end def set_content_type_header - if %w(rss_with_content rss_with_headlines).include?(action_name) - @response.headers['Content-Type'] = 'text/xml; charset=UTF-8' + if %w(atom_with_content atom_with_headlines).include?(action_name) + @response.headers['Content-Type'] = 'application/atom+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 @request.env.include?('HTTP_ACCEPT') && @@ -185,7 +185,7 @@ class ApplicationController < ActionController::Base end 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 def authorized? diff --git a/app/controllers/cache_sweeping_helper.rb b/app/controllers/cache_sweeping_helper.rb index bcb15649..4faacefd 100644 --- a/app/controllers/cache_sweeping_helper.rb +++ b/app/controllers/cache_sweeping_helper.rb @@ -16,7 +16,9 @@ module CacheSweepingHelper 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) end diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 17d20044..81e711d0 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -8,10 +8,10 @@ require 'string_utils' class WikiController < ApplicationController 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 - 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 @@ -132,17 +132,17 @@ class WikiController < ApplicationController end end - def rss_with_content - if rss_with_content_allowed? - render_rss(hide_description = false, *parse_rss_params) + def atom_with_content + if rss_with_content_allowed? + render_atom(hide_description = false) 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' end end - def rss_with_headlines - render_rss(hide_description = true, *parse_rss_params) + def atom_with_headlines + render_atom(hide_description = true) end def search @@ -392,18 +392,6 @@ class WikiController < ApplicationController @set_name = 'the web' 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 ip = @request.remote_ip @@ -411,20 +399,12 @@ class WikiController < ApplicationController ip end - def render_rss(hide_description = false, limit = 15, start_date = nil, end_date = nil) - if limit && !start_date && !end_date - @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 - + def render_atom(hide_description = false, limit = 15) + @pages_by_revision = @web.select.by_revision.first(limit) @hide_description = hide_description @link_action = @web.password ? 'published' : 'show' - - render :action => 'rss_feed' - end + render :action => 'atom' + end def render_tex_web @web.select.by_name.inject({}) do |tex_web, page| diff --git a/app/views/layouts/default.rhtml b/app/views/layouts/default.rhtml index 2c619055..d4dd27be 100644 --- a/app/views/layouts/default.rhtml +++ b/app/views/layouts/default.rhtml @@ -32,8 +32,8 @@ <%= javascript_include_tag :defaults %> <% if @web %> - <%= auto_discovery_link_tag(:rss, :controller => 'wiki', :web => @web.address, :action => 'rss_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_headlines') %> + <%= auto_discovery_link_tag(:atom, :controller => 'wiki', :web => @web.address, :action => 'atom_with_content') %> <% end %> diff --git a/app/views/wiki/atom.rxml b/app/views/wiki/atom.rxml new file mode 100644 index 00000000..e356d9ae --- /dev/null +++ b/app/views/wiki/atom.rxml @@ -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 diff --git a/app/views/wiki/feeds.rhtml b/app/views/wiki/feeds.rhtml index 389d6983..e84dffb0 100644 --- a/app/views/wiki/feeds.rhtml +++ b/app/views/wiki/feeds.rhtml @@ -1,14 +1,14 @@ <% @title = "Feeds" %> -

You can subscribe to this wiki by RSS and get either just the headlines of the pages that change or the entire page.

+

You can subscribe to this wiki's Atom feed and get either just the headlines of the pages that change or the entire page.