From 0d16fd57d46a4aaa1c170d79772e549bfadf288a Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Sun, 7 Jun 2009 02:39:45 +0000 Subject: [PATCH] Add RSS feed for global recent changes & changes within a bbox. Solves #1737 This has so much copy/paste code it hurts, the new list*_rss methods are just copies of the old list* methods, but see #1927 for that. --- app/controllers/changeset_controller.rb | 45 +++++++++++++++- app/views/changeset/list.rhtml | 6 +++ app/views/changeset/list_bbox.rhtml | 5 ++ app/views/changeset/list_bbox_rss.rxml | 51 +++++++++++++++++++ .../changeset/{rss.rxml => list_rss.rxml} | 12 +++-- app/views/changeset/list_user.rhtml | 4 +- config/locales/en.yml | 6 +++ config/routes.rb | 4 +- 8 files changed, 123 insertions(+), 10 deletions(-) create mode 100644 app/views/changeset/list_bbox_rss.rxml rename app/views/changeset/{rss.rxml => list_rss.rxml} (75%) diff --git a/app/controllers/changeset_controller.rb b/app/controllers/changeset_controller.rb index e8212d510..959957463 100644 --- a/app/controllers/changeset_controller.rb +++ b/app/controllers/changeset_controller.rb @@ -1,7 +1,7 @@ # The ChangesetController is the RESTful interface to Changeset objects class ChangesetController < ApplicationController - layout 'site', :except => :rss + layout 'site', :except => [ :list_rss, :list_user_rss, :list_bbox_rss ] require 'xml/libxml' before_filter :authorize_web, :only => [:list, :list_user, :list_bbox] @@ -273,6 +273,18 @@ class ChangesetController < ApplicationController :limit => 20) end + + ## + # list edits (open changesets) in reverse chronological order + def list_rss + conditions = conditions_nonempty + + @edits = Changeset.find(:all, + :order => "changesets.created_at DESC", + :conditions => conditions, + :limit => 20) + + end ## # list edits (changesets) belonging to a user @@ -301,7 +313,7 @@ class ChangesetController < ApplicationController ## # list edits (changesets) belonging to a user - def rss + def list_user_rss user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true}) if user @@ -352,6 +364,35 @@ class ChangesetController < ApplicationController @bbox = sanitise_boundaries(bbox.split(/,/)) unless bbox==nil end + + ## + # list changesets in a bbox + def list_bbox_rss + # support 'bbox' param or alternatively 'minlon', 'minlat' etc + if params['bbox'] + bbox = params['bbox'] + elsif params['minlon'] and params['minlat'] and params['maxlon'] and params['maxlat'] + bbox = h(params['minlon']) + ',' + h(params['minlat']) + ',' + h(params['maxlon']) + ',' + h(params['maxlat']) + else + #TODO: fix bugs in location determination for history tab (and other tabs) then uncomment this redirect + #redirect_to :action => 'list' + + # For now just render immediately, and skip the db + render + return + end + + conditions = conditions_bbox(bbox); + conditions = cond_merge conditions, conditions_nonempty + + @edit_pages, @edits = paginate(:changesets, + :include => [:user, :changeset_tags], + :conditions => conditions, + :order => "changesets.created_at DESC", + :per_page => 20) + + @bbox = sanitise_boundaries(bbox.split(/,/)) unless bbox==nil + end private #------------------------------------------------------------ diff --git a/app/views/changeset/list.rhtml b/app/views/changeset/list.rhtml index cfe4afd3f..affe10cc6 100644 --- a/app/views/changeset/list.rhtml +++ b/app/views/changeset/list.rhtml @@ -5,3 +5,9 @@

<%= t'changeset.list.for_more_changesets' %>


