Wiki2Go 1.14.4 → 1.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/bin/Wiki2Go_make_repository.rb +10 -0
  2. data/bin/Wiki2Go_make_site.rb +1 -1
  3. data/lib/Web2Go/ERB_Interpreter.rb +6 -1
  4. data/lib/Wiki2Go/FileStorage.rb +28 -12
  5. data/lib/Wiki2Go/Install/make_repository.rb +140 -0
  6. data/lib/Wiki2Go/Install/make_site.rb +98 -16
  7. data/lib/Wiki2Go/Install/site/html/admin.css +197 -101
  8. data/lib/Wiki2Go/Install/site/html/rssLogo.png +0 -0
  9. data/lib/Wiki2Go/Install/site/html/valid-html401.png +0 -0
  10. data/lib/Wiki2Go/Install/templates/admin.htm +51 -47
  11. data/lib/Wiki2Go/Install/templates/admin_pages/update_blacklist.txt +17 -0
  12. data/lib/Wiki2Go/Install/templates/edit.htm +9 -28
  13. data/lib/Wiki2Go/Install/templates/full_footer.htm +35 -0
  14. data/lib/Wiki2Go/Install/templates/header.htm +7 -0
  15. data/lib/Wiki2Go/Install/templates/pagelist.htm +2 -24
  16. data/lib/Wiki2Go/Install/templates/simple_footer.htm +17 -0
  17. data/lib/Wiki2Go/Install/templates/versionlist.htm +2 -24
  18. data/lib/Wiki2Go/Install/templates/view.htm +2 -42
  19. data/lib/Wiki2Go/Install/wiki/style.css +65 -67
  20. data/lib/Wiki2Go/Page.rb +14 -2
  21. data/lib/Wiki2Go/PrivateWikiConfig.rb +34 -19
  22. data/lib/Wiki2Go/PublicWikiConfig.rb +59 -41
  23. data/lib/Wiki2Go/ReadWriteWikiConfig.rb +24 -13
  24. data/lib/Wiki2Go/Server.rb +19 -18
  25. data/lib/Wiki2Go/SpamFilter.rb +31 -18
  26. data/lib/Wiki2Go/Web.rb +31 -17
  27. data/lib/Wiki2Go/Wiki2Go.rb +59 -15
  28. data/lib/Wiki2Go/Wiki2GoConfig.rb +10 -4
  29. data/lib/Wiki2Go/Wiki2GoServlet.rb +18 -4
  30. data/lib/Wiki2Go/WikiFormatter.rb +82 -26
  31. metadata +13 -4
  32. data/lib/Wiki2Go/cgi/display.rb +0 -20
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require_gem "Wiki2Go"
5
+
6
+ require 'fileutils'
7
+ require 'Wiki2Go/Install/make_repository'
8
+
9
+ Wiki2Go::RepositoryMaker::create(ARGV)
10
+
@@ -1,4 +1,4 @@
1
- #!/usr/local/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  require 'rubygems'
4
4
  require_gem "Wiki2Go"
@@ -26,7 +26,12 @@ module Web2Go
26
26
 
27
27
 
28
28
  # Execute an ERB script and return the resulting string
29
- def execute(script,params=nil)
29
+ def execute(script,safe_mode,params=nil)
30
+
31
+
32
+ # if safe_mode > 0 then
33
+ # script = "<% $SAFE = #{safe_mode};%>" + script
34
+ # end
30
35
 
31
36
  parser = ERB.new(script)
32
37
 
@@ -14,6 +14,7 @@ module Wiki2Go
14
14
  def initialize(dynamic_files,static_files)
15
15
  @path = dynamic_files
16
16
  @html = static_files
17
+ @cached_templates = Hash.new
17
18
  end
18
19
 
19
20
  def exists?(path)
@@ -26,7 +27,7 @@ module Wiki2Go
26
27
  lines = Array.new(1)
27
28
  lines[0] = ""
28
29
  modified_time = Time.now
