Class: WikiController

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

Overview

Motiro - A project tracking tool

Copyright (C) 2006-2008  Thiago Arrais

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation; either version 3 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 Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

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, #parsing_error_box, #render_diff_table, #render_wiki, #server_url_for

Constructor Details

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

Returns a new instance of WikiController.



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

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

Instance Method Details

#access_deniedObject



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

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

#check_edit_accessObject



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

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



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

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

#editObject



90
91
92
# File 'app/controllers/wiki_controller.rb', line 90

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

#fetch_diffObject



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

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



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

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



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

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



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

def history
  respond_to do |format|
    format.html
    format.xml do
      return head(:status => 404) unless @page.revisions.size > 0
      render(:action => 'page_feed')
      cache_page
    end
  end
end

#newObject



94
95
96
97
# File 'app/controllers/wiki_controller.rb', line 94

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

#protect?(action) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#saveObject



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

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