require "cgi" require "page" require "page_set" require "wiki_words" require "zip/zip" class Web attr_accessor :pages, :name, :address, :password, :menu_type, :menu_content, :rendered_menu, :menu_limit, :menu_category attr_accessor :markup, :color, :safe_mode, :additional_style, :published, :brackets_only, :count_pages @@BLIKI_TEMPLATE = "Try a weekly worksheet:\n\n| / | *Morning* | *Afternoon* |\n" + "| *Mon* | - | - |\n| *Tue* | - | - |\n| *Wed* | - | - |\n" + "| *Thu* | - | - |\n| *Fri* | - | - |\n" def bliki @bliki ||= Hash.new end def initialize(name, address, password = nil) @name, @address, @password, @safe_mode = name, address, password, false @pages = {} end def add_page(page) @pages[page.name] = page end def remove_pages(pages_to_be_removed) pages.delete_if { |page_name, page| pages_to_be_removed.include?(page) } end def revised_on pages.values.sort_by { |page| [page.created_at] }.reverse.first.created_at end def select(&accept) PageSet.new(self, @pages.values, accept) end def revised_on select.most_recent_revision end def authors select.authors end def categories select.map { |page| page.categories }.flatten.uniq.sort end # Create a link for the given page name and link text based # on the render mode in options and whether the page exists # in the this web. def make_link(name, text = nil, options = {}) page = pages[name] text = text || WikiWords.separate(name) link = CGI.escape(name) case options[:mode] when :export if page then "#{text}" else "#{text}" end when :publish if page then "#{text}" else "#{text}" end else if page then "#{text}" else "#{text}?" end end end # Clears the display cache for all the pages with references to def refresh_pages_with_references(page_name) select.pages_that_reference(page_name).each { |page| page.revisions.each { |revision| revision.clear_display_cache } } end def refresh_revisions select.each { |page| page.revisions.each { |revision| revision.clear_display_cache } } end # Default values def markup() @markup || :textile end def color() @color || "008B26" end def brackets_only() @brackets_only || false end def count_pages() @count_pages || false end def menu_content() @menu_content || '' end def menu_limit() @menu_limit || 20 end def menu_type() (@menu_type.nil? || @menu_type.empty?) ? 'linkers' : @menu_type end # create a Mind Map graph and return the PNG and HTML map files generated def create_mind_map(prog, missing, show_authors) dotFile = File.expand_path("#{WikiService.storage_path}/graph.dot") mapFile = File.expand_path("#{WikiService.storage_path}/graph.map") pngFile = File.expand_path("#{WikiService.storage_path}/map.png") File.open(dotFile, "w") do |file| # Graph properties: file.puts "digraph G {" file.puts 'size="7,5";' #file.puts 'ratio=fill;' file.puts 'concentrate=true;' file.puts 'node [fontsize=10,fontname="Tahoma"];' file.puts 'edge [len=1.5];' # Page Special nodes properties: file.puts "HomePage [color=\"##{color}\",style=bold];" # Links and node properties: nodes = pages.values auths = authors # avoid repeated selects unless show_authors == 'on' nodes.delete_if { |entry| auths.include? entry.name } end nodes.each do |page| file.puts "#{page.name} [URL=\"../show/#{page.name}\"];" page.references.each do |referer| unless page.name == referer.name unless show_authors != 'on' and auths.include? referer.name file.puts "#{referer.name} -> #{page.name};" end end end end # find missing pages: if missing missing.each do |wanted| file.puts "#{wanted} [URL=\"/#{@address}/show/#{wanted}\", fontsize=10,style=filled,color=grey];" end pages.values.each do |page| missing.each do |wanted| if page.content =~ /#{wanted}/ file.puts "#{page.name} -> #{wanted};" end end end end file.puts "}" end system("#{prog} -Tcmap #{dotFile} -o #{mapFile}") system("#{prog} -Tpng #{dotFile} -o #{pngFile}") [pngFile, mapFile] end def create_author_graph(prog) dotFile = File.expand_path("#{WikiService.storage_path}/graph.dot") mapFile = File.expand_path("#{WikiService.storage_path}/graph.map") pngFile = File.expand_path("#{WikiService.storage_path}/map.png") File.open(dotFile, "w") do |file| # Graph properties: file.puts "digraph G {" file.puts 'size="7,5";' #file.puts 'ratio=fill;' file.puts 'concentrate=true;' file.puts 'node [fontsize=10,fontname="Tahoma"];' file.puts 'edge [len=1.5];' # Links and node properties: auths = authors # avoid repeated selects auths.each do |auth| file.puts "#{auth} [style=filled,color=grey,URL=\"../show/#{auth}\"];" end nodes = pages.values nodes.delete_if { |entry| auths.include? entry.name } nodes.each do |page| file.puts "#{page.name} [URL=\"../show/#{page.name}\"];" page.authors.each do |auth| file.puts "#{auth} -> #{page.name};" end end file.puts "}" end system("#{prog} -Tcmap #{dotFile} -o #{mapFile}") system("#{prog} -Tpng #{dotFile} -o #{pngFile}") [pngFile, mapFile] end def create_category_graph(prog, show_authors) #{{{ dotFile = File.expand_path("#{WikiService.storage_path}/graph.dot") mapFile = File.expand_path("#{WikiService.storage_path}/graph.map") pngFile = File.expand_path("#{WikiService.storage_path}/map.png") File.open(dotFile, "w") do |file| # Graph properties: file.puts "digraph G {" file.puts 'size="7,5";' #file.puts 'ratio=fill;' file.puts 'concentrate=true;' file.puts 'node [fontsize=10,fontname="Tahoma"];' file.puts 'edge [len=1.5];' # Page Special nodes properties: file.puts "HomePage [color=\"##{color}\",style=bold];" categories.each do |category| file.puts "#{category} [fontsize=20,style=filled,color=grey,comment=\"#{category}\"];" end # Links and node properties: nodes = pages.values auths = authors # avoid repeated selects unless show_authors == 'on' nodes.delete_if { |entry| auths.include? entry.name } end nodes.each do |page| file.puts "#{page.name} [URL=\"../show/#{page.name}\"];" page.categories.each do |category| file.puts "#{category} -> #{page.name};" end end file.puts "}" end system("#{prog} -Tcmap #{dotFile} -o #{mapFile}") system("#{prog} -Tpng #{dotFile} -o #{pngFile}") [pngFile, mapFile] end #}}} ## Bliki methods def add_bliki_entry(page) bliki[page.name] = page end def bliki_entries_by_date bliki.values.sort_by { |page| page.revisions.first.created_at }.reverse end def bliki_entries_by_name pages.values.sort_by { |page| [page.name] } end def bliki_entries_that_match(regexp) bliki.values.select { |page| page.content =~ /#{regexp}/i } end def bliki_entries_that_reference(page_name) bliki.values.select { |page| page.wiki_words.include?(page_name) } end def bliki_entries_authored_by(author) bliki.values.select { |page| page.authors.include?(author) } end ## End bliki methods private # Returns an array of all the wiki words in any current revision def wiki_words pages.values.inject([]) { |wiki_words, page| wiki_words << page.wiki_words }.flatten.uniq end # Returns an array of all the page names on this web def page_names pages.keys end end # jEdit :folding=indent:collapseFolds=1: