From 5d967455821f381c9e9ce65f01685bd051e476e1 Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 22 May 2024 21:31:31 -0500 Subject: [PATCH] fandom: treat links to wiki pages as bad sources. Treat sources that link to the wiki page containing the image, rather than to the image itself, as bad sources. This is a good source because it identifies the actual image used: https://typemoon.fandom.com/wiki/Astolfo?file=Memories_of_Trifas.png This is a bad source because it doesn't identify which of the many images on the page was used: https://typemoon.fandom.com/wiki/Astolfo Wiki pages are bad sources because sometimes they can have hundreds of images and it can be hard to tell which image the post came from. Wikis can also be edited, so the image may no longer even be on the page. Or the image could be used on multiple pages, so it can't necessarily be tied to a single wiki page. --- app/logical/source/url/fandom.rb | 4 ++++ test/unit/sources/fandom_test.rb | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/app/logical/source/url/fandom.rb b/app/logical/source/url/fandom.rb index 5f377bd4b..59ba9bd36 100644 --- a/app/logical/source/url/fandom.rb +++ b/app/logical/source/url/fandom.rb @@ -150,6 +150,10 @@ def image_url? domain == "nocookie.net" end + def bad_source? + !image_url? && file.blank? + end + def full_image_url if wiki_db_name.present? && file.present? subdir = Digest::MD5.hexdigest(file) diff --git a/test/unit/sources/fandom_test.rb b/test/unit/sources/fandom_test.rb index 930f98bf0..778797dd1 100644 --- a/test/unit/sources/fandom_test.rb +++ b/test/unit/sources/fandom_test.rb @@ -158,6 +158,17 @@ class FandomTest < ActiveSupport::TestCase assert(Source::URL.profile_url?("https://typemoon.fandom.com")) assert(Source::URL.profile_url?("https://genshin-impact.fandom.com/pt-br")) end + + should "identify bad sources correctly" do + assert_not(Source::URL.parse("https://vignette.wikia.nocookie.net/valkyriecrusade/images/c/c5/Crimson_Hatsune_H.png/revision/latest?cb=20180702031954").bad_source?) + assert_not(Source::URL.parse("https://typemoon.fandom.com/wiki/Tamamo-no-Mae?file=Caster_Extra_Takeuchi_design_1.png").bad_source?) + assert_not(Source::URL.parse("https://typemoon.fandom.com/wiki/File:Memories_of_Trifas.png").bad_source?) + + assert(Source::URL.parse("https://typemoon.fandom.com").bad_source?) + assert(Source::URL.parse("https://typemoon.fandom.com/wiki/User:Lemostr00").bad_source?) + assert(Source::URL.parse("https://typemoon.fandom.com/f/p/4400000000000077950").bad_source?) + assert(Source::URL.parse("https://genshin-impact.fandom.com/wiki/Ningguang/Gallery").bad_source?) + end end end end