merge translated tags branch
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
class WikiPage < ActiveRecord::Base
|
||||
before_save :normalize_title
|
||||
before_save :normalize_other_names
|
||||
before_validation :initialize_creator, :on => :create
|
||||
before_validation :initialize_updater
|
||||
after_save :create_version
|
||||
@@ -10,7 +11,7 @@ class WikiPage < ActiveRecord::Base
|
||||
validates_presence_of :title
|
||||
validate :validate_locker_is_janitor
|
||||
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 :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
|
||||
@@ -32,6 +33,12 @@ class WikiPage < ActiveRecord::Base
|
||||
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 = {})
|
||||
q = where("true")
|
||||
params = {} if params.blank?
|
||||
@@ -48,6 +55,10 @@ class WikiPage < ActiveRecord::Base
|
||||
q = q.body_matches(params[:body_matches])
|
||||
end
|
||||
|
||||
if params[:other_names_match].present?
|
||||
q = q.other_names_match(params[:other_names_match].split(" "))
|
||||
end
|
||||
|
||||
if params[:creator_name].present?
|
||||
q = q.where("creator_id = (select _.id from users _ where lower(_.name) = ?)", params[:creator_name].tr(" ", "_").mb_chars.downcase)
|
||||
end
|
||||
@@ -65,7 +76,7 @@ class WikiPage < ActiveRecord::Base
|
||||
|
||||
module ApiMethods
|
||||
def hidden_attributes
|
||||
super + [:body_index]
|
||||
super + [:body_index, :other_names_index]
|
||||
end
|
||||
|
||||
def serializable_hash(options = {})
|
||||
@@ -113,6 +124,7 @@ class WikiPage < ActiveRecord::Base
|
||||
self.title = version.title
|
||||
self.body = version.body
|
||||
self.is_locked = version.is_locked
|
||||
self.other_names = version.other_names
|
||||
end
|
||||
|
||||
def revert_to!(version)
|
||||
@@ -124,6 +136,12 @@ class WikiPage < ActiveRecord::Base
|
||||
self.title = title.mb_chars.downcase.tr(" ", "_")
|
||||
end
|
||||
|
||||
def normalize_other_names
|
||||
normalized_other_names = other_names.to_s.gsub(/\u3000/, " ").scan(/\S+/)
|
||||
normalized_other_names = normalized_other_names.map{|name| name.downcase}
|
||||
self.other_names = normalized_other_names.uniq.join(" ")
|
||||
end
|
||||
|
||||
def creator_name
|
||||
User.id_to_name(creator_id).tr("_", " ")
|
||||
end
|
||||
@@ -141,7 +159,8 @@ class WikiPage < ActiveRecord::Base
|
||||
prev.update_attributes(
|
||||
:title => title,
|
||||
:body => body,
|
||||
:is_locked => is_locked
|
||||
:is_locked => is_locked,
|
||||
:other_names => other_names
|
||||
)
|
||||
end
|
||||
|
||||
@@ -156,12 +175,13 @@ class WikiPage < ActiveRecord::Base
|
||||
:updater_ip_addr => CurrentUser.ip_addr,
|
||||
:title => title,
|
||||
:body => body,
|
||||
:is_locked => is_locked
|
||||
:is_locked => is_locked,
|
||||
:other_names => other_names
|
||||
)
|
||||
end
|
||||
|
||||
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?
|
||||
merge_version
|
||||
else
|
||||
@@ -207,4 +227,8 @@ class WikiPage < ActiveRecord::Base
|
||||
def visible?
|
||||
artist.blank? || !artist.is_banned? || CurrentUser.user.is_janitor?
|
||||
end
|
||||
|
||||
def other_names_array
|
||||
other_names.to_s.scan(/\S+/)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@ class WikiPageVersion < ActiveRecord::Base
|
||||
belongs_to :wiki_page
|
||||
belongs_to :updater, :class_name => "User"
|
||||
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
|
||||
def for_user(user_id)
|
||||
@@ -43,4 +43,7 @@ class WikiPageVersion < ActiveRecord::Base
|
||||
artist.blank? || !artist.is_banned? || CurrentUser.user.is_janitor?
|
||||
end
|
||||
|
||||
def other_names_array
|
||||
other_names.to_s.scan(/\S+/)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user