/instiki/svnpassword

To download this project, use:
bzr branch https://golem.ph.utexas.edu/~distler/code/instiki/svn/
11 by Jacques Distler
Replaced diff.rb with xhtmldiff.rb, which (unlike its predecessor) produces well-formed redline documents.
1 
require 'xhtmldiff'
131 by Jacques Distler
More fixes, sync with HTML5lib
2 
1 by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
3 
# Temporary class containing all rendering stuff from a Revision 
4 
# I want to shift all rendering loguc to the controller eventually
5 
6 
class PageRenderer
7 
8 
 def self.setup_url_generator(url_generator)
9 
 @@url_generator = url_generator
10 
 end
11 
12 
 def self.teardown_url_generator
13 
 @@url_generator = nil
14 
 end
15 
16 
 attr_reader :revision
17 
18 
 def initialize(revision = nil)
19 
 self.revision = revision
20 
 end
21 
22 
 def revision=(r)
23 
 @revision = r
927 by Jacques Distler
Whitespace and a MIME-type
24 
 @display_content = @display_published = @wiki_words_cache = @wiki_includes_cache =
1 by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
25 
 @wiki_references_cache = nil
26 
 end
27 
28 
 def display_content(update_references = false)
29 
 @display_content ||= render(:update_references => update_references)
30 
 end
31 
32 
 def display_content_for_export
33 
 render :mode => :export
34 
 end
35 
36 
 def display_published
37 
 @display_published ||= render(:mode => :publish)
38 
 end
39 
861 by Jacques Distler
Atom feed for changes in XHTML diff form
40 
 def display_diff(styles = {})
1 by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
41 
 previous_revision = @revision.page.previous_revision(@revision)
42 
 if previous_revision
11 by Jacques Distler
Replaced diff.rb with xhtmldiff.rb, which (unlike its predecessor) produces well-formed redline documents.
43 
875 by Jacques Distler
Also fix generation of diffs for previous issue
44 
 previous_content = "<div xmlns:se='http://svg-edit.googlecode.com' xmlns:xlink='http://www.w3.org/1999/xlink'>" + WikiContent.new(previous_revision, @@url_generator).render!.to_s + "</div>"
45 
 current_content = "<div xmlns:se='http://svg-edit.googlecode.com' xmlns:xlink='http://www.w3.org/1999/xlink'>" + display_content.to_s + "</div>"
11 by Jacques Distler
Replaced diff.rb with xhtmldiff.rb, which (unlike its predecessor) produces well-formed redline documents.
46 
 diff_doc = REXML::Document.new
131 by Jacques Distler
More fixes, sync with HTML5lib
47 
 div = REXML::Element.new('div', nil, {:respect_whitespace =>:all})
48 
 div.attributes['class'] = 'xhtmldiff_wrapper'
49 
 diff_doc << div
861 by Jacques Distler
Atom feed for changes in XHTML diff form
50 
 hd = XHTMLDiff.new(div, styles)
11 by Jacques Distler
Replaced diff.rb with xhtmldiff.rb, which (unlike its predecessor) produces well-formed redline documents.
51 
52 
 parsed_previous_revision = REXML::HashableElementDelegator.new(
53 
 REXML::XPath.first(REXML::Document.new(previous_content), '/div'))
54 
 parsed_display_content = REXML::HashableElementDelegator.new(
55 
 REXML::XPath.first(REXML::Document.new(current_content), '/div'))
56 
 Diff::LCS.traverse_balanced(parsed_previous_revision, parsed_display_content, hd)
57 
58 
 diffs = ''
59 
 diff_doc.write(diffs, -1, true, true)
637 by Jacques Distler
Rails_xss Plugin
60 
 diffs.gsub(/\A<div class='xhtmldiff_wrapper'>(.*)<\/div>\Z/m, '1円').html_safe
1 by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
61 
 else
62 
 display_content
63 
 end
64 
 end
65 
152 by Jacques Distler
Use Standard PageRenderer for S5 Content
66 
 attr :s5_theme
67 
 def s5_theme=(s)
68 
 @s5_theme = s
69 
 end
70 
71 
 # Renders an S5 slideshow
72 
 def display_s5
73 
 @display_s5 ||= render(:mode => :s5,
265 by Jacques Distler
Upgrade to Rails 2.2.0
74 
 :engine_opts => {:author => @author, :title => @plain_name},
75 
 :renderer => self)
152 by Jacques Distler
Use Standard PageRenderer for S5 Content
76 
 end
77 
1 by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
78 
 # Returns an array of all the WikiIncludes present in the content of this revision.
79 
 def wiki_includes
927 by Jacques Distler
Whitespace and a MIME-type
80 
 unless @wiki_includes_cache
1 by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
81 
 chunks = display_content.find_chunks(Include)
82 
 @wiki_includes_cache = chunks.map { |c| ( c.escaped? ? nil : c.page_name ) }.compact.uniq
83 
 end
84 
 @wiki_includes_cache
85 
 end
86 
87 
 # Returns an array of all the WikiReferences present in the content of this revision.
88 
 def wiki_references
89 
 unless @wiki_references_cache 
90 
 chunks = display_content.find_chunks(WikiChunk::WikiReference)
91 
 @wiki_references_cache = chunks.map { |c| ( c.escaped? ? nil : c.page_name ) }.compact.uniq
92 
 end
93 
 @wiki_references_cache
94 
 end
95 
96 
 # Returns an array of all the WikiWords present in the content of this revision.
97 
 def wiki_words
98 
 @wiki_words_cache ||= find_wiki_words(display_content) 
99 
 end
927 by Jacques Distler
Whitespace and a MIME-type
100 
1 by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
101 
 def find_wiki_words(rendering_result)
