Class: WikiController
Constant Summary
ApplicationController::FILE_TYPES
Instance Method Summary
collapse
wiki, wiki=
Instance Method Details
#authenticate ⇒ Object
Outside a single web ——————————————————–
24
25
26
27
28
29
30
31
|
# File 'app/controllers/wiki_controller.rb', line 24
def authenticate
if password_check(@params['password'])
redirect_home
else
flash[:info] = password_error(@params['password'])
redirect_to :action => 'login', :web => @web_name
end
end
|
#authors ⇒ Object
Within a single web ———————————————————
44
45
46
|
# File 'app/controllers/wiki_controller.rb', line 44
def authors
@authors = @web.select.authors
end
|
#cancel_edit ⇒ Object
Within a single page ——————————————————–
118
119
120
121
|
# File 'app/controllers/wiki_controller.rb', line 118
def cancel_edit
@page.unlock
redirect_to_page(@page_name)
end
|
#edit ⇒ Object
123
124
125
126
127
128
129
130
131
|
# File 'app/controllers/wiki_controller.rb', line 123
def edit
if @page.nil?
redirect_to :action => 'index'
elsif @page.locked?(Time.now) and not @params['break_lock']
redirect_to :web => @web_name, :action => 'locked', :id => @page_name
else
@page.lock(Time.now, @author)
end
end
|
#export_html ⇒ Object
48
49
50
51
52
53
54
|
# File 'app/controllers/wiki_controller.rb', line 48
def export_html
export_pages_as_zip('html') do |page|
@page = page
@link_mode = :export
render_to_string('wiki/print', use_layout = true)
end
end
|
#export_markup ⇒ Object
56
57
58
|
# File 'app/controllers/wiki_controller.rb', line 56
def export_markup
export_pages_as_zip(@web.markup) { |page| page.content }
end
|
#export_pdf ⇒ Object
60
61
62
63
64
65
66
67
|
# File 'app/controllers/wiki_controller.rb', line 60
def export_pdf
file_name = "#{@web.address}-tex-#{@web.revised_on.strftime('%Y-%m-%d-%H-%M-%S')}"
file_path = File.join(@wiki.storage_path, file_name)
export_web_to_tex "#{file_path}.tex" unless FileTest.exists? "#{file_path}.tex"
convert_tex_to_pdf "#{file_path}.tex"
send_file "#{file_path}.pdf"
end
|
#export_tex ⇒ Object
69
70
71
72
73
74
|
# File 'app/controllers/wiki_controller.rb', line 69
def export_tex
file_name = "#{@web.address}-tex-#{@web.revised_on.strftime('%Y-%m-%d-%H-%M-%S')}.tex"
file_path = File.join(@wiki.storage_path, file_name)
export_web_to_tex(file_path) unless FileTest.exists?(file_path)
send_file file_path
end
|
#feeds ⇒ Object
76
77
78
79
|
# File 'app/controllers/wiki_controller.rb', line 76
def feeds
@rss_with_content_allowed =
end
|
#index ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
|
# File 'app/controllers/wiki_controller.rb', line 10
def index
if @web_name
redirect_home
elsif not @wiki.setup?
redirect_to :controller => 'admin', :action => 'create_system'
elsif @wiki.webs.length == 1
redirect_home @wiki.webs.values.first.address
else
redirect_to :action => 'web_list'
end
end
|
#list ⇒ Object
81
82
83
84
85
86
|
# File 'app/controllers/wiki_controller.rb', line 81
def list
parse_category
@pages_by_name = @pages_in_category.by_name
@page_names_that_are_wanted = @pages_in_category.wanted_pages
@pages_that_are_orphaned = @pages_in_category.orphaned_pages
end
|
#locked ⇒ Object
133
134
135
|
# File 'app/controllers/wiki_controller.rb', line 133
def locked
end
|
#login ⇒ Object
33
34
35
|
# File 'app/controllers/wiki_controller.rb', line 33
def login
end
|
#new ⇒ Object
137
138
139
|
# File 'app/controllers/wiki_controller.rb', line 137
def new
end
|
#pdf ⇒ Object
141
142
143
144
145
146
147
148
149
150
151
|
# File 'app/controllers/wiki_controller.rb', line 141
def pdf
page = wiki.read_page(@web_name, @page_name)
safe_page_name = @page.name.gsub(/\W/, '')
file_name = "#{safe_page_name}-#{@web.address}-#{@page.created_at.strftime('%Y-%m-%d-%H-%M-%S')}"
file_path = File.join(@wiki.storage_path, file_name)
export_page_to_tex("#{file_path}.tex") unless FileTest.exists?("#{file_path}.tex")
convert_tex_to_pdf("#{file_path}.tex")
send_file "#{file_path}.pdf"
end
|
#print ⇒ Object
153
154
155
156
|
# File 'app/controllers/wiki_controller.rb', line 153
def print
@link_mode ||= :show
end
|
#published ⇒ Object
158
159
160
161
162
163
164
|
# File 'app/controllers/wiki_controller.rb', line 158
def published
if @web.published
@page = wiki.read_page(@web_name, @page_name || 'HomePage')
else
redirect_home
end
end
|
#recently_revised ⇒ Object
88
89
90
91
|
# File 'app/controllers/wiki_controller.rb', line 88
def recently_revised
parse_category
@pages_by_revision = @pages_in_category.by_revision
end
|
#revision ⇒ Object
166
167
168
|
# File 'app/controllers/wiki_controller.rb', line 166
def revision
get_page_and_revision
end
|
#rollback ⇒ Object
170
171
172
|
# File 'app/controllers/wiki_controller.rb', line 170
def rollback
get_page_and_revision
end
|
93
94
95
96
97
98
99
100
|
# File 'app/controllers/wiki_controller.rb', line 93
def
if
(hide_description = false, *)
else
render_text 'RSS feed with content for this web is blocked for security reasons. ' +
'The web is password-protected and not published', '403 Forbidden'
end
end
|
102
103
104
|
# File 'app/controllers/wiki_controller.rb', line 102
def
(hide_description = true, *)
end
|
#save ⇒ Object
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'app/controllers/wiki_controller.rb', line 174
def save
redirect_to :action => 'index' if @page_name.nil?
cookies['author'] = @params['author']
begin
page = @web.pages[@page_name]
if @web.pages[@page_name]
wiki.revise_page(
@web_name, @page_name, @params['content'], Time.now,
Author.new(@params['author'], remote_ip)
)
page.unlock
else
wiki.write_page(
@web_name, @page_name, @params['content'], Time.now,
Author.new(@params['author'], remote_ip)
)
end
redirect_to_page @page_name
rescue Instiki::ValidationError => e
page.unlock if defined? page
flash[:error] = e
return_to_last_remembered
end
end
|
#search ⇒ Object
106
107
108
109
110
111
112
113
114
|
# File 'app/controllers/wiki_controller.rb', line 106
def search
@query = @params['query']
@title_results = @web.select { |page| page.name =~ /#{@query}/i }.sort
@results = @web.select { |page| page.content =~ /#{@query}/i }.sort
all_pages_found = (@results + @title_results).uniq
if all_pages_found.size == 1
redirect_to_page(all_pages_found.first.name)
end
end
|
#show ⇒ Object
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
# File 'app/controllers/wiki_controller.rb', line 200
def show
if @page
begin
render_action 'page'
rescue => e
logger.error e
if in_a_web?
redirect_to :web => @web_name, :action => 'edit',
:action_suffix => "#{@page_name}?msg=#{e.message}"
else
raise e
end
end
else
if not @page_name.nil? and not @page_name.empty?
redirect_to :web => @web_name, :action => 'new', :id => @page_name
else
render_text 'Page name is not specified', '404 Not Found'
end
end
end
|
#tex ⇒ Object
224
225
226
|
# File 'app/controllers/wiki_controller.rb', line 224
def tex
@tex_content = RedClothForTex.new(@page.content).to_tex
end
|
#web_list ⇒ Object
37
38
39
|
# File 'app/controllers/wiki_controller.rb', line 37
def web_list
@webs = wiki.webs.values.sort_by { |web| web.name }
end
|