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
data/lib/Wiki2Go/Web.rb CHANGED
@@ -22,14 +22,19 @@ module Wiki2Go
22
22
  attr_accessor :script_extension
23
23
  # directory containing scripts
24
24
  attr_accessor :script_prefix
25
+ # CGI/Webrick request
26
+ attr_reader :request
27
+ # subdirectory where to find the wiki
28
+ attr_accessor :subsite
25
29
 
26
30
  MARKER = "#-#"
27
31
 
28
- def initialize(server,port,before,verb,web,page,request=nil)
32
+ def initialize(server,port,subsite,before,verb,web,page,request=nil)
29
33
  @name = Web.clean(web)
30
34
  @current_page = Web.clean(page)
31
35
  @server = server
32
36
  @port = port
37
+ @subsite = Web.clean(subsite)
33
38
 
34
39
  @verb = verb
35
40
  @script_extension = Web.extension_of(verb)
@@ -41,7 +46,7 @@ module Wiki2Go
41
46
  end
42
47
 
43
48
  def clone
44
- return Web.new(@server,@port,@script_prefix,@verb,@name,@current_page,@request)
49
+ return Web.new(@server,@port,@subsite,@script_prefix,@verb,@name,@current_page,@request)
45
50
  end
46
51
 
47
52
  def user
@@ -76,6 +81,10 @@ module Wiki2Go
76
81
  else
77
82
  url = "http://#{@server}:#{@port}/"
78
83
  end
84
+ if !@subsite.empty? then
85
+ url += @subsite + '/'
86
+ end
87
+ url
79
88
  end
80
89
 
81
90
  def path
@@ -86,27 +95,27 @@ module Wiki2Go
86
95
  end
87
96
  end
88
97
 
89
- def Web.page_url(server,port,url,verb,multiwiki=true)
90
- before,verb,web,page = Web.parse_url(url,verb,multiwiki)
98
+ def Web.page_url(server,port,url,verb,config)
99
+ before,verb,web,page = Web.parse_url(url,verb,config)
91
100
  if !web.nil? && !page.nil? then
92
- return Web.new(server,port,before,verb,web,page)
101
+ return Web.new(server,port,'',before,verb,web,page)
93
102
  else
94
- return Web.new(server,port,before,verb,"Wiki2go","Frontpage")
103
+ return Web.new(server,port,'',before,verb,"Wiki2go","Frontpage")
95
104
  end
96
105
  end
97
106
 
98
- def Web.from_page_url(url,verb)
107
+ def Web.from_page_url(url,verb,config)
99
108
  uri = URI::parse(url)
100
- return Web.page_url(uri.host,uri.port,uri.path,verb)
109
+ return Web.page_url(uri.host,uri.port,uri.path,verb,config)
101
110
  end
102
111
 
103
112
 
104
- def Web.from_request(request,multiwiki)
113
+ def Web.from_request(request,config)
105
114
  server = request.host
106
115
  port = request.port
107
- before,verb = Web.parse_scriptpath(request.server_variable['SCRIPT_NAME'])
108
- web,page = Web.parse_path(request.path,multiwiki)
109
- web = Web.new(server,port,before,verb,web,page,request)
116
+ before,verb = Web.parse_scriptpath(request.server_variable['SCRIPT_NAME'],config)
117
+ web,page = Web.parse_path(request.path,config.multi_wiki)
118
+ web = Web.new(server,port,config.subsite,before,verb,web,page,request)
110
119
  return web
111
120
  end
112
121
 
@@ -135,9 +144,9 @@ module Wiki2Go
135
144
 
136
145
  private
137
146
 
138
- def Web.parse_url(path,verb,multiwiki)
147
+ def Web.parse_url(path,verb,config)
139
148
  scriptprefix , webpath = path.split(verb)
140
- web, name = parse_path(webpath,multiwiki)
149
+ web, name = parse_path(webpath,config.multi_wiki)
141
150
  return scriptprefix , verb, web, name
142
151
  end
143
152
 
@@ -159,10 +168,15 @@ module Wiki2Go
159
168
  end
160
169
  end
161
170
 
162
- def Web.parse_scriptpath(path)
171
+ def Web.parse_scriptpath(path,config)
172
+ if !config.subsite.nil? && !config.subsite.empty? then
173
+ if path =~ /^#{config.subsite}(.*)$/ then
174
+ path = $1
175
+ end
176
+ end
163
177
  if path =~ /\// then
164
- path =~ /^(.*)(\/+)([^\/]*)$/
165
- return $1,$3
178
+ path =~ /^(.*)(\/+)([^\/]*)$/
179
+ return $1,$3
166
180
  else
167
181
  return "",path
168
182
  end
@@ -13,6 +13,7 @@ module Wiki2Go
13
13
  end
14
14
 
15
15
  def view(web)
16
+ @config.log("Wiki2Go view #{web.inspect}")
16
17
  html = @config.redirect_to_html?(web)
17
18
  formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
18
19
 
@@ -90,7 +91,7 @@ module Wiki2Go
90
91
  if changed then
91
92
  if @config.accept_page?(web,new_content) then
92
93
  @config.save(web,new_content)
93
- changes = @config.storage.read_changes_in(web.name,20,true)
94
+ changes = @config.storage.read_changes_in(web.name,20)
94
95
  save_rss(web,changes)
95
96
  if @config.generate_html then
96
97
  if newfile then
@@ -110,14 +111,16 @@ module Wiki2Go
110
111
 
111
112
  def upload(web,name,content)
112
113
  if name.empty? || content.nil? then
113
- view(web)
114
+ html = @config.redirect_to_html?(web)
115
+ formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
116
+ return formatter.absolute_url
114
117
  else
115
118
  @config.storage.store_web_file(web.name,name,content)
116
119
  page = @config.storage.load_page(web.name,web.current_page)
120
+ web.title = page.name
117
121
  text = page.content
118
122
  text += "\n---\n{#{name}}"
119
- save(web,text)
120
- view(web)
123
+ return save(web,text)
121
124
  end
122
125
  end
123
126
 
@@ -125,7 +128,7 @@ module Wiki2Go
125
128
  html = @config.redirect_to_html?(web)
126
129
  formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
127
130
 
128
- topics = @config.storage.read_changes_in(web.name,20,false)
131
+ topics = @config.storage.read_changes_in(web.name,20)
129
132
  template = @config.storage.load_template(web.name,"pagelist.htm")
130
133
 
131
134
  return formatter.format_pagelist_in_template(template,topics,"","Recent Changes")
@@ -154,7 +157,7 @@ module Wiki2Go
154
157
  end
155
158
  end
156
159
  if any_changes then
157
- changes = @config.storage.read_changes_in(web.name,20,true)
160
+ changes = @config.storage.read_changes_in(web.name,20)
158
161
  save_rss(web,changes)
159
162
  end
160
163
  return changes(web)
@@ -179,10 +182,9 @@ module Wiki2Go
179
182
  report << "<li>#{file}</li>\r\n"
180
183
  pageweb = @config.static_web(web)
181
184
  pageweb.current_page = file
182
- # pageweb = Wiki2Go::Web.new(web.server,web.port,web.script_prefix,"view",web.name,file)
183
185
  save_html(pageweb)
184
186
  end
185
- changes = @config.storage.read_changes_in(web.name,20,true)
187
+ changes = @config.storage.read_changes_in(web.name,20)
186
188
  save_rss(web,changes)
187
189
  report << "</ul>\r\n"
188
190
  return report.join
@@ -190,7 +192,10 @@ module Wiki2Go
190
192
 
191
193
  def admin(request)
192
194
 
193
- wikiweb = Wiki2Go::Web.from_request(request,false)
195
+ old_config = @config.multi_wiki
196
+ @config.multi_wiki = false
197
+ wikiweb = Wiki2Go::Web.from_request(request,@config)
198
+ @config.multi_wiki = old_config
194
199
 
195
200
  template_name = wikiweb.current_page
196
201
  if template_name.nil? || template_name.empty?
@@ -205,22 +210,61 @@ module Wiki2Go
205
210
  erb.add_field(:@request,request)
206
211
  erb.add_field(:@config,@config)
207
212
  erb.add_field(:@web,wikiweb)
208
- result = erb.execute master
213
+ result = erb.execute master,0
209
214
 
210
215
  end
211
216
 
217
+ def perform(web,request)
218
+
219
+ @config.log("Wiki2Go perform #{web.inspect}")
220
+
221
+ if @config.allow_dynamic_pages then
222
+ html = @config.redirect_to_html?(web)
223
+ formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
224
+
225
+ text = @config.storage.load_page(web.name,web.current_page)
226
+
227
+ erb = Web2Go::ERB_Interpreter.new
228
+ erb.add_field(:@config,@config)
229
+ erb.add_field(:@web,web)
230
+ erb.add_field(:@request,request)
231
+
232
+ script = text.lines.join
233
+ output = erb.execute(script,1)
234
+ text.lines = output.split($/).collect {|line| line + $/ }
235
+
236
+ template = @config.storage.load_template(web.name,"view.htm")
237
+
238
+ return formatter.format_page_in_template(template,text)
239
+ else
240
+ view(web)
241
+ end
242
+ end
243
+
212
244
  private
213
245
 
214
246
  def save_rss(web,changes)
215
247
  rss = generate_rss(web,changes)
216
248
  @config.storage.store_web_file(web.name,"rss.xml",rss)
249
+ save_changes(web,changes)
250
+ end
251
+
252
+ def save_changes(web,changes)
253
+ if @config.generate_html then
254
+ html = true
255
+ formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
256
+
257
+ template = @config.storage.load_template(web.name,"pagelist.htm")
258
+
259
+ content = formatter.format_pagelist_in_template(template,changes,"","Recent Changes")
260
+ @config.storage.save_html(web.name,'recent_changes',content)
261
+ end
217
262
  end
218
263
 
219
264
  def save_html(web)
220
265
  @config.log("Save html for #{web.inspect}")
221
266
  if @config.generate_html then
222
267
  static_web = @config.static_web(web)
223
- @config.log("Save html for static #{static_web.inspect}")
224
268
  @config.storage.save_html(static_web.name,static_web.current_page, view_html(static_web))
225
269
  end
226
270
  end
@@ -231,9 +275,10 @@ module Wiki2Go
231
275
  files = @config.storage.search(web.name,pagename)
232
276
  files << @config.storage.load_page(web.name,pagename)
233
277
  files.each do |file|
234
- @config.log("Generating HTML for #{file.title}")
235
- pageweb = Wiki2Go::Web.new(web.server,web.port,web.script_prefix,"view",web.name,file.title)
278
+ pageweb = @config.static_web(web)
279
+ pageweb.current_page = file.title
236
280
  static_web = @config.static_web(pageweb)
281
+ @config.log("Generating HTML for #{file.title}, web = #{static_web.inspect}")
237
282
  @config.storage.save_html(static_web.name,static_web.current_page, view_html_of_page(static_web,file))
238
283
  end
239
284
  end
@@ -241,7 +286,6 @@ module Wiki2Go
241
286
  def view_html_of_page(web,text)
242
287
  html = true
243
288
  editable = @config.editable?(web)
244
- web = @config.static_web(web)
245
289
  formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,editable)
246
290
 
247
291
  template = @config.storage.load_template(web.name,"view.htm")
@@ -255,7 +299,7 @@ module Wiki2Go
255
299
 
256
300
  template = @config.storage.load_template(web.name,"view.htm")
257
301
 
258
- page = Wiki2Go::Page.new("Report",text,"system",Time.now,"Report")
302
+ page = Wiki2Go::Page.new("Report",text,"system",Time.now,Time.now,"Report")
259
303
  return formatter.format_page_in_template(template,page)
260
304
  end
261
305
 
@@ -19,7 +19,10 @@ module Wiki2Go
19
19
  attr_accessor :debug
20
20
  attr_accessor :multi_wiki
21
21
  attr_accessor :site_admin
22
-
22
+ attr_accessor :amazon_affiliate
23
+ attr_accessor :allow_dynamic_pages
24
+ attr_accessor :subsite
25
+
23
26
  def initialize(directory=nil)
24
27
  directory ||= Dir.getwd
25
28
 
@@ -36,6 +39,9 @@ module Wiki2Go
36
39
  @debug = false
37
40
  @multi_wiki = true
38
41
  @site_admin = 'wiki2go@nayima.be'
42
+ @amazon_affiliate = 'agilesystems-21'
43
+ @allow_dynamic_pages = false
44
+ @subsite = ''
39
45
  end
40
46
 
41
47
  def storage
@@ -64,11 +70,11 @@ module Wiki2Go
64
70
  end
65
71
 
66
72
  def logfile
67
- File.join( @root_directory,'wiki.log')
73
+ File.join( @root_directory,'logs','wiki.log')
68
74
  end
69
75
 
70
76
  def default_wiki
71
- return Wiki2Go::Web.new(@server,@port.to_s,"","view",(@multi_wiki ? @default_web : ''),@default_page)
77
+ return Wiki2Go::Web.new(@server,@port.to_s,'','','view',(@multi_wiki ? @default_web : ''),@default_page)
72
78
  end
73
79
 
74
80
  def editable?(web)
@@ -82,7 +88,7 @@ module Wiki2Go
82
88
  def static_web(web)
83
89
  server = web.server.gsub(/^edit\./,"www.")
84
90
  script_prefix = web.script_prefix.gsub(/\/secure/,"")
85
- return Wiki2Go::Web.new(server,web.port,script_prefix,web.verb,web.name,web.current_page)
91
+ return Wiki2Go::Web.new(server,web.port,@subsite,script_prefix,web.verb,web.name,web.current_page)
86
92
  end
87
93
 
88
94
  def accept_page?(web,content)
@@ -26,7 +26,19 @@ module Wiki2Go
26
26
  wiki = Wiki2Go::Wiki.new(@config)
27
27
 
28
28
  res.content_type = 'text/html'
29
- res.body = wiki.view(wikiweb)
29
+ if @config.allow_dynamic_pages && wikiweb.current_page =~ /\.rbl$/i then
30
+ res.body = wiki.perform(wikiweb,req)
31
+ else
32
+ res.body = wiki.view(wikiweb)
33
+ end
34
+ true
35
+ end
36
+
37
+ def perform_perform(req,res,wikiweb)
38
+ wiki = Wiki2Go::Wiki.new(@config)
39
+
40
+ res.content_type = 'text/html'
41
+ res.body = wiki.perform(wikiweb,req)
30
42
  true
31
43
  end
32
44
 
@@ -139,15 +151,17 @@ module Wiki2Go
139
151
  uploaded_file = req.uploaded_file('FILE')
140
152
  wiki = Wiki2Go::Wiki.new(@config)
141
153
 
154
+ redirect_to = wiki.upload(wikiweb,uploaded_file.filename,uploaded_file.content)
155
+ res.redirect_to = redirect_to
142
156
  res.content_type = "text/html"
143
- res.body = wiki.upload(wikiweb,uploaded_file.filename,uploaded_file.content)
157
+ res.body = "Redirect to #{redirect_to}"
144
158
  true
145
159
  end
146
160
 
147
161
  private
148
162
 
149
163
  def execute_command(req,res)
150
- wikiweb = Wiki2Go::Web.from_request(req,@config.multi_wiki)
164
+ wikiweb = Wiki2Go::Web.from_request(req,@config)
151
165
  @config.log("WIKI Web = #{wikiweb.inspect}")
152
166
  command = wikiweb.verb
153
167
  if command =~ /^([^\.]+)\./ then
@@ -175,7 +189,7 @@ module Wiki2Go
175
189
  author = cookie.value unless cookie.nil?
176
190
 
177
191
  if !author.nil? && author.length > 0 then # !wikiweb.secure &&
178
- wikiweb.alias = author
192
+ wikiweb.alias = author[0]
179
193
  end
180
194
 
181
195
  result = self.send(method,req,res,wikiweb)
@@ -30,6 +30,8 @@ module Wiki2Go
30
30
 
31
31
  class Formatter
32
32
 
33
+ attr_reader :config
34
+
33
35
  def initialize(web,storage,config,generate_html,editable)
34
36
  @web = web
35
37
  @storage = storage
@@ -40,6 +42,7 @@ module Wiki2Go
40
42
  @post_line = ""
41
43
  @generate_html = generate_html
42
44
  @editable = editable
45
+ @absolute_urls = false
43
46
  end
44
47
 
45
48
  public
@@ -75,6 +78,7 @@ module Wiki2Go
75
78
  result = format_page_content(content)
