From: Ævar Arnfjörð Bjarmason Date: Sun, 7 Jun 2009 01:32:19 +0000 (+0000) Subject: Implement /user/$user/edits/rss, partially solves #1737 X-Git-Tag: live~7659 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/011237c2c5c82a638e3bbd5b78196baea576a5a9?ds=sidebyside;hp=991c940138147756149ff297407d82c2cf7927af Implement /user/$user/edits/rss, partially solves #1737 --- diff --git a/app/controllers/changeset_controller.rb b/app/controllers/changeset_controller.rb index ca42751d3..e8212d510 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' + layout 'site', :except => :rss require 'xml/libxml' before_filter :authorize_web, :only => [:list, :list_user, :list_bbox] @@ -298,6 +298,31 @@ class ChangesetController < ApplicationController render :template => 'user/no_such_user', :status => :not_found end end + + ## + # list edits (changesets) belonging to a user + def rss + user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true}) + + if user + @display_name = user.display_name + if not user.data_public? and @user != user + @edits = nil + render + else + conditions = cond_merge conditions, ['user_id = ?', user.id] + 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) + end + else + @not_found_user = params[:display_name] + render :template => 'user/no_such_user', :status => :not_found + end + end ## # list changesets in a bbox diff --git a/app/views/changeset/list_user.rhtml b/app/views/changeset/list_user.rhtml index 7240e6027..46f5ef39e 100644 --- a/app/views/changeset/list_user.rhtml +++ b/app/views/changeset/list_user.rhtml @@ -11,3 +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' %> + +<% content_for :head do %> +<%= auto_discovery_link_tag :atom, :action => 'rss' %> +<% end %> diff --git a/app/views/changeset/rss.rxml b/app/views/changeset/rss.rxml new file mode 100644 index 000000000..c62de3044 --- /dev/null +++ b/app/views/changeset/rss.rxml @@ -0,0 +1,49 @@ +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_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.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) + 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) + xml.comments url_for(:controller => "message", :action => "new", :id => changeset.user.id, :only_path => false) + + 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/config/locales/en.yml b/config/locales/en.yml index dbcaa65e5..306036b52 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -238,6 +238,9 @@ en: no_visible_edits_by: "No visible edits by {{name}}." for_all_changes: "For changes by all users see {{recent_changes_link}}" recent_changes: "Recent Changes" + list_user_rss: + title: "Edits by {{user}}" + description: "Recent changesets by {{user}}" diary_entry: new: title: New Diary Entry diff --git a/config/routes.rb b/config/routes.rb index 4b1161012..87d5841d4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -143,6 +143,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/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'