29
- if exists(File.join(subwiki,name)) then
30
+ if exists?(File.join(subwiki,name)) then
30
31
  path = text_filename(subwiki,name,"txt")
31
32
  File.open(path) do |f|
32
33
  lines = f.readlines
@@ -71,10 +72,16 @@ module Wiki2Go
71
72
 
72
73
  def load_template(subwiki,name)
73
74
  path = template_filename(subwiki,name)
74
- template = ""
75
- File.open(path) do |f|
76
- template = f.gets(nil)
75
+ template = @cached_templates.fetch(path,nil)
76
+ if template.nil? then
77
+ template = ""
78
+ File.open(path) do |f|
79
+ template = f.gets(nil)
80
+ end
81
+ template.gsub!(/\<!--\s*include=(\S*)\s*--\>/i) { load_template(subwiki,$1).rstrip }
82
+ # @cached_templates[path] = template
77
83
  end
84
+ template
78
85
  end
79
86
 
80
87
  def store_web_file(subwiki,page,content)
@@ -87,7 +94,7 @@ module Wiki2Go
87
94
 
88
95
  def search(subwiki,phrase)
89
96
  pages = Array.new
90
- to_search_for = Regexp.new(phrase)
97
+ to_search_for = Regexp.new(phrase,Regexp::IGNORECASE)
91
98
  topics = all_pages_in(subwiki)
92
99
  topics.each do |topic|
93
100
  page = load_page(subwiki,topic)
@@ -98,14 +105,16 @@ module Wiki2Go
98
105
  end
99
106
  end
100
107
  end
108
+ pages.sort! { |a,b| b.lastmodified <=> a.lastmodified }
101
109
  return pages
102
110
  end
103
111
 
104
112
  def all_pages_in(subwiki)
105
113
  textdir = text_directory(subwiki)
106
114
  pattern = File.join(textdir,"**/*.txt")
115
+ files = Dir[pattern]
107
116
  dirlen = pattern.length - 8
108
- files = Dir[pattern].sort {|a,b| File.mtime(b) <=> File.mtime(a) }
117
+
109
118
  files = files.collect {|file| file[dirlen..-5] }
110
119
  return files
111
120
  end
@@ -120,14 +129,13 @@ module Wiki2Go
120
129
  dirs = dirs.collect { |name| File.basename(name) }
121
130
  end
122
131
 
123
- def read_changes_in(subwiki,max_number,with_body)
132
+ def read_changes_in(subwiki,max_number)
124
133
  files = all_pages_in(subwiki)
125
134
  nbfiles = (max_number < files.length ? max_number : files.length)
126
- changed_pages = Array.new
127
- for i in 0..nbfiles-1
128
- changed_pages << load_page(subwiki,files[i])
129
- end
130
- return changed_pages
135
+
136
+ changed_pages = files.collect { |file| load_page(subwiki,file) }
137
+ changed_pages.sort! { |a,b| b.lastmodified <=> a.lastmodified }
138
+ return changed_pages[0..nbfiles-1]
131
139
  end
132
140
 
133
141
  def all_versions_of(subwiki,topic)
@@ -194,6 +202,14 @@ module Wiki2Go
194
202
  end
195
203
  end
196
204
 
205
+ def update_chongqed_spamlist(content)
206
+ filename = config_filename('chonqed_blacklist','txt')
207
+ ensure_directory_exists(filename)
208
+ File.open(filename,File::CREAT|File::TRUNC|File::RDWR) do |f|
209
+ f.puts content
210
+ end
211
+ end
212
+
197
213
  private
198
214
 
199
215
  def add_new_version_to(versions,topic,lines,modified_time)
