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:
- 3668 Bytes
1 | class Web < ActiveRecord::Base |
2 | has_many :pages |
3 | has_many :wiki_files |
4 | |
5 | def wiki |
6 | Wiki.new |
7 | end |
8 | |
9 | def settings_changed?(markup, safe_mode, brackets_only) |
10 | self.markup != markup || |
11 | self.safe_mode != safe_mode || |
12 | self.brackets_only != brackets_only |
13 | end |
14 | |
15 | def add_page(name, content, time, author, renderer) |
16 | page = page(name) || Page.new(:web => self, :name => name) |
17 | page.revise(content, time, author, renderer) |
18 | end |
19 | |
20 | def authors |
21 | connection.select_all( |
22 | 'SELECT DISTINCT r.author AS author ' + |
23 | 'FROM revisions r ' + |
24 | 'JOIN pages p ON p.id = r.page_id ' + |
25 | 'ORDER by 1').collect { |row| row['author'] } |
26 | end |
27 | |
28 | def categories |
29 | select.map { |page| page.categories }.flatten.uniq.sort |
30 | end |
31 | |
32 | def page(name) |
33 | pages.find(:first, :conditions => ['name = ?', name]) |
34 | end |
35 | |
36 | def has_page?(name) |
37 | Page.count(['web_id = ? AND name = ?', id, name]) > 0 |
38 | end |
39 | |
40 | def has_file?(file_name) |
41 | WikiFile.find_by_file_name(file_name) != nil |
42 | end |
43 | |
44 | def markup |
45 | read_attribute('markup').to_sym |
46 | end |
47 | |
48 | def page_names_by_author |
49 | connection.select_all( |
50 | 'SELECT DISTINCT r.author AS author, p.name AS page_name ' + |
51 | 'FROM revisions r ' + |
52 | 'JOIN pages p ON r.page_id = p.id ' + |
53 | "WHERE p.web_id = #{self.id} " + |
54 | 'ORDER by p.name' |
55 | ).inject({}) { |result, row| |
56 | author, page_name = row['author'], row['page_name'] |
57 | result[author] = [] unless result.has_key?(author) |
58 | result[author] << page_name |
59 | result |
60 | } |
61 | end |
62 | |
63 | def remove_pages(pages_to_be_removed) |
64 | pages_to_be_removed.each { |p| p.destroy } |
65 | end |
66 | |
67 | def revised_at |
68 | select.most_recent_revision |
69 | end |
70 | |
71 | def select(&condition) |
72 | PageSet.new(self, pages, condition) |
73 | end |
74 | |
75 | def select_all |
76 | PageSet.new(self, pages, nil) |
77 | end |
78 | |
79 | def to_param |
80 | address |
81 | end |
82 | |
83 | def create_files_directory |
84 | return unless allow_uploads == 1 |
85 | dummy_file = self.wiki_files.build(:file_name => '0', :description => '0', :content => '0') |
86 | dir = File.dirname(dummy_file.content_path) |
87 | begin |
88 | require 'fileutils' |
89 | FileUtils.mkdir_p dir |
90 | dummy_file.save |
91 | dummy_file.destroy |
92 | rescue => e |
93 | logger.error("Failed create files directory for #{self.address}: #{e}") |
94 | raise "Instiki could not create directory to store uploaded files. " + |
95 | "Please make sure that Instiki is allowed to create directory " + |
96 | "#{File.expand_path(dir)} and add files to it." |
97 | end |
98 | end |
99 | |
100 | private |
101 | |
102 | # Returns an array of all the wiki words in any current revision |
103 | def wiki_words |
104 | pages.inject([]) { |wiki_words, page| wiki_words << page.wiki_words }.flatten.uniq |
105 | end |
106 | |
107 | # Returns an array of all the page names on this web |
108 | def page_names |
109 | pages.map { |p| p.name } |
110 | end |
111 | |
112 | protected |
113 | before_save :sanitize_markup |
114 | after_save :create_files_directory |
115 | before_validation :validate_address |
116 | validates_uniqueness_of :address |
117 | validates_length_of :color, :in => 3..6 |
118 | |
119 | def sanitize_markup |
120 | self.markup = markup.to_s |
121 | end |
122 | |
123 | def validate_address |
124 | unless address == CGI.escape(address) |
125 | self.errors.add(:address, 'should contain only valid URI characters') |
126 | raise Instiki::ValidationError.new("#{self.class.human_attribute_name('address')} #{errors.on(:address)}") |
127 | end |
128 | end |
129 | |
130 | def default_web? |
131 | defined? DEFAULT_WEB and self.address == DEFAULT_WEB |
132 | end |
133 | |
134 | def files_path |
135 | if default_web? |
136 | "#{RAILS_ROOT}/public/files" |
137 | else |
138 | "#{RAILS_ROOT}/public/#{self.address}/files" |
139 | end |
140 | end |
141 | end |