Class: WikiController

Inherits:
ApplicationController show all
Defined in:
app/controllers/wiki_controller.rb

Overview

Motiro - A project tracking tool

Copyright (C) 2006-2007  Thiago Arrais

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

Instance Method Summary collapse

Methods inherited from ApplicationController

#check_desired_login_available, #drop_top_crumbs, #set_locale, #setup_renderer

Methods included from ApplicationHelper

#current_locale, #current_user, #dynjs_include_tag, #pagetext, #render_diff_table, #server_url_for

Constructor Details

#initialize(page_provider = Page, renderer = nil) ⇒ WikiController



41
42
43
44
45
# File 'app/controllers/wiki_controller.rb', line 41

def initialize(page_provider=Page, renderer=nil)
  @renderer = renderer || create_renderer
  @real_page_provider = page_provider
  @default_page_provider = DefaultPageProvider.new
end

Instance Method Details

#access_deniedObject



117
118
119
120
# File 'app/controllers/wiki_controller.rb', line 117

def access_denied
  redirect_to :controller => 'wiki', :action => 'show',
              :page_name => params[:page_name] 
end

#check_edit_accessObject



82
83
84
85
86
87
88
89
90
# File 'app/controllers/wiki_controller.rb', line 82

def check_edit_access
  unless current_user.can_edit?(@page)
    flash[:not_authorized] = true
    redirect_to :action => 'show', :page_name => @page.name
    return false
  end
  
  return true
end

#choose_layoutObject



29
30
31
32
33
34
# File 'app/controllers/wiki_controller.rb', line 29

def choose_layout
  return if params[:context] == 'partial' ||
            params[:action] == 'properties_edit' ||
            params[:format] == 'xml'
  return 'application'
end

#editObject



92
93
94
# File 'app/controllers/wiki_controller.rb', line 92

def edit
  render(:layout => 'application')
end

#fetch_diffObject



69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/wiki_controller.rb', line 69

def fetch_diff
  redirect_to params.delete_if {|k,v| :btnCompare == k.to_sym} if params[:btnCompare]
  @old_revision_num = params[:old_revision]
  @new_revision_num = params[:new_revision]
  @old_revision = @page.revisions[@old_revision_num.to_i - 1]
  @new_revision = @page.revisions[@new_revision_num.to_i - 1]
  unless @old_revision && @new_revision
    flash[:notice] = '%s has no revision %s' / @page.name /
      (@old_revision.nil? ? @old_revision_num : @new_revision_num)
    redirect_to :action => 'show', :page_name => params[:page_name]
  end
end

#fetch_pageObject



47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/wiki_controller.rb', line 47

def fetch_page
  @page = find_page(params[:page_name])
  unless 'common' == @page.kind 
    @crumbs <<{ @page.kind.pluralize.capitalize.t  =>
                {:controller => 'report', :action => 'older',
                 :reporter => @page.kind.pluralize}}
  end
  @crumbs <<{ @page.title => {:controller => 'wiki', :action => 'show',
                              :page_name => @page.name} }
end

#fetch_revisionObject



58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/wiki_controller.rb', line 58

def fetch_revision
  rev = params[:revision]
  unless rev.nil?
    @page = @page.revisions[rev.to_i - 1]
    @page_revision_id = @page.id
    @crumbs << { 'Revision %s' / rev =>
                 { :controller => 'wiki', :action => 'show',
                   :page_name => @page.name, :revision => rev} }
  end
end

#historyObject



109
110
111
112
113
114
115
# File 'app/controllers/wiki_controller.rb', line 109

def history
  respond_to do |format|
    format.html
    format.xml { render(:action => 'page_feed')
                 cache_page}
  end
end

#newObject



96
97
98
99
# File 'app/controllers/wiki_controller.rb', line 96

def new
  @page.kind = params[:kind]
  render(:action => 'edit', :layout => 'application')
end

#protect?(action) ⇒ Boolean



36
37
38
39
# File 'app/controllers/wiki_controller.rb', line 36

def protect?(action)
  return false if 'show' == action
  return true    
end

#saveObject



101
102
103
104
105
106
107
# File 'app/controllers/wiki_controller.rb', line 101

def save
  if params['btnSave']
    really_save
  else
    redirect_to :controller => 'root', :action => 'index'
  end
end