@@ -0,0 +1,140 @@
1
+ require 'tmpdir'
2
+ require 'fileutils'
3
+ require 'optparse'
4
+ require 'etc'
5
+
6
+ require 'rubygems'
7
+ require_gem 'rscm'
8
+
9
+ module Wiki2Go
10
+ class RepositoryMaker
11
+
12
+ def RepositoryMaker.create(args)
13
+ opts = OptionParser.new
14
+
15
+ directory = ''
16
+ user = ''
17
+ group = ''
18
+ opts.on("-d",'--directory dir',String) { |val| directory = File.expand_path(val) }
19
+ opts.on("-u",'--user username',String) { |val| user = val }
20
+ opts.on("-g",'--group groupname',String) { |val| group = val }
21
+ opts.on_tail("-h", "--help", "Show this message") do
22
+ puts opts
23
+ exit
24
+ end
25
+ opts.parse(args)
26
+
27
+ puts "Directory = #{directory}"
28
+ if directory.empty? then
29
+ puts opts
30
+ else
31
+ puts "Creating CVS in directory #{directory}"
32
+ cvs = RepositoryMaker.new(directory)
33
+ cvs.make_empty_repository(user,group)
34
+ cvs.update_configuration
35
+ end
36
+ end
37
+
38
+ def initialize(dir)
39
+ @dir = dir
40
+ @repository = RSCM::Cvs.new(@dir)
41
+ end
42
+
43
+ def make_empty_repository(user,group)
44
+ FileUtils::mkdir_p @dir
45
+ FileUtils::chmod 02775,@dir
46
+
47
+ lockdir = File.join(@dir,'locks')
48
+ FileUtils::mkdir_p lockdir
49
+ FileUtils::chmod 02775,lockdir
50
+
51
+ @repository.create
52
+ set_owner(@dir,user,group)
53
+
54
+ end
55
+
56
+ def update_configuration
57
+ checkout_to = File.join(Dir.tmpdir,'cvs_config')
58
+ FileUtils::rm_r checkout_to if File.exists?(checkout_to)
59
+ cvsroot = RSCM::Cvs.new(@dir,'CVSROOT')
60
+ cvsroot.checkout(checkout_to)
61
+
62
+ update_cvswrappers(checkout_to)
63
+ update_config(checkout_to)
64
+
65
+ cvsroot.commit(checkout_to,'update cvswrappers for binary files')
66
+ FileUtils::rm_r(checkout_to)
67
+ end
68
+
69
+ private
70
+
71
+ def update_cvswrappers(dir)
72
+ File.open(File.join(dir,'cvswrappers'),File::APPEND|File::WRONLY) do |file|
73
+ file.write cvswrappers_content
74
+ end
75
+ end
76
+
77
+ def update_config(dir)
78
+ config_file = File.join(dir,'config')
79
+ lock_directory = File.join(@dir,'locks')
80
+ update_file(config_file,{/LockDir=/ => "LockDir=#{lock_directory}\n" ,
81
+ /LogHistory=/ => "LogHistory=TMAR\n" ,
82
+ /LockServer=/ => "LockServer=none\n" })
83
+ end
84
+
85
+ def update_file(name,substitutions)
86
+ lines = []
87
+ File.open(name,File::RDONLY) do |file|
88
+ lines = file.readlines
89
+ end
90
+
91
+ lines = lines.collect { |line| substitute(line,substitutions) }
92
+
93
+ File.open(name,File::WRONLY|File::TRUNC) do |file|
94
+ file.write lines
95
+ end
96
+ end
97
+
98
+ def substitute(line,substitutions)
99
+ substitutions.each do |key,replacement|
100
+ if key.match(line) then
101
+ return replacement
102
+ end
103
+ end
104
+ line
105
+ end
106
+
107
+ def cvswrappers_content
108
+ return <<-END_CVS_WRAPPERS
109
+ *.gif -k 'b'
110
+ *.jpg -k 'b'
111
+ *.jpeg -k 'b'
112
+ *.png -k 'b'
113
+
114
+ *.doc -k 'b'
115
+ *.pdf -k 'b'
116
+ END_CVS_WRAPPERS
117
+ end
118
+
119
+ def set_owner(dir,username,groupname)
120
+ info = Etc.getpwnam(username)
121
+ if !info.nil? then
122
+ user_id = info.uid
123
+ group_id = info.gid
124
+ if !groupname.nil? then
125
+ group_id = Etc.getgrnam(groupname).gid
126
+ end
127
+ File.chown(user_id,group_id,dir)
128
+ Dir.glob(File.join(dir,'**/*')).each do |file|
129
+ if file[0] != '.' then
130
+ mode = File.stat(file).mode | 0020
131
+ File.chmod(mode,file)
132
+ File.chown(user_id,group_id,file)
133
+ end
134
+ end
135
+ end
136
+ end
137
+
138
+ end
139
+
140
+ end
@@ -3,9 +3,10 @@
3
3
  require 'etc'