+ +<%= rss_link_to :action => 'list_rss' %> + +<% content_for :head do %> +<%= auto_discovery_link_tag :atom, :controller => 'changeset', :action => 'list_rss' %> +<% end %> diff --git a/app/views/changeset/list_bbox.rhtml b/app/views/changeset/list_bbox.rhtml index 87c61790c..354f77727 100644 --- a/app/views/changeset/list_bbox.rhtml +++ b/app/views/changeset/list_bbox.rhtml @@ -39,3 +39,8 @@ end %>
+<%= rss_link_to :action => 'list_bbox_rss', :bbox => @bbox.join(",") %> + +<% content_for :head do %> +<%= auto_discovery_link_tag :atom, :controller => 'changeset', :action => 'list_bbox_rss', :bbox => @bbox.join(",") %> +<% end %> diff --git a/app/views/changeset/list_bbox_rss.rxml b/app/views/changeset/list_bbox_rss.rxml new file mode 100644 index 000000000..73e705fe1 --- /dev/null +++ b/app/views/changeset/list_bbox_rss.rxml @@ -0,0 +1,51 @@ +xml.instruct! + +xml.rss("version" => "2.0", + "xmlns:geo" => "http://www.w3.org/2003/01/geo/wgs84_pos#", + "xmlns:georss" => "http://www.georss.org/georss") do + xml.channel do + xml.title t('changeset.list_bbox_rss.title', :bbox => @bbox.join(",")) + xml.description t('changeset.list_bbox_rss.description', :bbox => @bbox.join(",")) + xml.link url_for(:controller => "history", :bbox => @bbox.join(","), :only_path => false) + xml.image do + xml.url "http://www.openstreetmap.org/images/mag_map-rss2.0.png" + xml.title "OpenStreetMap" + xml.width "100" + xml.height "100" + xml.link url_for(:controller => "history", :bbox => @bbox.join(","), :only_path => false) + end + + + for changeset in @edits + xml.item do + xml.title t('browse.changeset.title') + " " + h(changeset.id) + xml.link url_for(:controller => 'browse', :action => "changeset", :id => changeset.id, :only_path => false) + xml.guid url_for(:controller => 'browse', :action => "changeset", :id => changeset.id, :only_path => false) + if changeset.user.data_public? + xml.author changeset.user.display_name + end + if changeset.tags['comment'] + xml.description changeset.tags['comment'] + end + xml.pubDate changeset.created_at.to_s(:rfc822) + if changeset.user.data_public? + xml.comments url_for(:controller => "message", :action => "new", :id => changeset.user.id, :only_path => false) + end + + unless changeset.min_lat.nil? + minlon = changeset.min_lon/GeoRecord::SCALE.to_f + minlat = changeset.min_lat/GeoRecord::SCALE.to_f + maxlon = changeset.max_lon/GeoRecord::SCALE.to_f + maxlat = changeset.max_lat/GeoRecord::SCALE.to_f + + # See http://georss.org/Encodings#Geometry + lower_corner = "#{minlat} #{minlon}" + upper_corner = "#{maxlat} #{maxlon}" + + xml.georss :box, lower_corner + " " + upper_corner + end + end + end + end +end + diff --git a/app/views/changeset/rss.rxml b/app/views/changeset/list_rss.rxml similarity index 75% rename from app/views/changeset/rss.rxml rename to app/views/changeset/list_rss.rxml index c62de3044..a22d834ea 100644 --- a/app/views/changeset/rss.rxml +++ b/app/views/changeset/list_rss.rxml @@ -4,15 +4,15 @@ xml.rss("version" => "2.0", "xmlns:geo" => "http://www.w3.org/2003/01/geo/wgs84_pos#", "xmlns:georss" => "http://www.georss.org/georss") do xml.channel do - xml.title t('changeset.list_user_rss.title', :user => @display_name) - xml.description t('changeset.list_user_rss.description', :user => @display_name) - xml.link url_for(:controller => "user", :action => "edits", :id => @display_name, :only_path => false) + xml.title t('changeset.list_rss.title') + xml.description t('changeset.list_rss.description') + xml.link url_for(:controller => "browse", :action => "changesets", :only_path => false) xml.image do xml.url "http://www.openstreetmap.org/images/mag_map-rss2.0.png" xml.title "OpenStreetMap" xml.width "100" xml.height "100" - xml.link url_for(:controller => "user", :action => "edits", :id => @display_name, :only_path => false) + xml.link url_for(:controller => "browse", :action => "changesets", :only_path => false) end @@ -28,7 +28,9 @@ xml.rss("version" => "2.0", xml.description changeset.tags['comment'] end xml.pubDate changeset.created_at.to_s(:rfc822) - xml.comments url_for(:controller => "message", :action => "new", :id => changeset.user.id, :only_path => false) + if changeset.user.data_public? + xml.comments url_for(:controller => "message", :action => "new", :id => changeset.user.id, :only_path => false) + end unless changeset.min_lat.nil? minlon = changeset.min_lon/GeoRecord::SCALE.to_f diff --git a/app/views/changeset/list_user.rhtml b/app/views/changeset/list_user.rhtml index 46f5ef39e..6f246f9d4 100644 --- a/app/views/changeset/list_user.rhtml +++ b/app/views/changeset/list_user.rhtml @@ -11,8 +11,8 @@

