Added max_ulpoad_sze property to web (not used yet), and redesigned edit_web page a little.

This commit is contained in:
Alexey Verkhovsky 2005-01-30 06:11:00 +00:00
parent 5ea3f93bf9
commit 9a5a195c47
3 changed files with 72 additions and 57 deletions

View file

@ -7,6 +7,7 @@ require "zip/zip"
class Web class Web
attr_accessor :name, :address, :password, :markup, :color, :safe_mode, :pages attr_accessor :name, :address, :password, :markup, :color, :safe_mode, :pages
attr_accessor :additional_style, :published, :brackets_only, :count_pages, :allow_uploads attr_accessor :additional_style, :published, :brackets_only, :count_pages, :allow_uploads
attr_accessor :max_upload_size
def initialize(parent_wiki, name, address, password = nil) def initialize(parent_wiki, name, address, password = nil)
@wiki, @name, @address, @password = parent_wiki, name, address, password @wiki, @name, @address, @password = parent_wiki, name, address, password
@ -22,24 +23,13 @@ class Web
@brackets_only = false @brackets_only = false
@count_pages = false @count_pages = false
@allow_uploads = true @allow_uploads = true
@max_upload_size = 100
end end
def add_page(page) def add_page(page)
@pages[page.name] = page @pages[page.name] = page
end end
def remove_pages(pages_to_be_removed)
pages.delete_if { |page_name, page| pages_to_be_removed.include?(page) }
end
def select(&condition)
PageSet.new(self, @pages.values, condition)
end
def revised_on
select.most_recent_revision
end
def authors def authors
select.authors select.authors
end end
@ -48,6 +38,32 @@ class Web
select.map { |page| page.categories }.flatten.uniq.sort select.map { |page| page.categories }.flatten.uniq.sort
end end
def has_page?(name)
pages[name]
end
def has_file?(name)
wiki.file_yard(self).has_file?(name)
end
def make_file_link(mode, name, text)
link = CGI.escape(name)
case mode
when :export
if has_file?(name) then "<a class=\"existingWikiWord\" href=\"#{link}.html\">#{text}</a>"
else "<span class=\"newWikiWord\">#{text}</span>" end
when :publish
if has_file?(name) then "<a class=\"existingWikiWord\" href=\"../published/#{link}\">#{text}</a>"
else "<span class=\"newWikiWord\">#{text}</span>" end
else
if has_file?(name)
"<a class=\"existingWikiWord\" href=\"../file/#{link}\">#{text}</a>"
else
"<span class=\"newWikiWord\">#{text}<a href=\"../file/#{link}\">?</a></span>"
end
end
end
# Create a link for the given page name and link text based # Create a link for the given page name and link text based
# on the render mode in options and whether the page exists # on the render mode in options and whether the page exists
# in the this web. # in the this web.
@ -85,24 +101,6 @@ class Web
end end
end end
def make_file_link(mode, name, text)
link = CGI.escape(name)
case mode
when :export
if has_file?(name) then "<a class=\"existingWikiWord\" href=\"#{link}.html\">#{text}</a>"
else "<span class=\"newWikiWord\">#{text}</span>" end
when :publish
if has_file?(name) then "<a class=\"existingWikiWord\" href=\"../published/#{link}\">#{text}</a>"
else "<span class=\"newWikiWord\">#{text}</span>" end
else
if has_file?(name)
"<a class=\"existingWikiWord\" href=\"../file/#{link}\">#{text}</a>"
else
"<span class=\"newWikiWord\">#{text}<a href=\"../file/#{link}\">?</a></span>"
end
end
end
def make_pic_link(mode, name, text) def make_pic_link(mode, name, text)
link = CGI.escape(name) link = CGI.escape(name)
case mode case mode
@ -118,12 +116,8 @@ class Web
end end
end end
def has_page?(name) def max_upload_size
pages[name] @max_upload_size || 100
end
def has_file?(name)
wiki.file_yard(self).has_file?(name)
end end
# Clears the display cache for all the pages with references to # Clears the display cache for all the pages with references to
@ -137,6 +131,18 @@ class Web
select.each { |page| page.revisions.each { |revision| revision.clear_display_cache } } select.each { |page| page.revisions.each { |revision| revision.clear_display_cache } }
end end
def remove_pages(pages_to_be_removed)
pages.delete_if { |page_name, page| pages_to_be_removed.include?(page) }
end
def revised_on
select.most_recent_revision
end
def select(&condition)
PageSet.new(self, @pages.values, condition)
end
private private
# Returns an array of all the wiki words in any current revision # Returns an array of all the wiki words in any current revision
def wiki_words def wiki_words
@ -152,4 +158,5 @@ class Web
def wiki def wiki
@wiki ||= WikiService.instance @wiki ||= WikiService.instance
end end
end end