4
4
  require 'fileutils'
5
5
  require 'optparse'
6
+ require "uri"
6
7
 
7
8
  require 'rubygems'
8
- WIKI2GO_VERSION = '1.14.0'
9
+ WIKI2GO_VERSION = '1.15.0'
9
10
  require_gem "Wiki2Go","~>#{WIKI2GO_VERSION}"
10
11
 
11
12
  require 'Wiki2Go/PublicWikiConfig'
@@ -33,6 +34,7 @@ module Wiki2Go
33
34
  attr_accessor :directory
34
35
  attr_accessor :type
35
36
  attr_reader :source_dir
37
+ attr_accessor :subsite
36
38
 
37
39
  def initialize
38
40
  @user = WebUser.new('www-data',nil)
@@ -42,6 +44,7 @@ module Wiki2Go
42
44
  @directory = Dir.getwd
43
45
  @type = ''
44
46
  @source_dir = File.expand_path(File.dirname(__FILE__))
47
+ @subsite = ''
45
48
  end
46
49
 
47
50
  def dotted_port
@@ -59,6 +62,17 @@ module Wiki2Go
59
62
  server + dotted_port
60
63
  end
61
64
  end
65
+
66
+ def server_at(url)
67
+ uri = URI::parse(url)
68
+ if uri.scheme.nil? then
69
+ @server = url
70
+ else
71
+ @server = uri.host
72
+ @subsite = uri.path
73
+ @port = uri.port.to_s
74
+ end
75
+ end
62
76
  end
63
77
 
64
78
  module Install
@@ -68,7 +82,7 @@ module Wiki2Go
68
82
 
69
83
  configuration = Configuration.new
70
84
 
71
- opts.on("-s URL",'--server URL',String) { |val| configuration.server = val }
85
+ opts.on("-s URL",'--server URL',String) { |val| configuration.server_at(val) }
72
86
  opts.on("-p",'--port URL',"(default is port 80)",String) { |val| configuration.port = val }
73
87
  opts.on("-u",'--user username',String) { |val| configuration.user.user = val }
74
88
  opts.on("-g",'--group groupname',String) { |val| configuration.user.group = val }
@@ -307,7 +321,7 @@ require "Wiki2Go/#{baseconfig}"
307
321
  # Uncomment if you want to add 'dot' graphics to your page (see http://www.graphviz.org)
308
322
  # require 'Wiki2Go/DotGraphics'
309
323
 
310
- class CgiOptions < #{baseconfig}
324
+ class CgiOptions < Wiki2Go::#{baseconfig}
311
325
 
312
326
  def initialize
313
327
  super('#{config.directory}')
@@ -316,6 +330,7 @@ class CgiOptions < #{baseconfig}
316
330
  @debug = true
317
331
  # Choose whether to have a single wiki or several subwikis
318
332
  @multi_wiki = #{ config.default_wiki.empty? ? 'false' : 'true' }
333
+
319
334
  # Email of administrator of the site. Will be obfuscated on the page.
320
335
  @site_admin = 'wiki2go@nayima.be'
321
336
 
@@ -324,6 +339,16 @@ class CgiOptions < #{baseconfig}
324
339
  # System group who has access to the files
325
340
  @group = '#{config.user.group}'
326
341
 
