Wiki2Go 1.17.5 → 1.22.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/Wiki2Go_firewall_blacklist.rb +8 -0
- data/bin/Wiki2Go_make_cvs_repository.rb +1 -0
- data/bin/Wiki2Go_make_site.rb +1 -2
- data/bin/Wiki2Go_update_site.rb +1 -2
- data/lib/Web2Go/CGIRequest.rb +8 -2
- data/lib/Web2Go/CGIResponse.rb +17 -14
- data/lib/Web2Go/MockRequest.rb +12 -2
- data/lib/Web2Go/MockResponse.rb +10 -7
- data/lib/Web2Go/WebrickRequest.rb +106 -101
- data/lib/Web2Go/WebrickResponse.rb +4 -8
- data/lib/Wiki2Go/BlackList.rb +48 -25
- data/lib/Wiki2Go/DotGraphics.rb +1 -1
- data/lib/Wiki2Go/FileStorage.rb +266 -266
- data/lib/Wiki2Go/HTMLFormatter.rb +28 -0
- data/lib/Wiki2Go/Install/config/chonqed_blacklist.txt +418 -0
- data/lib/Wiki2Go/Install/config/passwords +1 -1
- data/lib/Wiki2Go/Install/config/url_blacklist.txt +3855 -0
- data/lib/Wiki2Go/Install/make_repository.rb +32 -26
- data/lib/Wiki2Go/Install/make_site.rb +197 -111
- data/lib/Wiki2Go/Install/site/error.html +1 -1
- data/lib/Wiki2Go/Install/site/robots.txt +10 -1
- data/lib/Wiki2Go/Install/site/style.css +129 -64
- data/lib/Wiki2Go/Install/templates/admin.htm +1 -1
- data/lib/Wiki2Go/Install/templates/admin_pages/edit.txt +2 -1
- data/lib/Wiki2Go/Install/templates/admin_pages/format_for_fck.txt +31 -0
- data/lib/Wiki2Go/Install/templates/admin_pages/passwords.txt +1 -1
- data/lib/Wiki2Go/Install/templates/edit.htm +62 -46
- data/lib/Wiki2Go/Install/templates/full_footer.htm +31 -33
- data/lib/Wiki2Go/Install/templates/header.htm +0 -1
- data/lib/Wiki2Go/Install/templates/menu.htm +29 -0
- data/lib/Wiki2Go/Install/templates/pagelist.htm +46 -43
- data/lib/Wiki2Go/Install/templates/simple_footer.htm +20 -16
- data/lib/Wiki2Go/Install/templates/versionlist.htm +52 -40
- data/lib/Wiki2Go/Install/templates/view.htm +46 -29
- data/lib/Wiki2Go/Install/templates/wikiedit.htm +63 -0
- data/lib/Wiki2Go/Install/wiki/delete.png +0 -0
- data/lib/Wiki2Go/Install/wiki/style.css +133 -63
- data/lib/Wiki2Go/LineFormatter.rb +345 -197
- data/lib/Wiki2Go/Page.rb +16 -3
- data/lib/Wiki2Go/PrivateWikiConfig.rb +5 -5
- data/lib/Wiki2Go/PublicWikiConfig.rb +83 -37
- data/lib/Wiki2Go/ReadWriteWikiConfig.rb +8 -8
- data/lib/Wiki2Go/Server.rb +6 -1
- data/lib/Wiki2Go/SpamFilter.rb +32 -41
- data/lib/Wiki2Go/Web.rb +10 -3
- data/lib/Wiki2Go/Wiki2Go.rb +301 -94
- data/lib/Wiki2Go/Wiki2GoConfig.rb +87 -6
- data/lib/Wiki2Go/Wiki2GoServlet.rb +66 -12
- data/lib/Wiki2Go/WikiFormatter.rb +60 -30
- data/lib/Wiki2Go/cgi/diff.rb +20 -0
- data/lib/Wiki2Go/cgi/secure/log_rss.rb +21 -0
- data/lib/Wiki2Go/cgi/sidebyside.rb +20 -0
- data/lib/Wiki2Go/cgi/wikiedit.rb +20 -0
- data/lib/Wiki2Go/firewall_blacklist.rb +88 -0
- data/test/All.rb +5 -2
- data/test/TestBlackList.rb +70 -14
- data/test/TestConfig.rb +5 -5
- data/test/TestDiff.rb +95 -0
- data/test/TestFormatter.rb +14 -16
- data/test/TestHTMLFormatter.rb +37 -0
- data/test/TestInstall.rb +70 -27
- data/test/TestLineFormatter.rb +71 -15
- data/test/TestRSS.rb +8 -7
- data/test/TestRepository.rb +50 -0
- data/test/TestServer.rb +3 -8
- data/test/TestSpamFilter.rb +33 -1
- data/test/TestStorage.rb +11 -0
- data/test/TestWeb.rb +2 -2
- data/test/TestWiki2Go.rb +766 -166
- data/test/TestWiki2GoServlet.rb +1122 -524
- data/test/UnitTestFiles.rb +7 -3
- data/test/Wiki2GoConfigForTest.rb +40 -6
- data/test/checksite.rb +17 -50
- data/test/test_firewall_blacklist.rb +131 -0
- data/test/test_page.rb +45 -0
- data/test/testdata/Registration.rbl.txt +7 -0
- data/test/testdata/config/url_blacklist.txt +38822 -0
- data/test/testdata/expected_changes.html +1 -2
- data/test/testdata/expected_edit.html +108 -59
- data/test/testdata/expected_full_rss.xml +2 -2
- data/test/testdata/expected_out.html +97 -61
- data/test/testdata/expected_put.html +88 -53
- data/test/testdata/expected_save.html +88 -52
- data/test/testdata/expected_savehtml.html +88 -52
- data/test/testdata/expected_search.html +68 -53
- data/test/testdata/expected_upload.html +88 -53
- data/test/testdata/expected_versions.html +97 -82
- data/test/testdata/expected_view.html +97 -61
- data/test/testdata/firewall/iptables.config +37 -0
- data/test/testdata/firewall/user_blacklist.txt +162 -0
- data/test/testdata/logs/wiki.log +652 -0
- data/test/testdata/logs/wiki.log.0 +113 -0
- data/test/testdata/logs/wiki.log.1 +113 -0
- data/test/testdata/logs/wiki.log.2 +113 -0
- data/test/testdata/logs/wiki.log.3 +115 -0
- data/test/testdata/logs/wiki.log.4 +5 -0
- data/test/testdata/logs/wiki.log.5 +7 -0
- data/test/testdata/logs/wiki.log.6 +5 -0
- data/test/testdata/logs/wiki.log.7 +118 -0
- data/test/testdata/logs/wiki.log.8 +12 -0
- data/test/testdata/site/html/Xpday/rss.xml +53 -103
- data/test/testdata/texts/Bugs/FrontPage.txt +6 -0
- data/test/testdata/texts/Bugs/NoHidden.spam +17850 -0
- data/test/testdata/texts/Bugs/PairProgrammingParties.spam +102 -0
- data/test/testdata/texts/Bugs/PairProgrammingParties.txt +99 -0
- metadata +53 -7
- data/test/TestMail.rb +0 -29
- data/test/gc.log +0 -2
data/lib/Wiki2Go/Wiki2Go.rb
CHANGED
@@ -1,60 +1,147 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
gem 'diff-lcs'
|
6
|
+
|
7
|
+
require 'cgi'
|
2
8
|
|
3
9
|
require "Wiki2Go/WikiFormatter"
|
10
|
+
require "Wiki2Go/HTMLFormatter"
|
4
11
|
|
5
12
|
require 'Web2Go/ERB_Interpreter'
|
6
13
|
require 'Web2Go/MockRequest'
|
7
14
|
|
15
|
+
require 'diff/lcs'
|
16
|
+
|
8
17
|
module Wiki2Go
|
9
18
|
|
19
|
+
class SpamException < RuntimeError
|
20
|
+
end
|
21
|
+
|
10
22
|
class Wiki
|
11
23
|
def initialize(config)
|
12
24
|
@config = config
|
13
25
|
end
|
14
|
-
|
15
|
-
def view(web)
|
26
|
+
|
27
|
+
def view(web,version)
|
28
|
+
text = load_page_version(web,version)
|
29
|
+
|
30
|
+
template = @config.storage.load_template(web.name,"view.htm")
|
31
|
+
|
16
32
|
html = @config.redirect_to_html?(web)
|
17
33
|
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
return formatter.format_page_in_template(template,text)
|
34
|
+
|
35
|
+
result = formatter.format_page_in_template(template,text,version)
|
36
|
+
return result
|
23
37
|
end
|
24
|
-
|
38
|
+
|
25
39
|
def versions(web)
|
40
|
+
topics = all_good_versions(web)
|
41
|
+
template = @config.storage.load_template(web.name,"versionlist.htm")
|
42
|
+
|
26
43
|
html = @config.redirect_to_html?(web)
|
27
44
|
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
|
28
|
-
|
29
|
-
topics = @config.storage.all_versions_of(web.name,web.current_page)
|
30
|
-
template = @config.storage.load_template(web.name,"versionlist.htm")
|
31
|
-
|
45
|
+
|
32
46
|
return formatter.format_pagelist_in_template(template,topics,"","Versions of '#{web.current_page}'")
|
33
47
|
end
|
34
|
-
|
48
|
+
|
49
|
+
def diff(web,version1,version2)
|
50
|
+
from,from_page,to,to_page = load_two_versions(web,version1,version2)
|
51
|
+
|
52
|
+
from_lines = break_on_br(from_page.lines)
|
53
|
+
to_lines = break_on_br(to_page.lines)
|
54
|
+
|
55
|
+
html = @config.redirect_to_html?(web)
|
56
|
+
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
|
57
|
+
|
58
|
+
header = "<strong>#{to_page.name} "
|
59
|
+
header << append_blank(formatter.diff_link(web.name,from_page.filename,'<<',from-1,to))
|
60
|
+
header << formatter.view_version_link(web.name,from_page.filename,"v#{from.to_s} (by #{from_page.alias})",from)
|
61
|
+
link = formatter.diff_link(web.name,from_page.filename,'>>',from+1,to)
|
62
|
+
header << (link.length > 0 ? ' ' + link : '' )
|
63
|
+
header << ' => '
|
64
|
+
header << append_blank(formatter.diff_link(web.name,from_page.filename,'<<',from,to-1))
|
65
|
+
header << formatter.view_version_link(web.name,to_page.filename,"v#{to.to_s} (by #{to_page.alias})",to) + ' '
|
66
|
+
header << formatter.diff_link(web.name,from_page.filename,'>>',from,to+1)
|
67
|
+
header << "</strong>\n<hr>\n"
|
68
|
+
|
69
|
+
lines = Array.new
|
70
|
+
lines << header
|
71
|
+
sdiff = Diff::LCS.sdiff(from_lines,to_lines,nil) do |change|
|
72
|
+
case change.action
|
73
|
+
when '='
|
74
|
+
lines << "<div class=\"diff_kept\">= #{CGI::escapeHTML(change.old_element).gsub(' ',' ')}</div>"
|
75
|
+
when '!'
|
76
|
+
lines << "<div class=\"diff_deleted\">< #{CGI::escapeHTML(change.old_element).gsub(' ',' ')}</div>"
|
77
|
+
lines << "<div class=\"diff_added\">> #{CGI::escapeHTML(change.new_element).gsub(' ',' ')}</div>"
|
78
|
+
when '-'
|
79
|
+
lines << "<div class=\"diff_deleted\">< #{CGI::escapeHTML(change.old_element).gsub(' ',' ')}</div>"
|
80
|
+
when '+'
|
81
|
+
lines << "<div class=\"diff_added\">> #{CGI::escapeHTML(change.new_element).gsub(' ',' ')}</div>"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
to_page.lines = lines
|
86
|
+
template = @config.storage.load_template(web.name,"view.htm")
|
87
|
+
|
88
|
+
return formatter.dump_page_in_template(template,to_page,from,to)
|
89
|
+
end
|
90
|
+
|
91
|
+
def sidebyside(web,version1,version2)
|
92
|
+
|
93
|
+
from,from_page,to,to_page = load_two_versions(web,version1,version2)
|
94
|
+
|
95
|
+
template = @config.storage.load_template(web.name,"view.htm")
|
96
|
+
|
97
|
+
html = @config.redirect_to_html?(web)
|
98
|
+
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
|
99
|
+
|
100
|
+
left = formatter.format_page(from_page.content)
|
101
|
+
right = formatter.format_page(to_page.content)
|
102
|
+
|
103
|
+
|
104
|
+
leftheader = append_blank(formatter.sidebyside_link(web.name,from_page.filename,'<<',from-1,to))
|
105
|
+
leftheader << formatter.view_version_link(web.name,from_page.filename,"#{to_page.name} v#{from.to_s} (by #{from_page.alias})",from)
|
106
|
+
leftheader << formatter.sidebyside_link(web.name,from_page.filename,'>>',from+1,to)
|
107
|
+
|
108
|
+
rightheader = append_blank(formatter.sidebyside_link(web.name,from_page.filename,'<<',from,to-1))
|
109
|
+
rightheader << formatter.view_version_link(web.name,to_page.filename,"#{to_page.name} v#{to.to_s} (by #{to_page.alias})",to) + ' '
|
110
|
+
rightheader << formatter.sidebyside_link(web.name,from_page.filename,'>>',from,to+1)
|
111
|
+
|
112
|
+
|
113
|
+
content = "<table class=\"wikitable\" width=\"100%\"><tr>"
|
114
|
+
content += "<th>#{leftheader}</th><th>#{rightheader}</th></tr>\n"
|
115
|
+
content += "<tr><td width='50%' valign='top'>#{left}</td><td width='50%' valign='top'>#{right}</td></tr></table>"
|
116
|
+
to_page.lines = content.split($/)
|
117
|
+
|
118
|
+
|
119
|
+
return formatter.dump_page_in_template(template,to_page,from,to)
|
120
|
+
end
|
121
|
+
|
35
122
|
def view_dynamic(web)
|
36
123
|
html = false
|
37
124
|
editable = @config.editable?(web)
|
38
125
|
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,editable)
|
39
|
-
|
126
|
+
|
40
127
|
text = @config.storage.load_page(web.name,web.current_page)
|
41
128
|
template = @config.storage.load_template(web.name,"view.htm")
|
42
|
-
|
129
|
+
|
43
130
|
return formatter.format_page_in_template(template,text)
|
44
131
|
end
|
45
|
-
|
132
|
+
|
46
133
|
def view_html(web)
|
47
134
|
html = true
|
48
135
|
editable = @config.editable?(web)
|
49
136
|
web = @config.static_web(web)
|
50
137
|
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,editable)
|
51
|
-
|
138
|
+
|
52
139
|
text = @config.storage.load_page(web.name,web.current_page)
|
53
140
|
template = @config.storage.load_template(web.name,"view.htm")
|
54
|
-
|
141
|
+
|
55
142
|
return formatter.format_page_in_template(template,text)
|
56
143
|
end
|
57
|
-
|
144
|
+
|
58
145
|
def generate_rss(web,changes)
|
59
146
|
html = @config.generate_html
|
60
147
|
editable = false
|
@@ -64,7 +151,7 @@ module Wiki2Go
|
|
64
151
|
rss = formatter.generate_rss(template,changes)
|
65
152
|
return rss
|
66
153
|
end
|
67
|
-
|
154
|
+
|
68
155
|
def generate_rss_from_log(web,errorlog)
|
69
156
|
html = @config.generate_html
|
70
157
|
editable = false
|
@@ -73,35 +160,40 @@ module Wiki2Go
|
|
73
160
|
rss = formatter.generate_rss_from_log(errorlog)
|
74
161
|
return rss
|
75
162
|
end
|
76
|
-
|
163
|
+
|
77
164
|
def edit(web)
|
78
|
-
|
79
|
-
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
|
80
|
-
|
81
|
-
text = @config.storage.load_page(web.name,web.current_page)
|
82
|
-
template = @config.storage.load_template(web.name,"edit.htm")
|
83
|
-
|
84
|
-
return formatter.put_page_in_template(template,text)
|
165
|
+
do_edit(web,'edit.htm')
|
85
166
|
end
|
86
|
-
|
87
|
-
def
|
88
|
-
|
167
|
+
|
168
|
+
def wikiedit(web)
|
169
|
+
do_edit(web,'wikiedit.htm')
|
170
|
+
end
|
171
|
+
|
172
|
+
def save(web,new_content,checksum="")
|
89
173
|
new_content.gsub!(/\t/,' ')
|
174
|
+
|
175
|
+
blacklist_robots(web,checksum)
|
176
|
+
|
177
|
+
author = web.user
|
178
|
+
pagename = web.name.length > 0 ? "#{web.name}/#{web.current_page}" : web.current_page
|
90
179
|
|
91
180
|
changed = true
|
92
181
|
newfile = !@config.storage.exists(web.path)
|
93
182
|
newpage = Page.new(web.current_page,new_content,web.user,Time.now,web.title,web.alias)
|
183
|
+
current = @config.storage.load_page(web.name,web.current_page)
|
184
|
+
|
94
185
|
if !newfile then
|
95
|
-
current = @config.storage.load_page(web.name,web.current_page)
|
96
186
|
changed = (current.content != newpage.content) || newpage.name != current.name
|
97
187
|
newpage.created_on = current.created_on
|
98
188
|
end
|
99
|
-
|
189
|
+
|
100
190
|
if changed then
|
191
|
+
if !@config.accept_edit?(web,current,checksum) then
|
192
|
+
@config.errorlog("Edit by user #{author} of page '#{pagename}' clashes with edit of #{current.alias}")
|
193
|
+
end
|
101
194
|
if @config.accept_page?(web,new_content) then
|
102
195
|
@config.save(web,newpage)
|
103
|
-
|
104
|
-
save_rss(web,changes)
|
196
|
+
save_changes_in_rss(web)
|
105
197
|
@config.instant_commit_to_repository
|
106
198
|
if @config.generate_html then
|
107
199
|
if newfile then
|
@@ -112,13 +204,15 @@ module Wiki2Go
|
|
112
204
|
end
|
113
205
|
else
|
114
206
|
@config.storage.save_spam(web.name,web.current_page,new_content,web.user)
|
207
|
+
raise SpamException
|
208
|
+
return web.error_page
|
115
209
|
end
|
116
210
|
end
|
117
211
|
html = @config.redirect_to_html?(web)
|
118
212
|
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
|
119
213
|
return formatter.absolute_url
|
120
214
|
end
|
121
|
-
|
215
|
+
|
122
216
|
def upload(web,name,content)
|
123
217
|
if name.empty? || content.nil? then
|
124
218
|
html = @config.redirect_to_html?(web)
|
@@ -133,32 +227,32 @@ module Wiki2Go
|
|
133
227
|
return save(web,text)
|
134
228
|
end
|
135
229
|
end
|
136
|
-
|
230
|
+
|
137
231
|
def changes(web)
|
138
232
|
html = @config.redirect_to_html?(web)
|
139
233
|
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
|
140
|
-
|
141
|
-
topics = @config.storage.read_changes_in(web.name
|
234
|
+
|
235
|
+
topics = @config.storage.read_changes_in(web.name,@config.pages_in_recent_changes)
|
142
236
|
template = @config.storage.load_template(web.name,"pagelist.htm")
|
143
|
-
|
237
|
+
|
144
238
|
return formatter.format_pagelist_in_template(template,topics,"","Recent Changes")
|
145
239
|
end
|
146
|
-
|
240
|
+
|
147
241
|
def search(web,searchtopic)
|
148
242
|
searchtopic ||= ''
|
149
243
|
html = @config.redirect_to_html?(web)
|
150
244
|
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
|
151
|
-
|
245
|
+
|
152
246
|
topics = @config.storage.search(web.name,searchtopic)
|
153
247
|
template = @config.storage.load_template(web.name,"pagelist.htm")
|
154
|
-
|
248
|
+
|
155
249
|
return formatter.format_pagelist_in_template(template,topics,searchtopic,"Search for '#{searchtopic}'")
|
156
250
|
end
|
157
|
-
|
251
|
+
|
158
252
|
def remove_spam(web)
|
159
253
|
any_changes = false
|
160
254
|
files = @config.storage.all_pages_in(web.name)
|
161
|
-
blacklist = @config.
|
255
|
+
blacklist = @config.banned_users
|
162
256
|
files.each do |topic|
|
163
257
|
page = @config.storage.load_page(web.name,topic)
|
164
258
|
if blacklist.contains(page.author) then
|
@@ -167,147 +261,193 @@ module Wiki2Go
|
|
167
261
|
end
|
168
262
|
end
|
169
263
|
if any_changes then
|
170
|
-
|
171
|
-
save_rss(web,changes)
|
264
|
+
save_changes_in_rss(web)
|
172
265
|
end
|
173
|
-
|
266
|
+
html = @config.redirect_to_html?(web)
|
267
|
+
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
|
268
|
+
return formatter.changes_url
|
174
269
|
end
|
175
|
-
|
270
|
+
|
176
271
|
def blacklist(user)
|
177
272
|
@config.log("Adding #{user} to blacklist")
|
178
|
-
list = @config.
|
273
|
+
list = @config.banned_users
|
179
274
|
list.add(user)
|
180
275
|
@config.storage.save_list(list)
|
181
276
|
end
|
182
|
-
|
277
|
+
|
183
278
|
def log(msg)
|
184
279
|
@config.log(msg)
|
185
280
|
end
|
186
|
-
|
281
|
+
|
187
282
|
def generate_html(web)
|
188
|
-
report = ["Generating HTML
|
283
|
+
report = ["Generating HTML#{$/}" , "<ul>"]
|
189
284
|
files = @config.storage.all_pages_in(web.name)
|
190
285
|
files.each do |file|
|
191
|
-
report << "<li>#{file}</li
|
286
|
+
report << "<li>#{file}</li>#{$/}"
|
192
287
|
pageweb = @config.static_web(web)
|
193
288
|
pageweb.current_page = file
|
194
289
|
save_html(pageweb)
|
195
290
|
end
|
196
|
-
|
197
|
-
|
198
|
-
report << "</ul>\r\n"
|
291
|
+
save_changes_in_rss(web)
|
292
|
+
report << "</ul>#{$/}"
|
199
293
|
return report.join
|
200
294
|
end
|
201
|
-
|
295
|
+
|
296
|
+
def prepare_for_fckeditor(web)
|
297
|
+
report = ["Generating HTML#{$/}" , "<ul>"]
|
298
|
+
files = @config.storage.all_pages_in(web.name)
|
299
|
+
files.each do |file|
|
300
|
+
report << "<li>#{file}</li>#{$/}"
|
301
|
+
pageweb = @config.static_web(web)
|
302
|
+
pageweb.current_page = file
|
303
|
+
generate_fckeditor_html(pageweb)
|
304
|
+
end
|
305
|
+
report << "</ul>#{$/}"
|
306
|
+
return report.join
|
307
|
+
end
|
308
|
+
|
202
309
|
def admin(request)
|
203
|
-
|
310
|
+
|
204
311
|
old_config = @config.multi_wiki
|
205
312
|
@config.multi_wiki = false
|
206
313
|
wikiweb = Wiki2Go::Web.from_request(request,@config)
|
207
314
|
@config.multi_wiki = old_config
|
208
|
-
|
315
|
+
|
209
316
|
template_name = wikiweb.current_page
|
210
317
|
if template_name.nil? || template_name.empty?
|
211
318
|
template_name = 'admin'
|
212
319
|
end
|
213
320
|
master = @config.storage.load_template(wikiweb.name,'admin.htm')
|
214
321
|
template = @config.storage.load_template(wikiweb.name,File.join('admin_pages',template_name+'.txt'))
|
215
|
-
|
322
|
+
|
216
323
|
master = master.gsub(/\$BODY\$/,template)
|
217
|
-
|
324
|
+
|
218
325
|
erb = Web2Go::ERB_Interpreter.new
|
219
326
|
erb.add_field(:@request,request)
|
220
327
|
erb.add_field(:@config,@config)
|
221
328
|
erb.add_field(:@web,wikiweb)
|
222
329
|
result = erb.execute master,0
|
223
|
-
|
330
|
+
|
224
331
|
end
|
225
|
-
|
332
|
+
|
226
333
|
def perform(web,request)
|
227
|
-
|
334
|
+
|
228
335
|
if @config.allow_dynamic_pages then
|
229
336
|
html = @config.redirect_to_html?(web)
|
230
337
|
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
|
231
|
-
|
338
|
+
|
232
339
|
text = @config.storage.load_page(web.name,web.current_page)
|
233
|
-
|
340
|
+
|
234
341
|
erb = Web2Go::ERB_Interpreter.new
|
235
342
|
erb.add_field(:@config,@config)
|
236
343
|
erb.add_field(:@web,web)
|
237
344
|
erb.add_field(:@request,request)
|
238
|
-
|
239
|
-
|
345
|
+
erb.add_field(:@formatter,formatter)
|
346
|
+
|
347
|
+
script = text.lines.join($/)
|
240
348
|
output = erb.execute(script,1)
|
241
|
-
text.lines = output.split($/)
|
242
|
-
|
349
|
+
text.lines = output.split($/)
|
350
|
+
|
243
351
|
template = @config.storage.load_template(web.name,"view.htm")
|
244
|
-
|
352
|
+
|
245
353
|
return formatter.format_page_in_template(template,text)
|
246
354
|
else
|
247
|
-
|
355
|
+
log("Perform not allowed")
|
356
|
+
self.view(web,-1)
|
248
357
|
end
|
249
358
|
end
|
250
|
-
|
359
|
+
|
251
360
|
private
|
252
|
-
|
361
|
+
|
362
|
+
def append_blank(str)
|
363
|
+
return str.length == 0 ? '' : str + ' '
|
364
|
+
end
|
365
|
+
|
366
|
+
def generate_fckeditor_html(web)
|
367
|
+
formatter = Wiki2Go::HTMLFormatter.new(web,@config.storage,@config,true,@config.editable?(web))
|
368
|
+
pagename = web.current_page
|
369
|
+
@config.storage.backup_page(web.name,web.current_page)
|
370
|
+
page = @config.storage.load_page(web.name,web.current_page)
|
371
|
+
updated = formatter.format_page(page.content)
|
372
|
+
page.lines = updated.split($/)
|
373
|
+
@config.storage.save_page(web.name,page)
|
374
|
+
end
|
375
|
+
|
376
|
+
def select(changes,maximum_amount)
|
377
|
+
if maximum_amount < changes.length then
|
378
|
+
changes[0,maximum_amount]
|
379
|
+
else
|
380
|
+
changes
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
def save_changes_in_rss(web)
|
385
|
+
nb_changes = (@config.pages_in_rss > @config.pages_in_recent_changes ? @config.pages_in_rss : @config.pages_in_recent_changes )
|
386
|
+
changes = @config.storage.read_changes_in(web.name,nb_changes)
|
387
|
+
save_rss(web,select(changes,@config.pages_in_rss))
|
388
|
+
save_changes(web,select(changes,@config.pages_in_recent_changes))
|
389
|
+
end
|
390
|
+
|
253
391
|
def save_rss(web,changes)
|
254
392
|
static_web = @config.static_web(web)
|
255
393
|
rss = generate_rss(static_web,changes)
|
256
394
|
@config.storage.store_web_file(web.name,"rss.xml",rss)
|
257
|
-
save_changes(static_web,changes)
|
258
395
|
end
|
259
|
-
|
396
|
+
|
260
397
|
def save_changes(web,changes)
|
398
|
+
web = @config.static_web(web)
|
261
399
|
if @config.generate_html then
|
262
400
|
html = true
|
263
401
|
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
|
264
|
-
|
402
|
+
|
265
403
|
template = @config.storage.load_template(web.name,"pagelist.htm")
|
266
|
-
|
404
|
+
|
267
405
|
content = formatter.format_pagelist_in_template(template,changes,"","Recent Changes")
|
268
406
|
@config.storage.save_html(web.name,'recent_changes',content)
|
269
407
|
end
|
270
408
|
end
|
271
|
-
|
409
|
+
|
272
410
|
def save_html(web)
|
273
|
-
if @config.generate_html then
|
411
|
+
if @config.generate_html && !Page.is_dynamic?(web.current_page) then
|
274
412
|
static_web = @config.static_web(web)
|
275
413
|
@config.storage.save_html(static_web.name,static_web.current_page, view_html(static_web))
|
276
414
|
end
|
277
415
|
end
|
278
|
-
|
416
|
+
|
279
417
|
# Optimized method of regenerating only the HTML of pages that are affected by a new page
|
280
418
|
# Search for all pages containing the title of the new page and render those + the new page
|
281
419
|
def generate_html_for_page(web,pagename)
|
282
420
|
files = @config.storage.search(web.name,pagename)
|
283
421
|
files << @config.storage.load_page(web.name,pagename)
|
284
422
|
files.each do |file|
|
285
|
-
|
286
|
-
|
287
|
-
|
423
|
+
if !Page.is_dynamic?(file.filename) then
|
424
|
+
static_web = @config.static_web(web)
|
425
|
+
static_web.current_page = file.filename
|
426
|
+
@config.storage.save_html(static_web.name,static_web.current_page, view_html_of_page(static_web,file))
|
427
|
+
end
|
288
428
|
end
|
289
429
|
end
|
290
|
-
|
430
|
+
|
291
431
|
def view_html_of_page(web,text)
|
292
432
|
html = true
|
293
433
|
editable = @config.editable?(web)
|
294
434
|
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,editable)
|
295
|
-
|
435
|
+
|
296
436
|
template = @config.storage.load_template(web.name,"view.htm")
|
297
|
-
|
437
|
+
|
298
438
|
return formatter.format_page_in_template(template,text)
|
299
439
|
end
|
300
|
-
|
440
|
+
|
301
441
|
def view_text(web,text)
|
302
|
-
html = @config.generate_html && !web.secure
|
442
|
+
html = @config.generate_html && !web.secure?
|
303
443
|
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
|
304
|
-
|
444
|
+
|
305
445
|
template = @config.storage.load_template(web.name,"view.htm")
|
306
|
-
|
446
|
+
|
307
447
|
page = Wiki2Go::Page.new("Report",text,"system",Time.now,Time.now,"Report")
|
308
448
|
return formatter.format_page_in_template(template,page)
|
309
449
|
end
|
310
|
-
|
450
|
+
|
311
451
|
def restore_last_good_version(web,topic,blacklist)
|
312
452
|
versions = @config.storage.all_versions_of(web.name,topic)
|
313
453
|
first_good_version = versions.find do |v|
|
@@ -325,5 +465,72 @@ module Wiki2Go
|
|
325
465
|
save_html(thispage)
|
326
466
|
end
|
327
467
|
end
|
468
|
+
|
469
|
+
def do_edit(web,template)
|
470
|
+
html = @config.redirect_to_html?(web)
|
471
|
+
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
|
472
|
+
|
473
|
+
text,version = load_page_version(web,-1)
|
474
|
+
|
475
|
+
template = @config.storage.load_template(web.name,template)
|
476
|
+
|
477
|
+
return formatter.put_page_in_template(template,text)
|
478
|
+
end
|
479
|
+
|
480
|
+
def break_on_br(lines)
|
481
|
+
content = lines.join($/)
|
482
|
+
content.gsub!(/<br>/i,$/)
|
483
|
+
content.gsub!(/<br \/>/i,$/)
|
484
|
+
return content.split($/)
|
485
|
+
end
|
486
|
+
|
487
|
+
def load_page_version(web,version)
|
488
|
+
|
489
|
+
if version == -1 then
|
490
|
+
text = @config.storage.load_page(web.name,web.current_page)
|
491
|
+
else
|
492
|
+
topics = all_good_versions(web)
|
493
|
+
topics.reverse!
|
494
|
+
text = topics[version] || @config.storage.load_page(web.name,web.current_page)
|
495
|
+
end
|
496
|
+
|
497
|
+
return text
|
498
|
+
end
|
499
|
+
|
500
|
+
def load_two_versions(web,version1,version2)
|
501
|
+
from = (version1 < version2 ? version1 : version2)
|
502
|
+
to = (version1 < version2 ? version2 : version1)
|
503
|
+
|
504
|
+
topics = all_good_versions(web)
|
505
|
+
topics.reverse!
|
506
|
+
|
507
|
+
to = topics.length - 1 if to < 0 || to >= topics.length
|
508
|
+
from = to > 0 ? to -1 : 0 if from < 0 || from >= topics.length
|
509
|
+
|
510
|
+
from_page = topics[from] || topics[-2] || @config.storage.load_page(web.name,web.current_page)
|
511
|
+
to_page = topics[to] || @config.storage.load_page(web.name,web.current_page)
|
512
|
+
|
513
|
+
return from,from_page,to,to_page
|
514
|
+
end
|
515
|
+
|
516
|
+
def all_good_versions(web)
|
517
|
+
topics = @config.storage.all_versions_of(web.name,web.current_page)
|
518
|
+
blacklist = @config.banned_users
|
519
|
+
topics = topics.reject { |version| blacklist.contains(version.author) }
|
520
|
+
|
521
|
+
topics
|
522
|
+
end
|
523
|
+
|
524
|
+
def blacklist_robots(web,checksum)
|
525
|
+
if @config.checksum_required && @config.blacklist_when_no_checksum && checksum.length == 0 then
|
526
|
+
author = web.user
|
527
|
+
pagename = web.name.length > 0 ? "#{web.name}/#{web.current_page}" : web.current_page
|
528
|
+
|
529
|
+
@config.blacklist_user(author)
|
530
|
+
@config.errorlog("Edit by user #{author} of page '#{pagename}' does not have a checksum. Suspected robot blacklisted")
|
531
|
+
raise SpamException
|
532
|
+
end
|
533
|
+
end
|
534
|
+
|
328
535
|
end
|
329
536
|
end
|