]> git.openstreetmap.org Git - rails.git/commitdiff
Merge branch 'master' into openstreetbugs
authorTom Hughes <tom@compton.nu>
Fri, 7 May 2010 21:29:09 +0000 (22:29 +0100)
committerTom Hughes <tom@compton.nu>
Fri, 7 May 2010 21:29:09 +0000 (22:29 +0100)
Conflicts:
lib/osm.rb

1  2 
config/environment.rb
config/locales/en.yml
config/routes.rb
lib/osm.rb

diff --combined config/environment.rb
index 6158dfa8cdb3a7cd0dfaeebdea67d14188f43584,d8f9b2fc85ca0503146b1c55ff390c86bf1003cc..696a226e753ff7f8312918a62f9c239311698369
@@@ -100,9 -100,8 +100,9 @@@ Rails::Initializer.run do |config
    config.active_record.schema_format = :sql
  
    # Activate observers that should always be running
-   # config.active_record.observers = :cacher, :garbage_collector
+   config.active_record.observers = :spam_observer
  
    # Make Active Record use UTC-base instead of local time
    config.active_record.default_timezone = :utc
 +
  end
diff --combined config/locales/en.yml
index 7e9046c4f75948484273a77f7e1e156cbe27ca55,fbf8e7a0462ab620397b0f0f7133c744718234a4..8afaa971742e5ec07e3090067205b6e964649850
@@@ -262,17 -262,6 +262,17 @@@ en
        download_xml: "Download XML"
        view_history: "view history"
        edit: "edit"
 +    bug:
 +      open_title: "Unresolved issue: {{bug_name}}"
 +      closed_title: "Resolved issue: {{bug_name}}"
 +      created_at: "Created at:"
 +      edited_at: "Edited at:"
 +      closed_at: "Closed at:"
 +      opened_by: "Opened by:"
 +      description: "Description:"
 +      comment_by: "Comment by: "
 +      comment: "Comment:"
 +      date: "Date:"
    changeset:
      changeset_paging_nav:
        showing_page: "Showing page {{page}}"
        lost password link: "Lost your password?"
        login_button: "Login"
        account not active: "Sorry, your account is not active yet.<br />Please click on the link in the account confirmation email to activate your account."
+       account suspended: Sorry, your account has been suspended due to suspicious activity.<br />Please contact the <a href="mailto:webmaster@openstreetmap.org">webmaster</a> if you wish to discuss this.
        auth failure: "Sorry, could not log in with those details."
      logout:
        title: "Logout"
        ago: "({{time_in_words_ago}} ago)"
        email address: "Email address:"
        created from: "Created from:"
+       status: "Status:"
+       spam score: "Spam Score:"
        description: Description
        user location: User location
        if set location: "If you set your location, a pretty map and stuff will appear here. You can set your home location on your {{settings_link}} page."
        create_block: "block this user"
        activate_user: "activate this user"
        deactivate_user: "deactivate this user"
+       confirm_user: "confirm this user"
        hide_user: "hide this user"
        unhide_user: "unhide this user"
        delete_user: "delete this user"
        not_a_friend: "{{name}} is not one of your friends."
      filter:
        not_an_administrator: "You need to be an administrator to perform that action."
+     list:
+       title: Users
+       heading: Users
+       showing:
+         one: Showing page {{page}} ({{first_item}} of {{items}})
+         other: Showing page {{page}} ({{first_item}}-{{last_item}} of {{items}})
+       summary: "{{name}} created from {{ip_address}} on {{date}}"
+       summary_no_ip: "{{name}} created on {{date}}"
+       confirm: Confirm Selected Users
+       hide: Hide Selected Users
+       empty: No matching users found
+     suspended:
+       title: Account Suspended
+       heading: Account Suspended
+       body: |
+         <p>
+           Sorry, your account has been automatically suspended due to
+           suspicious activity.
+         </p>
+         <p>
+           This decision will be reviewed by an administrator shortly, or
+           you may contact the <a href="mailto:{{webmaster}}">webmaster</a> if
+           you wish to discuss this.
+         </p>
    user_role:
      filter:
        not_an_administrator: "Only administrators can perform user role management, and you are not an administrator."
        back: "View all blocks"
        revoker: "Revoker:"
        needs_view: "The user needs to log in before this block will be cleared."
 +  bugs:
 +    rss:
 +      description_area: "A list of bugs, reported, commented on or closed in your area [({{min_lat}}|{{min_lon}}) -- ({{max_lat}}|{{max_lon}})]"
 +      description_item: "An rss feed for bug {{id}}"
 +      closed: "closed bug (near {{place}})"
 +      new: "new bug (near {{place}})"
 +      comment: "new comment (near {{place}})"
 +    user:
 +      title_user: "Bugs submitted or commented on by {{user}}"
 +      heading_user: "{{user}}'s bugs"
 +      description_user: "Bugs submitted or commented on by {{user}}"
 +      id: "Id"
 +      last_changed: "Last changed"
 +
    javascripts:
      map:
        base:
diff --combined config/routes.rb
index d12bfbb5ae6391396f23c19db1f41a4a279f5602,7e27ee19ef70714f526111597df042e94c2f4bb7..579662979c9d083cb77c4530b4fa7cbc91280008
@@@ -70,27 -70,6 +70,27 @@@ ActionController::Routing::Routes.draw 
    map.connect "api/#{API_VERSION}/amf/read", :controller =>'amf', :action =>'amf_read'
    map.connect "api/#{API_VERSION}/amf/write", :controller =>'amf', :action =>'amf_write'
    map.connect "api/#{API_VERSION}/swf/trackpoints", :controller =>'swf', :action =>'trackpoints'
 +
 +  # Map Bugs API  
 +  map.connect "api/#{API_VERSION}/bugs/getBugs", :controller =>'map_bugs', :action =>'get_bugs'
 +  map.connect "api/#{API_VERSION}/bugs/addPOIexec", :controller =>'map_bugs', :action =>'add_bug'
 +  map.connect "api/#{API_VERSION}/bugs/closePOIexec", :controller =>'map_bugs', :action =>'close_bug'
 +  map.connect "api/#{API_VERSION}/bugs/editPOIexec", :controller =>'map_bugs', :action =>'edit_bug'
 +  map.connect "api/#{API_VERSION}/bugs/getGPX", :controller =>'map_bugs', :action =>'gpx_bugs'
 +  map.connect "api/#{API_VERSION}/bugs/getRSSfeed", :controller =>'map_bugs', :action =>'rss'
 +
 +  map.connect "api/#{API_VERSION}/bugs", :controller => 'map_bugs', :action => 'get_bugs'
 +  map.connect "api/#{API_VERSION}/bugs/search", :controller => 'map_bugs', :action => 'search'
 +  map.connect "api/#{API_VERSION}/bugs/rss", :controller =>'map_bugs', :action =>'rss'
 +  map.connect "api/#{API_VERSION}/bug/create", :controller => 'map_bugs', :action => 'add_bug'
 +  map.connect "api/#{API_VERSION}/bug/:id/comment", :controller => 'map_bugs', :action => 'edit_bug', :id => /\d+/
 +  map.connect "api/#{API_VERSION}/bug/:id/close", :controller => 'map_bugs', :action => 'close_bug', :id => /\d+/
 +  map.connect "api/#{API_VERSION}/bug/:id", :controller => 'map_bugs', :action => 'read', :id => /\d+/, :conditions => { :method => :get }
 +  map.connect "api/#{API_VERSION}/bug/:id", :controller => 'map_bugs', :action => 'delete', :id => /\d+/, :conditions => { :method => :delete }
 +
 +  map.connect '/user/:display_name/bugs', :controller => 'map_bugs', :action => 'my_bugs'
 +  
 +
    
    # Data browsing
    map.connect '/browse', :controller => 'changeset', :action => 'list'
    map.changeset '/browse/changeset/:id', :controller => 'browse', :action => 'changeset', :id => /\d+/
    map.connect '/browse/changesets', :controller => 'changeset', :action => 'list'
    map.connect '/browse/changesets/feed', :controller => 'changeset', :action => 'list', :format => :atom
 +  map.connect '/browse/bug/:id', :controller => 'browse', :action => 'bug', :id => /\d+/
    
    # web site
    map.root :controller => 'site', :action => 'index'
    map.connect '/user/go_public', :controller => 'user', :action => 'go_public'
    map.connect '/user/reset-password', :controller => 'user', :action => 'reset_password'
    map.connect '/user/forgot-password', :controller => 'user', :action => 'lost_password'
