app/models/wiki_service.rb in instiki-0.10.1 vs app/models/wiki_service.rb in instiki-0.10.2
- old
+ new
@@ -36,10 +36,38 @@
def init_wiki_service
@webs = {}
@system = {}
end
+ def edit_web(old_address, new_address, name, markup, color, additional_style, safe_mode = false,
+ password = nil, published = false, brackets_only = false, count_pages = false,
+ allow_uploads = true, max_upload_size = nil)
+
+ if not @webs.key? old_address
+ raise Instiki::ValidationError.new("Web with address '#{old_address}' does not exist")
+ end
+
+ if old_address != new_address
+ if @webs.key? new_address
+ raise Instiki::ValidationError.new("There is already a web with address '#{new_address}'")
+ end
+ @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, allow_uploads
+ web.allow_uploads, web.max_upload_size = allow_uploads, max_upload_size.to_i
+ end
+
def read_page(web_address, page_name)
ApplicationController.logger.debug "Reading page '#{page_name}' from web '#{web_address}'"
web = @webs[web_address]
if web.nil?
ApplicationController.logger.debug "Web '#{web_address}' not found"
@@ -56,17 +84,15 @@
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 setup(password, web_name, web_address)
@system[:password] = password
create_web(web_name, web_address)
@@ -74,47 +100,17 @@
def setup?
not (@webs.empty?)
end
- def edit_web(old_address, new_address, name, markup, color, additional_style, safe_mode = false,
- password = nil, published = false, brackets_only = false, count_pages = false,
- allow_uploads = true, max_upload_size = nil)
-
- if not @webs.key? old_address
- raise Instiki::ValidationError.new("Web with address '#{old_address}' does not exist")
- end
-
- if old_address != new_address
- if @webs.key? new_address
- raise Instiki::ValidationError.new("There is already a web with address '#{new_address}'")
- end
- @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, allow_uploads
- web.allow_uploads, web.max_upload_size = allow_uploads, max_upload_size.to_i
- 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 storage_path
self.class.storage_path
end
+ def write_page(web_address, page_name, content, written_on, author)
+ @webs[web_address].add_page(page_name, content, written_on, author)
+ end
+
private
def settings_changed?(web, markup, safe_mode, brackets_only)
web.markup != markup ||
web.safe_mode != safe_mode ||
web.brackets_only != brackets_only