require "madeleine_service" require "web" require "page" require "author" class WikiService < MadeleineService attr_reader :webs, :system def initialize @webs, @system = {}, {} end def setup? !@system.empty? end def authenticate(password) password == (@system["password"] || "instiki") 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, brackets_only = false, count_pages = false, mind_map_size="7,7", symbols_map=nil, links_map=nil) if old_address != new_address @webs[new_address] = @webs[old_address] @webs.delete(old_address) @webs[new_address].address = new_address end 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.brackets_only, web.count_pages = password, published, brackets_only, count_pages web.mind_map_size, web.symbols_map, web.links_map = mind_map_size, symbols_map, links_map end def read_page(web_address, page_name) @webs[web_address].pages[page_name] 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) page = read_page(web_address, page_name) page.revise(content, revised_on, author) 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 # 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};; #{pages.keys.join(',')}" page.name = new_page_name web.pages[new_page_name] = page end #}}} def save_menu_pref(web_address, type, limit, content, category) #{{{ web = @webs[web_address] web.menu_type = type web.menu_limit = limit web.menu_category = category # TODO: persist revisions of user specified content. web.menu_content = content if web.menu_type == 'user' # Only calculate the rendered content once: web.rendered_menu = Page.new( web, 'menu', content, Time.now, '' ).revisions.last.display_content 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: