<commit_before>class ArticlesController < ContentController
  before_filter :verify_config
  before_filter :auto_discovery_feed, :only => [:show, :index]

  layout :theme_layout, :except => [:comment_preview, :trackback]

  cache_sweeper :blog_sweeper

  cached_pages = [:index, :read, :show, :archives, :view_page]
  #caches_page *cached_pages
  caches_action_with_params *cached_page

  session :new_session => false

  helper :'admin/base'

  def index
    @articles = this_blog.requested_articles(params)
    respond_to do |format|
      format.html { render_paginated_index }
      format.atom do
        render :partial => 'atom_feed', :object => @articles[0,this_blog.limit_rss_display]
      end
      format.rss do
        render :partial => 'rss20_feed', :object => @articles[0,this_blog.limit_rss_display]
      end
    end
  end

  def show
    @article      = this_blog.requested_article(params)
    @comment      = Comment.new
    @page_title   = @article.title
    auto_discovery_feed
    respond_to do |format|
      format.html { render :action => 'read' }
      format.atom {  render :partial => 'atom_feed', :object => @article.published_feedback }
      format.rss  { render :partial => 'rss20_feed', :object => @article.published_feedback }
      format.xml  { redirect_to :format => 'atom' }
    end
    rescue ActiveRecord::RecordNotFound
      error("Post not found...")
  end

  def search
    @articles = this_blog.articles_matching(params[:q])
    render_paginated_index("No articles found...")
  end

  ### Deprecated Actions ###

  def archives
    @articles = this_blog.published_articles
  end

  def comment_preview
    if (params[:comment][:body].blank? rescue true)
      render :nothing => true
      return
    end

    set_headers
    @comment = this_blog.comments.build(params[:comment])
    @controller = self
  end

  def author
    response.headers['Status'] = "301 Moved Permanently"
    redirect_to authors_path
  end

  def category
    response.headers['Status'] = "301 Moved Permanently"
    redirect_to categories_path
  end

  def tag
    response.headers['Status'] = "301 Moved Permanently"
    redirect_to tags_path
  end

  def view_page
    debugger
    if(@page = Page.find_by_name(params[:name].to_a.join('/')))
      @page_title = @page.title
    else
      render :nothing => true, :status => 404
    end
  end

  def markup_help
    render :text => TextFilter.find(params[:id]).commenthelp
  end

  private

  def verify_config
    if User.count == 0
      redirect_to :controller => "accounts", :action => "signup"
    elsif ! this_blog.configured?
      redirect_to :controller => "admin/general", :action => "redirect"
    else
      return true
    end
  end

  alias_method :rescue_action_in_public, :error

  def render_error(object = '', status = 500)
    render(:text => (object.errors.full_messages.join(", ") rescue object.to_s), :status => status)
  end

  def set_headers
    headers["Content-Type"] = "text/html; charset=utf-8"
  end

  def render_paginated_index(on_empty = "No posts found...")
    return error(on_empty, :status => 200) if @articles.empty?

    @pages = Paginator.new self, @articles.size, this_blog.limit_article_display, params[:page]
    start = @pages.current.offset
    stop  = (@pages.current.next.offset - 1) rescue @articles.size
    # Why won't this work? @articles.slice!(start..stop)
    @articles = @articles.slice(start..stop)
    render :action => 'index'
  end
end
<commit_msg>Fixes a typo (sic) that made articles controller crash in production mode. Closes ticket 1163<commit_after>class ArticlesController < ContentController
  before_filter :verify_config
  before_filter :auto_discovery_feed, :only => [:show, :index]

  layout :theme_layout, :except => [:comment_preview, :trackback]

  cache_sweeper :blog_sweeper

  cached_pages = [:index, :read, :show, :archives, :view_page]
  #caches_page *cached_pages
  caches_action_with_params *cached_pages

  session :new_session => false

  helper :'admin/base'

  def index
    @articles = this_blog.requested_articles(params)
    respond_to do |format|
      format.html { render_paginated_index }
      format.atom do
        render :partial => 'atom_feed', :object => @articles[0,this_blog.limit_rss_display]
      end
      format.rss do
        render :partial => 'rss20_feed', :object => @articles[0,this_blog.limit_rss_display]
      end
    end
  end

  def show
    @article      = this_blog.requested_article(params)
    @comment      = Comment.new
    @page_title   = @article.title
    auto_discovery_feed
    respond_to do |format|
      format.html { render :action => 'read' }
      format.atom {  render :partial => 'atom_feed', :object => @article.published_feedback }
      format.rss  { render :partial => 'rss20_feed', :object => @article.published_feedback }
      format.xml  { redirect_to :format => 'atom' }
    end
    rescue ActiveRecord::RecordNotFound
      error("Post not found...")
  end

  def search
    @articles = this_blog.articles_matching(params[:q])
    render_paginated_index("No articles found...")
  end

  ### Deprecated Actions ###

  def archives
    @articles = this_blog.published_articles
  end

  def comment_preview
    if (params[:comment][:body].blank? rescue true)
      render :nothing => true
      return
    end

    set_headers
    @comment = this_blog.comments.build(params[:comment])
    @controller = self
  end

  def author
    response.headers['Status'] = "301 Moved Permanently"
    redirect_to authors_path
  end

  def category
    response.headers['Status'] = "301 Moved Permanently"
    redirect_to categories_path
  end

  def tag
    response.headers['Status'] = "301 Moved Permanently"
    redirect_to tags_path
  end

  def view_page
    debugger
    if(@page = Page.find_by_name(params[:name].to_a.join('/')))
      @page_title = @page.title
    else
      render :nothing => true, :status => 404
    end
  end

  def markup_help
    render :text => TextFilter.find(params[:id]).commenthelp
  end

  private

  def verify_config
    if User.count == 0
      redirect_to :controller => "accounts", :action => "signup"
    elsif ! this_blog.configured?
      redirect_to :controller => "admin/general", :action => "redirect"
    else
      return true
    end
  end

  alias_method :rescue_action_in_public, :error

  def render_error(object = '', status = 500)
    render(:text => (object.errors.full_messages.join(", ") rescue object.to_s), :status => status)
  end

  def set_headers
    headers["Content-Type"] = "text/html; charset=utf-8"
  end

  def render_paginated_index(on_empty = "No posts found...")
    return error(on_empty, :status => 200) if @articles.empty?

    @pages = Paginator.new self, @articles.size, this_blog.limit_article_display, params[:page]
    start = @pages.current.offset
    stop  = (@pages.current.next.offset - 1) rescue @articles.size
    # Why won't this work? @articles.slice!(start..stop)
    @articles = @articles.slice(start..stop)
    render :action => 'index'
  end
end

{'fraction_non_alphanumeric': 0.11458185432344171, 'fraction_numerical': 0.008235127076529888, 'mean_word_length': 3.3805970149253732, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6329569', 'n_tokens_mistral': 2324, 'n_tokens_neox': 2179, 'n_words': 528}