332 by Jacques Distler
Referring Pages for File List
102 
 the_wiki_words = wiki_links(rendering_result)
1 by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
103 
 # Exclude backslash-escaped wiki words, such as \WikiWord, as well as links to files 
104 
 # and pictures, such as [[foo.txt:file]] or [[foo.jpg:pic]]
792 by Jacques Distler
Missed this bit for CDF support
105 
 the_wiki_words.delete_if { |link| link.escaped? or [:pic, :file, :cdf, :audio, :video, :delete].include?(link.link_type) }
1 by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
106 
 # convert to the list of unique page names
332 by Jacques Distler
Referring Pages for File List
107 
 the_wiki_words.map { |link| ( link.page_name ) }.uniq
108 
 end
109 
110 
 # Returns an array of all the WikiWords present in the content of this revision.
111 
 def wiki_files
112 
 @wiki_files_cache ||= find_wiki_files(display_content) 
113 
 end
927 by Jacques Distler
Whitespace and a MIME-type
114 
332 by Jacques Distler
Referring Pages for File List
115 
 def find_wiki_files(rendering_result)
116 
 the_wiki_files = wiki_links(rendering_result)
792 by Jacques Distler
Missed this bit for CDF support
117 
 the_wiki_files.delete_if { |link| ![:pic, :file, :cdf, :audio, :video].include?(link.link_type) }
332 by Jacques Distler
Referring Pages for File List
118 
 the_wiki_files.map { |link| ( link.page_name ) }.uniq
119 
 end
120 
121 
 def wiki_links(rendering_result)
122 
 rendering_result.find_chunks(WikiChunk::WikiLink)
1 by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
123 
 end
124 
125 
 # Returns an array of all the WikiWords present in the content of this revision.
126 
 # that already exists as a page in the web.
127 
 def existing_pages
128 
 wiki_words.select { |wiki_word| @revision.page.web.page(wiki_word) }
129 
 end
130 
131 
 # Returns an array of all the WikiWords present in the content of this revision
132 
 # that *doesn't* already exists as a page in the web.
133 
 def unexisting_pages
134 
 wiki_words - existing_pages
135 
 end 
136 
137 
 private
138 
139 
 def render(options = {})
140 
 rendering_result = WikiContent.new(@revision, @@url_generator, options).render!
141 
 update_references(rendering_result) if options[:update_references]
142 
 rendering_result
143 
 end
144 
145 
 def update_references(rendering_result)
146 
 WikiReference.delete_all ['page_id = ?', @revision.page_id]
147 
148 
 references = @revision.page.wiki_references
149 
150 
 wiki_words = find_wiki_words(rendering_result)
151 
 # TODO it may be desirable to save links to files and pictures as WikiReference objects
152 
 # present version doesn't do it
153 
154 
 wiki_words.each do |referenced_name|
155 
 # Links to self are always considered linked
156 
 if referenced_name == @revision.page.name
157 
 link_type = WikiReference::LINKED_PAGE
158 
 else
159 
 link_type = WikiReference.link_type(@revision.page.web, referenced_name)
160 
 end
180 by Jacques Distler
New Version
161 
 references.build :referenced_name => referenced_name, :link_type => link_type
1 by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
162 
 end
927 by Jacques Distler
Whitespace and a MIME-type
163 
332 by Jacques Distler
Referring Pages for File List
164 
 wiki_files = find_wiki_files(rendering_result)
165 
 wiki_files.each do |referenced_name|
166 
 references.build :referenced_name => referenced_name, :link_type => WikiReference::FILE
167 
 end
927 by Jacques Distler
Whitespace and a MIME-type
168 
1 by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
169 
 include_chunks = rendering_result.find_chunks(Include)
170 
 includes = include_chunks.map { |c| ( c.escaped? ? nil : c.page_name ) }.compact.uniq
171 
 includes.each do |included_page_name|
927 by Jacques Distler
Whitespace and a MIME-type
172 
 references.build :referenced_name => included_page_name,
1 by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
173 
 :link_type => WikiReference::INCLUDED_PAGE
174 
 end
927 by Jacques Distler
Whitespace and a MIME-type
175 
389 by Jacques Distler
Wiki Redirects and Page Renaming
176 
 redirect_chunks = rendering_result.find_chunks(Redirect)
177 
 redirects = redirect_chunks.map { |c| ( c.escaped? ? nil : c.page_name ) }.compact.uniq
178 
 redirects.each do |redirected_page_name|
927 by Jacques Distler
Whitespace and a MIME-type
179 
 references.build :referenced_name => redirected_page_name,
389 by Jacques Distler
Wiki Redirects and Page Renaming
180 
 :link_type => WikiReference::REDIRECTED_PAGE
181 
 end
927 by Jacques Distler
Whitespace and a MIME-type
182 
391 by Jacques Distler
Expire Caches for Redirected Links
183 
 # ugly hack: store these in a thread-local variable, so that the cache-sweeper has access to it.
184 
 Thread.current[:page_redirects] ?
397 by Jacques Distler
Another Bug-fix and some tests
185 
 Thread.current[:page_redirects].update({ @revision.page => redirects}) :
186 
 Thread.current[:page_redirects] = { @revision.page => redirects}
927 by Jacques Distler
Whitespace and a MIME-type
187 
1 by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
188 
 categories = rendering_result.find_chunks(Category).map { |cat| cat.list }.flatten
189 
 categories.each do |category|
180 by Jacques Distler
New Version
190 
 references.build :referenced_name => category, :link_type => WikiReference::CATEGORY
1 by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
191 
 end
192 
 end
193 
end

AltStyle によって変換されたページ (->オリジナル) /