Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 344
- Log:
Massive changeset which brings the old, ROOL customised Instiki
version up to date, but without any ROOL customisations in this
latest checked-in version (which is 0.19.1). This is deliberate,
so that it's easy to see the changes made for the ROOL version
in a subsequent changeset. The 'app/views/shared' directory is not
part of Instiki but is kept to maintain the change history with
updated ROOL customisations, some of which involve the same files
in that same directory.
- Author:
- rool
- Date:
- Sat Mar 19 19:52:13 +0000 2011
- Size:
- 4054 Bytes
1 | class Page < ActiveRecord::Base |
2 | belongs_to :web |
3 | has_many :revisions, :order => 'id', :dependent => :destroy |
4 | has_many :wiki_references, :order => 'referenced_name' |
5 | has_one :current_revision, :class_name => 'Revision', :order => 'id DESC' |
6 | |
7 | def name |
8 | read_attribute(:name).as_utf8 |
9 | end |
10 | |
11 | def revise(content, name, time, author, renderer) |
12 | revisions_size = new_record? ? 0 : revisions.size |
13 | if (revisions_size > 0) and content == current_revision.content and name == self.name |
14 | raise Instiki::ValidationError.new( |
15 | "You have tried to save page '#{name}' without changing its content") |
16 | end |
17 | |
18 | self.name = name |
19 | author = Author.new(author.to_s) unless author.is_a?(Author) |
20 | |
21 | # Try to render content to make sure that markup engine can take it, |
22 | renderer.revision = Revision.new( |
23 | :page => self, :content => content, :author => author, :revised_at => time) |
24 | renderer.display_content(update_references = true) |
25 | |
26 | # A user may change a page, look at it and make some more changes - several times. |
27 | # Not to record every such iteration as a new revision, if the previous revision was done |
28 | # by the same author, not more than 30 minutes ago, then update the last revision instead of |
29 | # creating a new one |
30 | if (revisions_size > 0) && continous_revision?(time, author) |
31 | current_revision.update_attributes(:content => content, :revised_at => time) |
32 | else |
33 | revisions.build(:content => content, :author => author, :revised_at => time) |
34 | end |
35 | save |
36 | self |
37 | end |
38 | |
39 | def rollback(revision_number, time, author_ip, renderer) |
40 | roll_back_revision = self.revisions[revision_number] |
41 | if roll_back_revision.nil? |
42 | raise Instiki::ValidationError.new("Revision #{revision_number} not found") |
43 | end |
44 | author = Author.new(roll_back_revision.author.name, author_ip) |
45 | revise(roll_back_revision.content, self.name, time, author, renderer) |
46 | end |
47 | |
48 | def revisions? |
49 | revisions.size > 1 |
50 | end |
51 | |
52 | def previous_revision(revision) |
53 | revision_index = revisions.each_with_index do |rev, index| |
54 | if rev.id == revision.id |
55 | break index |
56 | else |
57 | nil |
58 | end |
59 | end |
60 | if revision_index.nil? or revision_index == 0 |
61 | nil |
62 | else |
63 | revisions[revision_index - 1] |
64 | end |
65 | end |
66 | |
67 | def references |
68 | web.select.pages_that_reference(name) |
69 | end |
70 | |
71 | def wiki_words |
72 | wiki_references.select { |ref| ref.wiki_word? }.map { |ref| ref.referenced_name } |
73 | end |
74 | |
75 | def categories |
76 | wiki_references.select { |ref| ref.category? }.map { |ref| ref.referenced_name } |
77 | end |
78 | |
79 | def linked_from |
80 | web.select.pages_that_link_to(name) |
81 | end |
82 | |
83 | def redirects |
84 | wiki_references.select { |ref| ref.redirected_page? }.map { |ref| ref.referenced_name } |
85 | end |
86 | |
87 | def included_from |
88 | web.select.pages_that_include(name) |
89 | end |
90 | |
91 | # Returns the original wiki-word name as separate words, so "MyPage" becomes "My Page". |
92 | def plain_name |
93 | web.brackets_only? ? name.escapeHTML.html_safe : WikiWords.separate(name).escapeHTML.html_safe |
94 | end |
95 | |
96 | LOCKING_PERIOD = 30.minutes |
97 | |
98 | def lock(time, locked_by) |
99 | update_attributes(:locked_at => time, :locked_by => locked_by) |
100 | end |
101 | |
102 | def lock_duration(time) |
103 | ((time - locked_at) / 60).to_i unless locked_at.nil? |
104 | end |
105 | |
106 | def unlock |
107 | update_attribute(:locked_at, nil) |
108 | end |
109 | |
110 | def locked?(comparison_time) |
111 | locked_at + LOCKING_PERIOD > comparison_time unless locked_at.nil? |
112 | end |
113 | |
114 | def to_param |
115 | name.as_utf8 |
116 | end |
117 | |
118 | private |
119 | |
120 | def continous_revision?(time, author) |
121 | (current_revision.author == author) && (revised_at + 30.minutes > time) |
122 | end |
123 | |
124 | # Forward method calls to the current revision, so the page responds to all revision calls |
125 | def method_missing(method_id, *args, &block) |
126 | method_name = method_id.to_s |
127 | # Perform a hand-off to AR::Base#method_missing |
128 | if @attributes.include?(method_name) or md = /(=|\?|_before_type_cast)$/.match(method_name) |
129 | super(method_id, *args, &block) |
130 | else |
131 | current_revision.send(method_id) |
132 | end |
133 | end |
134 | end |