Class: WikiController
- Inherits:
-
ActionControllerServlet
- Object
- ActionControllerServlet
- WikiController
- Defined in:
- app/controllers/wiki.rb
Constant Summary collapse
- EXPORT_DIRECTORY =
WikiService.storage_path
Instance Method Summary collapse
- #authenticate ⇒ Object
- #authors ⇒ Object
-
#bliki ⇒ Object
}}}.
-
#bliki_delete ⇒ Object
Bliki ———————————————————————-.
- #bliki_edit ⇒ Object
- #bliki_revision ⇒ Object
- #bliki_save ⇒ Object
- #cancel_bliki_edit ⇒ Object
- #cancel_edit ⇒ Object
- #create_system ⇒ Object
- #create_web ⇒ Object
- #edit ⇒ Object
-
#edit_menu ⇒ Object
}}}.
- #export_html ⇒ Object
- #export_markup ⇒ Object
- #export_pdf ⇒ Object
- #export_tex ⇒ Object
- #index ⇒ Object
- #list ⇒ Object
- #login ⇒ Object
-
#mind ⇒ Object
}}}.
- #new ⇒ Object
-
#new_system ⇒ Object
Administrating the Instiki setup ——————————————–.
- #new_web ⇒ Object
-
#parse_category ⇒ Object
Within a single web ———————————————————.
- #pdf ⇒ Object
- #print ⇒ Object
- #published ⇒ Object
- #recently_revised ⇒ Object
- #remove_orphaned_pages ⇒ Object
- #revision ⇒ Object
- #rollback ⇒ Object
- #rollback_bliki ⇒ Object
- #rss_with_content ⇒ Object
- #rss_with_headlines ⇒ Object
- #save ⇒ Object
-
#save_menu ⇒ Object
}}}.
- #search ⇒ Object
-
#set_menu_pages ⇒ Object
}}}.
-
#show ⇒ Object
Within a single page ——————————————————–.
- #static_style_sheet ⇒ Object
- #tex ⇒ Object
-
#todo ⇒ Object
{{{.
- #update_web ⇒ Object
-
#web_list ⇒ Object
Outside a single web ——————————————————–.
Instance Method Details
#authenticate ⇒ Object
52 53 54 |
# File 'app/controllers/wiki.rb', line 52 def authenticate password_check(@params["password"]) ? redirect_show("HomePage") : redirect_action("login") end |
#authors ⇒ Object
78 79 80 |
# File 'app/controllers/wiki.rb', line 78 def @authors = web.select. end |
#bliki ⇒ Object
}}}
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'app/controllers/wiki.rb', line 226 def bliki #{{{ @entries = web.bliki_entries_by_date unless @req.query['authorname'].nil? || @req.query['authorname'] == 'noselect' @entries = @entries.select { |page| page..include?(@req.query['authorname']) } end unless @req.query['regexp'].nil? @entries = @entries.select { |page| page.content =~ /#{@req.query['regexp']}/i } end @color = web.color @authors = web. end |
#bliki_delete ⇒ Object
Bliki ———————————————————————-
389 390 391 392 |
# File 'app/controllers/wiki.rb', line 389 def bliki_delete wiki.delete_bliki_entry(web_address, page_name) redirect_bliki("") end |
#bliki_edit ⇒ Object
394 395 396 397 398 399 400 401 402 403 404 |
# File 'app/controllers/wiki.rb', line 394 def bliki_edit @page = wiki.read_bliki_entry(web_address, page_name) if !@page.locked?(Time.now) || @params["break_lock"] @page.lock(Time.now, ) @author = render else redirect_path "#{web_address}/locked" end end |
#bliki_revision ⇒ Object
425 426 427 428 |
# File 'app/controllers/wiki.rb', line 425 def bliki_revision @page = wiki.read_bliki_entry(web_address, page_name || @params['pagename']) @revision = @page.revisions[@params["rev"].to_i] || @page.revisions.last end |
#bliki_save ⇒ Object
412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'app/controllers/wiki.rb', line 412 def bliki_save pname = page_name || @params["pagename"] if web.bliki[pname] page = wiki.revise_bliki_entry(web_address, pname, @params["content"], Time.now, @params["author"]) page.unlock else page = wiki.write_bliki_entry(web_address, pname, @params["content"], Time.now, @params["author"]) end ("author", @params["author"]) redirect_bliki('') end |
#cancel_bliki_edit ⇒ Object
406 407 408 409 410 |
# File 'app/controllers/wiki.rb', line 406 def cancel_bliki_edit @page = wiki.read_bliki_entry(web_address, page_name) @page.unlock if @page redirect_bliki(@page? @page.name : "") end |
#cancel_edit ⇒ Object
351 352 353 354 355 |
# File 'app/controllers/wiki.rb', line 351 def cancel_edit @page = wiki.read_page(web_address, page_name) @page.unlock redirect_show end |
#create_system ⇒ Object
29 30 31 32 |
# File 'app/controllers/wiki.rb', line 29 def create_system wiki.setup(@params["password"], @params["web_name"], @params["web_address"]) unless wiki.setup? redirect_path "/" end |
#create_web ⇒ Object
34 35 36 37 38 |
# File 'app/controllers/wiki.rb', line 34 def create_web redirect_path("/") unless wiki.authenticate(@params["system_password"]) wiki.create_web(@params["name"], @params["address"]) redirect_show("HomePage", @params["address"]) end |
#edit ⇒ Object
339 340 341 342 343 344 345 346 347 348 349 |
# File 'app/controllers/wiki.rb', line 339 def edit @page = wiki.read_page(web_address, page_name) if !@page.locked?(Time.now) || @params["break_lock"] @page.lock(Time.now, ) @author = render else render "wiki/locked" end end |
#edit_menu ⇒ Object
}}}
259 260 261 262 263 264 |
# File 'app/controllers/wiki.rb', line 259 def #{{{ @menu_type = web. @menu_content = web. @list_limit = web. @list_limit += 1 if @list_limit >= -1 end |
#export_html ⇒ Object
123 124 125 126 127 128 129 |
# File 'app/controllers/wiki.rb', line 123 def export_html file_name = "#{web.address}-html-#{web.revised_on.strftime("%Y-%m-%d-%H-%M")}.zip" file_path = EXPORT_DIRECTORY + file_name export_pages_to_zip_file(file_path) unless FileTest.exists?(file_path) send_export(file_name, file_path) end |
#export_markup ⇒ Object
131 132 133 134 135 136 137 |
# File 'app/controllers/wiki.rb', line 131 def export_markup file_name = "#{web.address}-markup-#{web.revised_on.strftime("%Y-%m-%d-%H-%M")}.zip" file_path = EXPORT_DIRECTORY + file_name export_markup_to_zip_file(file_path) unless FileTest.exists?(file_path) send_export(file_name, file_path) end |
#export_pdf ⇒ Object
139 140 141 142 143 144 145 146 |
# File 'app/controllers/wiki.rb', line 139 def export_pdf file_name = "#{web.address}-tex-#{web.revised_on.strftime("%Y-%m-%d-%H-%M")}" file_path = EXPORT_DIRECTORY + file_name export_web_to_tex(file_path + ".tex") unless FileTest.exists?(file_path + ".tex") convert_tex_to_pdf(file_path + ".tex") send_export(file_name + ".pdf", file_path + ".pdf") end |
#export_tex ⇒ Object
148 149 150 151 152 153 154 |
# File 'app/controllers/wiki.rb', line 148 def export_tex file_name = "#{web.address}-tex-#{web.revised_on.strftime("%Y-%m-%d-%H-%M")}.tex" file_path = EXPORT_DIRECTORY + file_name export_web_to_tex(file_path) unless FileTest.exists?(file_path) send_export(file_name, file_path) end |
#index ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/controllers/wiki.rb', line 7 def index if web_address redirect_show "HomePage" elsif !wiki.setup? redirect_path "/new_system/" elsif wiki.webs.length == 1 redirect_show "HomePage", wiki.webs.values.first.address else redirect_path "/web_list/" end end |
#list ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'app/controllers/wiki.rb', line 102 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 case @req.query['Action'] when 'Delete' # Handle page deletion wiki.delete_page(web_address, @req.query['sel_page_name']) redirect_action "list/" when 'Create' # Handle page creation redirect_show @req.query['newpage'] when 'Rename' # Handle page rename wiki.rename_page(web_address, @req.query['sel_page_name'], @req.query['newpage']) redirect_action "list/" end end |
#login ⇒ Object
48 49 50 |
# File 'app/controllers/wiki.rb', line 48 def login render "wiki/login" end |
#mind ⇒ Object
}}}
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'app/controllers/wiki.rb', line 243 def mind #{{{ parse_category @prog = @req.query['draw_type'] || 'neato' @graph_type = @req.query['graph_type'] || 'normal' missing = @pages_in_category.wanted_pages if @req.query['missing'] = @req.query['show_authors'] == 'on' @pngFile = @mapFile = nil case @graph_type when 'normal' then @pngFile, @mapFile = web.create_mind_map(@prog, missing, ) when 'author' then @pngFile, @mapFile = web.(@prog) when 'category' then @pngFile, @mapFile = web.create_category_graph(@prog, ) end end |
#new ⇒ Object
335 336 337 |
# File 'app/controllers/wiki.rb', line 335 def new @page_name, @author = page_name, end |
#new_system ⇒ Object
Administrating the Instiki setup ——————————————–
21 22 23 |
# File 'app/controllers/wiki.rb', line 21 def new_system wiki.setup? ? redirect_path("/") : render end |
#new_web ⇒ Object
25 26 27 |
# File 'app/controllers/wiki.rb', line 25 def new_web redirect_path("/") if wiki.system["password"].nil? end |
#parse_category ⇒ Object
Within a single web ———————————————————
60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/wiki.rb', line 60 def parse_category @categories = web.categories @category = @params["category"] @pages_in_category = web.select { |page| page.in_category?(@category) } @set_name = ( @categories.include?(@category) ? "category '#{@category}'" : "the web" ) @category_links = @categories.map do |c| (@category == c ? "<span class=\"selected\">#{c}</span>" : "<a href=\"?category=#{c}\">#{c}</a>") end end |
#pdf ⇒ Object
324 325 326 327 328 329 330 331 332 333 |
# File 'app/controllers/wiki.rb', line 324 def pdf page = wiki.read_page(web_address, 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")}" file_path = EXPORT_DIRECTORY + file_name export_page_to_tex(file_path + ".tex") unless FileTest.exists?(file_path + ".tex") convert_tex_to_pdf(file_path + ".tex") send_export(file_name + ".pdf", file_path + ".pdf") end |
#print ⇒ Object
315 316 317 |
# File 'app/controllers/wiki.rb', line 315 def print @page = wiki.read_page(web_address, page_name) end |
#published ⇒ Object
311 312 313 |
# File 'app/controllers/wiki.rb', line 311 def published if web.published then @page = wiki.read_page(web_address, page_name || "HomePage") else redirect_show("HomePage") end end |
#recently_revised ⇒ Object
82 83 84 85 86 |
# File 'app/controllers/wiki.rb', line 82 def recently_revised parse_category @pages_by_revision = @pages_in_category.by_revision end |
#remove_orphaned_pages ⇒ Object
173 174 175 176 177 178 179 180 |
# File 'app/controllers/wiki.rb', line 173 def remove_orphaned_pages if wiki.authenticate(@params["system_password"]) wiki.remove_orphaned_pages(web_address) redirect_action "list/" else redirect_show "HomePage" end end |
#revision ⇒ Object
376 377 378 379 |
# File 'app/controllers/wiki.rb', line 376 def revision @page = wiki.read_page(web_address, page_name) @revision = @page.revisions[@params["rev"].to_i] end |
#rollback ⇒ Object
381 382 383 384 385 |
# File 'app/controllers/wiki.rb', line 381 def rollback @page = wiki.read_page(web_address, page_name) wiki.rollback_page(web_address, page_name, @params["rev"].to_i, Time.now, remote_ip) redirect_show end |
#rollback_bliki ⇒ Object
430 431 432 433 434 |
# File 'app/controllers/wiki.rb', line 430 def rollback_bliki @page = wiki.read_bliki_entry(web_address, page_name) wiki.rollback_bliki_entry(web_address, page_name, @params["rev"].to_i, Time.now) redirect_bliki end |
#rss_with_content ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'app/controllers/wiki.rb', line 88 def rss_with_content @pages_by_revision = web.select.by_revision.first(15) @uri = @req.request_uri host = @req.["HTTP_X_FORWARDED_HOST"] || "#{@uri.host}:#{@uri.port.to_s}" @web_url = "#{@uri.scheme}://#{host}/#{@web.address}" @res["Content-Type"] = "text/xml" render "wiki/rss_feed" end |
#rss_with_headlines ⇒ Object
97 98 99 100 |
# File 'app/controllers/wiki.rb', line 97 def rss_with_headlines @hide_description = true rss_with_content end |
#save ⇒ Object
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
# File 'app/controllers/wiki.rb', line 357 def save if web.pages[page_name] page = wiki.revise_page( web_address, page_name, @params["content"], Time.now, Author.new(@params["author"], remote_ip) ) page.unlock else page = wiki.write_page( web_address, page_name, @params["content"], Time.now, Author.new(@params["author"], remote_ip) ) end ("author", @params["author"], true) redirect_show(page_name) end |
#save_menu ⇒ Object
}}}
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'app/controllers/wiki.rb', line 266 def #{{{ unless @req.query['action'] == 'Cancel Update' type = @req.query['type'] content = @req.query['content'] category = @req.query['category'] limit = @req.query['limit'].to_i rescue nil limit = 20 unless limit limit -= 1 if limit >= 0 # need to go through the WikiService to persist the command: wiki. web, type, limit, content, category end if web_address redirect_show "HomePage" elsif wiki.webs.length == 1 redirect_show "HomePage", wiki.webs.values.first.address else redirect_path "/web_list/" end end |
#search ⇒ Object
70 71 72 73 74 75 76 |
# File 'app/controllers/wiki.rb', line 70 def search @query = @params["query"] rex = /#{@query}/i @results = web.select { |page| rex.match(page.name) or rex.match(page.content) } @results.length == 1 ? redirect_show(@results.first.name) : render end |
#set_menu_pages ⇒ Object
}}}
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'app/controllers/wiki.rb', line 206 def #{{{ parse_category @all_pages = web.select { true } @menu_pages = case web. when 'all' then @all_pages.by_name when 'recent' then @all_pages.by_last_visited when 'viewed' then @all_pages.by_most_viewed when 'revised' then @all_pages.by_revision when 'user' then @menu_content = web.; nil when 'category' then web.select { |page| page.in_category?(web.) } when 'linkers' web.select { |page| page.wiki_words.size > 0 }.sort_by { |page| page.name } end if web. @menu_pages = @menu_pages[0..web.] end end |
#show ⇒ Object
Within a single page ——————————————————–
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'app/controllers/wiki.rb', line 292 def show if @page = wiki.read_page(web_address, page_name) unless page_name == 'HomePage' # HomePage should not be in the menu as there's a link at the top. @page.last_visited = Time.now @page.viewed += 1 end begin render_action "page" rescue => e $stderr << e.backtrace.join("\n") redirect_action "edit/#{CGI.escape(page_name)}?msg=#{CGI.escape(e.)}" end else redirect_action "new/#{CGI.escape(page_name)}" end end |
#static_style_sheet ⇒ Object
56 |
# File 'app/controllers/wiki.rb', line 56 def static_style_sheet() render "static_style_sheet" end |
#tex ⇒ Object
319 320 321 322 |
# File 'app/controllers/wiki.rb', line 319 def tex @page = wiki.read_page(web_address, page_name) @tex_content = RedClothForTex.new(@page.content).to_tex end |
#todo ⇒ Object
{{{
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'app/controllers/wiki.rb', line 182 def todo #{{{ parse_category @pages_by_name = @pages_in_category.by_name @todo_items = Hash.new { Array.new } @bliki_todo_items = Hash.new { Array.new } @pages_by_name.each do |page| if page.content =~ Todo.pattern # Page has todo items. Get the rendered version (marked-up and with links): content = page.revisions.last.display_content @todo_items[page] = content.scan /<span class="todo"><strong>TODO:<\/strong> (.*?)<\/span>/ end end @todo_items = @todo_items.sort_by { |page, items| page.name } web.bliki.each do |pname, entry| if entry.content =~ Todo.pattern # Entry has todo items. Get the rendered version (marked-up and with links): content = entry.revisions.last.display_content @bliki_todo_items[entry] = content.scan /<span class="todo"><strong>TODO:<\/strong> (.*?)<\/span>/ end end @bliki_todo_items = @bliki_todo_items.sort_by { |entry, items| entry.name } end |
#update_web ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'app/controllers/wiki.rb', line 156 def update_web redirect_show("HomePage") unless wiki.authenticate(@params["system_password"]) wiki.update_web( web.address, @params["address"], @params["name"], @params["markup"].intern, @params["color"], @params["additional_style"], @params["safe_mode"] ? true : false, @params["password"].empty? ? nil : @params["password"], @params["published"] ? true : false, @params["brackets_only"] ? true : false, @params["count_pages"] ? true : false ) redirect_show("HomePage", @params["address"]) end |
#web_list ⇒ Object
Outside a single web ——————————————————–
43 44 45 46 |
# File 'app/controllers/wiki.rb', line 43 def web_list @system, @webs = wiki.system, wiki.webs.values render "wiki/web_list" end |