Wiki2Go 1.22.1 → 1.24.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'rubygems'
4
+ gem "Wiki2Go"
5
+
6
+ require 'fileutils'
7
+ require 'Wiki2Go/Install/make_site'
8
+
9
+ Wiki2Go::Install::regenerate_wiki(ARGV)
@@ -0,0 +1,146 @@
1
+ # Akismet
2
+ #
3
+ # Author:: David Czarnecki
4
+ # Copyright:: Copyright (c) 2005 - David Czarnecki
5
+ # License:: BSD
6
+
7
+ require 'net/http'
8
+ require 'uri'
9
+
10
+
11
+ module Wiki2Go
12
+
13
+ class Akismet
14
+
15
+ STANDARD_HEADERS = {
16
+ 'User-Agent' => 'Akismet Ruby API/1.0',
17
+ 'Content-Type' => 'application/x-www-form-urlencoded'
18
+ }
19
+
20
+ # Instance variables
21
+ @apiKey
22
+ @blog
23
+ @verifiedKey
24
+ @proxyPort = nil
25
+ @proxyHost = nil
26
+
27
+ # Create a new instance of the Akismet class
28
+ #
29
+ # apiKey
30
+ # Your Akismet API key
31
+ # blog
32
+ # The blog associated with your api key
33
+ def initialize(apiKey, blog)
34
+ @apiKey = apiKey
35
+ @blog = blog
36
+ @verifiedKey = false
37
+ end
38
+
39
+ # Set proxy information
40
+ #
41
+ # proxyHost
42
+ # Hostname for the proxy to use
43
+ # proxyPort
44
+ # Port for the proxy
45
+ def set_proxy(proxyHost, proxyPort)
46
+ @proxyPort = proxyPort
47
+ @proxyHost = proxyHost
48
+ end
49
+
50
+ # Call to check and verify your API key. You may then call the #hasVerifiedKey method to see if your key has been validated.
51
+ def verify_API_key()
52
+ http = Net::HTTP.new('rest.akismet.com', 80, @proxyHost, @proxyPort)
53
+ path = '/1.1/verify-key'
54
+
55
+ data="key=#{@apiKey}&blog=#{@blog}"
56
+
57
+ resp, data = http.post(path, data, STANDARD_HEADERS)
58
+ @verifiedKey = (data == "valid")
59
+ end
60
+
61
+ # Returns <tt>true</tt> if the API key has been verified, <tt>false</tt> otherwise
62
+ def verified_key?()
63
+ return @verifiedKey
64
+ end
65
+
66
+ # Internal call to Akismet. Prepares the data for posting to the Akismet service.
67
+ #
68
+ # akismet_function
69
+ # The Akismet function that should be called
70
+ # user_ip (required)
71
+ # IP address of the comment submitter.
72
+ # user_agent (required)
73
+ # User agent information.
74
+ # referrer (note spelling)
75
+ # The content of the HTTP_REFERER header should be sent here.
76
+ # permalink
77
+ # The permanent location of the entry the comment was submitted to.
78
+ # comment_type
79
+ # May be blank, comment, trackback, pingback, or a made up value like "registration".
80
+ # comment_author
81
+ # Submitted name with the comment
82
+ # comment_author_email
83
+ # Submitted email address
84
+ # comment_author_url
85
+ # Commenter URL.
86
+ # comment_content
87
+ # The content that was submitted.
88
+ # Other server enviroment variables
89
+ # In PHP there is an array of enviroment variables called $_SERVER which contains information about the web server itself as well as a key/value for every HTTP header sent with the request. This data is highly useful to Akismet as how the submited content interacts with the server can be very telling, so please include as much information as possible.
90
+ def callAkismet(akismet_function, user_ip, user_agent, referrer, permalink, comment_type, comment_author, comment_author_email, comment_author_url, comment_content, other)
91
+ http = Net::HTTP.new("#{@apiKey}.rest.akismet.com", 80, @proxyHost, @proxyPort)
92
+ path = "/1.1/#{akismet_function}"
93
+
94
+ data = "blog=#{@blog}&user_ip=#{user_ip}&user_agent=#{user_agent}&referrer=#{referrer}&permalink=#{permalink}&comment_type=#{comment_type}&comment_author=#{comment_author}&comment_author_email=#{comment_author_email}&comment_author_url=#{comment_author_url}&comment_content=#{comment_content}"
95
+ if (other != nil)
96
+ other.each_pair {|key, value| data.concat("&#{key}=#{value}")}
97
+ end
98
+ data = URI.escape(data)
99
+
100
+ resp, data = http.post(path, data, STANDARD_HEADERS)
101
+
102
+ return (data != "false")
103
+ end
104
+
105
+ protected :callAkismet
106
+
107
+ # This is basically the core of everything. This call takes a number of arguments and characteristics about the submitted content and then returns a thumbs up or thumbs down. Almost everything is optional, but performance can drop dramatically if you exclude certain elements.
108
+ #
109
+ # user_ip (required)
110
+ # IP address of the comment submitter.
111
+ # user_agent (required)
112
+ # User agent information.
113
+ # referrer (note spelling)
114
+ # The content of the HTTP_REFERER header should be sent here.
115
+ # permalink
116
+ # The permanent location of the entry the comment was submitted to.
117
+ # comment_type
118
+ # May be blank, comment, trackback, pingback, or a made up value like "registration".
119
+ # comment_author
120
+ # Submitted name with the comment
121
+ # comment_author_email
122
+ # Submitted email address
123
+ # comment_author_url
124
+ # Commenter URL.
125
+ # comment_content
126
+ # The content that was submitted.
127
+ # Other server enviroment variables
128
+ # In PHP there is an array of enviroment variables called $_SERVER which contains information about the web server itself as well as a key/value for every HTTP header sent with the request. This data is highly useful to Akismet as how the submited content interacts with the server can be very telling, so please include as much information as possible.
129
+ def check_comment(user_ip, user_agent, referrer, permalink, comment_type, comment_author, comment_author_email, comment_author_url, comment_content, other)
130
+ return callAkismet('comment-check', user_ip, user_agent, referrer, permalink, comment_type, comment_author, comment_author_email, comment_author_url, comment_content, other)
131
+ end
132
+
133
+ # This call is for submitting comments that weren't marked as spam but should have been. It takes identical arguments as comment check.
134
+ # The call parameters are the same as for the #commentCheck method.
135
+ def submitSpam(user_ip, user_agent, referrer, permalink, comment_type, comment_author, comment_author_email, comment_author_url, comment_content, other)
136
+ callAkismet('submit-spam', user_ip, user_agent, referrer, permalink, comment_type, comment_author, comment_author_email, comment_author_url, comment_content, other)
137
+ end
138
+
139
+ # This call is intended for the marking of false positives, things that were incorrectly marked as spam. It takes identical arguments as comment check and submit spam.
140
+ # The call parameters are the same as for the #commentCheck method.
141
+ def submitHam(user_ip, user_agent, referrer, permalink, comment_type, comment_author, comment_author_email, comment_author_url, comment_content, other)
142
+ callAkismet('submit-ham', user_ip, user_agent, referrer, permalink, comment_type, comment_author, comment_author_email, comment_author_url, comment_content, other)
143
+ end
144
+ end
145
+
146
+ end
@@ -8,7 +8,7 @@ require 'rbconfig.rb'
8
8
 
9
9
  include Config
10
10
 
11
- WIKI2GO_VERSION = '1.22.1'
11
+ WIKI2GO_VERSION = '1.24.0'
12
12
  gem "Wiki2Go","~>#{WIKI2GO_VERSION}"
13
13
 
14
14
  require 'Wiki2Go/Web.rb'
@@ -40,6 +40,7 @@ module Wiki2Go
40
40
  attr_accessor :type
41
41
  attr_reader :source_dir
42
42
  attr_accessor :subsite
43
+ attr_reader :cgi_options
43
44
 
44
45
  def initialize
45
46
  @user = WebUser.new(nil,nil)
@@ -58,7 +59,8 @@ module Wiki2Go
58
59
  configfile = File.join(@directory,'site','scripts','CgiOptions.rb')
59
60
  if File.exists?(configfile) then
60
61
  load configfile
61
- return CgiOptions.new
62
+ @cgi_options = CgiOptions.new
63
+ return @cgi_options
62
64
  end
63
65
  return nil
64
66
  end
@@ -205,6 +207,41 @@ module Wiki2Go
205
207
  end
206
208
  end
207
209
 
210
+ def Install.regenerate_wiki(args,&block)
211
+ opts = OptionParser.new
212
+
213
+ configuration = Configuration.new
214
+ opts.on("-s URL",'--server URL',String) { |val| configuration.server_at(val) }
215
+ opts.on("-p",'--port URL',"(default is port 80)",String) { |val| configuration.port = val }
216
+ opts.on("-u",'--user username',String) { |val| configuration.user.user = val }
217
+ opts.on("-g",'--group groupname',String) { |val| configuration.user.group = val }
218
+ opts.on("-w",'--web default_web',String) { |val| configuration.default_wiki = val }
219
+ opts.on("-d",'--directory dir',"default = .",String) { |val| configuration.directory = File.expand_path(val) }
220
+ opts.on_tail("-h", "--help", "Show this message") do
221
+ puts opts
222
+ exit
223
+ end
224
+
225
+ opts.parse(args)
226
+
227
+ configuration.read_existing_configuration
228
+
229
+ if configuration.type.nil? then
230
+ puts "Wiki type (public, private, readwrite) must be specified" if configuration.type.nil?
231
+ puts opts
232
+ else
233
+ yield "Regenerating Wiki2Go site in #{configuration.directory}" if block_given?
234
+
235
+ oldmask = File.umask(02)
236
+ cd(configuration.directory) {
237
+ do_regenerate(configuration)
238
+ }
239
+ set_owner(configuration.directory,configuration.user)
240
+ File.umask(oldmask)
241
+ yield "Updated." if block_given?
242
+ end
243
+ end
244
+
208
245
  def Install.make_wiki(args,&block)
209
246
  opts = OptionParser.new
210
247
 
@@ -293,6 +330,12 @@ module Wiki2Go
293
330
  make_config( config,'PrivateWikiConfig')
294
331
  end
295
332
 
333
+ def Install.do_regenerate(config)
334
+ wiki = Wiki2Go::Wiki.new(config.cgi_options)
335
+ web = Wiki2Go::Web.from_page_url("http://#{config.server}:#{config.port}/scripts/secure/view/#{config.default_wiki}/FrontPage",'view',config.cgi_options)
336
+ puts wiki.generate_html(web)
337
+ end
338
+
296
339
  def Install.install_scripts(config)
297
340
  mkdir_p(File.join('site','scripts','secure'),{ :mode => 0775})
