<commit_before># encoding: UTF-8
class NewsController < ApplicationController
  before_filter :honeypot, :only => [:create]
  before_filter :find_news, :only => [:show, :anonymous]
  after_filter  :marked_as_read, :only => [:show], :if => :account_signed_in?
  caches_page :index, :if => Proc.new { |c| c.request.format.atom? && !c.request.ssl? }
  caches_action :show, :unless => :account_signed_in?, :expires_in => 5.minutes
  respond_to :html, :atom

  def index
    @order = params[:order]
    @order = "created_at" unless VALID_ORDERS.include?(@order)
    @nodes = Node.public_listing(News, @order).page(params[:page])
    respond_with(@nodes)
  end

  def calendar
    @year  = params[:year].to_i
    @month = params[:month].to_i
    @day   = params[:day].to_i
    @nodes = Node.public_listing(News, "created_at").published_on(Date.new(@year, @month, @day)).page(params[:page])
  end

  def show
    redirect_to [:redaction, @news] if @news.draft?
  end

  def new
    @news = News.new
  end

  def create
    @news = News.new
    @news.attributes   = params[:news]
    @news.author_name  = current_account.name  if current_account
    @news.author_email = current_account.email if current_account
    if !preview_mode && @news.save
      @news.submit!
      redirect_to news_index_url, :notice => "Votre proposition de dépêche a bien été soumise, et sera modérée dans les heures ou jours à venir"
    else
      @news.node = Node.new
      @news.valid?
      render :new
    end
  end

protected

  def honeypot
    honeypot = params[:news].delete(:pot_de_miel)
    links = params[:news][:links_attributes].values
    same  = links.group_by {|l| l["title"] }.map {|_,v| v.size }.max
    render :nothing => true if honeypot.present? || same >= 3
  end<commit_msg>Fix the antispam when lots of empty links<commit_after># encoding: UTF-8
class NewsController < ApplicationController
  before_filter :honeypot, :only => [:create]
  before_filter :find_news, :only => [:show, :anonymous]
  after_filter  :marked_as_read, :only => [:show], :if => :account_signed_in?
  caches_page :index, :if => Proc.new { |c| c.request.format.atom? && !c.request.ssl? }
  caches_action :show, :unless => :account_signed_in?, :expires_in => 5.minutes
  respond_to :html, :atom

  def index
    @order = params[:order]
    @order = "created_at" unless VALID_ORDERS.include?(@order)
    @nodes = Node.public_listing(News, @order).page(params[:page])
    respond_with(@nodes)
  end

  def calendar
    @year  = params[:year].to_i
    @month = params[:month].to_i
    @day   = params[:day].to_i
    @nodes = Node.public_listing(News, "created_at").published_on(Date.new(@year, @month, @day)).page(params[:page])
  end

  def show
    redirect_to [:redaction, @news] if @news.draft?
  end

  def new
    @news = News.new
  end

  def create
    @news = News.new
    @news.attributes   = params[:news]
    @news.author_name  = current_account.name  if current_account
    @news.author_email = current_account.email if current_account
    if !preview_mode && @news.save
      @news.submit!
      redirect_to news_index_url, :notice => "Votre proposition de dépêche a bien été soumise, et sera modérée dans les heures ou jours à venir"
    else
      @news.node = Node.new
      @news.valid?
      render :new
    end
  end

protected

  def honeypot
    honeypot = params[:news].delete(:pot_de_miel)
    links = params[:news][:links_attributes].values
    same  = links.map {|l| l["title"] }.reject(&:blank?).group_by(&:to_s).map {|_,v| v.size }.max.to_i
    render :nothing => true if honeypot.present? || same >= 3
  end
{'fraction_non_alphanumeric': 0.13722222222222222, 'fraction_numerical': 0.0016666666666666668, 'mean_word_length': 3.646451612903226, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '4492840', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1243, 'n_words': 300}