Class: ClWiki::PageController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#authorized, #current_owner, #current_user, #expire_old_session, #initialize_index, #logged_in?

Instance Method Details

#assign_page_nameObject



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

def assign_page_name
  @page_name = params[:page_name]
end

#editObject



20
21
22
23
24
25
26
27
28
# File 'app/controllers/cl_wiki/page_controller.rb', line 20

def edit
  @render_encryption_ui = $wiki_conf.use_authentication

  @page = instantiate_page
  @encrypt_default = determine_encryption_default

  @page.read_raw_content
  @page
end

#findObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/cl_wiki/page_controller.rb', line 42

def find
  @formatter = ClWiki::PageFormatter.new
  @search_text = params[:search_text]
  @results = []
  if @search_text
    hits = search(@search_text)

    hits.each do |full_name|
      @formatter.full_name = full_name
      @results << @formatter.convert_to_link(full_name).to_s
    end
  end
end

#front_page_nameObject



77
78
79
# File 'app/controllers/cl_wiki/page_controller.rb', line 77

def front_page_name
  'FrontPage'
end

#initialize_formatterObject



111
112
113
# File 'app/controllers/cl_wiki/page_controller.rb', line 111

def initialize_formatter
  @formatter = ClWiki::PageFormatter.new
end

#recentObject

recent published pages.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/cl_wiki/page_controller.rb', line 61

def recent
  page_names = ClWiki::MemoryIndexer.instance.recent(10, text: $wiki_conf.publishTag)

  without_header_and_footer = false
  @pages = page_names.map do |page_name|
    ClWiki::Page.new(page_name, owner: current_owner).tap do |page|
      page.read_content(without_header_and_footer)
    end
  end

  respond_to do |format|
    format.html
    format.rss { render layout: false }
  end
end

#redirect_legacy_cgi_urlsObject



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

def redirect_legacy_cgi_urls
  if request.fullpath.start_with?(legacy_path)
    page_name = (params[:page] || front_page_name).split('/')[-1]
    if request.query_parameters.include?('edit')
      redirect_to page_edit_url(page_name: page_name), status: '301'
    else
      redirect_to page_show_url(page_name: page_name), status: '301'
    end
  end
end

#redirect_to_front_page_if_bad_nameObject



96
97
98
99
100
101
102
# File 'app/controllers/cl_wiki/page_controller.rb', line 96

def redirect_to_front_page_if_bad_name
  if (@page_name.blank? || !@formatter.is_wiki_name?(@page_name)) ||
     (!$wiki_conf.editable && !ClWiki::Page.page_exists?(@page_name))
    redirect_to page_show_url(page_name: front_page_name)
    nil
  end
end

#redirect_to_show_if_read_onlyObject



104
105
106
107
108
109
# File 'app/controllers/cl_wiki/page_controller.rb', line 104

def redirect_to_show_if_read_only
  unless $wiki_conf.editable
    redirect_to page_show_url(page_name: @page_name)
    nil
  end
end

#search(text) ⇒ Object



56
57
58
# File 'app/controllers/cl_wiki/page_controller.rb', line 56

def search(text)
  ClWiki::MemoryIndexer.instance.search(text)
end

#showObject



14
15
16
17
18
# File 'app/controllers/cl_wiki/page_controller.rb', line 14

def show
  @page = instantiate_page
  @page.read_content
  @page
end

#updateObject



30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/cl_wiki/page_controller.rb', line 30

def update
  @page = instantiate_page

  mtime = Time.at(params[:client_mod_time].to_s.to_i)
  encrypt = params[:encrypt].present?
  @page.update_content(params[:page_content], mtime, encrypt)

  redirect_to params[:save_and_edit] ?
                page_edit_url(page_name: @page.page_name) :
                page_show_url(page_name: @page.page_name)
end