76
79
  emit_bullets
77
80
  result += @pre_line
81
+ @pre_line = ''
78
82
  return format_empty_lines(result)
79
83
  end
80
84
 
@@ -93,6 +97,10 @@ module Wiki2Go
93
97
 
94
98
  def generate_rss(template,changes)
95
99
 
100
+ # RSS must contain absolute URLs because some feedreaders don't honor the relative
101
+ # URLs to the content of the <link> tag
102
+ @absolute_urls = true
103
+
96
104
  template_after_items = <<-END_OF_AFTER_ITEMS_XML
97
105
  </channel>
98
106
  </rss>
@@ -103,7 +111,7 @@ module Wiki2Go
103
111
  changes.each do |page|
104
112
  items = items + <<-END_OF_ITEMS
105
113
  <item>
106
- <title>#{page.name}</title>
114
+ <title>#{CGI::escapeHTML(page.name)}</title>
107
115
  <author>#{page.alias}</author>
108
116
  <pubDate>#{page.lastmodified.strftime("%d %B %Y %H:%M GMT")}</pubDate>
109
117
  <link>#{absolute_url_of_topic(page.title)}</link>
@@ -183,13 +191,27 @@ module Wiki2Go
183
191
  end
184
192
 
185
193
  def changes_url
186
- return join(@web.script_prefix,'changes'+@web.script_extension,@web.name)
194
+ if @generate_html then
195
+ return join(@web.name,'recent_changes.html')
196
+ else
197
+ return join(@web.script_prefix,'changes'+@web.script_extension,@web.name)
198
+ end
187
199
  end
188
200
 
189
201
  def changes_link(desc)
190
202
  return "<a href=\"#{changes_url}\">#{desc}</a>"
191
203
  end
192
204
 
205
+ def view_url(subwiki,page)
206
+ if @generate_html then
207
+ return join(subwiki,page + ".html")
208
+ else
209
+ return join(@web.script_prefix,"view" + @web.script_extension,subwiki,page)
210
+ end
211
+ end
212
+
213
+
214
+
193
215
  def view_link(subwiki,page,name)
194
216
  if subwiki == @web.name then
195
217
  return "<a href=\"#{view_url(subwiki,page)}\">#{name}</a>"
@@ -198,6 +220,19 @@ module Wiki2Go
198
220
  end
199
221
  end
200
222
 
223
+ def perform_link(subwiki,page,name)
224
+ if @storage.exists(File.join(subwiki,page)) then
225
+ url = join(@web.script_prefix,"view" + @web.script_extension,subwiki,page)
226
+ if subwiki == @web.name then
227
+ return "<a href=\"#{url}\">#{name}</a>"
228
+ else
229
+ return "<a href=\"#{url}\">#{subwiki}:#{name}</a>"
230
+ end
231
+ else
232
+ return edit_link(subwiki,page,name)
233
+ end
234
+ end
235
+
201
236
  def view_version_link(subwiki,page,name,parameters=nil)
202
237
  return "<a href=\"#{view_version_url(subwiki,page)+query_string(parameters)}\">#{name}</a>"
203
238
  end
@@ -239,16 +274,13 @@ module Wiki2Go
239
274
 
240
275
  end
241
276
 
242
- def view_url(subwiki,page)
243
- if @generate_html then
244
- return join(subwiki,page + ".html")
245
- else
246
- return join(@web.script_prefix,"view" + @web.script_extension,subwiki,page)
247
- end
248
- end
249
277
 
250
278
  def resource_url(name)
251
- File.join('html',@web.name,name)
279
+ if @absolute_urls then
280
+ File.join(@web.base_url,'html',@web.name,name)
281
+ else
282
+ File.join('html',@web.name,name)
283
+ end
252
284
  end
253
285
 
254
286
  def encode_mail_to(addr)
@@ -261,7 +293,7 @@ module Wiki2Go
261
293
  end
262
294
 
263
295
  alias :encodeMailTo :encode_mail_to
264
-
296
+
265
297
  private
266
298
 
267
299
  def evaluate(erb,current)
@@ -286,7 +318,7 @@ module Wiki2Go
286
318
  end
287
319
  result
288
320
  end