342
+ # Set your Amazon affiliate ID for ISBN links
343
+ @amazon_affiliate = 'agilesystems-21'
344
+
345
+ # Set to true if you want to allow the execution of Ruby code inside pages
346
+ # SECURITY WARNING: this code can do absolutely anything, only allow for trusted users
347
+ @allow_dynamic_pages = false
348
+
349
+ # The base path of the wiki if it is a subsite of a larger site
350
+ @subsite = '#{config.subsite}'
351
+
327
352
  # Uncomment if you want to add 'dot' graphics to your page (see http://www.graphviz.org)
328
353
  # The path must point to the 'dot' exexcutable
329
354
  # add_processor('GRAPH',Wiki2Go::DotGraphics.new('/usr/bin/'))
@@ -339,7 +364,10 @@ TEMPLATE_END
339
364
  end
340
365
  end
341
366
 
342
- logfile = File.join(config.directory,'wiki.log')
367
+ logdir = File.join(config.directory,'logs')
368
+ mkdir_p(logdir,{ :mode => 0775}) unless File.exists?(logdir)
369
+
370
+ logfile = File.join(logdir,'wiki.log')
343
371
  if !File.exists?(logfile) then
344
372
  touch logfile
345
373
  end
@@ -383,7 +411,6 @@ TEMPLATE_END
383
411
  wiki_html = File.join('site','html',wikiname)
384
412
  mkdir_p(wiki_html,{ :mode => 0775})
385
413
  copy_if_not_exists(source,wiki_html)
386
-
387
414
 
388
415
  make_static_homepage(config)
389
416
 
@@ -433,13 +460,31 @@ AuthUserFile #{config.directory}/config/passwords
433
460
  require valid-user
434
461
  Options ExecCGI FollowSymLinks
435
462
  </Directory>
436
- ErrorLog /var/log/apache/wiki_#{config.default_wiki}_err.log
437
- CustomLog /var/log/apache/wiki_#{config.default_wiki}.log combined
463
+ ErrorLog #{config.directory}/logs/error.log
464
+ CustomLog #{config.directory}/logs/access.log.log combined
438
465
 
439
466
  </VirtualHost>
467
+ END_TEMPLATE
468
+
469
+ subsite_template = <<-END_TEMPLATE
470
+ RedirectMatch ^#{config.subsite}/$ http://#{File.join(config.server_url,config.subsite,config.default_wiki,'FrontPage.html')}
471
+ RedirectMatch ^#{config.subsite}$ http://#{File.join(config.server_url,config.subsite,config.default_wiki,'FrontPage.html')}
472
+ ScriptAlias #{config.subsite}/scripts #{config.directory}/site/scripts
473
+ ScriptAlias #{config.subsite}/scripts/secure #{config.directory}/site/scripts/secure
474
+ Alias #{config.subsite} #{config.directory}/site
475
+ <Directory "#{config.directory}/site/scripts">
476
+ Options ExecCGI FollowSymLinks
477
+ </Directory>
478
+ <Directory "#{config.directory}/site/scripts/secure">
479
+ AuthType Basic
480
+ AuthName "#{config.default_wiki} wiki site"
481
+ AuthUserFile #{config.directory}/config/passwords
482
+ require valid-user
483
+ Options ExecCGI FollowSymLinks
484
+ </Directory>
440
485
  END_TEMPLATE
441
486
 
442
- write_apache_config(config,template)
487
+ write_apache_config(config,(config.subsite.empty? ? template : subsite_template))
443
488
  end
444
489
 
445
490
  def Install.make_readwrite_apache_config(config)
@@ -461,13 +506,31 @@ AuthUserFile #{config.directory}/config/passwords
461
506
  require valid-user
462
507
  Options ExecCGI FollowSymLinks
463
508
  </Directory>
464
- ErrorLog /var/log/apache/wiki_#{config.default_wiki}_err.log
465
- CustomLog /var/log/apache/wiki_#{config.default_wiki}.log combined
509
+ ErrorLog #{config.directory}/logs/error.log
510
+ CustomLog #{config.directory}/logs/access.log.log combined
466
511
 
467
512
  </VirtualHost>
