WikiController (Class)

In: app/controllers/wiki.rb
Parent: ActionControllerServlet

Constants

EXPORT_DIRECTORY = File.dirname(__FILE__) + "/../../storage/" unless const_defined?("EXPORT_DIRECTORY")

Public Instance methods

[Source]

    # File app/controllers/wiki.rb, line 52
52:   def authenticate
53:     password_check(@params["password"]) ? redirect_show("HomePage") : redirect_action("login")
54:   end

[Source]

    # File app/controllers/wiki.rb, line 77
77:   def authors
78:     @authors = web.select.authors
79:   end

[Source]

     # File app/controllers/wiki.rb, line 221
221:   def cancel_edit
222:     @page = wiki.read_page(web_address, page_name)
223:     @page.unlock
224:     redirect_show
225:   end

[Source]

    # File app/controllers/wiki.rb, line 29
29:   def create_system
30:     wiki.setup(@params["password"], @params["web_name"], @params["web_address"]) unless wiki.setup? 
31:     redirect_path "/"
32:   end

[Source]

    # File app/controllers/wiki.rb, line 34
34:   def create_web
35:     redirect_path("/") unless wiki.authenticate(@params["system_password"])
36:     wiki.create_web(@params["name"], @params["address"])
37:     redirect_show("HomePage", @params["address"])
38:   end

[Source]

     # File app/controllers/wiki.rb, line 209
209:   def edit
210:     @page = wiki.read_page(web_address, page_name)
211: 
212:     if !@page.locked?(Time.now) || @params["break_lock"]
213:       @page.lock(Time.now, default_author)
214:       @author = default_author
215:       render
216:     else
217:       render "wiki/locked"
218:     end
219:   end

[Source]

     # File app/controllers/wiki.rb, line 107
107:   def export_html
108:     file_name = "#{web.address}-html-#{web.revised_on.strftime("%Y-%m-%d-%H-%M")}.zip"
109:     file_path = EXPORT_DIRECTORY + file_name
110: 
111:     export_pages_to_zip_file(file_path) unless FileTest.exists?(file_path)
112:     send_export(file_name, file_path)
113:   end

[Source]

     # File app/controllers/wiki.rb, line 115
115:   def export_markup
116:     file_name = "#{web.address}-markup-#{web.revised_on.strftime("%Y-%m-%d-%H-%M")}.zip"
117:     file_path = EXPORT_DIRECTORY + file_name
118: 
119:     export_markup_to_zip_file(file_path) unless FileTest.exists?(file_path)
120:     send_export(file_name, file_path)
121:   end

[Source]

     # File app/controllers/wiki.rb, line 123
123:   def export_pdf
124:     file_name = "#{web.address}-tex-#{web.revised_on.strftime("%Y-%m-%d-%H-%M")}"
125:     file_path = EXPORT_DIRECTORY + file_name
126: 
127:     export_web_to_tex(file_path + ".tex") unless FileTest.exists?(file_path + ".tex")
128:     convert_tex_to_pdf(file_path + ".tex")
129:     send_export(file_name + ".pdf", file_path + ".pdf")
130:   end

[Source]

     # File app/controllers/wiki.rb, line 132
132:   def export_tex
133:     file_name = "#{web.address}-tex-#{web.revised_on.strftime("%Y-%m-%d-%H-%M")}.tex"
134:     file_path = EXPORT_DIRECTORY + file_name
135: 
136:     export_web_to_tex(file_path) unless FileTest.exists?(file_path)
137:     send_export(file_name, file_path)
138:   end

[Source]

    # File app/controllers/wiki.rb, line 7
 7:   def index
 8:     if web_address
 9:       redirect_show "HomePage"
10:     elsif !wiki.setup?
11:       redirect_path "/new_system/"
12:     elsif wiki.webs.length == 1
13:       redirect_show "HomePage", wiki.webs.values.first.address
14:     else
15:       redirect_path "/web_list/"
16:     end
17:   end

[Source]

     # File app/controllers/wiki.rb, line 100
100:   def list
101:     parse_category
102:     @pages_by_name = @pages_in_category.by_name 
103:     @page_names_that_are_wanted = @pages_in_category.wanted_pages
104:     @pages_that_are_orphaned = @pages_in_category.orphaned_pages
105:   end

[Source]

    # File app/controllers/wiki.rb, line 48
48:   def login
49:     render "wiki/login"
50:   end

[Source]

     # File app/controllers/wiki.rb, line 205
205:   def new
206:     @page_name, @author = page_name, default_author
207:   end

Administrating the Instiki setup ———————————————

[Source]

    # File app/controllers/wiki.rb, line 21
21:   def new_system
22:     wiki.setup? ? redirect_path("/") : render
23:   end

[Source]

    # File app/controllers/wiki.rb, line 25
25:   def new_web
26:     redirect_path("/") if wiki.system["password"].nil?
27:   end

Within a single web ———————————————————

[Source]

    # File app/controllers/wiki.rb, line 61
61:   def parse_category
62:     @categories = web.categories
63:     @category = @params["category"]
64:     @pages_in_category = web.select { |page| page.in_category?(@category) }
65:     @set_name = ( @categories.include?(@category) ? "category '#{@category}'" : "the web" )
66:     @category_links = @categories.map do |c| 
67:       (@category == c ? "<span class=\"selected\">#{c}</span>" : "<a href=\"?category=#{c}\">#{c}</a>")
68:     end
69:   end