View file

@ -17,18 +17,6 @@
</div> </div>
<h2 style="margin-bottom: 3px">Specialize</h2> <h2 style="margin-bottom: 3px">Specialize</h2>
<div class="help">
Turning safe mode on will strip HTML tags and stylesheet options from the content of all pages.
Turning on "brackets only" will require all wiki words to be as [[wiki word]] and WikiWord
won't work.
Turning "allow uploads" on will let wiki users to upload pictures and other files to the wiki
and include them on wiki pages.
Additions to the stylesheet take precedence over the existing styles.
<i>Hint:</i> View source on a page you want to style to find ID names on individual tags.
<a href="#" onClick="document.getElementById('additionalStyle').style.display='block';return false;">
See styles &gt;&gt;
</a>
</div>
<div class="inputBox, disableAutoComplete"> <div class="inputBox, disableAutoComplete">
Markup: Markup:
<select name="markup"> <select name="markup">
@ -43,20 +31,39 @@
<%= html_options({ "Green" => "008B26", "Purple" => "504685", "Red" => "DA0006", <%= html_options({ "Green" => "008B26", "Purple" => "504685", "Red" => "DA0006",
"Orange" => "FA6F00", "Grey" => "8BA2B0" }, @web.color) %> "Orange" => "FA6F00", "Grey" => "8BA2B0" }, @web.color) %>
</select> </select>
<br/>
&nbsp;&nbsp; <p>
<small> <small>
<input type="checkbox" name="safe_mode" <%= 'checked="on"' if @web.safe_mode %> /> Safe mode <input type="checkbox" name="safe_mode" <%= 'checked="on"' if @web.safe_mode %> />
&nbsp;&nbsp; Safe mode
<em>- strip HTML tags and stylesheet options from the content of all pages</em>
<br/>
<input type="checkbox" name="brackets_only" <%= 'checked="on"' if @web.brackets_only %> /> <input type="checkbox" name="brackets_only" <%= 'checked="on"' if @web.brackets_only %> />
Brackets only Brackets only
&nbsp;&nbsp; <em>- require all wiki words to be as [[wiki word]], WikiWord links won't be created</em>
<input type="checkbox" name="count_pages" <%= 'checked="on"' if @web.count_pages %> /> Count pages <br/>
&nbsp;&nbsp; <input type="checkbox" name="count_pages" <%= 'checked="on"' if @web.count_pages %> />
<input type="checkbox" name="allow_uploads" <%= 'checked="on"' if @web.allow_uploads %> /> Allow uploads Count pages
<br/>
<input type="checkbox" name="allow_uploads" <%= 'checked="on"' if @web.allow_uploads %> />
Allow uploads of no more than
<input type="text" name="max_upload_size" value="<%= @web.max_upload_size %>"
width="20" />
kbytes
<em>-
let wiki users to upload pictures and other files and include or link to them on wiki pages
</em>
<br/>
</small> </small>
</p>
<a href="#" onClick="document.getElementById('additionalStyle').style.display='block';return false;">
Stylesheet tweaks &gt;&gt;</a>
<small><em>
- add or change styles used by this web; styles defined here take precedence over
instiki.css. Hint: View HTML source of a page you want to style to find ID names on individual
tags.</em></small>
<br/>
<textarea id="additionalStyle" <textarea id="additionalStyle"
style="display: none; margin-top: 10px; margin-bottom: 5px; width: 560px; height: 200px" style="display: none; margin-top: 10px; margin-bottom: 5px; width: 560px; height: 200px"
name="additional_style"><%= @web.additional_style %> name="additional_style"><%= @web.additional_style %>

View file

@ -116,6 +116,7 @@ class WebTest < Test::Unit::TestCase
assert !web.brackets_only assert !web.brackets_only
assert !web.count_pages assert !web.count_pages
assert web.allow_uploads assert web.allow_uploads
assert_equal 100, web.max_upload_size
end end