<commit_before>require 'hpricot'

class Article < ActiveRecord::Base

  SEARCHABLE_FIELDS = {
    :name => 10,
    :abstract => 3,
    :body => 2,
    :slug => 1,
    :filename => 1,
  }

  SEARCH_FILTERS = %w[
    more_recent
    more_popular
    more_comments
  ]

  SEARCH_DISPLAYS = %w[full]

  def self.default_search_display
    'full'
  end

  #FIXME This is necessary because html is being generated on the model...
  include ActionView::Helpers::TagHelper

  # use for internationalizable human type names in search facets
  # reimplement on subclasses
  def self.type_name
    _('Content')
  end

  track_actions :create_article, :after_create, :keep_params => [:name, :url, :lead, :first_image], :if => Proc.new { |a| a.is_trackable? && !a.image? }

  # xss_terminate plugin can't sanitize array fields
  before_save :sanitize_tag_list

  before_create do |article|
    if article.last_changed_by_id
      article.author_name = Person.find(article.last_changed_by_id).name
    end
  end

  belongs_to :profile
  validates_presence_of :profile_id, :name
  validates_presence_of :slug, :path, :if => lambda { |article| !article.name.blank? }

  validates_length_of :name, :maximum => 150

  validates_uniqueness_of :slug, :scope => ['profile_id', 'parent_id'], :message => N_('The title (article name) is already being used by another article, please use another title.'), :if => lambda { |article| !article.slug.blank? }

  belongs_to :last_changed_by, :class_name => 'Person', :foreign_key => 'last_changed_by_id'

  has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc'

  has_many :article_categorizations, :conditions => [ 'articles_categories.virtual = ?', false ]
  has_many :categories, :through => :article_categorizations

  has_many :article_categorizations_including_virtual, :class_name => 'ArticleCategorization', :dependent => :destroy
  has_many :categories_including_virtual, :through => :article_categorizations_including_virtual, :source => :category

  acts_as_having_settings :field => :setting

  settings_items :display_hits, :type => :boolean, :default => true
  settings_items :author_name, :type => :string, :default => ""
  settings_items :allow_members_to_edit, :type => :boolean, :default => false
  settings_items :moderate_comments, :type => :boolean, :default => false
  settings_items :followers, :type => Array, :default => []<commit_msg>[postgres-tests] Removing unnecessary dependent => destroy from article_categorization<commit_after>require 'hpricot'

class Article < ActiveRecord::Base

  SEARCHABLE_FIELDS = {
    :name => 10,
    :abstract => 3,
    :body => 2,
    :slug => 1,
    :filename => 1,
  }

  SEARCH_FILTERS = %w[
    more_recent
    more_popular
    more_comments
  ]

  SEARCH_DISPLAYS = %w[full]

  def self.default_search_display
    'full'
  end

  #FIXME This is necessary because html is being generated on the model...
  include ActionView::Helpers::TagHelper

  # use for internationalizable human type names in search facets
  # reimplement on subclasses
  def self.type_name
    _('Content')
  end

  track_actions :create_article, :after_create, :keep_params => [:name, :url, :lead, :first_image], :if => Proc.new { |a| a.is_trackable? && !a.image? }

  # xss_terminate plugin can't sanitize array fields
  before_save :sanitize_tag_list

  before_create do |article|
    if article.last_changed_by_id
      article.author_name = Person.find(article.last_changed_by_id).name
    end
  end

  belongs_to :profile
  validates_presence_of :profile_id, :name
  validates_presence_of :slug, :path, :if => lambda { |article| !article.name.blank? }

  validates_length_of :name, :maximum => 150

  validates_uniqueness_of :slug, :scope => ['profile_id', 'parent_id'], :message => N_('The title (article name) is already being used by another article, please use another title.'), :if => lambda { |article| !article.slug.blank? }

  belongs_to :last_changed_by, :class_name => 'Person', :foreign_key => 'last_changed_by_id'

  has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc'

  has_many :article_categorizations, :conditions => [ 'articles_categories.virtual = ?', false ]
  has_many :categories, :through => :article_categorizations

  has_many :article_categorizations_including_virtual, :class_name => 'ArticleCategorization'
  has_many :categories_including_virtual, :through => :article_categorizations_including_virtual, :source => :category

  acts_as_having_settings :field => :setting

  settings_items :display_hits, :type => :boolean, :default => true
  settings_items :author_name, :type => :string, :default => ""
  settings_items :allow_members_to_edit, :type => :boolean, :default => false
  settings_items :moderate_comments, :type => :boolean, :default => false
  settings_items :followers, :type => Array, :default => []
{'fraction_non_alphanumeric': 0.12028254288597376, 'fraction_numerical': 0.003632694248234107, 'mean_word_length': 4.9, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4971599', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1580, 'n_words': 398}