<%= t'changeset.list_user.for_all_changes', :recent_changes_link => link_to(t('changeset.list_user.recent_changes'), :controller => "browse", :action => "changesets") %>


-<%= rss_link_to :action => 'rss' %> +<%= rss_link_to :action => 'list_user_rss' %> <% content_for :head do %> -<%= auto_discovery_link_tag :atom, :action => 'rss' %> +<%= auto_discovery_link_tag :atom, :controller => 'changeset', :action => 'list_user_rss' %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 306036b52..a4b0f352c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -233,6 +233,12 @@ en: recent_changes: "Recent Changes" recently_edited_changesets: "Recently edited changesets:" for_more_changesets: "For more changesets, select a user and view their edits, or see the editing 'history' of a specific area." + list_rss: + title: "Recent changes" + description: "Recently edited changesets" + list_bbox_rss: + title: "Recent changesets within {{bbox}}" + description: "Recently edited changesets within the area {{bbox}}" list_user: edits_by_username: "Edits by {{username_link}}" no_visible_edits_by: "No visible edits by {{name}}." diff --git a/config/routes.rb b/config/routes.rb index 87d5841d4..aead14cf9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -83,12 +83,14 @@ ActionController::Routing::Routes.draw do |map| map.connect '/browse/relation/:id/history', :controller => 'browse', :action => 'relation_history', :id => /\d+/ map.connect '/browse/changeset/:id', :controller => 'browse', :action => 'changeset', :id => /\d+/ map.connect '/browse/changesets', :controller => 'changeset', :action => 'list' + map.connect '/browse/changesets/rss', :controller => 'changeset', :action => 'list_rss' # web site map.root :controller => 'site', :action => 'index' map.connect '/', :controller => 'site', :action => 'index' map.connect '/edit', :controller => 'site', :action => 'edit' map.connect '/history', :controller => 'changeset', :action => 'list_bbox' + map.connect '/history/rss', :controller => 'changeset', :action => 'list_bbox_rss' map.connect '/export', :controller => 'site', :action => 'export' map.connect '/login', :controller => 'user', :action => 'login' map.connect '/logout', :controller => 'user', :action => 'logout' @@ -143,7 +145,7 @@ ActionController::Routing::Routes.draw do |map| # user pages map.connect '/user/:display_name', :controller => 'user', :action => 'view' map.connect '/user/:display_name/edits', :controller => 'changeset', :action => 'list_user' - map.connect '/user/:display_name/edits/rss', :controller => 'changeset', :action => 'rss' + map.connect '/user/:display_name/edits/rss', :controller => 'changeset', :action => 'list_user_rss' map.connect '/user/:display_name/make_friend', :controller => 'user', :action => 'make_friend' map.connect '/user/:display_name/remove_friend', :controller => 'user', :action => 'remove_friend' map.connect '/user/:display_name/diary', :controller => 'diary_entry', :action => 'list' -- 2.43.2