513
+ END_TEMPLATE
514
+
515
+ subsite_template = <<-END_TEMPLATE
516
+ RedirectMatch ^#{config.subsite}/$ http://#{File.join(config.server_url,config.subsite,config.default_wiki,'FrontPage.html')}
517
+ RedirectMatch ^#{config.subsite}$ http://#{File.join(config.server_url,config.subsite,config.default_wiki,'FrontPage.html')}
518
+ ScriptAlias #{config.subsite}/scripts #{config.directory}/site/scripts
519
+ ScriptAlias #{config.subsite}/scripts/secure #{config.directory}/site/scripts/secure
520
+ Alias #{config.subsite} #{config.directory}/site
521
+ <Directory "#{config.directory}/site/scripts">
522
+ Options ExecCGI FollowSymLinks
523
+ </Directory>
524
+ <Directory "#{config.directory}/site/scripts/secure">
525
+ AuthType Basic
526
+ AuthName "#{config.default_wiki} wiki site"
527
+ AuthUserFile #{config.directory}/config/passwords
528
+ require valid-user
529
+ Options ExecCGI FollowSymLinks
530
+ </Directory>
468
531
  END_TEMPLATE
469
532
 
470
- write_apache_config(config,template)
533
+ write_apache_config(config,(config.subsite.empty? ? template : subsite_template))
471
534
  end
472
535
 
473
536
  def Install.make_apache_private_config(config)
@@ -488,13 +551,31 @@ Options ExecCGI FollowSymLinks
488
551
  <Directory "#{config.directory}/site/scripts/">
489
552
  Options ExecCGI FollowSymLinks
490
553
  </Directory>
491
- ErrorLog /var/log/apache/wiki_#{config.default_wiki}_err.log
492
- CustomLog /var/log/apache/wiki_#{config.default_wiki}.log combined
554
+ ErrorLog #{config.directory}/logs/error.log
555
+ CustomLog #{config.directory}/logs/access.log.log combined
493
556
 
494
557
  </VirtualHost>
558
+ END_TEMPLATE
559
+
560
+ subsite_template = <<-END_TEMPLATE
561
+ RedirectMatch ^#{config.subsite}/$ http://#{File.join(config.server_url,config.subsite,config.default_wiki,'FrontPage.html')}
562
+ RedirectMatch ^#{config.subsite}$ http://#{File.join(config.server_url,config.subsite,config.default_wiki,'FrontPage.html')}
563
+ ScriptAlias #{config.subsite}/scripts #{config.directory}/site/scripts
564
+ Alias #{config.subsite} #{config.directory}/site
565
+ <Directory "#{config.directory}/site/">
566
+ AuthType Basic
567
+ AuthName "#{config.default_wiki} wiki site"
568
+ AuthUserFile #{config.directory}/config/passwords
569
+ require valid-user
570
+ Options ExecCGI FollowSymLinks
571
+ </Directory>
572
+ <Directory "#{config.directory}/site/scripts/">
573
+ Options ExecCGI FollowSymLinks
574
+ </Directory>
575
+
495
576
  END_TEMPLATE
496
577
 
497
- write_apache_config(config,template)
578
+ write_apache_config(config,(config.subsite.empty? ? template : subsite_template))
498
579
  end
499
580
 
500
581
  def Install.make_static_homepage(configuration)
@@ -504,12 +585,13 @@ END_TEMPLATE
504
585
  when "public" then
505
586
  configtype = PublicWikiConfig
506
587
  else
507
- configtype =ReadWriteWikiConfig
588
+ configtype = ReadWriteWikiConfig
508
589
  end
509
590
  config = configtype.new(configuration.directory)
510
591
  if config.generate_html then
592
+ config.subsite = configuration.subsite
511
593
  wiki = Wiki2Go::Wiki.new(config)
512
- web = Wiki2Go::Web.new(configuration.server,configuration.port,"scripts","view.rb",configuration.default_wiki,"FrontPage")
594
+ web = Wiki2Go::Web.new(configuration.server,configuration.port,configuration.subsite,"scripts","view.rb",configuration.default_wiki,"FrontPage")
513
595
  wiki.generate_html(web)
514
596
  end
515
597
  end