298
341
  source = File.join(config.source_dir,'..','cgi')
@@ -361,7 +404,7 @@ module Wiki2Go
361
404
  end
362
405
 
363
406
  def Install.set_owner(dir,owner)
364
- if !owner.user.nil? then
407
+ if !owner.user.nil? && owner.user.length > 0 then
365
408
  info = Etc.getpwnam(owner.user)
366
409
  if !info.nil? then
367
410
  user_id = info.uid
@@ -460,6 +503,10 @@ class CgiOptions < Wiki2Go::#{baseconfig}
460
503
  @checksum_salt = '#{config.directory}'
461
504
  # Set to true to add users who save without checksum to the blacklist
462
505
  @blacklist_when_no_checksum = false
506
+
507
+ # Enable the Akismet (http://akismet.com/) spam engine
508
+ # Get a free API key and configure the key and your URL
509
+ # use_akismet(api_key,#{config.server})
463
510
  end
464
511
 
465
512
  end
@@ -70,8 +70,10 @@ module Wiki2Go
70
70
  result = @web.subsite.empty? ? '' : ('/' + @web.subsite)
71
71
  parameters.each do |name|
72
72
  if !name.nil? and !name.empty? then
73
- result += '/'
74
- result += name
73
+ name.split('/').each do |subname|
74
+ result += '/'
75
+ result += ERB::Util::url_encode(subname)
76
+ end
75
77
  end
76
78
  end
77
79
  result.squeeze('/')
@@ -148,7 +150,7 @@ module Wiki2Go
148
150
  end
149
151
  end
150
152
 
151
- # Return a link suitable for creating a new page with the confgured editor, if editing is allowed
153
+ # Return a link suitable for creating a new page with the confgured editor, if editing is allowed
152
154
  # Return the name of the page, otherwise
153
155
  def editor_link2(subwiki,page,name)
154
156
  if @editable then
@@ -350,16 +352,12 @@ module Wiki2Go
350
352
 
351
353
  end
352
354
 
353
- def escape_spaces(name)
354
- name.gsub(/ /,'%20')
355
- end
356
-
357
355
  # URL to a static resource (under the html subdirectory of the site)
358
356
  def resource_url(name)
359
357
  if @absolute_urls then
360
- @web.base_url.chop + make_url('html',@web.name,escape_spaces(name))
358
+ @web.base_url.chop + make_url('html',@web.name,name)
361
359
  else
362
- make_url('html',@web.name,escape_spaces(name))
360
+ make_url('html',@web.name,name)
363
361
  end
364
362
  end
365
363
 
@@ -41,6 +41,7 @@ module Wiki2Go
41
41
  # * OR the user is not on the blacklist and none of the URLs on the page are on the blacklist and no more than 5 urls added
42
42
  # * AND no hidden style in tags
43
43
  # * AND page not erased
44
+ # * AND Akismet (if configured) accepts the page
44
45
  def accept_page?(web,content)
45
46
 
46
47
  return true if web.secure?
@@ -75,7 +76,7 @@ module Wiki2Go
75
76
 
76
77
  current_page = storage.load_page(web.name,web.current_page)
77
78
  urls = @spamfilter.added_urls(current_page.content,content)
78
-
79
+
79
80
  if @spamfilter.edit_by_banned_user?(author) then
80
81
  @spamfilter.blacklist_urls(urls)
81
82
 
@@ -100,6 +101,16 @@ module Wiki2Go
100
101
 
101
102
  tarpit
102
103
  return false
104
+ elsif @spamfilter.stopped_by_spam_engine(web.url,content,author,web.alias) then
105
+ blacklist_user(author)
106
+ @spamfilter.blacklist_urls(urls)
107
+
108
+ errorlog("Edit by user #{author} of page '#{pagename}' caught by Akismet. Blacklisting #{urls.join(', ')}")
109
+ errorlog(content)
110
+
111
+ tarpit
112
+ return false
113
+
103
114
  else
104
115
  if urls.length > 0 then
105
116
  @spamfilter.greylist_urls(author,urls)
@@ -128,6 +139,9 @@ module Wiki2Go
128
139
  return redirect
129
140
  end
130
141
 
142
+ def use_akismet(api_key,blog)
143
+ @spamfilter.use_akismet(api_key,blog)
144
+ end
131
145
  end
132
146
  end
133
147
 
@@ -3,11 +3,16 @@ require 'Wiki2Go/UrlFinder'
3
3
  require "uri"
4
4
  require 'net/http'
5
5
 
6
+ require "Wiki2Go/Akismet"
7
+
6
8
  module Wiki2Go
7
9
  class SpamFilter
8
10
 
9
11
  def initialize(config)
10
12
  @config = config
13
+ @akismet = nil
14
+ @akismet_api_key = nil
15
+ @akismet_blog = nil
11
16
  end
12
17
 
13
18
  def edit_by_banned_user?(author)
@@ -110,8 +115,27 @@ module Wiki2Go
110
115
  content !~ /\S/
111
116
  end
112
117
 
118
+ def use_akismet(api_key,blog)
119
+ @akismet_api_key = api_key
120
+ @akismet_blog = blog
121
+ end
122
+
123
+ def stopped_by_spam_engine(url,content,user_ip,author_alias)
124
+ engine = akismet
125
+ return false if engine.nil?
126
+
127
+ return engine.check_comment(user_ip, "","", url, "wiki page", author_alias, "", "", content, {})
128
+ end
129
+
113
130
  private
