# Main AMF handlers: process the raw AMF string (using AMF library) and
# calls each action (private method) accordingly.
# Main AMF handlers: process the raw AMF string (using AMF library) and
# calls each action (private method) accordingly.
- when 'getpresets' then result = getpresets(*args)
- when 'whichways' then result = whichways(*args)
- when 'whichways_deleted' then result = whichways_deleted(*args)
- when 'getway' then result = getway(args[0].to_i)
- when 'getrelation' then result = getrelation(args[0].to_i)
- when 'getway_old' then result = getway_old(args[0].to_i, args[1])
- when 'getway_history' then result = getway_history(args[0].to_i)
- when 'getnode_history' then result = getnode_history(args[0].to_i)
- when 'findgpx' then result = findgpx(*args)
- when 'findrelations' then result = findrelations(*args)
- when 'getpoi' then result = getpoi(*args)
+ when "getpresets" then result = getpresets(*args)
+ when "whichways" then result = whichways(*args)
+ when "whichways_deleted" then result = whichways_deleted(*args)
+ when "getway" then result = getway(args[0].to_i)
+ when "getrelation" then result = getrelation(args[0].to_i)
+ when "getway_old" then result = getway_old(args[0].to_i, args[1])
+ when "getway_history" then result = getway_history(args[0].to_i)
+ when "getnode_history" then result = getnode_history(args[0].to_i)
+ when "findgpx" then result = findgpx(*args)
+ when "findrelations" then result = findrelations(*args)
+ when "getpoi" then result = getpoi(*args)
orn = renumberednodes.dup
result = putway(renumberednodes, *args)
result[4] = renumberednodes.reject { |k, _v| orn.key?(k) }
orn = renumberednodes.dup
result = putway(renumberednodes, *args)
result[4] = renumberednodes.reject { |k, _v| orn.key?(k) }
- if result[0] == 0 && result[2] != result[3] then renumberedways[result[2]] = result[3] end
- when 'putrelation' then
+ renumberedways[result[2]] = result[3] if result[0] == 0 && result[2] != result[3]
+ when "putrelation" then
- if result[0] == 0 && result[2] != result[3] then renumberednodes[result[2]] = result[3] end
- when 'startchangeset' then
+ renumberednodes[result[2]] = result[3] if result[0] == 0 && result[2] != result[3]
+ when "startchangeset" then
def startchangeset(usertoken, cstags, closeid, closecomment, opennew)
amf_handle_error("'startchangeset'", nil, nil) do
user = getuser(usertoken)
def startchangeset(usertoken, cstags, closeid, closecomment, opennew)
amf_handle_error("'startchangeset'", nil, nil) do
user = getuser(usertoken)
- unless user then return -1, "You are not logged in, so Potlatch can't write any changes to the database." end
- if user.blocks.active.exists? then return -1, t('application.setup_user_auth.blocked') end
- if REQUIRE_TERMS_AGREED && user.terms_agreed.nil? then return -1, "You must accept the contributor terms before you can edit." end
+ return -1, "You are not logged in, so Potlatch can't write any changes to the database." unless user
+ return -1, t("application.setup_user_auth.blocked") if user.blocks.active.exists?
+ return -1, "You must accept the contributor terms before you can edit." if REQUIRE_TERMS_AGREED && user.terms_agreed.nil?
def getpresets(usertoken, lang) #:doc:
user = getuser(usertoken)
def getpresets(usertoken, lang) #:doc:
user = getuser(usertoken)
- if user && !user.languages.empty?
- http_accept_language.user_preferred_languages = user.languages
- end
+ langs = if user && !user.languages.empty?
+ Locale.list(user.languages)
+ else
+ Locale.list(http_accept_language.user_preferred_languages)
+ end
- lang = http_accept_language.compatible_language_from(getlocales)
- (real_lang, localised) = getlocalized(lang)
+ lang = getlocales.preferred(langs)
+ (real_lang, localised) = getlocalized(lang.to_s)
- [0, '', ways, points, relations]
+ [0, "", ways, points, relations]
nodes_in_area = Node.bbox(bbox).joins(:ways_via_history).where(:current_ways => { :visible => false })
way_ids = nodes_in_area.collect { |node| node.ways_via_history.invisible.collect(&:id) }.flatten.uniq
nodes_in_area = Node.bbox(bbox).joins(:ways_via_history).where(:current_ways => { :visible => false })
way_ids = nodes_in_area.collect { |node| node.ways_via_history.invisible.collect(&:id) }.flatten.uniq
# Returns the way id, a Potlatch-style array of points, a hash of tags, the version number, and the user ID.
def getway(wayid) #:doc:
# Returns the way id, a Potlatch-style array of points, a hash of tags, the version number, and the user ID.
def getway(wayid) #:doc:
[node.lon, node.lat, node.id, nodetags, node.version]
end
tags = way.tags
[node.lon, node.lat, node.id, nodetags, node.version]
end
tags = way.tags
- [0, '', wayid, points, tags, version, uid]
+ [0, "", wayid, points, tags, version, uid]
# 5. is this the current, visible version? (boolean)
def getway_old(id, timestamp) #:doc:
# 5. is this the current, visible version? (boolean)
def getway_old(id, timestamp) #:doc:
- amf_handle_error_with_timeout("'getway_old' #{id}, #{timestamp}", 'way', id) do
- if timestamp == ''
+ amf_handle_error_with_timeout("'getway_old' #{id}, #{timestamp}", "way", id) do
+ if timestamp == ""
# undelete
old_way = OldWay.where(:visible => true, :way_id => id).unredacted.order("version DESC").first
points = old_way.get_nodes_undelete unless old_way.nil?
# undelete
old_way = OldWay.where(:visible => true, :way_id => id).unredacted.order("version DESC").first
points = old_way.get_nodes_undelete unless old_way.nil?
timestamp = DateTime.strptime(timestamp.to_s, "%d %b %Y, %H:%M:%S")
old_way = OldWay.where("way_id = ? AND timestamp <= ?", id, timestamp).unredacted.order("timestamp DESC").first
unless old_way.nil?
timestamp = DateTime.strptime(timestamp.to_s, "%d %b %Y, %H:%M:%S")
old_way = OldWay.where("way_id = ? AND timestamp <= ?", id, timestamp).unredacted.order("timestamp DESC").first
unless old_way.nil?
return [-1, "Sorry, the way was deleted at that time - please revert to a previous version.", id]
end
end
return [-1, "Sorry, the way was deleted at that time - please revert to a previous version.", id]
end
end
return [-1, "Sorry, the server could not find a way at that time.", id]
else
curway = Way.find(id)
return [-1, "Sorry, the server could not find a way at that time.", id]
else
curway = Way.find(id)
- old_way.tags['history'] = "Retrieved from v#{old_way.version}"
- return [0, '', id, points, old_way.tags, curway.version, (curway.version == old_way.version && curway.visible)]
+ old_way.tags["history"] = "Retrieved from v#{old_way.version}"
+ return [0, "", id, points, old_way.tags, curway.version, (curway.version == old_way.version && curway.visible)]
history = Node.find(nodeid).old_nodes.unredacted.reverse.collect do |old_node|
[(old_node.timestamp + 1).strftime("%d %b %Y, %H:%M:%S")] + change_user(old_node)
end
history = Node.find(nodeid).old_nodes.unredacted.reverse.collect do |old_node|
[(old_node.timestamp + 1).strftime("%d %b %Y, %H:%M:%S")] + change_user(old_node)
end
user = getuser(usertoken)
return -1, "You must be logged in to search for GPX traces." unless user
user = getuser(usertoken)
return -1, "You must be logged in to search for GPX traces." unless user
- if searchterm.to_i > 0
- query = query.where(:id => searchterm.to_i)
- else
- query = query.where("MATCH(name) AGAINST (?)", searchterm).limit(21)
- end
+ query = if searchterm.to_i > 0
+ query.where(:id => searchterm.to_i)
+ else
+ query.where("MATCH(name) AGAINST (?)", searchterm).limit(21)
+ end
gpxs = query.collect do |gpx|
[gpx.id, gpx.name, gpx.description]
end
gpxs = query.collect do |gpx|
[gpx.id, gpx.name, gpx.description]
end
- return [-4, 'relation', relid] if rel.nil? || !rel.visible
- [0, '', relid, rel.tags, rel.members, rel.version]
+ return [-4, "relation", relid] if rel.nil? || !rel.visible
+ [0, "", relid, rel.tags, rel.members, rel.version]
# 3. version.
def putrelation(renumberednodes, renumberedways, usertoken, changeset_id, version, relid, tags, members, visible) #:doc:
# 3. version.
def putrelation(renumberednodes, renumberedways, usertoken, changeset_id, version, relid, tags, members, visible) #:doc:
- unless user then return -1, "You are not logged in, so the relation could not be saved." end
- if user.blocks.active.exists? then return -1, t('application.setup_user_auth.blocked') end
- if REQUIRE_TERMS_AGREED && user.terms_agreed.nil? then return -1, "You must accept the contributor terms before you can edit." end
- unless tags_ok(tags) then return -1, "One of the tags is invalid. Linux users may need to upgrade to Flash Player 10.1." end
+ return -1, "You are not logged in, so the relation could not be saved." unless user
+ return -1, t("application.setup_user_auth.blocked") if user.blocks.active.exists?
+ return -1, "You must accept the contributor terms before you can edit." if REQUIRE_TERMS_AGREED && user.terms_agreed.nil?
+
+ return -1, "One of the tags is invalid. Linux users may need to upgrade to Flash Player 10.1." unless tags_ok(tags)
end
if mid
typedmembers << [m[0], mid, m[2].delete("\000-\037\ufffe\uffff", "^\011\012\015")]
end
if mid
typedmembers << [m[0], mid, m[2].delete("\000-\037\ufffe\uffff", "^\011\012\015")]
- return [0, '', relid, new_relation.id, new_relation.version]
+ return [0, "", relid, new_relation.id, new_relation.version]
- return [0, '', relid, relid, relation.version]
+ return [0, "", relid, relid, relation.version]
def putway(renumberednodes, usertoken, changeset_id, wayversion, originalway, pointlist, attributes, nodes, deletednodes) #:doc:
def putway(renumberednodes, usertoken, changeset_id, wayversion, originalway, pointlist, attributes, nodes, deletednodes) #:doc:
- unless user then return -1, "You are not logged in, so the way could not be saved." end
- if user.blocks.active.exists? then return -1, t('application.setup_user_auth.blocked') end
- if REQUIRE_TERMS_AGREED && user.terms_agreed.nil? then return -1, "You must accept the contributor terms before you can edit." end
+ return -1, "You are not logged in, so the way could not be saved." unless user
+ return -1, t("application.setup_user_auth.blocked") if user.blocks.active.exists?
+ return -1, "You must accept the contributor terms before you can edit." if REQUIRE_TERMS_AGREED && user.terms_agreed.nil?
- if id == 0 then return -2, "Server error - node with id 0 found in way #{originalway}." end
- if lat == 90 then return -2, "Server error - node with latitude -90 found in way #{originalway}." end
+ return -2, "Server error - node with id 0 found in way #{originalway}." if id == 0
+ return -2, "Server error - node with latitude -90 found in way #{originalway}." if lat == 90
- [0, '', originalway, way.id, renumberednodes, way.version, nodeversions, deletednodes]
+ [0, "", originalway, way.id, renumberednodes, way.version, nodeversions, deletednodes]
# 4. version.
def putpoi(usertoken, changeset_id, version, id, lon, lat, tags, visible) #:doc:
# 4. version.
def putpoi(usertoken, changeset_id, version, id, lon, lat, tags, visible) #:doc:
- unless user then return -1, "You are not logged in, so the point could not be saved." end
- if user.blocks.active.exists? then return -1, t('application.setup_user_auth.blocked') end
- if REQUIRE_TERMS_AGREED && user.terms_agreed.nil? then return -1, "You must accept the contributor terms before you can edit." end
+ return -1, "You are not logged in, so the point could not be saved." unless user
+ return -1, t("application.setup_user_auth.blocked") if user.blocks.active.exists?
+ return -1, "You must accept the contributor terms before you can edit." if REQUIRE_TERMS_AGREED && user.terms_agreed.nil?
- unless visible
- unless node.ways.empty? then return -1, "Point #{id} has since become part of a way, so you cannot save it as a POI.", id, id, version end
+ unless visible || node.ways.empty?
+ return -1, "Point #{id} has since become part of a way, so you cannot save it as a POI.", id, id, version
- return [0, '', id, new_node.id, new_node.version]
+ return [0, "", id, new_node.id, new_node.version]
- return [0, '', id, node.id, node.version]
+ return [0, "", id, node.id, node.version]
# Returns array of id, long, lat, hash of tags, (current) version.
def getpoi(id, timestamp) #:doc:
# Returns array of id, long, lat, hash of tags, (current) version.
def getpoi(id, timestamp) #:doc:
- n = Node.find(id)
- v = n.version
- unless timestamp == ''
- n = OldNode.where("node_id = ? AND timestamp <= ?", id, timestamp).unredacted.order("timestamp DESC").first
+ n = Node.where(:id => id).first
+ if n
+ v = n.version
+ unless timestamp == ""
+ n = OldNode.where("node_id = ? AND timestamp <= ?", id, timestamp).unredacted.order("timestamp DESC").first
+ end
- return [0, '', n.id, n.lon, n.lat, n.tags, v]
+ return [0, "", id, n.lon, n.lat, n.tags, v]
# Returns 0 (success), unchanged way id, new way version, new node versions.
def deleteway(usertoken, changeset_id, way_id, way_version, deletednodes) #:doc:
# Returns 0 (success), unchanged way id, new way version, new node versions.
def deleteway(usertoken, changeset_id, way_id, way_version, deletednodes) #:doc:
- unless user then return -1, "You are not logged in, so the way could not be deleted." end
- if user.blocks.active.exists? then return -1, t('application.setup_user_auth.blocked') end
- if REQUIRE_TERMS_AGREED && user.terms_agreed.nil? then return -1, "You must accept the contributor terms before you can edit." end
+ return -1, "You are not logged in, so the way could not be deleted." unless user
+ return -1, t("application.setup_user_auth.blocked") if user.blocks.active.exists?
+ return -1, "You must accept the contributor terms before you can edit." if REQUIRE_TERMS_AGREED && user.terms_agreed.nil?
- [0, '', way_id, old_way.version, nodeversions]
+ [0, "", way_id, old_way.version, nodeversions]
AND current_ways.visible=TRUE
AND #{OSM.sql_for_area(bbox, "current_nodes.")}
EOF
AND current_ways.visible=TRUE
AND #{OSM.sql_for_area(bbox, "current_nodes.")}
EOF
ActiveRecord::Base.connection.select_all(sql).each do |row|
poitags = {}
ActiveRecord::Base.connection.select_all("SELECT k,v FROM current_node_tags WHERE id=#{row['id']}").each do |n|
ActiveRecord::Base.connection.select_all(sql).each do |row|
poitags = {}
ActiveRecord::Base.connection.select_all("SELECT k,v FROM current_node_tags WHERE id=#{row['id']}").each do |n|
- pois << [row['id'].to_i, row['lon'].to_f, row['lat'].to_f, poitags, row['version'].to_i]
+ pois << [row["id"].to_i, row["lon"].to_f, row["lat"].to_f, poitags, row["version"].to_i]
ActiveRecord::Base.connection.select_all(sql).each do |row|
nodetags = {}
ActiveRecord::Base.connection.select_all("SELECT k,v FROM current_node_tags WHERE id=#{row['id']}").each do |n|
ActiveRecord::Base.connection.select_all(sql).each do |row|
nodetags = {}
ActiveRecord::Base.connection.select_all("SELECT k,v FROM current_node_tags WHERE id=#{row['id']}").each do |n|
- nodetags.delete('created_by')
- points << [row['lon'].to_f, row['lat'].to_f, row['id'].to_i, nodetags, row['version'].to_i]
+ nodetags.delete("created_by")
+ points << [row["lon"].to_f, row["lat"].to_f, row["id"].to_i, nodetags, row["version"].to_i]
def sql_get_tags_in_way(wayid)
tags = {}
ActiveRecord::Base.connection.select_all("SELECT k,v FROM current_way_tags WHERE id=#{wayid.to_i}").each do |row|
def sql_get_tags_in_way(wayid)
tags = {}
ActiveRecord::Base.connection.select_all("SELECT k,v FROM current_way_tags WHERE id=#{wayid.to_i}").each do |row|