<commit_before>#
# This controller is in charge of rendering the root url.
#
class RootController < ApplicationController

  helper :groups, :account, :wiki
  stylesheet 'wiki_edit'
  javascript 'wiki_edit'
  permissions 'groups/base'
  before_filter :login_required, :except => ['index']
  before_filter :fetch_network

  def index
    if !logged_in?
      login_page
    elsif current_site.network
      site_home
    else
      redirect_to me_url
    end
  end

  ##
  ## TAB CONTENT, PULLED BY AJAX
  ##

  def featured
    update_page_list('featured_panel',
      :pages => paginate('featured_by', @group.id, 'descending', 'updated_at')
    )
  end

  def most_viewed
    update_page_list("most_viewed_panel",
      :pages => pages_for_timespan('most_views'),
      :columns => [:views, :icon, :title, :last_updated],
      :sortable => false,
      :heading_partial => 'root/time_links',
      :pagination_options => {:params => {:time_span => params[:time_span]}}
    )
  end

  def most_active
    update_page_list("most_active_panel",
      :pages => pages_for_timespan('most_edits'),
      :columns => [:contributors, :icon, :title, :last_updated],
      :sortable => false,
      :heading_partial => 'root/time_links',
      :pagination_options => {:params => {:time_span => params[:time_span]}}
    )
  end

  def most_stars
    update_page_list("most_stars_panel",
      :pages => pages_for_timespan('most_stars'),
      :columns => [:stars, :icon, :title, :last_updated],
      :sortable => false, 
      :heading_partial => 'root/time_links', 
      :pagination_options => {:params => {:time_span => params[:time_span]}}
    )
  end

  def announcements
    update_page_list('announcements_panel', 
      :pages => paginate('descending','created_at', :flow => :announcement)
    )
  end

  def recent_pages
    if params[:type]
      page = paginate('descending', 'updated_at', 'type', params[:type])
    else
      page = paginate('descending', 'updated_at')
    end
    update_page_list('recent_pages_panel', 
      :pages => page,
      :columns => [:stars, :icon, :title, :last_updated], 
      :heading_partial => 'root/type_links',
      :sortable => false,
      :show_time_dividers => true
    )
  end

  protected

  def pages_for_timespan(filter_by)
    time_span = params[:time_span] || 'all_time'
    case time_span
    when 'today' then
      paginate(filter_by, '24', 'hours')
    when 'this_week' then
      paginate(filter_by, '7', 'days')
    when 'this_month' then
      paginate(filter_by, '30', 'days')
    when 'all_time' then
      case filter_by
      when 'most_views' then
        paginate('descending','views_count')
      when 'most_edits' then
        paginate('descending', 'contributors_count') #TODO: contributors count does not seem to get updated
      when 'most_stars' then
        paginate('descending','stars_count')
      end
    end
  end

  def authorized?
    true
  end<commit_msg>fixed pagination for site home recent pages.<commit_after>#
# This controller is in charge of rendering the root url.
#
class RootController < ApplicationController

  helper :groups, :account, :wiki
  stylesheet 'wiki_edit'
  javascript 'wiki_edit'
  permissions 'groups/base'
  before_filter :login_required, :except => ['index']
  before_filter :fetch_network

  def index
    if !logged_in?
      login_page
    elsif current_site.network
      site_home
    else
      redirect_to me_url
    end
  end

  ##
  ## TAB CONTENT, PULLED BY AJAX
  ##

  def featured
    update_page_list('featured_panel',
      :pages => paginate('featured_by', @group.id, 'descending', 'updated_at')
    )
  end

  def most_viewed
    update_page_list("most_viewed_panel",
      :pages => pages_for_timespan('most_views'),
      :columns => [:views, :icon, :title, :last_updated],
      :sortable => false,
      :heading_partial => 'root/time_links',
      :pagination_options => {:params => {:time_span => params[:time_span]}}
    )
  end

  def most_active
    update_page_list("most_active_panel",
      :pages => pages_for_timespan('most_edits'),
      :columns => [:contributors, :icon, :title, :last_updated],
      :sortable => false,
      :heading_partial => 'root/time_links',
      :pagination_options => {:params => {:time_span => params[:time_span]}}
    )
  end

  def most_stars
    update_page_list("most_stars_panel",
      :pages => pages_for_timespan('most_stars'),
      :columns => [:stars, :icon, :title, :last_updated],
      :sortable => false, 
      :heading_partial => 'root/time_links', 
      :pagination_options => {:params => {:time_span => params[:time_span]}}
    )
  end

  def announcements
    update_page_list('announcements_panel', 
      :pages => paginate('descending','created_at', :flow => :announcement)
    )
  end

  def recent_pages
    if params[:type]
      page = paginate('descending', 'updated_at', 'type', params[:type])
    else
      page = paginate('descending', 'updated_at')
    end
    update_page_list('recent_pages_panel', 
      :pages => page,
      :columns => [:stars, :icon, :title, :last_updated], 
      :heading_partial => 'root/type_links',
      :sortable => false,
      :show_time_dividers => true,
      :pagination_options => {:params => {:type => params[:type]}}
    )
  end

  protected

  def pages_for_timespan(filter_by)
    time_span = params[:time_span] || 'all_time'
    case time_span
    when 'today' then
      paginate(filter_by, '24', 'hours')
    when 'this_week' then
      paginate(filter_by, '7', 'days')
    when 'this_month' then
      paginate(filter_by, '30', 'days')
    when 'all_time' then
      case filter_by
      when 'most_views' then
        paginate('descending','views_count')
      when 'most_edits' then
        paginate('descending', 'contributors_count') #TODO: contributors count does not seem to get updated
      when 'most_stars' then
        paginate('descending','stars_count')
      end
    end
  end

  def authorized?
    true
  end
{'fraction_non_alphanumeric': 0.12820083682008368, 'fraction_numerical': 0.0016736401673640166, 'mean_word_length': 3.333575054387237, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 66, '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': '4918726', 'n_tokens_mistral': 2000, 'n_tokens_neox': 1913, 'n_words': 431}