114
131
 
132
+ def akismet
133
+ return nil if @akismet_api_key.nil?
134
+
135
+ @akismet ||= Wiki2Go::Akismet.new(@akismet_api_key,@akismet_blog)
136
+ @akismet.verify_API_key unless @akismet.verified_key?
137
+ return @akismet.verified_key? ? @akismet : nil
138
+ end
115
139
 
116
140
 
117
141
  end
@@ -49,15 +49,19 @@ module Wiki2Go
49
49
  return copy
50
50
  end
51
51
 
52
+ def url
53
+ File.join(base_url,@subsite,script_prefix,@verb + @script_extension,path)
54
+ end
55
+
52
56
  def user
53
57
  @request.nil? ? 'unknown' : @request.user
54
58
  end
55
59
 
56
60
  def secure?
57
61
  @request.nil? ? false : @request.authenticated?
58
- end
62
+ end
59
63
 
60
- alias :secure :secure?
64
+ alias :secure :secure?
61
65
 
62
66
  def alias=(name)
63
67
  @alias = name
@@ -161,8 +165,8 @@ module Wiki2Go
161
165
  end
162
166
  end
163
167
  if path =~ /\// then
164
- path =~ /^(.*)(\/+)([^\/]*)$/
165
- return $1,$3
168
+ path =~ /^(.*)(\/+)([^\/]*)$/
169
+ return $1,$3
166
170
  else
167
171
  return "",path
168
172
  end
@@ -34,13 +34,13 @@ module Wiki2Go
34
34
  end
35
35
 
36
36
  def versions(from,to)
37
- if to > 0 then
38
- @to = to
39
- @from = from
40
- else
41
- @from = -1
42
- @to = -1
43
- end
37
+ if to > 0 then
38
+ @to = to
39
+ @from = from
40
+ else
41
+ @from = -1
42
+ @to = -1
43
+ end
44
44
  end
45
45
  end
46
46
 
@@ -80,7 +80,7 @@ module Wiki2Go
80
80
  return template
81
81
  end
82
82
 
83
- def dump_page_in_template(template,page,from,to)
83
+ def dump_page_in_template(template,page,from,to)
84
84
  formatted_page = page.content
85
85
 
86
86
  template = splice_variable_values(template,page,formatted_page)
@@ -100,20 +100,20 @@ module Wiki2Go
100
100
 
101
101
  def generate_rss(template,changes)
102
102
 
103
- # RSS must contain absolute URLs because some feedreaders don't honor the relative
104
- # URLs to the content of the <link> tag
105
- old_absolute_urls = @absolute_urls
106
- @absolute_urls = true
103
+ # RSS must contain absolute URLs because some feedreaders don't honor the relative
104
+ # URLs to the content of the <link> tag
105
+ old_absolute_urls = @absolute_urls
106
+ @absolute_urls = true
107
107
 
108
- template_after_items = <<-END_OF_AFTER_ITEMS_XML
108
+ template_after_items = <<-END_OF_AFTER_ITEMS_XML
109
109
  </channel>
110
110
  </rss>
111
111
  END_OF_AFTER_ITEMS_XML
112
112
 
113
- items = ""
113
+ items = ""
114
114
 
115
- changes.each do |page|
116
- items = items + <<-END_OF_ITEMS
115
+ changes.each do |page|
116
+ items = items + <<-END_OF_ITEMS
117
117
  <item>
118
118
  <title>#{CGI::escapeHTML(page.name)}</title>
119
119
  <author>#{page.alias}</author>
@@ -122,22 +122,22 @@ module Wiki2Go
122
122
  <guid isPermaLink="true">#{absolute_url_of_topic(page.filename)}</guid>
123
123
  END_OF_ITEMS
124
124
 
125
- if !Page.is_dynamic?(page.filename) then
126
- items += "<description><![CDATA[#{format_page(page.content).strip}]]></description>\n"
127
- end
128
- items += "</item>\n"
129
-
125
+ if !Page.is_dynamic?(page.filename) then
126
+ items += "<description><![CDATA[#{format_page(page.content).strip}]]></description>\n"
130
127
  end
128
+ items += "</item>\n"
129
+
130
+ end
131
131
 
132
- template = template + items + template_after_items
132
+ template = template + items + template_after_items
133
133
 
134
- # We're using hard coded GMT, because %Z returns something strange
135
- time = Time.new.gmtime.strftime("%d %B %Y %H:%M GMT")
136
- template.gsub!(/\$DATE\$/, time)
137
- template = splice_web_values(template)
134
+ # We're using hard coded GMT, because %Z returns something strange
135
+ time = Time.new.gmtime.strftime("%d %B %Y %H:%M GMT")
136
+ template.gsub!(/\$DATE\$/, time)
137
+ template = splice_web_values(template)
138
138
 
139
- @absolute_urls = old_absolute_urls
140
- return template
139
+ @absolute_urls = old_absolute_urls
140
+ return template
141
141
  end
142
142
 
143
143
  def generate_rss_from_log(log)
@@ -166,8 +166,8 @@ END_OF_HEADER
166
166
  type = $1
167
167
  datetime = $2
168
168
  message = $3
169
- if type == 'E' then
170
- items = items + <<-END_OF_ITEMS
169
+ if type == 'E' then
170
+ items = items + <<-END_OF_ITEMS
171
171
  <item>
172
172
  <title>#{CGI::escapeHTML('errormessage')}</title>
