From ab4f955593dfc671af4a4e75791324e0c205d64a Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Fri, 18 Jan 2013 20:08:39 +0100 Subject: Add support for relation type images --- sources/wiki/get_image_info.rb | 1 + sources/wiki/get_wiki_data.rb | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'sources') 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", -- cgit v1.2.3