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:
- 3643 Bytes
1 | class Page < ActiveRecord::Base |
2 | belongs_to :web |
3 | has_many :revisions, :order => 'id' |
4 | has_many :wiki_references, :order => 'referenced_name' |
5 | has_one :current_revision, :class_name => 'Revision', :order => 'id DESC' |
6 | |
7 | def revise(content, time, author, renderer) |
8 | revisions_size = new_record? ? 0 : revisions.size |
9 | if (revisions_size > 0) and content == current_revision.content |
10 | raise Instiki::ValidationError.new( |
11 | "You have tried to save page '#{name}' without changing its content") |
12 | end |
13 | |
14 | author = Author.new(author.to_s) unless author.is_a?(Author) |
15 | |
16 | # Try to render content to make sure that markup engine can take it, |
17 | renderer.revision = Revision.new( |
18 | :page => self, :content => content, :author => author, :revised_at => time) |
19 | renderer.display_content(update_references = true) |
20 | |
21 | # A user may change a page, look at it and make some more changes - several times. |
22 | # Not to record every such iteration as a new revision, if the previous revision was done |
23 | # by the same author, not more than 30 minutes ago, then update the last revision instead of |
24 | # creating a new one |
25 | if (revisions_size > 0) && continous_revision?(time, author) |
26 | current_revision.update_attributes(:content => content, :revised_at => time) |
27 | else |
28 | revisions.create(:content => content, :author => author, :revised_at => time) |
29 | end |
30 | save |
31 | self |
32 | end |
33 | |
34 | def rollback(revision_number, time, author_ip, renderer) |
35 | roll_back_revision = self.revisions[revision_number] |
36 | if roll_back_revision.nil? |
37 | raise Instiki::ValidationError.new("Revision #{revision_number} not found") |
38 | end |
39 | author = Author.new(roll_back_revision.author.name, author_ip) |
40 | revise(roll_back_revision.content, time, author, renderer) |
41 | end |
42 | |
43 | def revisions? |
44 | revisions.size > 1 |
45 | end |
46 | |
47 | def previous_revision(revision) |
48 | revision_index = revisions.each_with_index do |rev, index| |
49 | if rev.id == revision.id |
50 | break index |
51 | else |
52 | nil |
53 | end |
54 | end |
55 | if revision_index.nil? or revision_index == 0 |
56 | nil |
57 | else |
58 | revisions[revision_index - 1] |
59 | end |
60 | end |
61 | |
62 | def references |
63 | web.select.pages_that_reference(name) |
64 | end |
65 | |
66 | def wiki_words |
67 | wiki_references.select { |ref| ref.wiki_word? }.map { |ref| ref.referenced_name } |
68 | end |
69 | |
70 | def linked_from |
71 | web.select.pages_that_link_to(name) |
72 | end |
73 | |
74 | def included_from |
75 | web.select.pages_that_include(name) |
76 | end |
77 | |
78 | # Returns the original wiki-word name as separate words, so "MyPage" becomes "My Page". |
79 | def plain_name |
80 | web.brackets_only? ? name : WikiWords.separate(name) |
81 | end |
82 | |
83 | LOCKING_PERIOD = 30.minutes |
84 | |
85 | def lock(time, locked_by) |
86 | update_attributes(:locked_at => time, :locked_by => locked_by) |
87 | end |
88 | |
89 | def lock_duration(time) |
90 | ((time - locked_at) / 60).to_i unless locked_at.nil? |
91 | end |
92 | |
93 | def unlock |
94 | update_attribute(:locked_at, nil) |
95 | end |
96 | |
97 | def locked?(comparison_time) |
98 | locked_at + LOCKING_PERIOD > comparison_time unless locked_at.nil? |
99 | end |
100 | |
101 | def to_param |
102 | name |
103 | end |
104 | |
105 | private |
106 | |
107 | def continous_revision?(time, author) |
108 | (current_revision.author == author) && (revised_at + 30.minutes > time) |
109 | end |
110 | |
111 | # Forward method calls to the current revision, so the page responds to all revision calls |
112 | def method_missing(method_id, *args, &block) |
113 | method_name = method_id.to_s |
114 | # Perform a hand-off to AR::Base#method_missing |
115 | if @attributes.include?(method_name) or md = /(=|\?|_before_type_cast)$/.match(method_name) |
116 | super(method_id, *args, &block) |
117 | else |
118 | current_revision.send(method_id) |
119 | end |
120 | end |
121 | end |