From 0793beded9c13e43e6482bc08928e2765ff84b79 Mon Sep 17 00:00:00 2001
From: evazion
Date: Thu, 23 Mar 2017 02:43:55 -0500
Subject: [PATCH 1/5] alias_and_implication_list: refactor alias/implication
lookup.
Add alias and implications associations to Tag. Use them in
alias_and_implication list instead of duplicating the alias/implication
lookup code.
---
app/helpers/artists_helper.rb | 7 +------
app/helpers/tags_helper.rb | 20 +++++++++++---------
app/helpers/wiki_pages_helper.rb | 7 +------
app/models/tag.rb | 4 ++++
app/presenters/wiki_page_presenter.rb | 16 ----------------
5 files changed, 17 insertions(+), 37 deletions(-)
diff --git a/app/helpers/artists_helper.rb b/app/helpers/artists_helper.rb
index d9490d71e..cf1e7198d 100644
--- a/app/helpers/artists_helper.rb
+++ b/app/helpers/artists_helper.rb
@@ -1,11 +1,6 @@
module ArtistsHelper
def artist_alias_and_implication_list(artist)
- consequent_tag_aliases = TagAlias.where("status in ('active', 'processing') and consequent_name = ?", artist.name)
- antecedent_tag_alias = TagAlias.where("status in ('active', 'processing') and antecedent_name = ?", artist.name).first
- consequent_tag_implications = TagImplication.where("status in ('active', 'processing') and consequent_name = ?", artist.name)
- antecedent_tag_implications = TagImplication.where("status in ('active', 'processing') and antecedent_name = ?", artist.name)
-
- alias_and_implication_list(antecedent_tag_alias, consequent_tag_aliases, antecedent_tag_implications, consequent_tag_implications)
+ alias_and_implication_list(artist.tag)
end
def link_to_artist(name)
diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb
index 60788bb8d..990f479fb 100644
--- a/app/helpers/tags_helper.rb
+++ b/app/helpers/tags_helper.rb
@@ -1,28 +1,30 @@
module TagsHelper
- def alias_and_implication_list(antecedent_alias, consequent_aliases, antecedent_implications, consequent_implications)
+ def alias_and_implication_list(tag)
+ return "" if tag.nil?
+
html = ""
- if antecedent_alias
+ if tag.antecedent_alias
html << "This tag has been aliased to "
- html << link_to(antecedent_alias.consequent_name, show_or_new_wiki_pages_path(:title => antecedent_alias.consequent_name))
+ html << link_to(tag.antecedent_alias.consequent_name, show_or_new_wiki_pages_path(:title => tag.antecedent_alias.consequent_name))
html << ".
"
end
- if consequent_aliases.any?
+ if tag.consequent_aliases.any?
html << "The following tags are aliased to this tag: "
- html << raw(consequent_aliases.map {|x| link_to(x.antecedent_name, show_or_new_wiki_pages_path(:title => x.antecedent_name))}.join(", "))
+ html << raw(tag.consequent_aliases.map {|x| link_to(x.antecedent_name, show_or_new_wiki_pages_path(:title => x.antecedent_name))}.join(", "))
html << ".
"
end
- if antecedent_implications.any?
+ if tag.antecedent_implications.any?
html << "This tag implicates "
- html << raw(antecedent_implications.map {|x| link_to(x.consequent_name, show_or_new_wiki_pages_path(:title => x.consequent_name))}.join(", "))
+ html << raw(tag.antecedent_implications.map {|x| link_to(x.consequent_name, show_or_new_wiki_pages_path(:title => x.consequent_name))}.join(", "))
html << ".
"
end
- if consequent_implications.any?
+ if tag.consequent_implications.any?
html << "The following tags implicate this tag: "
- html << raw(consequent_implications.map {|x| link_to(x.antecedent_name, show_or_new_wiki_pages_path(:title => x.antecedent_name))}.join(", "))
+ html << raw(tag.consequent_implications.map {|x| link_to(x.antecedent_name, show_or_new_wiki_pages_path(:title => x.antecedent_name))}.join(", "))
html << ".
"
end
diff --git a/app/helpers/wiki_pages_helper.rb b/app/helpers/wiki_pages_helper.rb
index 24f1c8149..3e55ee9d9 100644
--- a/app/helpers/wiki_pages_helper.rb
+++ b/app/helpers/wiki_pages_helper.rb
@@ -1,11 +1,6 @@
module WikiPagesHelper
def wiki_page_alias_and_implication_list(wiki_page)
- antecedent_alias = wiki_page.presenter.antecedent_tag_alias
- consequent_aliases = wiki_page.presenter.consequent_tag_aliases
- antecedent_implications = wiki_page.presenter.antecedent_tag_implications
- consequent_implications = wiki_page.presenter.consequent_tag_implications
-
- alias_and_implication_list(antecedent_alias, consequent_aliases, antecedent_implications, consequent_implications)
+ alias_and_implication_list(wiki_page.tag)
end
def wiki_page_post_previews(wiki_page)
diff --git a/app/models/tag.rb b/app/models/tag.rb
index 5c8402e6d..f1e9a4fcf 100644
--- a/app/models/tag.rb
+++ b/app/models/tag.rb
@@ -5,6 +5,10 @@ class Tag < ActiveRecord::Base
attr_accessible :category, :as => [:moderator, :janitor, :gold, :platinum, :member, :anonymous, :default, :builder, :admin]
attr_accessible :is_locked, :as => [:moderator, :admin]
has_one :wiki_page, :foreign_key => "title", :primary_key => "name"
+ has_one :antecedent_alias, lambda {active}, :class_name => "TagAlias", :foreign_key => "antecedent_name", :primary_key => "name"
+ has_many :consequent_aliases, lambda {active}, :class_name => "TagAlias", :foreign_key => "consequent_name", :primary_key => "name"
+ has_many :antecedent_implications, lambda {active}, :class_name => "TagImplication", :foreign_key => "antecedent_name", :primary_key => "name"
+ has_many :consequent_implications, lambda {active}, :class_name => "TagImplication", :foreign_key => "consequent_name", :primary_key => "name"
validates :name, uniqueness: true, tag_name: true, on: :create
diff --git a/app/presenters/wiki_page_presenter.rb b/app/presenters/wiki_page_presenter.rb
index 95d59aafe..c389b914d 100644
--- a/app/presenters/wiki_page_presenter.rb
+++ b/app/presenters/wiki_page_presenter.rb
@@ -13,22 +13,6 @@ class WikiPagePresenter
DText.strip(excerpt.to_s)
end
- def consequent_tag_aliases
- @consequent_tag_aliases ||= TagAlias.where("status in ('active', 'processing') and consequent_name = ?", wiki_page.title)
- end
-
- def antecedent_tag_alias
- @antecedent_tag_alias ||= TagAlias.where("status in ('active', 'processing') and antecedent_name = ?", wiki_page.title).first
- end
-
- def consequent_tag_implications
- @consequent_tag_implications ||= TagImplication.where("status in ('active', 'processing') and consequent_name = ?", wiki_page.title)
- end
-
- def antecedent_tag_implications
- @antecedent_tag_implications ||= TagImplication.where("status in ('active', 'processing') and antecedent_name = ?", wiki_page.title)
- end
-
# Produce a formatted page that shows the difference between two versions of a page.
def diff(other_version)
pattern = Regexp.new('(?:<.+?>)|(?:[0-9_A-Za-z\x80-\xff]+[\x09\x20]?)|(?:[ \t]+)|(?:\r?\n)|(?:.+?)')
From 4fde2a26fb215cc067f146a5f4824f6ed7eb82c5 Mon Sep 17 00:00:00 2001
From: evazion
Date: Thu, 23 Mar 2017 02:48:03 -0500
Subject: [PATCH 2/5] post.rb: handle automatic *_(cosplay) tags in
TagImplication.
---
app/models/post.rb | 5 +----
app/models/tag_implication.rb | 6 ++++++
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/app/models/post.rb b/app/models/post.rb
index cb14a1792..d8053308a 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -636,6 +636,7 @@ class Post < ActiveRecord::Base
normalized_tags = %w(tagme) if normalized_tags.empty?
normalized_tags = TagAlias.to_aliased(normalized_tags)
normalized_tags = add_automatic_tags(normalized_tags)
+ normalized_tags = normalized_tags + TagImplication.automatic_tags_for(normalized_tags)
normalized_tags = TagImplication.with_descendants(normalized_tags)
normalized_tags = normalized_tags.compact
normalized_tags.sort!
@@ -705,10 +706,6 @@ class Post < ActiveRecord::Base
tags << "ugoira"
end
- characters = tags.grep(/\A(.+)_\(cosplay\)\Z/) { $1 }
- tags += characters
- tags << "cosplay" if characters.present?
-
return tags
end
diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb
index 96d2a58b3..cae1ff91b 100644
--- a/app/models/tag_implication.rb
+++ b/app/models/tag_implication.rb
@@ -32,6 +32,12 @@ class TagImplication < ActiveRecord::Base
def with_descendants(names)
(names + where("antecedent_name in (?) and status in (?)", names, ["active", "processing"]).map(&:descendant_names_array)).flatten.uniq
end
+
+ def automatic_tags_for(names)
+ tags = names.grep(/\A(.+)_\(cosplay\)\Z/) { $1 }
+ tags << "cosplay" if tags.present?
+ tags.uniq
+ end
end
def descendants
From 267d70bd52329b2b82f5adf756c02bab380476d2 Mon Sep 17 00:00:00 2001
From: evazion
Date: Thu, 23 Mar 2017 02:49:17 -0500
Subject: [PATCH 3/5] Fix #2931: mention automated implications on *_(cosplay)
wikis.
---
app/helpers/tags_helper.rb | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb
index 990f479fb..6497c80af 100644
--- a/app/helpers/tags_helper.rb
+++ b/app/helpers/tags_helper.rb
@@ -16,6 +16,13 @@ module TagsHelper
html << ".
"
end
+ automatic_tags = TagImplication.automatic_tags_for([tag.name])
+ if automatic_tags.any?
+ html << "This tag automatically adds "
+ html << raw(automatic_tags.map {|x| link_to(x, show_or_new_wiki_pages_path(:title => x))}.join(", "))
+ html << ".
"
+ end
+
if tag.antecedent_implications.any?
html << "This tag implicates "
html << raw(tag.antecedent_implications.map {|x| link_to(x.consequent_name, show_or_new_wiki_pages_path(:title => x.consequent_name))}.join(", "))
From 8918e301b4f4a622703c0933bff7f5f8b5e625b0 Mon Sep 17 00:00:00 2001
From: evazion
Date: Thu, 23 Mar 2017 03:18:41 -0500
Subject: [PATCH 4/5] alias_and_implication_list: add help links for
aliases/implications.
---
app/helpers/tags_helper.rb | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb
index 6497c80af..e1979f317 100644
--- a/app/helpers/tags_helper.rb
+++ b/app/helpers/tags_helper.rb
@@ -7,32 +7,32 @@ module TagsHelper
if tag.antecedent_alias
html << "This tag has been aliased to "
html << link_to(tag.antecedent_alias.consequent_name, show_or_new_wiki_pages_path(:title => tag.antecedent_alias.consequent_name))
- html << ".
"
+ html << " (#{link_to "learn more", wiki_pages_path(title: "help:tag_aliases")}).
"
end
if tag.consequent_aliases.any?
html << "The following tags are aliased to this tag: "
html << raw(tag.consequent_aliases.map {|x| link_to(x.antecedent_name, show_or_new_wiki_pages_path(:title => x.antecedent_name))}.join(", "))
- html << ".
"
+ html << " (#{link_to "learn more", wiki_pages_path(title: "help:tag_aliases")})."
end
automatic_tags = TagImplication.automatic_tags_for([tag.name])
if automatic_tags.any?
html << "This tag automatically adds "
html << raw(automatic_tags.map {|x| link_to(x, show_or_new_wiki_pages_path(:title => x))}.join(", "))
- html << ".
"
+ html << " (#{link_to "learn more", wiki_pages_path(title: "help:autotags")})."
end
if tag.antecedent_implications.any?
html << "This tag implicates "
html << raw(tag.antecedent_implications.map {|x| link_to(x.consequent_name, show_or_new_wiki_pages_path(:title => x.consequent_name))}.join(", "))
- html << ".
"
+ html << " (#{link_to "learn more", wiki_pages_path(title: "help:tag_implications")})."
end
if tag.consequent_implications.any?
html << "The following tags implicate this tag: "
html << raw(tag.consequent_implications.map {|x| link_to(x.antecedent_name, show_or_new_wiki_pages_path(:title => x.antecedent_name))}.join(", "))
- html << ".
"
+ html << " (#{link_to "learn more", wiki_pages_path(title: "help:tag_implications")})."
end
html.html_safe
From 90cd029f6f89c332c666c009fea8a482af0a397f Mon Sep 17 00:00:00 2001
From: evazion
Date: Thu, 23 Mar 2017 03:54:42 -0500
Subject: [PATCH 5/5] wiki excerpts: show alias/implication lists even for tags
without a wiki.
---
app/logical/post_sets/post.rb | 5 +++++
app/views/posts/partials/index/_excerpt.html.erb | 2 ++
2 files changed, 7 insertions(+)
diff --git a/app/logical/post_sets/post.rb b/app/logical/post_sets/post.rb
index 071e95f62..5e2247a43 100644
--- a/app/logical/post_sets/post.rb
+++ b/app/logical/post_sets/post.rb
@@ -37,6 +37,11 @@ module PostSets
end
end
+ def tag
+ return nil if !is_single_tag?
+ @tag ||= Tag.find_by(name: Tag.normalize_name(tag_string))
+ end
+
def has_artist?
is_single_tag? && artist.present? && artist.visible?
end
diff --git a/app/views/posts/partials/index/_excerpt.html.erb b/app/views/posts/partials/index/_excerpt.html.erb
index a12807bee..3acf78220 100644
--- a/app/views/posts/partials/index/_excerpt.html.erb
+++ b/app/views/posts/partials/index/_excerpt.html.erb
@@ -82,6 +82,8 @@
<% else %>
<% if post_set.tag_string.present? %>
There is currently no wiki page for the tag "<%= post_set.tag_string %>". You can <%= link_to "create one", new_wiki_page_path(:wiki_page => {:title => post_set.tag_string}) %>.
+
+ <%= alias_and_implication_list(post_set.tag) %>
<% end %>
<% end %>