<commit_before># Author::    <NAME>  (mailto: <EMAIL> at rocket<EMAIL>)
# Copyright:: Copyright (c) 2008 Rocket Boys Ltd
# License::   BSD Licence, see application root.

# This class takes care of the user-created Pages in the site
class PagesController < ApplicationController
  layout 'admin'
  
  before_filter :find_page, :only => [:show, :edit, :update, :destroy, :versions, :enable, :revert_to_version]
  before_filter :login_required, :except => [:show, :index, :sitemap]
  before_filter :page_enabled, :only => :show
  before_filter :check_administrator_role, :only => [:list, :destroy, :enable]

  # If there is a homepage set, redirect to it, otherwise display the uber-basic welcome page.
  def index # todo: not redirect?
    if @page = Page.home
      # included for places that redirect here with a flash
      flash.keep
      redirect_to(@page)
    else
      render :layout => 'master'
    end
  end

  # List all pages. Requires Admin User
  def list
    @pages = Page.parentless
    render :action => "list"
  end

  # Show the page and its details. Page must be enabled or user must be admin.
  def show
    respond_to do |format|
      format.html { render :layout => 'master' } # show.html.erb
      format.xml  { render :xml => @page }
    end
  end

  # Create a new page
  def new
    @page = Page.new
    
    if Page.find_by_permalink(params[:id])
      @parent_id = Page.find_by_permalink(params[:id]).id
    else
      @parent_id = "0"
    end
  end

  # GET /pages/1/edit
  def edit
  end

  # Save the new page. Second half of the new method.
  def create
    @page = Page.new(params[:page])
    @page.user = current_user
    
    # set the first page created as main home page
    if @page.first_page?
      @page.home_page = true
      @page.enabled = true # TODO reflect view with this
    end
    
    respond_to do |format|
      if @page.save
        flash[:notice] = 'Page was successfully created.'
        format.html { redirect_to_pages }
        format.xml  { render :xml => @page, :status => :created, :location => @page }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @page.errors, :status => :unprocessable_entity }
      end
    end
  end

  # Update the pages details. Second half of the edit method.
  def update
    respond_to do |format|
      if @page.update_attributes(params[:page])
        flash[:notice] = 'Page was successfully updated.'
        format.html { redirect_to_pages }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @page.errors, :status => :unprocessable_entity }
      end
    end
  end

  # Delete the page. Does not delete children.
  def destroy
    @page.destroy
    redirect_to_pages
  end
  
  # Toggle the enabled/disabled state of a page.
  def enable
    @page.enabled = !@page.enabled
    @page.save
    redirect_to_pages
  end
  
  # Return a list of all the versions of a page.
  def versions
    @versions = @page.versions
  end<commit_msg>Revisions are orderded descending.<commit_after># Author::    <NAME>  (mailto: rocketboys at rocketboys dot co dot nz)
# Copyright:: Copyright (c) 2008 Rocket Boys Ltd
# License::   BSD Licence, see application root.

# This class takes care of the user-created Pages in the site
class PagesController < ApplicationController
  layout 'admin'
  
  before_filter :find_page, :only => [:show, :edit, :update, :destroy, :versions, :enable, :revert_to_version]
  before_filter :login_required, :except => [:show, :index, :sitemap]
  before_filter :page_enabled, :only => :show
  before_filter :check_administrator_role, :only => [:list, :destroy, :enable]

  # If there is a homepage set, redirect to it, otherwise display the uber-basic welcome page.
  def index # todo: not redirect?
    if @page = Page.home
      # included for places that redirect here with a flash
      flash.keep
      redirect_to(@page)
    else
      render :layout => 'master'
    end
  end

  # List all pages. Requires Admin User
  def list
    @pages = Page.parentless
    render :action => "list"
  end

  # Show the page and its details. Page must be enabled or user must be admin.
  def show
    respond_to do |format|
      format.html { render :layout => 'master' } # show.html.erb
      format.xml  { render :xml => @page }
    end
  end

  # Create a new page
  def new
    @page = Page.new
    
    if Page.find_by_permalink(params[:id])
      @parent_id = Page.find_by_permalink(params[:id]).id
    else
      @parent_id = "0"
    end
  end

  # GET /pages/1/edit
  def edit
  end

  # Save the new page. Second half of the new method.
  def create
    @page = Page.new(params[:page])
    @page.user = current_user
    
    # set the first page created as main home page
    if @page.first_page?
      @page.home_page = true
      @page.enabled = true # TODO reflect view with this
    end
    
    respond_to do |format|
      if @page.save
        flash[:notice] = 'Page was successfully created.'
        format.html { redirect_to_pages }
        format.xml  { render :xml => @page, :status => :created, :location => @page }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @page.errors, :status => :unprocessable_entity }
      end
    end
  end

  # Update the pages details. Second half of the edit method.
  def update
    respond_to do |format|
      if @page.update_attributes(params[:page])
        flash[:notice] = 'Page was successfully updated.'
        format.html { redirect_to_pages }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @page.errors, :status => :unprocessable_entity }
      end
    end
  end

  # Delete the page. Does not delete children.
  def destroy
    @page.destroy
    redirect_to_pages
  end
  
  # Toggle the enabled/disabled state of a page.
  def enable
    @page.enabled = !@page.enabled
    @page.save
    redirect_to_pages
  end
  
  # Return a list of all the versions of a page.
  def versions
    @versions = @page.versions.reverse # TODO set versions to order by revisions descending by default
  end
{'fraction_non_alphanumeric': 0.09856890175269335, 'fraction_numerical': 0.001929570670525808, 'mean_word_length': 2.6652916912197995, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 18}, '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': '5506986', 'n_tokens_mistral': 1939, 'n_tokens_neox': 1901, 'n_words': 660}