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
attr_accessor :name, :address, :password, :markup, :color, :safe_mode, :pages
attr_accessor :additional_style, :published, :brackets_only, :count_pages, :allow_uploads
attr_accessor :max_upload_size
def initialize(parent_wiki, name, address, password = nil)
@wiki, @name, @address, @password = parent_wiki, name, address, password
@ -22,24 +23,13 @@ class Web
@brackets_only = false
@count_pages = false
@allow_uploads = true
@max_upload_size = 100
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 select(&condition)
PageSet.new(self, @pages.values, condition)
end
def revised_on
select.most_recent_revision
end
def authors
select.authors
end
@ -48,6 +38,32 @@ class Web
select.map { |page| page.categories }.flatten.uniq.sort
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
# on the render mode in options and whether the page exists
# in the this web.
@ -85,24 +101,6 @@ class Web
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)
link = CGI.escape(name)
case mode
@ -118,12 +116,8 @@ class Web
end
end
def has_page?(name)
pages[name]
end
def has_file?(name)
wiki.file_yard(self).has_file?(name)
def max_upload_size
@max_upload_size || 100
end
# 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 } }
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
# Returns an array of all the wiki words in any current revision
def wiki_words
@ -152,4 +158,5 @@ class Web
def wiki
@wiki ||= WikiService.instance
end
end

View file

@ -17,18 +17,6 @@
</div>
<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">
Markup:
<select name="markup">
@ -43,20 +31,39 @@
<%= html_options({ "Green" => "008B26", "Purple" => "504685", "Red" => "DA0006",
"Orange" => "FA6F00", "Grey" => "8BA2B0" }, @web.color) %>
</select>
&nbsp;&nbsp;
<br/>
<p>
<small>
<input type="checkbox" name="safe_mode" <%= 'checked="on"' if @web.safe_mode %> /> Safe mode
&nbsp;&nbsp;
<input type="checkbox" name="safe_mode" <%= 'checked="on"' if @web.safe_mode %> />
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 %> />
Brackets only
&nbsp;&nbsp;
<input type="checkbox" name="count_pages" <%= 'checked="on"' if @web.count_pages %> /> Count pages
&nbsp;&nbsp;
<input type="checkbox" name="allow_uploads" <%= 'checked="on"' if @web.allow_uploads %> /> Allow uploads
<em>- require all wiki words to be as [[wiki word]], WikiWord links won't be created</em>
<br/>
<input type="checkbox" name="count_pages" <%= 'checked="on"' if @web.count_pages %> />
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>
</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"
style="display: none; margin-top: 10px; margin-bottom: 5px; width: 560px; height: 200px"
name="additional_style"><%= @web.additional_style %>

View file

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