Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 2
- Log:
Initial import of Instiki 0.11.0 sources from a downloaded Tarball.
Instiki is a Ruby On Rails based Wiki clone.
- Author:
- adh
- Date:
- Sat Jul 22 14:54:51 +0100 2006
- Size:
- 1738 Bytes
1 | class WikiFile < ActiveRecord::Base |
2 | belongs_to :web |
3 | |
4 | before_save :write_content_to_file |
5 | before_destroy :delete_content_file |
6 | |
7 | validates_presence_of %w( web file_name ) |
8 | validates_length_of :file_name, :within=>1..50 |
9 | validates_length_of :description, :maximum=>255 |
10 | |
11 | def self.find_by_file_name(file_name) |
12 | find(:first, :conditions => ['file_name = ?', file_name]) |
13 | end |
14 | |
15 | SANE_FILE_NAME = /^[a-zA-Z0-9\-_\. ]*$/ |
16 | def validate |
17 | if file_name |
18 | if file_name !~ SANE_FILE_NAME |
19 | errors.add("file_name", "is invalid. Only latin characters, digits, dots, underscores, " + |
20 | "dashes and spaces are accepted") |
21 | elsif file_name == '.' or file_name == '..' |
22 | errors.add("file_name", "cannot be '.' or '..'") |
23 | end |
24 | end |
25 | |
26 | if @web and @content |
27 | if (@content.size > @web.max_upload_size.kilobytes) |
28 | errors.add("content", "size (#{(@content.size / 1024.0).round} kilobytes) exceeds " + |
29 | "the maximum (#{web.max_upload_size} kilobytes) set for this wiki") |
30 | end |
31 | end |
32 | |
33 | errors.add("content", "is empty") if @content.nil? or @content.empty? |
34 | end |
35 | |
36 | def content=(content) |
37 | if content.respond_to? :read |
38 | @content = content.read |
39 | else |
40 | @content = content |
41 | end |
42 | end |
43 | |
44 | def content |
45 | @content ||= ( File.open(content_path, 'rb') { |f| f.read } ) |
46 | end |
47 | |
48 | def content_path |
49 | web.files_path + '/' + file_name |
50 | end |
51 | |
52 | def write_content_to_file |
53 | web.create_files_directory unless File.exists?(web.files_path) |
54 | File.open(self.content_path, 'wb') { |f| f.write(@content) } |
55 | end |
56 | |
57 | def delete_content_file |
58 | require 'fileutils' |
59 | FileUtils.rm_f(content_path) if File.exists?(content_path) |
60 | end |
61 | |
62 | |
63 | |
64 | end |