<commit_before>class BbchyscommentsController < ApplicationController
  layout 'newsniffer'
  before_filter :get_random_comment, :except => %w(vote list_rss)
  before_filter :check_admin, :only => :uncensor

  session :off, :only => %w(list_rss)
  
  def list
    @title = "Watch Your Mouth - latest censored comments"  
    @discovery_links = [ [url_for(:action => "list_rss"), "Latest censored comments"] ]
    @comments_pages, @comments =
      paginate :hys_comments, :order => 'hys_comments.updated_at desc', 
      :include => 'hys_thread',
      :conditions => ['censored = 0 and hys_comments.updated_at < (now() - INTERVAL 25 minute)']
  end
  
  def recommended
    @title = "Watch Your Mouth - recommended censored comments"  
    @comments_pages, @comments =
      paginate :hys_comments, :order => 'votes desc', 
      :include => 'hys_thread',
      :conditions => ['votes > 0']
  end
  
  def list_rss
    headers["Content-Type"] = "application/xml"
    rss = RubyRSS.new nil
    rss.title = "BBC Watch Your Mouth Censored Comment Feed"
    rss.link = "http://newsniffer.newworldodour.co.uk/"
    rss.desc = "Comments that were censored from the BBC News 'Have Your Say' section"
    comments = HysComment.find( :all, :include => 'hys_thread', :order => 'hys_comments.updated_at desc', 
      :conditions => ['hys_comments.censored = 0 and hys_comments.updated_at < (now() - INTERVAL 25 minute)'], :limit => 25 )
    rss.date = comments.first.updated_at.httpdate
    comments.each do  |c|
      c_url = url_for( :controller => 'bbchysthreads', 
        :action => 'show', :id => c.hys_thread.bbcid, :comment_id => c.bbcid ) + "##{c.bbcid}"
      text = c.text + "<br/><br/>Written by <strong>#{c.author}</strong>"
      i = RubyRSS::Item.new( c.hys_thread.title, c_url, text, c.updated_at.httpdate )
      rss.items << i
    end
    render :text => rss.generate("rss2.0")
  end

  def show
    @comment = HysComment.find_by_bbcid(params[:id], :include => 'hys_thread')
  end

  def search
    session[:wym_search] = params[:search] if params[:search]
    @search = session[:wym_search]
    @title = "Watch Your Mouth - search for '#{@search}'"
    @comments_pages, @comments =
      paginate :hys_comments,
      :conditions => ['censored = 0 and MATCH (text) AGAINST (? IN BOOLEAN MODE)', @search]
    render :action => 'list'
  end

  def uncensor
    c = HysComment.find(params[:id])
    c.censored = 1
    c.save
    flash[:notice] = 'Comment uncensored'
    redirect_to :back
  end

  def vote
    @comment = HysComment.find(params[:id])
    if is_admin?
      # An admin vote is with 5, and gets unlimited votes
      5.times { @voted = Vote.vote @comment }
    else
      @voted = Vote.vote @comment, cookies['_session_id']
    end
    unless request.xhr?
      flash[:notice] = 'Thank you for your recommendation'
      redirect_to :controller => 'bbchyscomments', :action => 'recommend'
    end
  end
end<commit_msg>converted rss feed to rxml template expire hys_thread fragment on vote drop random comment feature<commit_after>class BbchyscommentsController < ApplicationController
  layout 'newsniffer'
  before_filter :check_admin, :only => :uncensor

  session :off, :only => %w(list_rss)
  
  def list
    @title = "Watch Your Mouth - latest censored comments"  
    @discovery_links = [ [url_for(:action => "list_rss"), "Latest censored comments"] ]
    @comments_pages, @comments =
      paginate :hys_comments, :order => 'hys_comments.updated_at desc', 
      :include => 'hys_thread',
      :conditions => ['censored = 0 and hys_comments.updated_at < (now() - INTERVAL 25 minute)']
  end
  
  def recommended
    @title = "Watch Your Mouth - recommended censored comments"  
    @comments_pages, @comments =
      paginate :hys_comments, :order => 'votes desc', 
      :include => 'hys_thread',
      :conditions => ['votes > 0']
  end
  
  def list_rss
    headers["Content-Type"] = "application/xml"
    @comments = HysComment.find( :all, :include => 'hys_thread', :order => 'hys_comments.updated_at desc', 
      :conditions => ['hys_comments.censored = 0 and hys_comments.updated_at < (now() - INTERVAL 25 minute)'], :limit => 25 )
    render :layout => false
  end

  def show
    @comment = HysComment.find_by_bbcid(params[:id], :include => 'hys_thread')
  end

  def search
    session[:wym_search] = params[:search] if params[:search]
    @search = session[:wym_search]
    @title = "Watch Your Mouth - search for '#{@search}'"
    @comments_pages, @comments =
      paginate :hys_comments,
      :conditions => ['censored = 0 and MATCH (text) AGAINST (? IN BOOLEAN MODE)', @search]
    render :action => 'list'
  end

  def uncensor
    c = HysComment.find(params[:id])
    c.censored = 1
    c.save
    flash[:notice] = 'Comment uncensored'
    redirect_to :back
  end

  def vote
    @comment = HysComment.find(params[:id], :include => :hys_thread)
    if is_admin?
      # An admin vote is with 5, and gets unlimited votes
      5.times { @voted = Vote.vote @comment }
    else
      @voted = Vote.vote @comment, cookies['_session_id']
    end
    expire_fragment( "hys_thread_#{@comment.hys_thread.bbcid}" )
    unless request.xhr?
      flash[:notice] = 'Thank you for your recommendation'
      redirect_to :controller => 'bbchyscomments', :action => 'recommend'
    end
  end
end
{'fraction_non_alphanumeric': 0.1317814905199925, 'fraction_numerical': 0.005256241787122208, 'mean_word_length': 3.3672131147540982, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, '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': '2391634', 'n_tokens_mistral': 1817, 'n_tokens_neox': 1750, 'n_words': 462}