Implentation for #2141
This commit is contained in:
@@ -125,6 +125,7 @@
|
|||||||
this.build_recent_and_frequent($dest);
|
this.build_recent_and_frequent($dest);
|
||||||
|
|
||||||
$dest.append(this.build_html(query, related_tags, "general"));
|
$dest.append(this.build_html(query, related_tags, "general"));
|
||||||
|
this.build_translated($dest);
|
||||||
if (wiki_page_tags.length) {
|
if (wiki_page_tags.length) {
|
||||||
$dest.append(Danbooru.RelatedTag.build_html("wiki:" + query, wiki_page_tags, "wiki"));
|
$dest.append(Danbooru.RelatedTag.build_html("wiki:" + query, wiki_page_tags, "wiki"));
|
||||||
}
|
}
|
||||||
@@ -173,6 +174,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Danbooru.RelatedTag.build_translated = function($dest) {
|
||||||
|
if (Danbooru.RelatedTag.translated_tags && Danbooru.RelatedTag.translated_tags.length) {
|
||||||
|
$dest.append(this.build_html("translated", Danbooru.RelatedTag.translated_tags, "translated"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Danbooru.RelatedTag.build_html = function(query, related_tags, name, is_wide_column) {
|
Danbooru.RelatedTag.build_html = function(query, related_tags, name, is_wide_column) {
|
||||||
if (query === null || query === "") {
|
if (query === null || query === "") {
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
@@ -67,6 +67,9 @@
|
|||||||
$("#source-artist").html('<a href="' + data.profile_url + '">' + data.artist_name + '</a>');
|
$("#source-artist").html('<a href="' + data.profile_url + '">' + data.artist_name + '</a>');
|
||||||
$("#source-tags").html(tag_html);
|
$("#source-tags").html(tag_html);
|
||||||
|
|
||||||
|
Danbooru.RelatedTag.translated_tags = data.translated_tags;
|
||||||
|
Danbooru.RelatedTag.build_all();
|
||||||
|
|
||||||
var new_artist_link = '<a target="_blank" href="/artists/new?name=' + data.unique_id + '&other_names=' + data.artist_name + '&urls=' + encodeURIComponent(data.profile_url) + '+' + encodeURIComponent(data.image_url) + '">new</a>';
|
var new_artist_link = '<a target="_blank" href="/artists/new?name=' + data.unique_id + '&other_names=' + data.artist_name + '&urls=' + encodeURIComponent(data.profile_url) + '+' + encodeURIComponent(data.image_url) + '">new</a>';
|
||||||
|
|
||||||
$("#source-record").html(new_artist_link);
|
$("#source-record").html(new_artist_link);
|
||||||
|
|||||||
@@ -27,4 +27,12 @@ div#c-wiki-pages {
|
|||||||
margin-left: 15em;
|
margin-left: 15em;
|
||||||
padding-left: 1em;
|
padding-left: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hint {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.other-name {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,4 +48,24 @@ module WikiPageVersionsHelper
|
|||||||
|
|
||||||
output.join.gsub(/\r?\n/, '<br>').html_safe
|
output.join.gsub(/\r?\n/, '<br>').html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def wiki_page_other_names_diff(thispage, otherpage)
|
||||||
|
new_names = otherpage.other_names_array
|
||||||
|
old_names = thispage.other_names_array
|
||||||
|
added_names = new_names - old_names
|
||||||
|
removed_names = old_names - new_names
|
||||||
|
unchanged_names = new_names & old_names
|
||||||
|
|
||||||
|
html = []
|
||||||
|
added_names.each do |name|
|
||||||
|
html << '<ins>' + name + '</ins>'
|
||||||
|
end
|
||||||
|
removed_names.each do |name|
|
||||||
|
html << '<del>' + name + '</del>'
|
||||||
|
end
|
||||||
|
unchanged_names.each do |name|
|
||||||
|
html << '<span>' + name + '</span>'
|
||||||
|
end
|
||||||
|
return html.join(" ").html_safe
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -47,4 +47,9 @@ module WikiPagesHelper
|
|||||||
|
|
||||||
html.html_safe
|
html.html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def wiki_page_other_names_list(wiki_page)
|
||||||
|
names_html = wiki_page.other_names_array.map{|name| content_tag("span", name, :class => "other-name")}
|
||||||
|
names_html.join(", ").html_safe
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,12 +18,17 @@ module Sources
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def translated_tags
|
||||||
|
WikiPage.other_names_match(tags.map(&:first)).map{|wiki_page| [wiki_page.title, wiki_page.category_name]}
|
||||||
|
end
|
||||||
|
|
||||||
def to_json
|
def to_json
|
||||||
return {
|
return {
|
||||||
:artist_name => artist_name,
|
:artist_name => artist_name,
|
||||||
:profile_url => profile_url,
|
:profile_url => profile_url,
|
||||||
:image_url => image_url,
|
:image_url => image_url,
|
||||||
:tags => tags,
|
:tags => tags,
|
||||||
|
:translated_tags => translated_tags,
|
||||||
:danbooru_name => artist_record.try(:first).try(:name),
|
:danbooru_name => artist_record.try(:first).try(:name),
|
||||||
:danbooru_id => artist_record.try(:first).try(:id),
|
:danbooru_id => artist_record.try(:first).try(:id),
|
||||||
:unique_id => unique_id
|
:unique_id => unique_id
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class WikiPage < ActiveRecord::Base
|
|||||||
validates_presence_of :title
|
validates_presence_of :title
|
||||||
validate :validate_locker_is_janitor
|
validate :validate_locker_is_janitor
|
||||||
validate :validate_not_locked
|
validate :validate_not_locked
|
||||||
attr_accessible :title, :body, :is_locked
|
attr_accessible :title, :body, :is_locked, :other_names
|
||||||
has_one :tag, :foreign_key => "name", :primary_key => "title"
|
has_one :tag, :foreign_key => "name", :primary_key => "title"
|
||||||
has_one :artist, lambda {where(:is_active => true)}, :foreign_key => "name", :primary_key => "title"
|
has_one :artist, lambda {where(:is_active => true)}, :foreign_key => "name", :primary_key => "title"
|
||||||
has_many :versions, lambda {order("wiki_page_versions.id ASC")}, :class_name => "WikiPageVersion", :dependent => :destroy
|
has_many :versions, lambda {order("wiki_page_versions.id ASC")}, :class_name => "WikiPageVersion", :dependent => :destroy
|
||||||
@@ -32,6 +32,12 @@ class WikiPage < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def other_names_match(names)
|
||||||
|
names = names.map{|name| name.to_escaped_for_tsquery}
|
||||||
|
query_sql = names.join(" | ")
|
||||||
|
where("other_names_index @@ to_tsquery('danbooru', E?)", query_sql)
|
||||||
|
end
|
||||||
|
|
||||||
def search(params = {})
|
def search(params = {})
|
||||||
q = where("true")
|
q = where("true")
|
||||||
params = {} if params.blank?
|
params = {} if params.blank?
|
||||||
@@ -48,6 +54,10 @@ class WikiPage < ActiveRecord::Base
|
|||||||
q = q.body_matches(params[:body_matches])
|
q = q.body_matches(params[:body_matches])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if params[:other_names_match].present?
|
||||||
|
q = q.other_names_match(params[:other_names_match].split(" "))
|
||||||
|
end
|
||||||
|
|
||||||
if params[:creator_name].present?
|
if params[:creator_name].present?
|
||||||
q = q.where("creator_id = (select _.id from users _ where lower(_.name) = ?)", params[:creator_name].tr(" ", "_").mb_chars.downcase)
|
q = q.where("creator_id = (select _.id from users _ where lower(_.name) = ?)", params[:creator_name].tr(" ", "_").mb_chars.downcase)
|
||||||
end
|
end
|
||||||
@@ -113,6 +123,7 @@ class WikiPage < ActiveRecord::Base
|
|||||||
self.title = version.title
|
self.title = version.title
|
||||||
self.body = version.body
|
self.body = version.body
|
||||||
self.is_locked = version.is_locked
|
self.is_locked = version.is_locked
|
||||||
|
self.other_names = version.other_names
|
||||||
end
|
end
|
||||||
|
|
||||||
def revert_to!(version)
|
def revert_to!(version)
|
||||||
@@ -141,7 +152,8 @@ class WikiPage < ActiveRecord::Base
|
|||||||
prev.update_attributes(
|
prev.update_attributes(
|
||||||
:title => title,
|
:title => title,
|
||||||
:body => body,
|
:body => body,
|
||||||
:is_locked => is_locked
|
:is_locked => is_locked,
|
||||||
|
:other_names => other_names
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -156,12 +168,13 @@ class WikiPage < ActiveRecord::Base
|
|||||||
:updater_ip_addr => CurrentUser.ip_addr,
|
:updater_ip_addr => CurrentUser.ip_addr,
|
||||||
:title => title,
|
:title => title,
|
||||||
:body => body,
|
:body => body,
|
||||||
:is_locked => is_locked
|
:is_locked => is_locked,
|
||||||
|
:other_names => other_names
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_version
|
def create_version
|
||||||
if title_changed? || body_changed? || is_locked_changed?
|
if title_changed? || body_changed? || is_locked_changed? || other_names_changed?
|
||||||
if merge_version?
|
if merge_version?
|
||||||
merge_version
|
merge_version
|
||||||
else
|
else
|
||||||
@@ -207,4 +220,8 @@ class WikiPage < ActiveRecord::Base
|
|||||||
def visible?
|
def visible?
|
||||||
artist.blank? || !artist.is_banned? || CurrentUser.user.is_janitor?
|
artist.blank? || !artist.is_banned? || CurrentUser.user.is_janitor?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def other_names_array
|
||||||
|
other_names.to_s.scan(/\S+/)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ class WikiPageVersion < ActiveRecord::Base
|
|||||||
belongs_to :wiki_page
|
belongs_to :wiki_page
|
||||||
belongs_to :updater, :class_name => "User"
|
belongs_to :updater, :class_name => "User"
|
||||||
belongs_to :artist
|
belongs_to :artist
|
||||||
attr_accessible :wiki_page_id, :title, :body, :is_locked, :updater_id, :updater_ip_addr, :version
|
attr_accessible :wiki_page_id, :title, :body, :is_locked, :updater_id, :updater_ip_addr, :version, :other_names
|
||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
def for_user(user_id)
|
def for_user(user_id)
|
||||||
@@ -43,4 +43,7 @@ class WikiPageVersion < ActiveRecord::Base
|
|||||||
artist.blank? || !artist.is_banned? || CurrentUser.user.is_janitor?
|
artist.blank? || !artist.is_banned? || CurrentUser.user.is_janitor?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def other_names_array
|
||||||
|
other_names.to_s.scan(/\S+/)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
<p>Showing differences between <%= compact_time @thispage.created_at %> (<%= link_to_user @thispage.updater %>) and <%= compact_time @otherpage.created_at %> (<%= link_to_user @otherpage.updater %>)</p>
|
<p>Showing differences between <%= compact_time @thispage.created_at %> (<%= link_to_user @thispage.updater %>) and <%= compact_time @otherpage.created_at %> (<%= link_to_user @otherpage.updater %>)</p>
|
||||||
|
|
||||||
|
<p><%= wiki_page_other_names_diff(@thispage, @otherpage) %></p>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<%= wiki_page_diff(@thispage, @otherpage) %>
|
<%= wiki_page_diff(@thispage, @otherpage) %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -7,6 +7,10 @@
|
|||||||
|
|
||||||
<div id="wiki-page-body" class="dtext prose">
|
<div id="wiki-page-body" class="dtext prose">
|
||||||
<% if @wiki_page_version.visible? %>
|
<% if @wiki_page_version.visible? %>
|
||||||
|
<% if @wiki_page_version.other_names.present? %>
|
||||||
|
<p><%= wiki_page_other_names_list(@wiki_page_version) %></p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<%= format_text(@wiki_page_version.body) %>
|
<%= format_text(@wiki_page_version.body) %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<p>This artist has requested removal of their information.</p>
|
<p>This artist has requested removal of their information.</p>
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
<%= f.input :title, :as => :string %>
|
<%= f.input :title, :as => :string %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<%= f.input :other_names, :as => :text, :hint => "Names used for this tag on other sites such as Pixiv. Separate with spaces." %>
|
||||||
|
|
||||||
<%= dtext_field "wiki_page", "body" %>
|
<%= dtext_field "wiki_page", "body" %>
|
||||||
|
|
||||||
<% if CurrentUser.user.is_janitor? %>
|
<% if CurrentUser.user.is_janitor? %>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
<%= search_field "title", :hint => "Use * for wildcard searches" %>
|
<%= search_field "title", :hint => "Use * for wildcard searches" %>
|
||||||
<%= search_field "creator_name" %>
|
<%= search_field "creator_name" %>
|
||||||
<%= search_field "body_matches", :label => "Body" %>
|
<%= search_field "body_matches", :label => "Body" %>
|
||||||
|
<%= search_field "other_names_match", :label => "Other names" %>
|
||||||
|
|
||||||
<div class="input">
|
<div class="input">
|
||||||
<label for="search_order">Order</label>
|
<label for="search_order">Order</label>
|
||||||
|
|||||||
@@ -14,6 +14,10 @@
|
|||||||
|
|
||||||
<div id="wiki-page-body" class="prose">
|
<div id="wiki-page-body" class="prose">
|
||||||
<% if @wiki_page.visible? %>
|
<% if @wiki_page.visible? %>
|
||||||
|
<% if @wiki_page.other_names.present? %>
|
||||||
|
<p><%= wiki_page_other_names_list(@wiki_page) %></p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<%= format_text(@wiki_page.body) %>
|
<%= format_text(@wiki_page.body) %>
|
||||||
|
|
||||||
<% if @wiki_page.artist %>
|
<% if @wiki_page.artist %>
|
||||||
|
|||||||
10
db/migrate/20140505000956_add_other_names_to_wiki_pages.rb
Normal file
10
db/migrate/20140505000956_add_other_names_to_wiki_pages.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class AddOtherNamesToWikiPages < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :wiki_pages, :other_names, :text
|
||||||
|
add_column :wiki_pages, :other_names_index, :tsvector
|
||||||
|
add_column :wiki_page_versions, :other_names, :text
|
||||||
|
|
||||||
|
execute "CREATE INDEX index_wiki_pages_on_other_names_index ON wiki_pages USING GIN (other_names_index)"
|
||||||
|
execute "CREATE TRIGGER trigger_wiki_pages_on_update_for_other_names BEFORE INSERT OR UPDATE ON wiki_pages FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('other_names_index', 'public.danbooru', 'other_names')"
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user