+   map.connect '/user/suspended', :controller => 'user', :action => 'suspended'
  
    map.connect '/index.html', :controller => 'site', :action => 'index'
    map.connect '/edit.html', :controller => 'site', :action => 'edit'
    map.connect '/user/:display_name/diary/:id/hide', :controller => 'diary_entry', :action => 'hide', :id => /\d+/
    map.connect '/user/:display_name/diary/:id/hidecomment/:comment', :controller => 'diary_entry', :action => 'hidecomment', :id => /\d+/, :comment => /\d+/
    map.connect '/user/:display_name/account', :controller => 'user', :action => 'account'
-   map.connect '/user/:display_name/activate', :controller => 'user', :action => 'activate'
-   map.connect '/user/:display_name/deactivate', :controller => 'user', :action => 'deactivate'
-   map.connect '/user/:display_name/hide', :controller => 'user', :action => 'hide'
-   map.connect '/user/:display_name/unhide', :controller => 'user', :action => 'unhide'
+   map.connect '/user/:display_name/set_status', :controller => 'user', :action => 'set_status'
    map.connect '/user/:display_name/delete', :controller => 'user', :action => 'delete'
    map.connect '/diary/new', :controller => 'diary_entry', :action => 'new'
    map.connect '/diary', :controller => 'diary_entry', :action => 'list'
    map.connect '/diary/:language', :controller => 'diary_entry', :action => 'list'
    map.connect '/diary/:language/rss', :controller => 'diary_entry', :action => 'rss'
  
-   
+   # user lists
+   map.connect '/users', :controller => 'user', :action => 'list'
+   map.connect '/users/:status', :controller => 'user', :action => 'list'
    # test pages
    map.connect '/test/populate/:table/:from/:count', :controller => 'test', :action => 'populate'
    map.connect '/test/populate/:table/:count', :controller => 'test', :action => 'populate', :from => 1
diff --combined lib/osm.rb
index 1358c993af7cdeaae4709f091c12055aa40d32b4,46b90447781b23938a6cc3820403381c8ba30272..2a1ca089eb70ca681af2b7b3c2e1259d72e3de11
@@@ -7,6 -7,7 +7,7 @@@ module OS
    require 'xml/libxml'
    require 'digest/md5'
    require 'RMagick'
+   require 'nokogiri'
  
    # The base class for API Errors.
    class APIError < RuntimeError
  
    # Return an SQL fragment to select a given area of the globe
    def self.sql_for_area(minlat, minlon, maxlat, maxlon, prefix = nil)
 -    tilesql = QuadTile.sql_for_area(minlat, minlon, maxlat, maxlon, prefix)
 +      tilesql = QuadTile.sql_for_area(minlat, minlon, maxlat, maxlon, prefix)
      minlat = (minlat * 10000000).round
      minlon = (minlon * 10000000).round
      maxlat = (maxlat * 10000000).round
      return "#{tilesql} AND #{prefix}latitude BETWEEN #{minlat} AND #{maxlat} AND #{prefix}longitude BETWEEN #{minlon} AND #{maxlon}"
    end
  
 +  # Return an SQL fragment to select a given area of the globe without using the quadtile index
 +  def self.sql_for_area_no_quadtile(minlat, minlon, maxlat, maxlon, prefix = nil, without_quadtile = :false)
 +    minlat = (minlat * 10000000).round
 +    minlon = (minlon * 10000000).round
 +    maxlat = (maxlat * 10000000).round
 +    maxlon = (maxlon * 10000000).round
 +
 +    return "#{prefix}latitude BETWEEN #{minlat} AND #{maxlat} AND #{prefix}longitude BETWEEN #{minlon} AND #{maxlon}"
 +  end
 +
+   # Return a spam score for a chunk of text
+   def self.spam_score(text)
+     link_count = 0
+     link_size = 0
  
+     doc = Nokogiri::HTML(text)
+     if doc.content.length > 0
+       doc.xpath("//a").each do |link|
+         link_count += 1
+         link_size += link.content.length
+       end
+       link_proportion = link_size.to_f / doc.content.length.to_f
+     else
+       link_proportion = 0
+     end
+     return [link_proportion - 0.2, 0.0].max * 200 + link_count * 20
+   end
  end