require "madeleine_service" require "web" require "page" require "author" class WikiService < MadeleineService attr_reader :webs, :system attr_accessor :default_web # These methods do not change the state of persistent objects, and # should not be logged by Madeleine automatic_read_only :authenticate, :read_page, :read_bliki_entry, :setup?, :webs def initialize @webs, @system = {}, {} end def setup? !@system.empty? end def authenticate(password) password == (@system["password"] || "pimki") end def setup(password, web_name, web_address) @system["password"] = password create_web(web_name, web_address) end def create_web(name, address, password = nil) @webs[address] = Web.new(name, address, password) unless @webs[address] end def update_web(old_address, new_address, name, markup, color, additional_style, safe_mode = false, password = nil, published = false, default_to_published = false, brackets_only = false, count_pages = false, mind_map_size="7,7", symbols_map=nil, links_map=nil, snapshots_interval = 1, enable_dclick_edit=nil, enable_menu=true, check_pass_on_edit=false, prog=nil, graph_type=nil, missing=nil, show_authors=nil, show_leaves=nil, selected_categories=nil) if old_address != new_address @webs[new_address] = @webs[old_address] @webs.delete(old_address) @webs[new_address].address = new_address end self.class.snapshot_interval_hours = snapshots_interval web = @webs[new_address] web.refresh_revisions if settings_changed?(web, markup, safe_mode, brackets_only) web.name, web.markup, web.color, web.additional_style, web.safe_mode = name, markup, color, additional_style, safe_mode web.password, web.published, web.default_to_published, web.brackets_only, web.count_pages = password, published, default_to_published, brackets_only, count_pages web.enable_dclick_edit, web.enable_menu, web.check_pass_on_edit = enable_dclick_edit, enable_menu, check_pass_on_edit web.mind_map_size, web.mm_prog, web.mm_graph_type, web.mm_show_missing = mind_map_size, prog, graph_type, missing web.mm_show_authors, web.mm_show_leaves, web.mm_selected_categories = show_authors, show_leaves, selected_categories web.symbols_map, web.links_map = symbols_map, links_map end def read_page(web_address, page_name) web = @webs[web_address] web ? web.pages[page_name] : nil end def write_page(web_address, page_name, content, written_on, author) page = Page.new(@webs[web_address], page_name, content, written_on, author) @webs[web_address].add_page(page) page end def revise_page(web_address, page_name, content, revised_on, author, edit_type) page = read_page(web_address, page_name) page.revise(content, revised_on, author, edit_type) page end def rollback_page(web_address, page_name, revision_number, created_at, author_id = nil) page = read_page(web_address, page_name) page.rollback(revision_number, created_at, author_id) page end def remove_orphaned_pages(web_address) @webs[web_address].remove_pages(@webs[web_address].select.orphaned_pages) end # Page Admin commands -------------------------------------------------------- # deletes a page from the web. def delete_page(web_address, page_name) #{{{ @webs[web_address].pages.delete(page_name) end #}}} # renames a page in the web. def rename_page(web_address, old_page_name, new_page_name) #{{{ web = @webs[web_address] page = web.pages.delete(old_page_name) page or raise "unknown page: #{old_page_name.to_s}; #{web.pages.keys.join(',')}" page.name = new_page_name web.pages[new_page_name] = page end #}}} # Menu commands -------------------------------------------------------------- def save_menu_pref(web_address, type, limit, content, category, author) #{{{ web = @webs[web_address] web.menu_type = type web.menu_limit = limit web.menu_category = category if Page === web.menu_content web.menu_content.revise( content, Time.now, '', author ) else # Protect old Pimki storages. web.menu_content = Page.new( web, 'menu', content, Time.now, '' ) end end #}}} # Bliki commands ------------------------------------------------------------- def read_bliki_entry(web_address, page_name) @webs[web_address].bliki[page_name] end def write_bliki_entry(web_address, page_name, content, written_on, author) page = Page.new(@webs[web_address], page_name, content, written_on, author) @webs[web_address].add_bliki_entry(page) page end def revise_bliki_entry(web_address, page_name, content, revised_on, author) page = read_bliki_entry(web_address, page_name) page.revise(content, revised_on, author) page end def rollback_bliki_entry(web_address, page_name, revision_number, created_at) page = read_bliki_entry(web_address, page_name) page.rollback(revision_number, created_at) page end def delete_bliki_entry(web_address, page_name) #{{{ @webs[web_address].bliki.delete(page_name) end #}}} private def settings_changed?(web, markup, safe_mode, brackets_only) web.markup != markup || web.safe_mode != safe_mode || web.brackets_only != brackets_only end end # jEdit :folding=indent:collapseFolds=1: