Ticket #1737: add-feed-to-user-edits.patch

File add-feed-to-user-edits.patch, 4.3 KB (added by avar, 10 years ago)

Work in progress patch to add feeds to /$user/edits

  • app/controllers/changeset_controller.rb

     
    11# The ChangesetController is the RESTful interface to Changeset objects
    22
    33class ChangesetController < ApplicationController
    4   layout 'site'
     4  layout 'site', :except => :rss
    55  require 'xml/libxml'
    66
    77  before_filter :authorize_web, :only => [:list, :list_user, :list_bbox]
     
    298298      render :template => 'user/no_such_user', :status => :not_found
    299299    end
    300300  end
     301
     302  ##
     303  # list edits (changesets) belonging to a user
     304  def rss
     305    user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
     306   
     307    if user
     308      @display_name = user.display_name
     309      if not user.data_public? and @user != user
     310        @edits = nil
     311        render
     312      else
     313        conditions = cond_merge conditions, ['user_id = ?', user.id]
     314        conditions = cond_merge conditions, conditions_nonempty
     315        @edit_pages, @edits = paginate(:changesets,
     316                                        :include => [:user, :changeset_tags],
     317                                        :conditions => conditions,
     318                                        :order => "changesets.created_at DESC",
     319                                        :per_page => 20)
     320      end
     321    else
     322      @not_found_user = params[:display_name]
     323      render :template => 'user/no_such_user', :status => :not_found
     324    end
     325  end
    301326 
    302327  ##
    303328  # list changesets in a bbox
  • app/views/changeset/list_user.rhtml

     
    1111<p><%= t'changeset.list_user.for_all_changes', :recent_changes_link => link_to(t('changeset.list_user.recent_changes'), :controller => "browse", :action => "changesets") %></p>
    1212<br>
    1313
     14<%= rss_link_to :action => 'rss' %>
     15
     16<% content_for :head do %>
     17<%= auto_discovery_link_tag :atom, :action => 'rss' %>
     18<% end %>
  • config/routes.rb

     
    143143  # user pages
    144144  map.connect '/user/:display_name', :controller => 'user', :action => 'view'
    145145  map.connect '/user/:display_name/edits', :controller => 'changeset', :action => 'list_user'
     146  map.connect '/user/:display_name/edits/rss', :controller => 'changeset', :action => 'rss'
    146147  map.connect '/user/:display_name/make_friend', :controller => 'user', :action => 'make_friend'
    147148  map.connect '/user/:display_name/remove_friend', :controller => 'user', :action => 'remove_friend'
    148149  map.connect '/user/:display_name/diary', :controller => 'diary_entry', :action => 'list'
  • app/views/changeset/rss.rxml

     
     1xml.instruct!
     2
     3xml.rss("version" => "2.0",
     4        "xmlns:geo" => "http://www.w3.org/2003/01/geo/wgs84_pos#",
     5        "xmlns:georss" => "http://www.georss.org/georss") do
     6  xml.channel do
     7    xml.title @title
     8    xml.description @description
     9    xml.link url_for(:action => "list", :only_path => false)
     10    xml.image do
     11      xml.url "http://www.openstreetmap.org/images/mag_map-rss2.0.png"
     12      xml.title "OpenStreetMap"
     13      xml.width "100"
     14      xml.height "100"
     15      xml.link url_for(:action => "list", :only_path => false)
     16    end
     17
     18
     19    for changeset in @edits
     20      xml.item do
     21        xml.title t('browse.changeset.title') + " " + h(changeset.id)
     22        xml.link url_for(:controller => 'browse', :action => "changeset", :id => changeset.id, :only_path => false)
     23        xml.guid url_for(:controller => 'browse', :action => "changeset", :id => changeset.id, :only_path => false)
     24        xml.author changeset.user.display_name
     25        if changeset.tags['comment']
     26          xml.description htmlize(changeset.tags['comment'])
     27        else
     28          xml.description htmlize(t 'changeset.changeset.no_comment')
     29        end
     30        xml.pubDate changeset.created_at.to_s(:rfc822)
     31      end
     32    end
     33  end
     34end
     35