Class: WikiController
- Inherits:
-
ActionControllerServlet
- Object
- ActionControllerServlet
- WikiController
- Defined in:
- app/controllers/wiki.rb
Constant Summary collapse
- EXPORT_DIRECTORY =
WikiService.storage_path
- FAR_FUTURE =
Date.new(4000,1,1).freeze
- TODO_RE =
%r{<todo-tag context='(.*?)' due_date='(.*?)'><span class="todo"><strong>TODO(?:[^:]*)?:</strong> (.*?)</span></todo-tag>}
Instance Method Summary collapse
- #administrate ⇒ Object
- #adv_search ⇒ Object
-
#analyse_rendered_todo_items(pages) ⇒ Object
}}}.
- #authenticate ⇒ Object
- #authors ⇒ Object
-
#bliki ⇒ Object
}}}.
-
#bliki_delete ⇒ Object
Bliki ———————————————————————-.
- #bliki_edit ⇒ Object
- #bliki_new ⇒ Object
- #bliki_revision ⇒ Object
- #bliki_save ⇒ Object
- #cancel_bliki_edit ⇒ Object
- #cancel_edit ⇒ Object
- #check_external_req_and_redirect(web) ⇒ Object
- #clear_render_cache(dont_redirect = false) ⇒ Object
- #create_system ⇒ Object
- #create_web ⇒ Object
- #edit ⇒ Object
-
#edit_menu ⇒ Object
}}}.
-
#edit_web ⇒ Object
{{{.
- #export ⇒ Object
- #export_html ⇒ Object
- #export_markup ⇒ Object
- #export_pdf ⇒ Object
- #export_tex ⇒ Object
- #feeds ⇒ Object
-
#get_map_img ⇒ Object
}}}.
- #get_todo_display_style(due_date) ⇒ Object
- #glossary ⇒ 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 ———————————————————.
-
#parse_multi_select(field) ⇒ Object
}}}.
- #pdf ⇒ Object
- #print ⇒ Object
- #published ⇒ Object
- #recently_revised ⇒ Object
- #revision ⇒ Object
- #rollback ⇒ Object
- #rollback_bliki ⇒ Object
- #rss_bliki_only ⇒ Object
- #rss_todo_items ⇒ Object
- #rss_with_content ⇒ Object
- #rss_with_headlines ⇒ Object
- #save ⇒ Object
-
#save_menu ⇒ Object
}}}.
- #search ⇒ Object
-
#set_menu_pages(published = false) ⇒ Object
{{{.
-
#set_mm_options ⇒ Object
}}}.
-
#show ⇒ Object
Within a single page ——————————————————–.
- #sort_and_filter_todo_items(items, sort_order, context) ⇒ Object
- #static_style_sheet ⇒ Object
- #stop ⇒ Object
- #tex ⇒ Object
-
#todo ⇒ Object
{{{.
-
#update_web ⇒ Object
}}}.
-
#web_list ⇒ Object
Outside a single web ——————————————————–.
Instance Method Details
#administrate ⇒ Object
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'app/controllers/wiki.rb', line 340 def administrate @logger.info "Taking administrative action: #{@params['action']}" redirect_show 'HomePage' unless wiki.authenticate(@params['system_password']) case @params['action'] when 'Delete Orphan Pages' wiki.remove_orphaned_pages(web_address) when 'Clear Render Cache' clear_render_cache true when 'Force Data Snapshot' WikiService.take_snapshot when 'Clean Storage' WikiService.clean_old_snapshots when 'Make This Web Default' wiki.default_web = web_address when 'Remove This Web' wiki.webs.delete web_address redirect_path '/' end @message = 'Operation succeeded' redirect_action 'edit_web/' end |
#adv_search ⇒ Object
579 580 581 582 |
# File 'app/controllers/wiki.rb', line 579 def adv_search parse_category end |
#analyse_rendered_todo_items(pages) ⇒ Object
}}}
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'app/controllers/wiki.rb', line 397 def analyse_rendered_todo_items pages items = Hash.new { Array.new } pages.each do |page| if page.has_todos? # Page has todo items. Get the rendered version (marked-up and with links): # I specifically don't use the todo chunkss because I want the fully marked-up # text of the item. content = page.revisions.last.display_content items[page] = content.scan(TODO_RE).map { |match| RenderedTodo.new match[2], (match[0].empty? ? [] : match[0].split(',') ), (Date.parse(match[1]) rescue FAR_FUTURE) } end end items end |
#authenticate ⇒ Object
64 65 66 |
# File 'app/controllers/wiki.rb', line 64 def authenticate password_check(@params["password"]) ? redirect_show("HomePage") : redirect_action("login") end |
#authors ⇒ Object
199 200 201 202 |
# File 'app/controllers/wiki.rb', line 199 def @authors = web.select. end |
#bliki ⇒ Object
}}}
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
# File 'app/controllers/wiki.rb', line 476 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 ———————————————————————-
697 698 699 700 701 702 703 |
# File 'app/controllers/wiki.rb', line 697 def bliki_delete # redirect_bliki if web.check_pass_on_edit and not password_check(@params['password']) wiki.delete_bliki_entry(web_address, page_name) clear_render_cache true redirect_bliki end |
#bliki_edit ⇒ Object
705 706 707 708 709 710 711 712 713 714 715 716 717 718 |
# File 'app/controllers/wiki.rb', line 705 def bliki_edit # redirect_bliki if web.check_pass_on_edit and not password_check(@params['password']) @page = wiki.read_bliki_entry(web_address, page_name) if !@page.locked?(Time.now) || @params["break_lock"] @page.lock(Time.now, ) @author = render else @bliki_entry = true render "wiki/locked" end end |
#bliki_new ⇒ Object
726 727 728 729 |
# File 'app/controllers/wiki.rb', line 726 def bliki_new @entry_name = @params['entry_name'] @author = end |
#bliki_revision ⇒ Object
746 747 748 749 750 751 752 753 754 755 |
# File 'app/controllers/wiki.rb', line 746 def bliki_revision parse_category @page = wiki.read_bliki_entry(web_address, page_name || @params['pagename']) if @page.nil? render_text "Unable to find bliki entry #{page_name || @params['pagename']}" return end @revision = @page.revisions[@params["rev"].to_i] || @page.revisions.last end |
#bliki_save ⇒ Object
731 732 733 734 735 736 737 738 739 740 741 742 743 744 |
# File 'app/controllers/wiki.rb', line 731 def bliki_save # redirect_bliki if web.check_pass_on_edit and not password_check(@params['password']) 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
720 721 722 723 724 |
# File 'app/controllers/wiki.rb', line 720 def cancel_bliki_edit @page = wiki.read_bliki_entry(web_address, page_name) @page.unlock if @page redirect_bliki end |
#cancel_edit ⇒ Object
651 652 653 654 655 |
# File 'app/controllers/wiki.rb', line 651 def cancel_edit @page = wiki.read_page(web_address, page_name) @page.unlock redirect_show end |
#check_external_req_and_redirect(web) ⇒ Object
23 24 25 26 27 28 29 |
# File 'app/controllers/wiki.rb', line 23 def check_external_req_and_redirect web if web.default_to_published and @req.addr[2] != @req.peeraddr[2] redirect_action("published/", web.address) else redirect_show("HomePage", web.address) end end |
#clear_render_cache(dont_redirect = false) ⇒ Object
444 445 446 447 |
# File 'app/controllers/wiki.rb', line 444 def clear_render_cache dont_redirect=false web.refresh_revisions redirect_path "/#{web_address}/edit_web/" unless dont_redirect end |
#create_system ⇒ Object
41 42 43 44 |
# File 'app/controllers/wiki.rb', line 41 def create_system wiki.setup(@params["password"], @params["web_name"], @params["web_address"]) unless wiki.setup? redirect_path "/" end |
#create_web ⇒ Object
46 47 48 49 50 |
# File 'app/controllers/wiki.rb', line 46 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
639 640 641 642 643 644 645 646 647 648 649 |
# File 'app/controllers/wiki.rb', line 639 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
}}}
545 546 547 548 549 550 551 |
# File 'app/controllers/wiki.rb', line 545 def #{{{ @menu_type = web. @menu_content = web. @list_limit = web. @list_limit += 1 if @list_limit >= -1 @author = end |
#edit_web ⇒ Object
{{{
305 306 307 308 309 |
# File 'app/controllers/wiki.rb', line 305 def edit_web #{{{ parse_category @snapshot_interval = WikiService.snapshot_interval_hours end |
#export ⇒ Object
268 269 270 |
# File 'app/controllers/wiki.rb', line 268 def export end |
#export_html ⇒ Object
272 273 274 275 276 277 278 |
# File 'app/controllers/wiki.rb', line 272 def export_html file_name = "#{web.address}-html-#{web.revised_on.strftime("%Y-%m-%d-%H-%M")}.zip" file_path = File.join 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
280 281 282 283 284 285 286 |
# File 'app/controllers/wiki.rb', line 280 def export_markup file_name = "#{web.address}-markup-#{web.revised_on.strftime("%Y-%m-%d-%H-%M")}.zip" file_path = File.join 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
288 289 290 291 292 293 294 295 |
# File 'app/controllers/wiki.rb', line 288 def export_pdf file_name = "#{web.address}-tex-#{web.revised_on.strftime('%Y-%m-%d-%H-%M')}" file_path = File.join 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
297 298 299 300 301 302 303 |
# File 'app/controllers/wiki.rb', line 297 def export_tex file_name = "#{web.address}-tex-#{web.revised_on.strftime('%Y-%m-%d-%H-%M')}.tex" file_path = File.join EXPORT_DIRECTORY, file_name export_web_to_tex(file_path) unless FileTest.exists?(file_path) send_export(file_name, file_path) end |
#feeds ⇒ Object
236 237 238 |
# File 'app/controllers/wiki.rb', line 236 def feeds end |
#get_map_img ⇒ Object
}}}
573 574 575 576 577 |
# File 'app/controllers/wiki.rb', line 573 def get_map_img file_name = "map.png" file_path = File.join WikiService.storage_path, file_name send_export(file_name, file_path, "image/png") end |
#get_todo_display_style(due_date) ⇒ Object
438 439 440 441 442 |
# File 'app/controllers/wiki.rb', line 438 def get_todo_display_style due_date # default is the muted 'darkred', to prevent to many bright red # items on one page: (See also chunks/todo.rb) (due_date <=> Date.today) > -1 ? "todoFuture" : "todo" end |
#glossary ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'app/controllers/wiki.rb', line 180 def glossary rex = %r{([A-Z\d]+)\(([\w\s]+)\)} scan_results = web.select.map { |page| [page.link, page.content.scan(rex)] } scan_results += web.bliki.values.map { |entry| [link_to_bliki(entry), entry.content.scan(rex)] } results = Hash.new { Array.new } scan_results.each { |page, acronyms| acronyms.each { |ac| results[ac] += [page] } } @results = results.map{ |(ac, df), pg|[[ac,df], pg.uniq] }.sort_by{ |(ac, df), pg| ac } acronyms = @results.map { |(ac, df), pg| ac } rex = %r{(#{acronyms.join('|')})[^\(]} results = web.select.map { |page| [page.link, page.content.scan(rex)] } results += web.bliki.values.map { |entry| [link_to_bliki(entry), entry.content.scan(rex)] } @undefined_on = Hash.new { Array.new } results.each { |page, acronyms| acronyms.each { |ac| @undefined_on[ac[0]] += [page] } } @undefined_on = @undefined_on.inject({}) { |hsh, (k, v)| hsh[k] = v.uniq; hsh } end |
#index ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/controllers/wiki.rb', line 9 def index if web_address check_external_req_and_redirect web elsif !wiki.setup? redirect_path "/new_system/" elsif wiki.webs.length == 1 check_external_req_and_redirect wiki.webs.values.first else wiki.default_web ? check_external_req_and_redirect(wiki.webs[wiki.default_web]) : redirect_path("/web_list/") end end |
#list ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'app/controllers/wiki.rb', line 240 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 if @req.query['Action'] # redirect_action 'list/' if web.check_pass_on_edit and not password_check(@params['password']) case @req.query['Action'] when 'Delete' # Handle page deletion wiki.delete_page(web_address, @req.query['del_sel_page_name']) clear_render_cache true 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['ren_sel_page_name'], @req.query['ren_newpage']) clear_render_cache true redirect_action "list/" end end end |
#login ⇒ Object
60 61 62 |
# File 'app/controllers/wiki.rb', line 60 def login render "wiki/login" end |
#mind ⇒ Object
}}}
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
# File 'app/controllers/wiki.rb', line 493 def mind #{{{ parse_category @pngFile = @mapFile = nil case @graph_type when 'normal' @pngFile, @mapFile = web.create_mind_map(@prog, @missing, @show_authors, @show_leaves, @selected_categories, @mm_size) when 'author' @pngFile, @mapFile = web.(@prog, @selected_categories, @mm_size) when 'category' @pngFile, @mapFile = web.create_category_graph(@prog, @show_authors, @selected_categories, @mm_size) end end |
#new ⇒ Object
634 635 636 637 |
# File 'app/controllers/wiki.rb', line 634 def new # redirect_show("HomePage") if web.check_pass_on_edit and not password_check(@params['password']) @page_name, @author = page_name, end |
#new_system ⇒ Object
Administrating the Instiki setup ——————————————–
33 34 35 |
# File 'app/controllers/wiki.rb', line 33 def new_system wiki.setup? ? redirect_path("/") : render end |
#new_web ⇒ Object
37 38 39 |
# File 'app/controllers/wiki.rb', line 37 def new_web redirect_path("/") if wiki.system["password"].nil? end |
#parse_category ⇒ Object
Within a single web ———————————————————
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/controllers/wiki.rb', line 87 def parse_category @categories = web.categories @category = @params["category"] @pages_in_category = web.select { |page| page.in_category?(@category) } @pages_without_category = web.select { |page| page.categories.length == 0 } if @category == 'none' @pages_in_category = @pages_without_category end @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 |
#parse_multi_select(field) ⇒ Object
}}}
535 536 537 538 539 540 541 542 543 |
# File 'app/controllers/wiki.rb', line 535 def parse_multi_select field #{{{ if @req.body @req.body.split('&').map { |pair| pair.split('=') }.select { |k,v| k == field }.map { |k,v| v } else [] end end |
#pdf ⇒ Object
623 624 625 626 627 628 629 630 631 632 |
# File 'app/controllers/wiki.rb', line 623 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 = File.join 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
614 615 616 |
# File 'app/controllers/wiki.rb', line 614 def print @page = wiki.read_page(web_address, page_name) end |
#published ⇒ Object
609 610 611 612 |
# File 'app/controllers/wiki.rb', line 609 def published true if web.published then @page = wiki.read_page(web_address, page_name || "HomePage") else redirect_show("HomePage") end end |
#recently_revised ⇒ Object
204 205 206 207 208 |
# File 'app/controllers/wiki.rb', line 204 def recently_revised parse_category @pages_by_revision = @pages_in_category.by_revision end |
#revision ⇒ Object
681 682 683 684 685 686 |
# File 'app/controllers/wiki.rb', line 681 def revision redirect_show 'HomePage' if page_name.nil? @page = wiki.read_page(web_address, page_name) @revision = @page.revisions[@params["rev"].to_i] end |
#rollback ⇒ Object
688 689 690 691 692 693 |
# File 'app/controllers/wiki.rb', line 688 def rollback # redirect_show("HomePage") if web.check_pass_on_edit and not password_check(@params['password']) @page = wiki.read_page(web_address, page_name) @revision = @page.revisions[@params["rev"].to_i] end |
#rollback_bliki ⇒ Object
757 758 759 760 761 762 763 |
# File 'app/controllers/wiki.rb', line 757 def rollback_bliki # redirect_bliki if web.check_pass_on_edit and not password_check(@params['password']) @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_bliki_only ⇒ Object
225 226 227 228 |
# File 'app/controllers/wiki.rb', line 225 def rss_bliki_only @rss_bliki_only = true rss_with_content end |
#rss_todo_items ⇒ Object
230 231 232 233 234 |
# File 'app/controllers/wiki.rb', line 230 def rss_todo_items todo @display_todo = true rss_with_content end |
#rss_with_content ⇒ Object
210 211 212 213 214 215 216 217 218 |
# File 'app/controllers/wiki.rb', line 210 def rss_with_content @pages_by_revision = @rss_bliki_only ? [] : web.select.by_revision.first(15) @bliki_entries = web.bliki_entries_by_date @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
220 221 222 223 |
# File 'app/controllers/wiki.rb', line 220 def rss_with_headlines @hide_description = true rss_with_content end |
#save ⇒ Object
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 |
# File 'app/controllers/wiki.rb', line 657 def save # if web.check_pass_on_edit and not password_check(@params['password']) # wiki.read_page(web_address, page_name).unlock if web.pages[page_name] # redirect_show("HomePage") # end if web.pages[page_name] page = wiki.revise_page( web_address, page_name, @params["content"], Time.now, Author.new(@params["author"], remote_ip), @params['edit_type'] ) 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
}}}
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
# File 'app/controllers/wiki.rb', line 553 def #{{{ redirect_show("HomePage") unless wiki.authenticate(@params["system_password"]) unless @req.query['action'] == 'Cancel Update' type = @req.query['type'] content = @req.query['content'] sel_category = @req.query['sel_category'] = @req.query['author'] 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_address, type, limit, content, sel_category, Author.new(, remote_ip)) end redirect_action 'edit_web/' # go back to web options page end |
#search ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'app/controllers/wiki.rb', line 101 def search @query = @params["query"] search_content = [nil, 'both', 'contents'].include? @params['fields'] search_names = [nil, 'both', 'names'].include? @params['fields'] case @params['expression'] when 'regex', nil rex = Regexp.new @query, (Regexp::IGNORECASE unless @params['case']) @results = if [nil, 'all', 'pages', nil].include? @params['where'] web.select do |page| (search_names and rex.match(page.name)) or (search_content and rex.match(page.content)) end else [] end @bliki_results = if [nil, 'all', 'bliki'].include? @params['where'] web.bliki.values.select do |entry| (search_names and rex.match(entry.name)) or (search_content and rex.match(entry.content)) end else [] end when 'all' words = @query.split(/\s/).reject { |w| w.empty? } @results = if [nil, 'all', 'pages'].include? @params['where'] web.select do |page| words.all? do |word| (search_names and page.name.index(word)) or (search_content and page.content.index(word)) end end else [] end @bliki_results = if [nil, 'all', 'bliki'].include? @params['where'] web.bliki.values.select do |entry| words.all? do |word| (search_names and entry.name.index(word)) or (search_content and entry.content.index(word)) end end else [] end when 'exact' @results = if [nil, 'all', 'pages'].include? @params['where'] web.select do |page| (search_names and page.name.index(@query)) or (search_content and page.content.index(@query)) end else [] end @bliki_results = if [nil, 'all', 'bliki'].include? @params['where'] web.bliki.values.select do |entry| (search_names and entry.name.index(@query)) or (search_content and entry.content.index(@query)) end else [] end end if !@params['category'].nil? and @params['category'] != 'noselect' @selected_categories = parse_multi_select 'category' @results.reject! { |page| (page.categories & @selected_categories).empty? } @bliki_results.reject! { |page| (page.categories & @selected_categories).empty? } end if !@params['author'].nil? and @params['author'] != 'noselect' @selected_authors = parse_multi_select 'author' @results.reject! { |page| (page. & @selected_authors).empty? } @bliki_results.reject! { |page| (page. & @selected_authors).empty? } end redirect_show(@results.first.name) if @results.length == 1 && @bliki_results.length == 0 redirect_path("/#{web_address}/bliki_revision/#{@bliki_results.first.name}?rev=#{@bliki_results.first.revisions.size-1}") if @results.length == 0 && @bliki_results.length == 1 render_action "search" end |
#set_menu_pages(published = false) ⇒ Object
{{{
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
# File 'app/controllers/wiki.rb', line 449 def published = false #{{{ 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 'category' then web.select { |page| page.in_category?(web.) } when 'user' @menu_content = if Page === web. web..revisions.last.display_content else web. end @menu_content = @menu_content.gsub('/show/', '/published/').gsub( %r{<a href="../published/.*?">\?</a>}, '') if published nil when 'linkers' web.select { |page| page.wiki_words.size > 0 }.sort_by { |page| page.name } end if web. && @menu_pages @menu_pages = @menu_pages[0..web.] end end |
#set_mm_options ⇒ Object
}}}
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 |
# File 'app/controllers/wiki.rb', line 513 def #{{{ if @req.query.empty? @prog = web.mm_prog @graph_type = web.mm_graph_type @missing = @pages_in_category.wanted_pages if web.mm_show_missing @show_authors = web. @show_leaves = web.mm_show_leaves @selected_categories = web.mm_selected_categories @mm_size = web.mind_map_size else @prog = @req.query['draw_type'] || 'neato' @graph_type = @req.query['graph_type'] || 'normal' @missing = @pages_in_category.wanted_pages if @req.query['missing'] @show_authors = @req.query['show_authors'] == 'on' @show_leaves = @req.query.empty? || @req.query['show_leaves'] == 'on' @selected_categories = parse_multi_select 'selected_categs' @selected_categories = [] if @selected_categories.include? 'all' @mm_size = @params['mind_map_size'] || web.mind_map_size end end |
#show ⇒ Object
Within a single page ——————————————————–
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 |
# File 'app/controllers/wiki.rb', line 586 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 if page_name redirect_action "new/#{CGI.escape(page_name)}" else redirect_show "HomePage" end end end |
#sort_and_filter_todo_items(items, sort_order, context) ⇒ Object
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
# File 'app/controllers/wiki.rb', line 413 def sort_and_filter_todo_items items, sort_order, context case sort_order when 'due_date' result = items.map { |page, todos| # sort the to items themselves [page, todos.sort_by { |i| i.due_date } ] }.sort_by { |page, todos| # sort the pages by the one with the most urgent todo todos.map{ |i| i.due_date }.min } else # default = sort by page name result = items.sort_by { |page, items| page.name } end if context # filter the items to those that are in context result = result.map { |page, items| [ page, items.select { |item| item.context.include? context } ] }.select { |page, items| not items.empty? } end result end |
#static_style_sheet ⇒ Object
68 |
# File 'app/controllers/wiki.rb', line 68 def static_style_sheet() render "static_style_sheet" end |
#stop ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/controllers/wiki.rb', line 70 def stop redirect_show("HomePage") unless wiki.authenticate(@params["system_password"]) begin secs = @params['seconds'].to_i raise if secs.zero? @logger.warn "Pimki server will stop in #{secs} seconds!" WikiService.request_stop render_text "Pimki server will stop in #{secs} seconds!" Thread.new { sleep secs; Kernel.exit! } rescue redirect_show("HomePage") end end |
#tex ⇒ Object
618 619 620 621 |
# File 'app/controllers/wiki.rb', line 618 def tex @page = wiki.read_page(web_address, page_name) @tex_content = RedClothForTex.new(@page.content).to_tex end |
#todo ⇒ Object
{{{
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'app/controllers/wiki.rb', line 371 def todo #{{{ parse_category @context = @params['context'] @sort_order = @params['sort_order'] # the clear_render_cache hack to make sure we don't have old-style rendered # todos is no longer needed - can go thru the edit web to explicitely clear the cache. @todo_items = analyse_rendered_todo_items @pages_in_category.by_name @bliki_todo_items = analyse_rendered_todo_items web.bliki.values @context_links = @todo_items.clone.update(@bliki_todo_items).map { |page, items| # 'items' contain the full 'todo' info items.map { |item| item.context } }.flatten.compact.uniq.reject { |c| c.nil? || c.empty? }.map { |context| @context == context ? "[<span class='selected'>#{context}</span>]" : "<a href='?context=#{context}#{"&sort_order=#{@sort_order}" if @sort_order}'>#{context}</a>" } @todo_items = sort_and_filter_todo_items @todo_items, @sort_order, @context @bliki_todo_items = sort_and_filter_todo_items @bliki_todo_items, @sort_order, @context end |
#update_web ⇒ Object
}}}
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'app/controllers/wiki.rb', line 311 def update_web redirect_show("HomePage") unless wiki.authenticate(@params["system_password"]) parse_category 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['default_to_published'] ? true : false, @params["brackets_only"] ? true : false, @params["count_pages"] ? true : false, @params['mind_map_size'], @params['symbols_map'], @params['links_map'], @params['snapshots_interval'], @params['enable_dclick_edit'] ? true : false, @params['enable_menu'] ? true : false, @params['check_pass_on_edit'] == 'each_edit', @prog, @graph_type, @missing, @show_authors, @show_leaves, @selected_categories ) redirect_show("HomePage", @params["address"]) end |
#web_list ⇒ Object
Outside a single web ——————————————————–
55 56 57 58 |
# File 'app/controllers/wiki.rb', line 55 def web_list @system, @webs = wiki.system, wiki.webs.values render "wiki/web_list" end |