[Source]

     # File app/controllers/wiki.rb, line 194
194:   def pdf
195:     page = wiki.read_page(web_address, page_name)
196:     safe_page_name = page.name.gsub(/\W/, "")
197:     file_name = "#{safe_page_name}-#{web.address}-#{page.created_at.strftime("%Y-%m-%d-%H-%M")}"
198:     file_path = EXPORT_DIRECTORY + file_name
199: 
200:     export_page_to_tex(file_path + ".tex") unless FileTest.exists?(file_path + ".tex")
201:     convert_tex_to_pdf(file_path + ".tex")
202:     send_export(file_name + ".pdf", file_path + ".pdf")
203:   end

[Source]

     # File app/controllers/wiki.rb, line 185
185:   def print
186:     @page = wiki.read_page(web_address, page_name)
187:   end

[Source]

     # File app/controllers/wiki.rb, line 181
181:   def published
182:     if web.published then @page = wiki.read_page(web_address, page_name || "HomePage") else redirect_show("HomePage") end
183:   end

[Source]

    # File app/controllers/wiki.rb, line 81
81:   def recently_revised
82:     parse_category
83:     @pages_by_revision = @pages_in_category.by_revision
84:   end

[Source]

     # File app/controllers/wiki.rb, line 157
157:   def remove_orphaned_pages
158:     if wiki.authenticate(@params["system_password"])
159:       wiki.remove_orphaned_pages(web_address)
160:       redirect_action "list/"
161:     else
162:       redirect_show "HomePage"
163:     end
164:   end

[Source]

     # File app/controllers/wiki.rb, line 246
246:   def revision
247:     @page = wiki.read_page(web_address, page_name)
248:     @revision = @page.revisions[@params["rev"].to_i]
249:   end

[Source]

     # File app/controllers/wiki.rb, line 251
251:   def rollback
252:     @page = wiki.read_page(web_address, page_name)
253:     @revision = @page.revisions[@params["rev"].to_i]  
254:   end

[Source]

    # File app/controllers/wiki.rb, line 86
86:   def rss_with_content
87:     @pages_by_revision = web.select.by_revision.first(15)
88:     @uri = @req.request_uri
89:     host = @req.meta_vars["HTTP_X_FORWARDED_HOST"] || "#{@uri.host}:#{@uri.port.to_s}"
90:     @web_url = "#{@uri.scheme}://#{host}/#{@web.address}"
91:     @res["Content-Type"] = "text/xml"
92:     render "wiki/rss_feed"
93:   end

[Source]

    # File app/controllers/wiki.rb, line 95
95:   def rss_with_headlines
96:     @hide_description = true
97:     rss_with_content
98:   end

[Source]

     # File app/controllers/wiki.rb, line 227
227:   def save
228:     if web.pages[page_name]
229:       page = wiki.revise_page(
230:         web_address, page_name, @params["content"], Time.now, 
231:         Author.new(@params["author"], remote_ip)
232:       )
233: 
234:       page.unlock
235:     else
236:       page = wiki.write_page(
237:         web_address, page_name, @params["content"], Time.now, 
238:         Author.new(@params["author"], remote_ip)
239:       )
240:     end
241: 
242:     write_cookie("author", @params["author"], true)
243:     redirect_show(page_name)
244:   end

[Source]

    # File app/controllers/wiki.rb, line 71
71:   def search
72:     @query   = @params["query"]
73:     @results = web.select { |page| page.content =~ /#{@query}/i }
74:     @results.length == 1 ? redirect_show(@results.first.name) : render
75:   end

Within a single page ———————————————————

[Source]

     # File app/controllers/wiki.rb, line 168
168:   def show
169:     if @page = wiki.read_page(web_address, page_name)
170:       begin
171:         render_action "page"
172:       rescue => e
173:         $stderr << e.backtrace.join("\n")
174:         redirect_action "edit/#{CGI.escape(page_name)}?msg=#{CGI.escape(e.message)}"
175:       end
176:     else
177:       redirect_action "new/#{CGI.escape(page_name)}"
178:     end
179:   end

[Source]

    # File app/controllers/wiki.rb, line 56
56:   def static_style_sheet() render "static_style_sheet" end

[Source]

     # File app/controllers/wiki.rb, line 189
189:   def tex
190:     @page = wiki.read_page(web_address, page_name)
191:     @tex_content = RedClothForTex.new(@page.content).to_tex
192:   end

[Source]

     # File app/controllers/wiki.rb, line 140
140:   def update_web
141:     redirect_show("HomePage") unless wiki.authenticate(@params["system_password"])
142: 
143:     wiki.update_web(
144:       web.address, @params["address"], @params["name"], 
145:       @params["markup"].intern, 
146:       @params["color"], @params["additional_style"], 
147:       @params["safe_mode"] ? true : false, 
148:       @params["password"].empty? ? nil : @params["password"],
149:       @params["published"] ? true : false, 
150:       @params["brackets_only"] ? true : false,
151:       @params["count_pages"] ? true : false
152:     )
153: 
154:     redirect_show("HomePage", @params["address"])
155:   end

Outside a single web ———————————————————

[Source]

    # File app/controllers/wiki.rb, line 43
43:   def web_list
44:     @system, @webs = wiki.system, wiki.webs.values
45:     render "wiki/web_list"
46:   end

[Validate]