summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorJochen Topf <jochen@topf.org>2013-01-09 19:18:55 +0100
committerJochen Topf <jochen@topf.org>2013-01-09 19:18:55 +0100
commit64a047f622a5ed15dea94b5e52dd8c948fce9e95 (patch)
tree1dfeecec0fa0477c1a246ef6567dffc56592d325 /web
parent9cadfd89c12c9223e7c572646680d0bcce57310c (diff)
downloadtaginfo-64a047f622a5ed15dea94b5e52dd8c948fce9e95.tar
taginfo-64a047f622a5ed15dea94b5e52dd8c948fce9e95.tar.gz
Better support for wiki images.
Key and tag wiki pages can contain images. Until now we only got the titles of those images. Now we also get the URL to the image, URL to thumbnails, width, height, and mime type. This information is now exposed in the API and it is used to show the images in the Overview tab of the key and tag pages. While we are changing the update process anyway, I changed the program that gets the list of all pages to also output the time those pages changed last. This information is currently not used, but it could be used to cache those pages locally making the update much faster and adding less strain to the wiki server.
Diffstat (limited to 'web')
-rw-r--r--web/lib/api/v4/key.rb12
-rw-r--r--web/lib/api/v4/tag.rb12
-rw-r--r--web/lib/ui/keys_tags.rb22
-rw-r--r--web/lib/utils.rb10
-rw-r--r--web/views/key.erb5
-rw-r--r--web/views/tag.erb5
-rw-r--r--web/viewsjs/key.js.erb2
-rw-r--r--web/viewsjs/tag.js.erb2
8 files changed, 63 insertions, 7 deletions
diff --git a/web/lib/api/v4/key.rb b/web/lib/api/v4/key.rb
index 7cc9532..420ef37 100644
--- a/web/lib/api/v4/key.rb
+++ b/web/lib/api/v4/key.rb
@@ -283,7 +283,15 @@ class Taginfo < Sinatra::Base
[:language_en, :STRING, 'Language name in English.'],
[:title, :STRING, 'Wiki page title.'],
[:description, :STRING, 'Short description of key from wiki page.'],
- [:image, :STRING, 'Wiki page title of associated image.'],
+ [:image, :HASH, 'Associated image.', [
+ [:title, :STRING, 'Wiki page title of associated image.' ],
+ [:width, :INT, 'Width of image.' ],
+ [:height, :INT, 'Height of image.' ],
+ [:mime, :STRING, 'MIME type of image.' ],
+ [:image_url, :STRING, 'Image URL' ],
+ [:thumb_url_prefix, :STRING, 'Prefix of thumbnail URL.' ],
+ [:thumb_url_suffix, :STRING, 'Suffix of thumbnail URL.' ]
+ ]],
[:on_node, :BOOL, 'Is this a key for nodes?'],
[:on_way, :BOOL, 'Is this a key for ways?'],
[:on_area, :BOOL, 'Is this a key for areas?'],
@@ -297,7 +305,7 @@ class Taginfo < Sinatra::Base
}) do
key = params[:key]
- res = @db.execute('SELECT * FROM wikipages WHERE value IS NULL AND key = ? ORDER BY lang', key)
+ res = @db.execute('SELECT * FROM wikipages LEFT OUTER JOIN wiki_images USING (image) WHERE value IS NULL AND key = ? ORDER BY lang', key)
return get_wiki_result(res)
end
diff --git a/web/lib/api/v4/tag.rb b/web/lib/api/v4/tag.rb
index 50e26c7..20a0559 100644
--- a/web/lib/api/v4/tag.rb
+++ b/web/lib/api/v4/tag.rb
@@ -177,7 +177,15 @@ class Taginfo < Sinatra::Base
[:language_en, :STRING, 'Language name in English.'],
[:title, :STRING, 'Wiki page title.'],
[:description, :STRING, 'Short description of tag from wiki page.'],
- [:image, :STRING, 'Wiki page title of associated image.'],
+ [:image, :HASH, 'Associated image.', [
+ [:title, :STRING, 'Wiki page title of associated image.' ],
+ [:width, :INT, 'Width of image.' ],
+ [:height, :INT, 'Height of image.' ],
+ [:mime, :STRING, 'MIME type of image.' ],
+ [:image_url, :STRING, 'Image URL' ],
+ [:thumb_url_prefix, :STRING, 'Prefix of thumbnail URL.' ],
+ [:thumb_url_suffix, :STRING, 'Suffix of thumbnail URL.' ]
+ ]],
[:on_node, :BOOL, 'Is this a tag for nodes?'],
[:on_way, :BOOL, 'Is this a tag for ways?'],
[:on_area, :BOOL, 'Is this a tag for areas?'],
@@ -192,7 +200,7 @@ class Taginfo < Sinatra::Base
key = params[:key]
value = params[:value]
- res = @db.execute('SELECT * FROM wikipages WHERE key = ? AND value = ? ORDER BY lang', key, value)
+ res = @db.execute('SELECT * FROM wikipages LEFT OUTER JOIN wiki_images USING (image) WHERE key = ? AND value = ? ORDER BY lang', key, value)
return get_wiki_result(res)
end
diff --git a/web/lib/ui/keys_tags.rb b/web/lib/ui/keys_tags.rb
index feaf90d..5e21c6e 100644
--- a/web/lib/ui/keys_tags.rb
+++ b/web/lib/ui/keys_tags.rb
@@ -1,6 +1,17 @@
# web/lib/ui/keys_tags.rb
class Taginfo < Sinatra::Base
+ MAX_IMAGE_WIDTH = 300
+
+ def build_image_url(row)
+ w = row['width'].to_i
+ h = row['height'].to_i
+ if w > 0 && h > 0
+ return "#{row['thumb_url_prefix']}#{ h <= w ? MAX_IMAGE_WIDTH : (MAX_IMAGE_WIDTH * w / h).to_i }#{ row['thumb_url_suffix'] }"
+ end
+ return nil
+ end
+
get %r{^/keys/(.*)} do |key|
if params[:key].nil?
@key = key
@@ -28,6 +39,11 @@ class Taginfo < Sinatra::Base
@desc = "<span title='#{ t.pages.key.description_from_wiki }' tipsy='w'>#{ @desc }</span"
end
+ @db.select("SELECT width, height, thumb_url_prefix, thumb_url_suffix FROM wiki.wikipages LEFT OUTER JOIN wiki.wiki_images USING(image) WHERE lang=? AND key=? AND value IS NULL UNION SELECT width, height, thumb_url_prefix, thumb_url_suffix FROM wiki.wikipages LEFT OUTER JOIN wiki.wiki_images USING(image) WHERE lang='en' AND key=? AND value IS NULL LIMIT 1", r18n.locale.code, @key, @key).
+ execute() do |row|
+ @image_url = build_image_url(row)
+ end
+
@prevalent_values = @db.select("SELECT value, count_#{@filter_type} AS count FROM tags").
condition('key=?', @key).
condition('count > ?', @count_all_values * 0.02).
@@ -107,8 +123,14 @@ class Taginfo < Sinatra::Base
@desc = "<span title='#{ t.pages.tag.description_from_wiki }' tipsy='w'>#{ @desc }</span"
end
+ @db.select("SELECT width, height, thumb_url_prefix, thumb_url_suffix FROM wiki.wikipages LEFT OUTER JOIN wiki.wiki_images USING(image) WHERE lang=? AND key=? AND value=? UNION SELECT width, height, thumb_url_prefix, thumb_url_suffix FROM wiki.wikipages LEFT OUTER JOIN wiki.wiki_images USING(image) WHERE lang='en' AND key=? AND value=? LIMIT 1", r18n.locale.code, @key, @value, @key, @value).
+ execute() do |row|
+ @image_url = build_image_url(row)
+ end
+
javascript "#{ r18n.locale.code }/tag"
erb :tag
end
end
+
diff --git a/web/lib/utils.rb b/web/lib/utils.rb
index 20a4dab..2549b57 100644
--- a/web/lib/utils.rb
+++ b/web/lib/utils.rb
@@ -184,7 +184,15 @@ def get_wiki_result(res)
:language_en => h(::Language[row['lang']].english_name),
:title => h(row['title']),
:description => h(row['description']),
- :image => h(row['image']),
+ :image => {
+ :title => h(row['image']),
+ :width => row['width'].to_i,
+ :height => row['height'].to_i,
+ :mime => h(row['mime']),
+ :image_url => h(row['image_url']),
+ :thumb_url_prefix => h(row['thumb_url_prefix']),
+ :thumb_url_suffix => h(row['thumb_url_suffix'])
+ },
:on_node => row['on_node'].to_i == 1,
:on_way => row['on_way'].to_i == 1,
:on_area => row['on_area'].to_i == 1,
diff --git a/web/views/key.erb b/web/views/key.erb
index 14f952a..c51af26 100644
--- a/web/views/key.erb
+++ b/web/views/key.erb
@@ -33,6 +33,11 @@
<p><%= t.pages.key.overview.distribution_of_values %></p>
<div class="canvas" id="canvas-values"></div>
</div>
+<% if @image_url %>
+ <div style="float: right; padding: 0 20px 20px 20px;">
+ <img src="<%= @image_url %>" style="border: 1px solid #a0a0a0; border-radius: 4px; padding: 1px;" alt=""/>
+ </div>
+<% end %>
<h2><%= t.taginfo.overview %></h2>
<table id="grid-overview">
</table>
diff --git a/web/views/tag.erb b/web/views/tag.erb
index 70ebd8c..243954d 100644
--- a/web/views/tag.erb
+++ b/web/views/tag.erb
@@ -28,6 +28,11 @@
</ul>
<div id="overview">
<h2><%= t.taginfo.overview %></h2>
+<% if @image_url %>
+ <div style="float: right;">
+ <img src="<%= @image_url %>" style="border: 1px solid #a0a0a0; border-radius: 4px; padding: 1px;" alt=""/>
+ </div>
+<% end %>
<table id="grid-overview">
</table>
</div>
diff --git a/web/viewsjs/key.js.erb b/web/viewsjs/key.js.erb
index 8fc4a04..e2bdcd3 100644
--- a/web/viewsjs/key.js.erb
+++ b/web/viewsjs/key.js.erb
@@ -104,7 +104,7 @@ var create_flexigrid_for = {
print_language(row.lang, row.language, row.language_en),
print_wiki_link(row.title),
row.description,
- row.image == '' ? empty('<%= misc.no_image %>') : hover_expand(print_wiki_link(row.image)),
+ row.image.title ? hover_expand(print_wiki_link(row.image.title)) : empty('<%= misc.no_image %>'),
print_type_icon('node', row.on_node) +
print_type_icon('way', row.on_way) +
print_type_icon('area', row.on_area) +
diff --git a/web/viewsjs/tag.js.erb b/web/viewsjs/tag.js.erb
index 88e1e41..c98d7c5 100644
--- a/web/viewsjs/tag.js.erb
+++ b/web/viewsjs/tag.js.erb
@@ -76,7 +76,7 @@ var create_flexigrid_for = {
print_language(row.lang, row.language, row.language_en),
print_wiki_link(row.title),
row.description,
- row.image == '' ? empty('<%= misc.no_image %>') : hover_expand(print_wiki_link(row.image)),
+ row.image.title ? hover_expand(print_wiki_link(row.image.title)) : empty('<%= misc.no_image %>'),
print_type_icon('node', row.on_node) +
print_type_icon('way', row.on_way) +
print_type_icon('area', row.on_area) +