<commit_before>class AdminController < ApplicationController

  cache_sweeper :page_sweeper, :only => [:delete]

  before_filter :admin_login_required

  def index
  end

  def config
    @siteinfo = Siteinfo.main
  end

  def config_update
    @siteinfo = Siteinfo.main
    if !@siteinfo.update_attributes(params[:siteinfo])
      render :action => 'config'
      return
    end
    flash[:notice] = "Site configuration updated"
    redirect_to :action => 'index'
  end

  # Delete a page and all its revisions.
  def delete
    @page = Page.find_by_title(title_param)
    @spammer = nil
    @page.destroy
    expire_page(:controller => 'page', :action => 'show', :title => @page.title)
  end

  # Delete a page, all its revisions, and mark the author of the last
  # revision a spammer.
  def delete_spam
    @page = Page.find_by_title(title_param)

    @spammer = Spammer.new(:ip => @page.revisions[0].ip)
    @spammer.save

    @page.destroy
    expire_page(:controller => 'page', :action => 'show', :title => @page.title)
    render :action => 'delete'
  end

  # Roll back to an older version.
  def rollback_not_spam
    @page = Page.find(params[:id])
    @good = params[:old].to_i
    @bad = @good + 1

    @goodrev = @page.revisions.reverse[@good - 1]
    @badrev = @page.revisions.reverse[@bad - 1]

    @page.content = @goodrev.content
    @page.save

    @page.revisions.reverse[@bad - 1 .. -1].each do |r|
      logger.info "Destroying revision: #{r.inspect}"
      r.destroy
    end

    expire_fragment(/history-diff-#{@page.id}-.*/)
    expire_page(:controller => 'page', :action => 'show', :title => @page.title)
  end

  def rollback
    @spammer = Spammer.new(:ip => @badrev.ip)
    @spammer.save
    rollback_not_spam
  end

  private

  # Make sure the user is an admin.
  def admin_login_required
    if !logged_in? || !current_user.admin?
      redirect_to :controller => 'account', :action => 'signup'
      return false
    end
  end
end<commit_msg>* app/controllers/admin_controller.rb: A few more tweaks to the spam   rollback system.<commit_after>class AdminController < ApplicationController

  cache_sweeper :page_sweeper, :only => [:delete]

  before_filter :admin_login_required

  def index
  end

  def config
    @siteinfo = Siteinfo.main
  end

  def config_update
    @siteinfo = Siteinfo.main
    if !@siteinfo.update_attributes(params[:siteinfo])
      render :action => 'config'
      return
    end
    flash[:notice] = "Site configuration updated"
    redirect_to :action => 'index'
  end

  # Delete a page and all its revisions.
  def delete
    @page = Page.find_by_title(title_param)
    @spammer = nil
    @page.destroy
    expire_page(:controller => 'page', :action => 'show', :title => @page.title)
  end

  # Delete a page, all its revisions, and mark the author of the last
  # revision a spammer.
  def delete_spam
    @page = Page.find_by_title(title_param)

    @spammer = Spammer.new(:ip => @page.revisions[0].ip)
    @spammer.save

    @page.destroy
    expire_page(:controller => 'page', :action => 'show', :title => @page.title)
    render :action => 'delete'
  end

  # Roll back to an older version.
  def rollback_not_spam
    # Used in the spam rollback
    @ips = []

    @page = Page.find(params[:id])
    @good = params[:old].to_i
    @bad = @good + 1

    @goodrev = @page.revisions.reverse[@good - 1]
    @badrev = @page.revisions.reverse[@bad - 1]

    @page.content = @goodrev.content
    @page.save

    @page.revisions.reverse[@bad - 1 .. -1].each do |r|
      @ips << r.ip
      logger.info "Destroying revision: #{r.inspect}"
      r.destroy
    end

    expire_fragment(/history-diff-#{@page.id}-.*/)
    expire_page(:controller => 'page', :action => 'show', :title => @page.title)
  end

  def rollback
    rollback_not_spam
    @ips.each do |ip|
      @spammer = Spammer.new(:ip => ip)
      @spammer.save
    end
  end

  private

  # Make sure the user is an admin.
  def admin_login_required
    if !logged_in? || !current_user.admin?
      redirect_to :controller => 'account', :action => 'signup'
      return false
    end
  end
end
{'fraction_non_alphanumeric': 0.12858531842489063, 'fraction_numerical': 0.002916869227029655, 'mean_word_length': 2.975845410628019, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 37, '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': '1865596', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1381, 'n_words': 353}