diff options
-rwxr-xr-x | sources/wiki/get_image_info.rb | 1 | ||||
-rwxr-xr-x | sources/wiki/get_wiki_data.rb | 23 | ||||
-rw-r--r-- | web/lib/ui/keys_tags.rb | 14 | ||||
-rw-r--r-- | web/lib/ui/relation.rb | 5 | ||||
-rw-r--r-- | web/lib/utils.rb | 14 | ||||
-rw-r--r-- | web/views/relation.erb | 5 |
6 files changed, 40 insertions, 22 deletions
diff --git a/sources/wiki/get_image_info.rb b/sources/wiki/get_image_info.rb index caaf952..1593bbe 100755 --- a/sources/wiki/get_image_info.rb +++ b/sources/wiki/get_image_info.rb @@ -80,6 +80,7 @@ until image_titles.empty? if normalized normalized.each do |n| db.execute('UPDATE wikipages SET image=? WHERE image=?', n['to'], n['from']) + db.execute('UPDATE relation_pages SET image=? WHERE image=?', n['to'], n['from']) end end diff --git a/sources/wiki/get_wiki_data.rb b/sources/wiki/get_wiki_data.rb index 2803d33..36f0fab 100755 --- a/sources/wiki/get_wiki_data.rb +++ b/sources/wiki/get_wiki_data.rb @@ -142,6 +142,16 @@ class WikiPage @parsed = false end + def set_image(ititle, db) + if !ititle.nil? && ititle.match(%r{^(file|image):(.*)$}i) + @image = "File:#{$2}" + else + puts "invalid image: page='#{title}' image='#{ititle}'" + db.execute('INSERT INTO invalid_image_titles (page_title, image_title) VALUES (?, ?)', title, ititle) + @image = '' + end + end + def parse_template(template, db) puts "Template: #{template.name} [#{template.parameters.join(',')}] #{template.named_parameters.inspect}" if template.name == 'Key' || template.name == 'Tag' @@ -165,14 +175,7 @@ class WikiPage end end if template.named_parameters['image'] - ititle = template.named_parameters['image'][0] - if !ititle.nil? && ititle.match(%r{^(file|image):(.*)$}i) - @image = "File:#{$2}" - else - puts "invalid image: page='#{title}' image='#{ititle}'" - db.execute('INSERT INTO invalid_image_titles (page_title, image_title) VALUES (?, ?)', title, ititle) - @image = '' - end + set_image(template.named_parameters['image'][0], db) end if template.named_parameters['group'] @group = template.named_parameters['group'][0] @@ -280,6 +283,10 @@ class RelationPage < WikiPage end end + def set_image(ititle, db) + @image = "File:#{ititle}" + end + def insert(db) db.execute( "INSERT INTO relation_pages (lang, rtype, title, body, tgroup, type, has_templ, parsed, description, image, tags_linked) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", diff --git a/web/lib/ui/keys_tags.rb b/web/lib/ui/keys_tags.rb index 9d9653f..d944e91 100644 --- a/web/lib/ui/keys_tags.rb +++ b/web/lib/ui/keys_tags.rb @@ -1,20 +1,6 @@ # 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 <= MAX_IMAGE_WIDTH - return row['image_url'] - end - 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 diff --git a/web/lib/ui/relation.rb b/web/lib/ui/relation.rb index 1e1fe71..5801ae2 100644 --- a/web/lib/ui/relation.rb +++ b/web/lib/ui/relation.rb @@ -21,6 +21,11 @@ class Taginfo < Sinatra::Base @desc = "<span title='#{ t.pages.relation.description_from_wiki }' tipsy='w'>#{ @desc }</span>" end + @db.select("SELECT width, height, image_url, thumb_url_prefix, thumb_url_suffix FROM wiki.relation_pages LEFT OUTER JOIN wiki.wiki_images USING(image) WHERE lang=? AND rtype=? UNION SELECT width, height, image_url, thumb_url_prefix, thumb_url_suffix FROM wiki.relation_pages LEFT OUTER JOIN wiki.wiki_images USING(image) WHERE lang='en' AND rtype=? LIMIT 1", r18n.locale.code, @rtype, @rtype). + execute() do |row| + @image_url = build_image_url(row) + end + @count_relation_roles = @db.count('relation_roles'). condition("rtype=?", rtype). get_first_value().to_i diff --git a/web/lib/utils.rb b/web/lib/utils.rb index 875584c..343c6df 100644 --- a/web/lib/utils.rb +++ b/web/lib/utils.rb @@ -200,3 +200,17 @@ def no_paging_results(array) ]; end +MAX_IMAGE_WIDTH = 300 + +def build_image_url(row) + w = row['width'].to_i + h = row['height'].to_i + if w <= MAX_IMAGE_WIDTH + return row['image_url'] + end + 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 + diff --git a/web/views/relation.erb b/web/views/relation.erb index d1aea0d..a92c5df 100644 --- a/web/views/relation.erb +++ b/web/views/relation.erb @@ -17,6 +17,11 @@ </ul> <div id="overview"> <h2><%= t.pages.relation.overview.title %></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> <p><%= t.pages.relation.overview.see_also %>: type=<span id="taglink"></span></p> |