app/controllers/wiki.rb in Pimki-1.6.092 vs app/controllers/wiki.rb in Pimki-1.7.092

- old
+ new

@@ -2,23 +2,33 @@ require "redcloth_for_tex" RenderedTodo = Struct.new( :text, :context, :due_date ) class WikiController < ActionControllerServlet - EXPORT_DIRECTORY = WikiService.storage_path unless const_defined?("EXPORT_DIRECTORY") + EXPORT_DIRECTORY = WikiService.storage_path def index if web_address - redirect_show "HomePage" + check_external_req_and_redirect web elsif !wiki.setup? redirect_path "/new_system/" elsif wiki.webs.length == 1 - redirect_show "HomePage", wiki.webs.values.first.address + check_external_req_and_redirect wiki.webs.values.first else - redirect_path "/web_list/" + wiki.default_web ? + check_external_req_and_redirect(wiki.webs[wiki.default_web]) : + redirect_path("/web_list/") end end + + 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 # Administrating the Instiki setup -------------------------------------------- def new_system wiki.setup? ? redirect_path("/") : render @@ -164,23 +174,43 @@ 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 - + + def glossary + set_menu_pages + + 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 + def authors + set_menu_pages @authors = web.select.authors end def recently_revised parse_category set_menu_pages @pages_by_revision = @pages_in_category.by_revision end def rss_with_content - @pages_by_revision = web.select.by_revision.first(15) + @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.meta_vars["HTTP_X_FORWARDED_HOST"] || "#{@uri.host}:#{@uri.port.to_s}" @web_url = "#{@uri.scheme}://#{host}/#{@web.address}" @res["Content-Type"] = "text/xml" @@ -189,65 +219,84 @@ def rss_with_headlines @hide_description = true rss_with_content end - + + def rss_bliki_only + @rss_bliki_only = true + rss_with_content + end + + def rss_todo_items + todo + @display_todo = true + rss_with_content + end + + def feeds + set_menu_pages + end + def list parse_category set_menu_pages @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 authenticate + # 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']) 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['newpage']) redirect_action "list/" end end end + def export + set_menu_pages + end + def export_html file_name = "#{web.address}-html-#{web.revised_on.strftime("%Y-%m-%d-%H-%M")}.zip" - file_path = EXPORT_DIRECTORY + file_name + 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 def export_markup file_name = "#{web.address}-markup-#{web.revised_on.strftime("%Y-%m-%d-%H-%M")}.zip" - file_path = EXPORT_DIRECTORY + file_name + 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 def export_pdf file_name = "#{web.address}-tex-#{web.revised_on.strftime('%Y-%m-%d-%H-%M')}" - file_path = EXPORT_DIRECTORY + file_name + 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 def export_tex file_name = "#{web.address}-tex-#{web.revised_on.strftime('%Y-%m-%d-%H-%M')}.tex" - file_path = EXPORT_DIRECTORY + file_name + 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 @@ -266,51 +315,57 @@ 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["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'], + @params['enable_menu'], @params['check_pass_on_edit'] == 'each_edit', @prog, @graph_type, @missing, @show_authors, @show_leaves, @selected_categories ) redirect_show("HomePage", @params["address"]) end def administrate @logger.info "Taking administrative action: #{@params['action']}" - if wiki.authenticate(@params['system_password']) - case @params['action'] - when 'Delete Orphan Pages' - wiki.remove_orphaned_pages(web_address) + 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 'Clear Render Cache' - clear_render_cache true + when 'Clean Storage' + WikiService.clean_old_snapshots - when 'Force Data Snapshot' - WikiService.take_snapshot - - when 'Clean Storage' - WikiService.clean_old_snapshots + when 'Make This Web Default' + wiki.default_web = web_address - end - @message = 'Operation succeeded' - redirect_action 'edit_web/' - else - redirect_show 'HomePage' + when 'Remove This Web' + wiki.webs.delete web_address + redirect_path '/' + end + @message = 'Operation succeeded' + redirect_action 'edit_web/' end 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>} + TODO_RE = %r{<todo-tag context='(.*?)' due_date='(.*?)'><span class="todo"><strong>TODO(?:[^:]*)?:</strong> (.*?)</span></todo-tag>} def todo #{{{ parse_category set_menu_pages @@ -439,18 +494,18 @@ @pngFile = @mapFile = nil case @graph_type when 'normal' @pngFile, @mapFile = web.create_mind_map(@prog, @missing, - @show_authors, @show_leaves, @selected_categories) + @show_authors, @show_leaves, @selected_categories, @mm_size) when 'author' - @pngFile, @mapFile = web.create_author_graph(@prog, @selected_categories) + @pngFile, @mapFile = web.create_author_graph(@prog, @selected_categories, @mm_size) when 'category' @pngFile, @mapFile = web.create_category_graph(@prog, - @show_authors, @selected_categories) + @show_authors, @selected_categories, @mm_size) end end #}}} def set_mm_options #{{{ if @req.query.empty? @@ -458,19 +513,21 @@ @graph_type = web.mm_graph_type @missing = @pages_in_category.wanted_pages if web.mm_show_missing @show_authors = web.mm_show_authors @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 #}}} def parse_multi_select field #{{{ if @req.body @@ -485,10 +542,11 @@ def edit_menu #{{{ @menu_type = web.menu_type @menu_content = web.menu_content @list_limit = web.menu_limit @list_limit += 1 if @list_limit >= -1 + @author = default_author end #}}} def save_menu #{{{ redirect_show("HomePage") unless wiki.authenticate(@params["system_password"]) @@ -504,32 +562,24 @@ # need to go through the WikiService to persist the command: wiki.save_menu_pref(web_address, type, limit, content, category, Author.new(author, remote_ip)) end - # redirect to the most recently viewed page, or the home page. - if web_address - pname = begin - web.select{ true }.by_last_visited.first.name - rescue - "HomePage" - end - redirect_show pname - elsif wiki.webs.length == 1 - # only one web, so go there. - redirect_show "HomePage", wiki.webs.values.first.address - else - redirect_path "/web_list/" - end + redirect_action 'edit_web/' # go back to web options page end #}}} 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 + def adv_search + parse_category + set_menu_pages + end + # Within a single page -------------------------------------------------------- def show set_menu_pages if @page = wiki.read_page(web_address, page_name) @@ -569,19 +619,19 @@ 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 + 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 def new - redirect_show("HomePage") if web.check_pass_on_edit and not authenticate + # redirect_show("HomePage") if web.check_pass_on_edit and not password_check(@params['password']) @page_name, @author = page_name, default_author end def edit @page = wiki.read_page(web_address, page_name) @@ -600,14 +650,14 @@ @page.unlock redirect_show end def save - if web.check_pass_on_edit and not authenticate - wiki.read_page(web_address, page_name).unlock if web.pages[page_name] - redirect_show("HomePage") - end + # 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'] @@ -624,52 +674,60 @@ write_cookie("author", @params["author"], true) redirect_show(page_name) end def revision + redirect_show 'HomePage' if page_name.nil? + set_menu_pages @page = wiki.read_page(web_address, page_name) @revision = @page.revisions[@params["rev"].to_i] end def rollback - redirect_show("HomePage") if web.check_pass_on_edit and not authenticate + # 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 # Bliki ---------------------------------------------------------------------- def bliki_delete - redirect_bliki if web.check_pass_on_edit and not authenticate + # redirect_bliki if web.check_pass_on_edit and not password_check(@params['password']) wiki.delete_bliki_entry(web_address, page_name) redirect_bliki end def bliki_edit - redirect_bliki if web.check_pass_on_edit and not authenticate + # 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, default_author) @author = default_author render else - redirect_path "#{web_address}/locked" + @bliki_entry = true + render "wiki/locked" end end def cancel_bliki_edit @page = wiki.read_bliki_entry(web_address, page_name) @page.unlock if @page redirect_bliki end + def bliki_new + @entry_name = @params['entry_name'] + @author = default_author + end + def bliki_save - redirect_bliki if web.check_pass_on_edit and not authenticate + # 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 @@ -687,11 +745,11 @@ @page = wiki.read_bliki_entry(web_address, page_name || @params['pagename']) @revision = @page.revisions[@params["rev"].to_i] || @page.revisions.last end def rollback_bliki - redirect_bliki if web.check_pass_on_edit and not authenticate + # 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 @@ -775,11 +833,26 @@ Zip::ZipOutputStream.open(zip_file_path) do |zos| web.select.by_name.each do |@page| zos.put_next_entry(@page.name + ".html") zos.puts(template_engine("print").result(binding)) end + + zos.put_next_entry "pages-metadata.txt" + web.select.by_name.each do |page| + zos.puts "#{page.name}: by #{page.author}, created on #{page.pretty_created_at}" + end + web.select_bliki.by_name.each do |@page| + zos.put_next_entry("bliki/#{@page.name}.html") + zos.puts(template_engine("print").result(binding)) + end + + zos.put_next_entry "bliki/bliki-metadata.txt" + web.select_bliki.by_name.each do |page| + zos.puts "#{page.name}: by #{page.author}, created on #{page.revisions.first.pretty_created_at}" + end + zos.put_next_entry("index.html") zos.puts('<html><head><META HTTP-EQUIV="Refresh" CONTENT="0;URL=HomePage.html"></head></html>') end end @@ -787,23 +860,45 @@ Zip::ZipOutputStream.open(zip_file_path) do |zos| web.select.by_name.each do |page| zos.put_next_entry(page.name + ".#{web.markup}") zos.puts(page.content) end + + zos.put_next_entry "pages-metadata.txt" + web.select.by_name.each do |page| + zos.puts "#{page.name}: by #{page.author}, created on #{page.pretty_created_at}" + end + + web.select_bliki.by_name.each do |page| + zos.put_next_entry("bliki/#{page.name}.#{web.markup}") + zos.puts(page.content) + end + + zos.put_next_entry "bliki/bliki-metadata.txt" + web.select_bliki.by_name.each do |page| + zos.puts "#{page.name}: by #{page.author}, created on #{page.revisions.first.pretty_created_at}" + end end end def export_web_to_tex(file_path) @web_name = web.name @tex_content = table_of_contents(web.pages["HomePage"].content.dup, render_tex_web) File.open(file_path, "w") { |f| f.write(template_engine("tex_web").result(binding)) } end def render_tex_web - web.select.by_name.inject({}) do |tex_web, page| + pages = web.select.by_name.inject({}) do |tex_web, page| tex_web[page.name] = RedClothForTex.new(page.content).to_tex tex_web end + + bliki_entries = web.select_bliki.by_name.inject({}) do |tex_web, page| + tex_web["bliki/#{page.name}"] = RedClothForTex.new(page.content).to_tex + tex_web + end + + pages.update bliki_entries end def export_page_to_tex(file_path) tex File.open(file_path, "w") { |f| f.write(template_engine("tex").result(binding)) } \ No newline at end of file