289
-
321
+
290
322
  def format_page_content(content)
291
323
  if content.length == 0 then
292
324
  return ''
@@ -296,6 +328,9 @@ module Wiki2Go
296
328
  elsif content =~ /^(.*)(<pre>(.*)<\/pre>)(.*)$/im then
297
329
  before,match,after = $1,$2,$4
298
330
  return append(format_page_content(before),match,format_page_content(after))
331
+ elsif content =~ /^(.*)\{\{\!(.*)\!\}\}(.*)$/im then
332
+ before,match,after = $1,$2,$3
333
+ return append(format_page_content(before),match,format_page_content(after))
299
334
  else
300
335
  result = ''
301
336
  lines = content.split($/)
@@ -351,16 +386,22 @@ module Wiki2Go
351
386
  end
352
387
 
353
388
  def format_wiki_markup(line)
354
- if line =~ /^(.*)<(\S.*)\>(.*)$/ then
389
+ if line =~ /^(.*)\{\!(.*)\!\}(.*)$/im then
390
+ before,match,after = $1,$2,$3
391
+ return append(format_wiki_markup(before),match,format_wiki_markup(after))
392
+ elsif line =~ /^(.*)<(\S.*)\>(.*)$/ then
355
393
  before,match,after = $1,$2,$3
356
394
  line = append(format_wiki_markup(before),escape_url_markers(format_tag(match)),format_wiki_markup(after))
395
+ elsif line =~ /^(.*)\{\%([^\}]*)\%\}(.*)$/ then
396
+ before,match,after = $1,$2,$3
397
+ line = append(format_wiki_markup(before),escape_url_markers(format_dynamic_link(match)),format_wiki_markup(after))
357
398
  elsif line =~ /^(.*)\{([^\}]*)\}(.*)$/ then
358
399
  before,match,after = $1,$2,$3
359
400
  line = append(format_wiki_markup(before),escape_url_markers(format_forced_link(match)),format_wiki_markup(after))
360
401
  elsif line =~ /^(.*)\%([^\%]*)\%(.*)$/ then
361
402
  before,match,after = $1,$2,$3
362
403
  line = append(format_wiki_markup(before),escape_url_markers(format_forced_link(match)),format_wiki_markup(after))