173
173
  <link>#{File.join(@web.base_url,'scripts/secure/admin/show_log')}</link>
@@ -175,13 +175,13 @@ END_OF_HEADER
175
175
  <pubDate>#{parse_log_date(datetime).strftime("%d %B %Y %H:%M GMT")}</pubDate>
176
176
  <description><![CDATA[#{CGI::escapeHTML(message)}]]></description>
177
177
  </item>
178
- END_OF_ITEMS
179
- end
180
- end
178
+ END_OF_ITEMS
179
+ end
180
+ end
181
181
  end
182
182
 
183
- # <link>#{absolute_url_of_topic(page.filename)}</link>
184
- # <guid isPermaLink="true">#{@web.name}/#{page.filename}</guid>
183
+ # <link>#{absolute_url_of_topic(page.filename)}</link>
184
+ # <guid isPermaLink="true">#{@web.name}/#{page.filename}</guid>
185
185
 
186
186
  return header + items + template_after_items
187
187
 
@@ -21,4 +21,3 @@ require 'TestWiki2GoServlet'
21
21
  require 'TestSyntaxHighlighter'
22
22
  require 'TestHTMLFormatter'
23
23
  require 'test_firewall_blacklist.rb'
24
- #require 'TestInstall'
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/ruby
2
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
3
+
4
+ require 'test/unit'
5
+ require 'test/unit/ui/console/testrunner'
6
+
7
+ require 'test_akismet'
8
+ require 'TestSpamFilterWithAkismet'
9
+ require 'TestInstall.rb'
@@ -131,6 +131,26 @@ class TestInstall < Test::Unit::TestCase
131
131
  assert_wiki_structure_exists(wiki_dir,'Wiki2Go')
132
132
  end
133
133
 
134
+ def test_regeneration_of_static_html
135
+ wiki_dir = scratch_dir('regen')
136
+ args = ['-s', 'wiki2go.nayima.be' , '-w' , 'Wiki2Go' , '-t' , 'private', '-d' , wiki_dir]
137
+ Wiki2Go::Install.make_site(args)
138
+
139
+ File.open("#{wiki_dir}/texts/Wiki2Go/FrontPage.txt",File::CREAT|File::TRUNC|File::RDWR) do |file|
140
+ file.write "Regenerated file"
141
+ end
142
+
143
+ static_frontpage = "#{wiki_dir}/site/Wiki2Go/FrontPage.html"
144
+ assert File.exists?(static_frontpage)
145
+ rm static_frontpage
146
+ assert !File.exists?(static_frontpage)
147
+
148
+ args = ['-s', 'wiki2go.nayima.be' , '-w' , 'Wiki2Go' , '-d' , wiki_dir]
149
+ Wiki2Go::Install.regenerate_wiki(args)
150
+
151
+ assert File.exists?(static_frontpage)
152
+ end
153
+
134
154
  private
135
155
 
136
156
  def scratch_dir(type)
@@ -158,8 +178,8 @@ class TestInstall < Test::Unit::TestCase
158
178
  end
159
179
 
160
180
  def assert_exists(wiki_dir,*dirs)
161
- dir = File.join(wiki_dir,dirs)
162
- assert("#{dir} must exist",File.exists?(dir))
181
+ dir = File.join(wiki_dir,dirs)
182
+ assert("#{dir} must exist",File.exists?(dir))
163
183
  end
164
184
  end
165
185
 
@@ -113,7 +113,7 @@ class TestLineFormatter < Test::Unit::TestCase
113
113
 
114
114
  end
115
115
 
116
- def test_Markup
116
+ def test_markup
117
117
  formatter = makeFormatter
118
118
 
119
119
  formatted = formatter.format_line(" *bold* *nothing ")
@@ -181,6 +181,13 @@ class TestLineFormatter < Test::Unit::TestCase
181
181
  assert_equal '/view/Xpday/Registration.rbl',formatted
182
182
  end
183
183
 
184
+ def test_bug_spaces_are_not_escaped
185
+ formatter = makePublicFormatter
186
+
187
+ formatted = formatter.format_line("{Toyota Way}")
188
+ assert_equal "<a href=\"/Xpday/Toyota%20Way.html\">Toyota Way</a>",formatted
189
+ end
190
+
184
191
  def test_links_with_redirect
185
192
  formatter = makeFormatter
186
193
 
@@ -405,7 +412,7 @@ class TestLineFormatter < Test::Unit::TestCase
405
412
 
406
413
  end
407
414
 
408
- def test_PageExistence
415
+ def test_page_existence
409
416
  storage = LineMockStorage.new
410
417
  formatter = makeFormatterWithStorage(storage)
411
418
 
@@ -419,7 +426,7 @@ class TestLineFormatter < Test::Unit::TestCase
419
426
 
420
427
  end
421
428
 
422
- def test_Tables
429
+ def test_tables
423
430
  formatter = makeFormatter
424
431
 
425
432
  formatted = formatter.format_line("|-------------| ")
@@ -433,7 +440,7 @@ class TestLineFormatter < Test::Unit::TestCase
433
440
  assert_equal("| kol 1 | kol 2 | ",formatted)
434
441
  end
435
442
 
436
- def test_Tables_WrongSyntax
443
+ def test_tables_wrong_syntax
437
444
  formatter = makeFormatter
438
445
 
439
446
  formatted = formatter.format_line("|-------------| ")
@@ -442,21 +449,21 @@ class TestLineFormatter < Test::Unit::TestCase
442
449
  assert_equal("<tr><td> kol 1 </td><td> kol 2 ",formatted)
443
450
  end
444
451
 
445
- def test_Tables_SpecifyClass
452
+ def test_tables_specify_class
446
453
  formatter = makeFormatter
447
454
 
448
455
  formatted = formatter.format_line("|(test)-------------| ")
449
456
  assert_equal('<table class="test" > ',formatted)
450
457
  end
451
458
 
452
- def test_Tables_SpecifyEmptyClass
459
+ def test_tables_specify_empty_class
453
460
  formatter = makeFormatter
454
461
 
455
462
  formatted = formatter.format_line("|()-------------| ")
456
463
  assert_equal('|()-------------| ',formatted)
457
464
  end
458
465
 
459
- def test_BulletLists
466
+ def test_bullet_lists
460
467
  formatter = makeFormatter
461
468
 
462
469
  formatted = formatter.format_line(" * bullet 1")
@@ -48,6 +48,8 @@ class SpamMockConfig < Wiki2Go::Config
48
48
  end
49
49
 
50
50
  class TestSpamFilter < Test::Unit::TestCase
51
+
52
+
51
53
 
52
54
  def setup
53
55
  @config = SpamMockConfig.new
@@ -158,5 +160,14 @@ EMPTY_URLS
158
160
 
159
161
  assert !@spam_filter.cleared_page?(" \r\n a word \t \r \n")
160
162
  end
163
+
164
+ def test_spamfilter_accepts_page_if_akismet_not_configured
165
+ assert !@spam_filter.stopped_by_spam_engine('http://wiki.xp.be/SandBox.html',spammy_message,'59.92.162.46','59.92.162.46')
166
+ end
161
167
 
168
+ def spammy_message
169
+ return <<SPAM
170
+ Hi, good site, <a href=" http://www.videocodezone.com/users/nexiumdrg ">cheap nexium order online</a>, >:OO, <a href=" http://www.videocodezone.com/users/nexiumxtv ">buy nexium from canada</a>, :OO, <a href=" http://www.videocodezone.com/users/nexiumtej ">buy b nexium b</a>, vjy,
171
+ SPAM
172
+ end
162
173
  end
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/ruby
2
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
3
+
4
+ require 'test/unit'
5
+
6
+ require 'Wiki2Go/SpamFilter'
7
+ require 'Wiki2Go/BlackList'
8
+ require 'Wiki2Go/GreyList'
9
+ require 'Wiki2Go/Wiki2GoConfig'
10
+
11
+ class SpamMockStorage
12
+
13
+ def initialize
14
+ @blacklists = Hash.new
15
+ end
16
+
17
+ def load_page(subwiki,name)
18
+ if (subwiki == 'xpbe' && name == 'FrontPage') then
19
+ lines = Array.new(1)
20
+ lines[0] = ""
21
+ return Wiki2Go::Page.make_page(name,lines,Time.now)
22
+ else
23
+ return nil
24
+ end
25
+ end
26
+
27
+ def load_blacklist(type,normalize_urls=false)
28
+ @blacklists[type] = Wiki2Go::BlackList.new(type,[]) if !@blacklists.has_key?(type)
29
+ @blacklists[type]
30
+ end
31
+
32
+ def save_list(list)
33
+ # puts list.inspect
34
+ end
35
+
36
+ def load_greylist
37
+ @greylist ||= Wiki2Go::GreyList.new('greylist',[])
38
+ @greylist
39
+ end
40
+
41
+ end
42
+
43
+ class SpamMockConfig < Wiki2Go::Config
44
+
45
+ def make_storage
46
+ SpamMockStorage.new
47
+ end
48
+ end
49
+
50
+ class TestSpamFilter < Test::Unit::TestCase
51
+
52
+
53
+
54
+ def setup
55
+ @config = SpamMockConfig.new
56
+ @spam_filter = Wiki2Go::SpamFilter.new(@config)
57
+ end
58
+
59
+ def test_spamfilter_stops_page_if_akismet_configured
60
+
61
+ @spam_filter.use_akismet("b463507ab767","http://wiki.xp.be")
62
+ assert @spam_filter.stopped_by_spam_engine('http://wiki.xp.be/SandBox.html',spammy_message,'59.92.162.46','59.92.162.46')
63
+ end
64
+
65
+ def spammy_message
66
+ return <<SPAM
67
+ Hi, good site, <a href=" http://www.videocodezone.com/users/nexiumdrg ">cheap nexium order online</a>, >:OO, <a href=" http://www.videocodezone.com/users/nexiumxtv ">buy nexium from canada</a>, :OO, <a href=" http://www.videocodezone.com/users/nexiumtej ">buy b nexium b</a>, vjy,
68
+ SPAM
69
+ end
70
+ end
@@ -188,6 +188,15 @@ class TestWeb < Test::Unit::TestCase
188
188
  assert_equal("http://wiki.xp.be/",web.base_url)
189
189
  assert_equal('sub_site',web.subsite)
190
190
  end
191
+
192
+ def test_reconsitute_url
193
+ env = {"HTTP_HOST"=>"wiki.xp.be", "HTTP_REFERER"=>"http://wiki.xp.be/scripts/view/Xpbe/PairProgrammingParty2004September14", "HTTP_USER_AGENT"=>"Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0", "PATH"=>"/sbin:/bin:/usr/sbin:/usr/bin:/usr/bin/X11:/usr/local/sbin:/usr/local/bin", "REMOTE_ADDR"=>"80.200.195.232", "REMOTE_PORT"=>"62539", "SCRIPT_FILENAME"=>"/home/pvc/sites/xpbe/wiki2/site//view", "SERVER_ADDR"=>"212.13.211.135", "SERVER_ADMIN"=>"webmaster@nayima.vm.bytemark.co.uk", "SERVER_NAME"=>"wiki.xp.be", "SERVER_PORT"=>"80", "SERVER_SIGNATURE"=>"<ADDRESS>Apache/1.3.26 Server at wiki.xp.be Port 80</ADDRESS>\n", "SERVER_SOFTWARE"=>"Apache/1.3.26 (Unix) Debian GNU/Linux PHP/4.1.2", "GATEWAY_INTERFACE"=>"CGI/1.1", "SERVER_PROTOCOL"=>"HTTP/1.1", "REQUEST_METHOD"=>"GET", "QUERY_STRING"=>"", "REQUEST_URI"=>"sub_site/scripts/view/Xpbe/PairProgrammingParties", "SCRIPT_NAME"=>"sub_site/scripts/view", "PATH_INFO"=>"/Xpbe/PairProgramming/Parties"}
194
+
195
+ @config.multi_wiki = true
196
+ @config.subsite = 'sub_site'
197
+ web = Wiki2Go::Web.from_request(Web2Go::MockRequest.new('http://wiki.xp.be/sub_site/scripts/view/Xpbe/PairProgramming/Parties',env),@config)
198
+ assert_equal 'http://wiki.xp.be/sub_site/scripts/view/Xpbe/PairProgramming/Parties',web.url
199
+ end
191
200
 
192
201
  end
193
202
 
@@ -0,0 +1,101 @@
1
+ #
2
+ # To change this template, choose Tools | Templates
3
+ # and open the template in the editor.
4
+
5
+
6
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
7
+
8
+ require 'test/unit'
9
+ require 'Wiki2Go/Akismet'
10
+
11
+ class TestAkismet < Test::Unit::TestCase
12
+ def test_verify_my_key
13
+ akismet = Wiki2Go::Akismet.new("b463507ab767","http://wiki.xp.be")
14
+ assert_not_nil akismet
15
+ assert akismet.verify_API_key
16
+
17
+ assert akismet.verified_key?
18
+
19
+ spam_message = <<SPAM
20
+ Hi, good site, <a href=" http://www.videocodezone.com/users/nexiumdrg ">cheap nexium order online</a>, >:OO, <a href=" http://www.videocodezone.com/users/nexiumxtv ">buy nexium from canada</a>, :OO, <a href=" http://www.videocodezone.com/users/nexiumtej ">buy b nexium b</a>, vjy,
21
+ SPAM
22
+
23
+ result = akismet.check_comment('59.92.162.46',"","",'http://wiki.xp.be/Xpbe/SandBox.html','comment','59.92.162.46','','',spam_message,{})
24
+ assert result,"Message recognized as spam"
25
+
26
+ good_message = <<GOOD
27
+ <!--GRAPH:p.png
28
+
29
+ digraph g {
30
+ hello->world
31
+ }
32
+ -->
33
+
34
+ <b>bold</b> - <i>italics</i>
35
+
36
+ NieuwePagina
37
+
38
+ wiki test
39
+
40
+ a link to the SandBox page
41
+
42
+ * a list
43
+ * a list
44
+ * a sublist
45
+ * a list
46
+
47
+ 9 a numbered list
48
+ 9 a numbered list fdgsdfs
49
+
50
+
51
+ ik kan alles schrijven wat ik wil
52
+ Format *bold* or _italic_
53
+
54
+ The idea is great but if you think AboutThis then you will see that it is better.
55
+
56
+ I want to TryIt and I want to TrySomething too!
57
+
58
+ trial and error and error and trial
59
+
60
+ ---
61
+ <br>
62
+ test test test
63
+ urltest http://www.cnn.com http://www.microsoft.com http://www.slashdot.org <a href="http://www.netscape.com/">netscape</a>
64
+
65
+ ---
66
+ Some examples of external links
67
+
68
+ %wiki:ExtremeProgramming% links to the ExtremeProgramming discussion on the C2 wiki
69
+
70
+ %xpnl:FrontPage% links to the frontpage of the Dutch XP group
71
+
72
+ %book:BookOfChanges% links to the recent changes on LaurentBossavit's BookShelved wiki about books<br>
73
+
74
+ ik ben nu aan het typen
75
+
76
+ CategoryCategory CategoryHomepage
77
+
78
+
79
+ <pre>
80
+ # some programming code
81
+ a=1
82
+ </pre>
83
+
84
+ <!--Syntax:ruby
85
+ # some ruby code, syntax colored
86
+ class Foo
87
+ def bar
88
+ "It works"
89
+ end
90
+ end
91
+ a=1
92
+ -->
93
+
94
+ *eins*
95
+ * zwei
96
+ GOOD
97
+ result = akismet.check_comment('87.202.103.174',"","",'http://wiki.xp.be/Xpbe/SandBox.html','comment','pascal','','',good_message,{})
98
+ assert !result,"Message recognized as ham"
99
+
100
+ end
101
+ end
@@ -654,3 +654,23 @@ I, [2008-08-23 19:35:13#1908] INFO -- : >> perform_view(Bugs,FrontPage) {}
654
654
  I, [2008-08-23 19:35:14#1908] INFO -- : << perform_view 0.578 sec elapsed {}
655
655
  I, [2008-08-23 21:30:08#756] INFO -- : >> perform_view(Bugs,FrontPage) {}
656
656
  I, [2008-08-23 21:30:08#756] INFO -- : << perform_view 0.578 sec elapsed {}
657
+ I, [2008-12-29 12:52:03#3988] INFO -- : >> perform_view(Bugs,FrontPage) {}
658
+ I, [2008-12-29 12:52:03#3988] INFO -- : << perform_view 0.453 sec elapsed {}
659
+ I, [2008-12-29 12:55:31#3536] INFO -- : >> perform_view(Bugs,FrontPage) {}
660
+ I, [2008-12-29 12:55:32#3536] INFO -- : << perform_view 0.438 sec elapsed {}
661
+ I, [2008-12-29 13:40:31#2248] INFO -- : >> perform_view(Bugs,FrontPage) {}
662
+ I, [2008-12-29 13:40:31#2248] INFO -- : << perform_view 0.594 sec elapsed {}
663
+ I, [2008-12-30 13:46:31#1492] INFO -- : >> perform_view(Bugs,FrontPage) {}
664
+ I, [2008-12-30 13:46:32#1492] INFO -- : << perform_view 0.453 sec elapsed {}
665
+ I, [2008-12-30 13:46:55#1332] INFO -- : >> perform_view(Bugs,FrontPage) {}
666
+ I, [2008-12-30 13:46:56#1332] INFO -- : << perform_view 0.453 sec elapsed {}
667
+ I, [2008-12-30 19:17:16#1828] INFO -- : >> perform_view(Bugs,FrontPage) {}
668
+ I, [2008-12-30 19:17:17#1828] INFO -- : << perform_view 0.594 sec elapsed {}
669
+ I, [2009-01-25 15:12:11#3528] INFO -- : >> perform_view(Bugs,FrontPage) {}
670
+ I, [2009-01-25 15:12:12#3528] INFO -- : << perform_view 0.468 sec elapsed {}
671
+ I, [2009-01-25 15:21:41#3016] INFO -- : >> perform_view(Bugs,FrontPage) {}
672
+ I, [2009-01-25 15:21:41#3016] INFO -- : << perform_view 0.453 sec elapsed {}
673
+ I, [2009-01-25 15:41:46#1492] INFO -- : >> perform_view(Bugs,FrontPage) {}
674
+ I, [2009-01-25 15:41:47#1492] INFO -- : << perform_view 0.609 sec elapsed {}
675
+ I, [2009-02-23 21:57:42#280] INFO -- : >> perform_view(Bugs,FrontPage) {}
676
+ I, [2009-02-23 21:57:43#280] INFO -- : << perform_view 0.531 sec elapsed {}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Wiki2Go
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.22.1
4
+ version: 1.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pascal Van Cauwenberghe
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-31 00:00:00 +02:00
12
+ date: 2009-04-11 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: diff-lcs
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -30,6 +31,7 @@ executables:
30
31
  - Wiki2Go_update_site.rb
31
32
  - Wiki2Go_make_cvs_repository.rb
32
33
  - Wiki2Go_firewall_blacklist.rb
34
+ - Wiki2Go_regenerate.rb
33
35
  extensions: []
34
36
 
35
37
  extra_rdoc_files: []
@@ -46,6 +48,7 @@ files:
46
48
  - lib/Web2Go/WebrickRequest.rb
47
49
  - lib/Web2Go/WebrickResponse.rb
48
50
  - lib/Wiki2Go
51
+ - lib/Wiki2Go/Akismet.rb
49
52
  - lib/Wiki2Go/BlackList.rb
50
53
  - lib/Wiki2Go/cgi
51
54
  - lib/Wiki2Go/cgi/changes.rb
@@ -142,9 +145,11 @@ files:
142
145
  - bin/Wiki2Go_make_cvs_repository.rb
143
146
  - bin/Wiki2Go_make_site.rb
144
147
  - bin/Wiki2Go_make_wiki.rb
148
+ - bin/Wiki2Go_regenerate.rb
145
149
  - bin/Wiki2Go_update_site.rb
146
150
  - test/All.rb
147
151
  - test/checksite.rb
152
+ - test/Slow.rb
148
153
  - test/TestBlackList.rb
149
154
  - test/TestConfig.rb
150
155
  - test/testdata
@@ -221,6 +226,7 @@ files:
221
226
  - test/TestRSS.rb
222
227
  - test/TestServer.rb
223
228
  - test/TestSpamFilter.rb
229
+ - test/TestSpamFilterWithAkismet.rb
224
230
  - test/TestStorage.rb
225
231
  - test/TestSyntaxHighlighter.rb
226
232
  - test/TestUnitTestFiles.rb
@@ -229,6 +235,7 @@ files:
229
235
  - test/TestWeb2Go.rb
230
236
  - test/TestWiki2Go.rb
231
237
  - test/TestWiki2GoServlet.rb
238
+ - test/test_akismet.rb
232
239
  - test/test_firewall_blacklist.rb
233
240
  - test/test_page.rb
234
241
  - test/UnitTestFiles.rb
@@ -255,7 +262,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
255
262
  requirements: []
256
263
 
257
264
  rubyforge_project: wiki2go
258
- rubygems_version: 1.1.0
265
+ rubygems_version: 1.3.1
259
266
  signing_key:
260
267
  specification_version: 2
261
268
  summary: Wiki2Go is a Ruby Wiki