363
- elsif line =~ /^(.*)((http|ftp|gopher|news|https)\:(\w|\/|\.|_|-|\?|\=|&|;|\~|#|,)+)(.*)$/ then
404
+ elsif line =~ /^(.*)((http|ftp|gopher|news|https)\:\/\/(\w|\/|\.|_|-|\?|\=|&|;|\~|#|,)+)(.*)$/ then
364
405
  before,match,after = $1,$2,$5
365
406
  line = append(format_wiki_markup(before),escape_url_markers(external_link(match)),format_wiki_markup(after))
366
407
  elsif line =~ /^(.*)mailto\:([a-zA-Z0-9\-\_\.]+@[a-zA-Z0-9\-\_\.]+)(.*)$/ then
@@ -397,7 +438,7 @@ module Wiki2Go
397
438
  line = line.gsub(/\{\{/,"&openingbrace;")
398
439
  line = line.gsub(/\}\}/,"&closingbrace;")
399
440
  end
400
-
441
+
401
442
  def escape_url_markers(line)
402
443
  line = line.gsub(/%/ ,'&percent;')
403
444
  line = line.gsub(/\{/,'&openingbrace;')
@@ -418,7 +459,7 @@ module Wiki2Go
418
459
  return line
419
460
  end
420
461
 
421
-
462
+
422
463
  def format_brackets(line)
423
464
  line = line.gsub(/</,"&lt\;") ;
424
465
  line = line.gsub(/>/,"&gt\;") ;
@@ -440,7 +481,6 @@ module Wiki2Go
440
481
  line = line.gsub(/\*([^\*]+)\*/,"<STRONG>\\1<\/STRONG>")
441
482
  line = line.gsub(/\b_([^_]*)_/,"<EM>\\1<\/EM>")
442
483
  line = line.gsub(/^---+/,"<hr>")
443
- # line = line.gsub(/^\s*$/,"\n<p>")
444
484
  return line
445
485
  end
446
486
 
@@ -489,12 +529,16 @@ module Wiki2Go
489
529
  end
490
530
 
491
531
  def format_forced_link(link)
492
- if ! link.gsub!(/^([^%@]+)@(http[^%]+)$/) { labelLink($1,$2) } then
493
- link.gsub!(/^(([^\%@]+)@)?(([^\%:]+):)?([^%]+)$/) { mega_link($2,$4,$5,@web.name) }
494
- end
495
- link
532
+ if ! link.gsub!(/^([^%@]+)@(http[^%]+)$/) { labelLink($1,$2) } then
533
+ link.gsub!(/^(([^\%@]+)@)?(([^\%:]+):)?([^%]+)$/) { mega_link($2,$4,$5,@web.name) }
534
+ end
535
+ link
496
536
  end
497
-
537
+
538
+ def format_dynamic_link(link)
539
+ return link.gsub(/^(([^\%@]+)@)?(([^\%:]+):)?([^%]+)$/) { dynamic_link($2,$4,$5,@web.name) }
540
+ end
541
+
498
542
  def labelLink(label,url)
499
543
  return redirect_link(label,url)
500
544
  end
@@ -509,6 +553,12 @@ module Wiki2Go
509
553
  internalSubwikiNamedLink(subwiki,page,name)
510
554
  end
511
555
 
556
+ def dynamic_link(name,subwiki,page,default_wiki)
557
+ name = page if name.nil? || name.empty?
558
+ subwiki = default_wiki if subwiki.nil? || subwiki.empty?
559
+ perform_link(subwiki,page+'.rbl',name)
560
+ end
561
+
512
562
  def internalSubwikiNamedLink(subwiki,page,name)
513
563
  if subwiki == "xpnl" then
514
564
  return "<a href=\"http://www.xpnl.org/Wiki/#{page}\" target=\"_blank\">xpnl:#{page}</a>"
@@ -522,10 +572,10 @@ module Wiki2Go
522
572
  return "<a href=\"http://wiki2go.nayima.be/Wiki2Go/#{page}.html\" target=\"_blank\">wiki2go:#{page}</a>"
523
573
  elsif subwiki =~ /^isbn$/i then
524
574
  name = "ISBN " + page if page == name
525
- return "<a href=\"http://www.amazon.co.uk/exec/obidos/ASIN/#{page}/agilesystems-21\" target=\"_blank\">#{name}</a>"
575
+ return "<a href=\"http://www.amazon.co.uk/exec/obidos/ASIN/#{page}/#{@config.amazon_affiliate}\" target=\"_blank\">#{name}</a>"
526
576
  elsif page =~ /^isbn(.+)$/i then
527
577
  name = "ISBN " + $1 if page == name
528
- return "<a href=\"http://www.amazon.co.uk/exec/obidos/ASIN/#{$1}/agilesystems-21\" target=\"_blank\">#{name}</a>"
578
+ return "<a href=\"http://www.amazon.co.uk/exec/obidos/ASIN/#{$1}/#{@config.amazon_affiliate}\" target=\"_blank\">#{name}</a>"
529
579
  elsif page =~ /\./ then
530
580
  return resource_link(subwiki,page,name)
531
581
  elsif @storage.exists(File.join(subwiki,page)) then
@@ -542,14 +592,20 @@ module Wiki2Go
542
592
  if page == name || url?(name) then
543
593
  alt_label = filename
544
594
  end
545
- image_link = "<img src=\"html/#{subwiki}/#{page}\" border=0 alt=\"#{alt_label}\" >"
595
+ image_link = "<img src=\"#{resource_url(page)}\" border=0 alt=\"#{alt_label}\" >"
546
596
  if url?(name) then
547
597
  return redirect_link(image_link,name)
548
598
  else
549
599
  return image_link
550
600
  end
601
+ elsif page =~ /^(.*)\.rbl$/i then
602
+ page_name = $1
603
+ if page == name then
604
+ name = page_name
605
+ end
606
+ return perform_link(subwiki,page,name)
551
607
  else
552
- return "<a href=\"html/#{subwiki}/#{page}\" target=\"_blank\">#{name}</a>"
608
+ return "<a href=\"#{resource_url(page)}\" target=\"_blank\">#{name}</a>"
553
609
  end
554
610
  end
555
611