Wiki2Go 1.17.5 → 1.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/bin/Wiki2Go_firewall_blacklist.rb +8 -0
  2. data/bin/Wiki2Go_make_cvs_repository.rb +1 -0
  3. data/bin/Wiki2Go_make_site.rb +1 -2
  4. data/bin/Wiki2Go_update_site.rb +1 -2
  5. data/lib/Web2Go/CGIRequest.rb +8 -2
  6. data/lib/Web2Go/CGIResponse.rb +17 -14
  7. data/lib/Web2Go/MockRequest.rb +12 -2
  8. data/lib/Web2Go/MockResponse.rb +10 -7
  9. data/lib/Web2Go/WebrickRequest.rb +106 -101
  10. data/lib/Web2Go/WebrickResponse.rb +4 -8
  11. data/lib/Wiki2Go/BlackList.rb +48 -25
  12. data/lib/Wiki2Go/DotGraphics.rb +1 -1
  13. data/lib/Wiki2Go/FileStorage.rb +266 -266
  14. data/lib/Wiki2Go/HTMLFormatter.rb +28 -0
  15. data/lib/Wiki2Go/Install/config/chonqed_blacklist.txt +418 -0
  16. data/lib/Wiki2Go/Install/config/passwords +1 -1
  17. data/lib/Wiki2Go/Install/config/url_blacklist.txt +3855 -0
  18. data/lib/Wiki2Go/Install/make_repository.rb +32 -26
  19. data/lib/Wiki2Go/Install/make_site.rb +197 -111
  20. data/lib/Wiki2Go/Install/site/error.html +1 -1
  21. data/lib/Wiki2Go/Install/site/robots.txt +10 -1
  22. data/lib/Wiki2Go/Install/site/style.css +129 -64
  23. data/lib/Wiki2Go/Install/templates/admin.htm +1 -1
  24. data/lib/Wiki2Go/Install/templates/admin_pages/edit.txt +2 -1
  25. data/lib/Wiki2Go/Install/templates/admin_pages/format_for_fck.txt +31 -0
  26. data/lib/Wiki2Go/Install/templates/admin_pages/passwords.txt +1 -1
  27. data/lib/Wiki2Go/Install/templates/edit.htm +62 -46
  28. data/lib/Wiki2Go/Install/templates/full_footer.htm +31 -33
  29. data/lib/Wiki2Go/Install/templates/header.htm +0 -1
  30. data/lib/Wiki2Go/Install/templates/menu.htm +29 -0
  31. data/lib/Wiki2Go/Install/templates/pagelist.htm +46 -43
  32. data/lib/Wiki2Go/Install/templates/simple_footer.htm +20 -16
  33. data/lib/Wiki2Go/Install/templates/versionlist.htm +52 -40
  34. data/lib/Wiki2Go/Install/templates/view.htm +46 -29
  35. data/lib/Wiki2Go/Install/templates/wikiedit.htm +63 -0
  36. data/lib/Wiki2Go/Install/wiki/delete.png +0 -0
  37. data/lib/Wiki2Go/Install/wiki/style.css +133 -63
  38. data/lib/Wiki2Go/LineFormatter.rb +345 -197
  39. data/lib/Wiki2Go/Page.rb +16 -3
  40. data/lib/Wiki2Go/PrivateWikiConfig.rb +5 -5
  41. data/lib/Wiki2Go/PublicWikiConfig.rb +83 -37
  42. data/lib/Wiki2Go/ReadWriteWikiConfig.rb +8 -8
  43. data/lib/Wiki2Go/Server.rb +6 -1
  44. data/lib/Wiki2Go/SpamFilter.rb +32 -41
  45. data/lib/Wiki2Go/Web.rb +10 -3
  46. data/lib/Wiki2Go/Wiki2Go.rb +301 -94
  47. data/lib/Wiki2Go/Wiki2GoConfig.rb +87 -6
  48. data/lib/Wiki2Go/Wiki2GoServlet.rb +66 -12
  49. data/lib/Wiki2Go/WikiFormatter.rb +60 -30
  50. data/lib/Wiki2Go/cgi/diff.rb +20 -0
  51. data/lib/Wiki2Go/cgi/secure/log_rss.rb +21 -0
  52. data/lib/Wiki2Go/cgi/sidebyside.rb +20 -0
  53. data/lib/Wiki2Go/cgi/wikiedit.rb +20 -0
  54. data/lib/Wiki2Go/firewall_blacklist.rb +88 -0
  55. data/test/All.rb +5 -2
  56. data/test/TestBlackList.rb +70 -14
  57. data/test/TestConfig.rb +5 -5
  58. data/test/TestDiff.rb +95 -0
  59. data/test/TestFormatter.rb +14 -16
  60. data/test/TestHTMLFormatter.rb +37 -0
  61. data/test/TestInstall.rb +70 -27
  62. data/test/TestLineFormatter.rb +71 -15
  63. data/test/TestRSS.rb +8 -7
  64. data/test/TestRepository.rb +50 -0
  65. data/test/TestServer.rb +3 -8
  66. data/test/TestSpamFilter.rb +33 -1
  67. data/test/TestStorage.rb +11 -0
  68. data/test/TestWeb.rb +2 -2
  69. data/test/TestWiki2Go.rb +766 -166
  70. data/test/TestWiki2GoServlet.rb +1122 -524
  71. data/test/UnitTestFiles.rb +7 -3
  72. data/test/Wiki2GoConfigForTest.rb +40 -6
  73. data/test/checksite.rb +17 -50
  74. data/test/test_firewall_blacklist.rb +131 -0
  75. data/test/test_page.rb +45 -0
  76. data/test/testdata/Registration.rbl.txt +7 -0
  77. data/test/testdata/config/url_blacklist.txt +38822 -0
  78. data/test/testdata/expected_changes.html +1 -2
  79. data/test/testdata/expected_edit.html +108 -59
  80. data/test/testdata/expected_full_rss.xml +2 -2
  81. data/test/testdata/expected_out.html +97 -61
  82. data/test/testdata/expected_put.html +88 -53
  83. data/test/testdata/expected_save.html +88 -52
  84. data/test/testdata/expected_savehtml.html +88 -52
  85. data/test/testdata/expected_search.html +68 -53
  86. data/test/testdata/expected_upload.html +88 -53
  87. data/test/testdata/expected_versions.html +97 -82
  88. data/test/testdata/expected_view.html +97 -61
  89. data/test/testdata/firewall/iptables.config +37 -0
  90. data/test/testdata/firewall/user_blacklist.txt +162 -0
  91. data/test/testdata/logs/wiki.log +652 -0
  92. data/test/testdata/logs/wiki.log.0 +113 -0
  93. data/test/testdata/logs/wiki.log.1 +113 -0
  94. data/test/testdata/logs/wiki.log.2 +113 -0
  95. data/test/testdata/logs/wiki.log.3 +115 -0
  96. data/test/testdata/logs/wiki.log.4 +5 -0
  97. data/test/testdata/logs/wiki.log.5 +7 -0
  98. data/test/testdata/logs/wiki.log.6 +5 -0
  99. data/test/testdata/logs/wiki.log.7 +118 -0
  100. data/test/testdata/logs/wiki.log.8 +12 -0
  101. data/test/testdata/site/html/Xpday/rss.xml +53 -103
  102. data/test/testdata/texts/Bugs/FrontPage.txt +6 -0
  103. data/test/testdata/texts/Bugs/NoHidden.spam +17850 -0
  104. data/test/testdata/texts/Bugs/PairProgrammingParties.spam +102 -0
  105. data/test/testdata/texts/Bugs/PairProgrammingParties.txt +99 -0
  106. metadata +53 -7
  107. data/test/TestMail.rb +0 -29
  108. data/test/gc.log +0 -2
Binary file
@@ -10,76 +10,77 @@ body
10
10
  text-align: justify;
11
11
  }
12
12
 
13
- ul
14
- {
15
- margin-left:0.5em;
16
- padding-top : 0.5em ;
17
- padding-left : 0em ;
18
- padding-right : 0em ;
19
- padding-bottom : 0.5em ;
20
- margin-right:1em
13
+ /* Main structure */
14
+ #container {
15
+ margin: 0;
16
+ margin-left: 2em;
17
+ margin-right: 2em;
18
+ background: #fff;
19
+ border-left: 1px solid #ccc;
20
+ border-right: 1px solid #ccc;
21
+ border-top: 1px solid #ccc;
22
+ border-bottom: 1px solid #ccc;
21
23
  }
22
24
 
23
- li
25
+ #menu
24
26
  {
25
- margin-left:0.5em;
26
- margin-right:1em ;
27
- padding : 0em 0em 0em 0em ;
27
+ border-right: black thin solid;
28
+ background-color: #F8F7F0;
29
+ padding-right : 0.5em ;
30
+
28
31
  }
29
32
 
30
- h1
33
+ #body
31
34
  {
32
- font-weight: bold;
33
- font-size: 28pt;
34
- color: black;
35
- margin : 0em ;
35
+ padding-left : 0.5em ;
36
+ padding-right : 0.5em ;
37
+ width: 100%;
38
+ background-color: #FFFFFF;
36
39
  }
37
40
 
38
- h2,h3,h4,h5,h6
41
+ #header
39
42
  {
40
- color:black
43
+ padding-right: 1em;
44
+ padding-left: 1em;
45
+ padding-bottom: 0.5em;
46
+ margin: 0px;
47
+ padding-top: 0px;
48
+ background-color: #B82619;
49
+ border-bottom: grey thin solid;
50
+ color : White ;
41
51
  }
42
52
 
43
- h2,h3.frontpage {
44
- text-align: center ;
45
- }
46
-
47
- table.Header
53
+ #header a:link
48
54
  {
49
- padding-right: 0.1em;
50
- padding-left: 0.5em;
51
- padding-bottom: 0.1em;
52
- padding-top: 0em;
53
- color: black;
54
- background-color: white;
55
- text-align: left;
56
- border-bottom: 1px solid #ccc;
55
+ color: White;
56
+ font-weight: bolder ;
57
+ text-decoration: none;
57
58
  }
58
59
 
59
- table.Footer
60
- {
61
-
62
- clear: both;
63
- margin: 100px 0 0 0;
64
- padding: 6px;
65
- color: #000;
66
- background: #fff;
67
- border-top: 1px solid #ccc;
60
+ #header a:visited {
61
+ color: White;
62
+ text-decoration: none;
63
+ font-weight: normal ;
68
64
  }
69
65
 
70
- hr {
71
- color: #ccc;
66
+ #header a:hover
67
+ {
68
+ color: cornsilk;
72
69
  }
73
70
 
74
- table.Body
71
+ #header h1
75
72
  {
76
- text-align: left;
73
+ color : White ;
77
74
  }
78
75
 
79
- td[class=search] {
80
- text-align: right;
76
+ #footer
77
+ {
78
+ border-top: grey thin solid;
79
+ background-color : silver;
81
80
  }
82
81
 
82
+ /* Links */
83
+
83
84
  a:link
84
85
  {
85
86
  color: #a50a11;
@@ -97,28 +98,76 @@ a:hover {
97
98
  text-decoration: underline;
98
99
  }
99
100
 
100
- #container {
101
- margin-left: 2em;
102
- margin-right: 2em;
103
- margin-bottom: 40px;
104
- margin-top: 5px;
105
- padding-left: 15px;
106
- padding-right: 15px;
107
- padding-top: 5px;
108
- padding-bottom: 5px;
109
- background: #fff;
110
- border-left: 1px solid #ccc;
111
- border-right: 1px solid #ccc;
112
- border-top: 1px solid #ccc;
113
- border-bottom: 1px solid #ccc;
101
+ /* Headers */
102
+
103
+ h1
104
+ {
105
+ font-weight: bold;
106
+ font-size: 28pt;
107
+ color: black;
108
+ margin : 0em ;
109
+ }
110
+
111
+ h2,h3,h4,h5,h6
112
+ {
113
+ color:black
114
+ }
115
+
116
+ h2,h3.frontpage {
117
+ text-align: center ;
118
+ }
119
+
120
+ /* Style for tables drawn with --- and | in wiki markup */
121
+
122
+ table.wikitable
123
+ {
124
+ border-collapse: collapse;
125
+ }
126
+
127
+ table.wikitable tr
128
+ {
129
+ padding-right: 0.4em;
130
+ padding-left: 0.4em;
131
+ padding-bottom: 0.4em;
132
+ margin: 0em;
133
+ padding-top: 0.4em;
114
134
  }
115
-
135
+
136
+ table.wikitable td
137
+ {
138
+ border-right: 1px solid;
139
+ padding-right: 0.5em;
140
+ border-top: 1px solid;
141
+ padding-left: 0.5em;
142
+ padding-bottom: 0.5em;
143
+ border-left: 1px solid;
144
+ padding-top: 0.5em;
145
+ border-bottom: 1px solid;
146
+ }
147
+
148
+ /* Menu items */
149
+
150
+ #menu ul
151
+ {
152
+ margin-left : 0 ;
153
+ padding-left : 0.5em ;
154
+ }
155
+
156
+ #menu li
157
+ {
158
+ list-style-type: none;
159
+ margin-left : 0 ;
160
+ padding-left : 0 ;
161
+ }
162
+
163
+ /* Style for lists of pages or versions (recent changes, search, versions */
164
+
116
165
  table.topiclist
117
166
  {
118
167
  width: 100%;
119
168
  }
120
169
 
121
- table.topiclist tr.date
170
+ table.topiclist td.date
122
171
  {
123
172
  font-weight: bold;
124
173
  }
@@ -131,3 +180,24 @@ table.topiclist tr.odd
131
180
  table.topiclist tr.even
132
181
  {
133
182
  }
183
+
184
+ /* Style for the display of differences */
185
+ div.diff_kept
186
+ {
187
+ display : block ;
188
+ font-family: 'Courier New';
189
+ }
190
+
191
+ div.diff_added
192
+ {
193
+ background-color: #ffffcc;
194
+ display : block ;
195
+ font-family: 'Courier New';
196
+ }
197
+
198
+ div.diff_deleted
199
+ {
200
+ background-color: #ffcc33;
201
+ display : block ;
202
+ font-family: 'Courier New';
203
+ }
@@ -8,9 +8,9 @@ require 'English'
8
8
  module Wiki2Go
9
9
 
10
10
  class LineFormatter
11
-
11
+
12
12
  attr_reader :config
13
-
13
+
14
14
  def initialize(web,storage,config,generate_html,editable)
15
15
  @web = web
16
16
  @storage = storage
@@ -23,36 +23,47 @@ module Wiki2Go
23
23
  @editable = editable
24
24
  @absolute_urls = false
25
25
  end
26
-
26
+
27
27
  public
28
-
28
+
29
+ # Format one line with wiki formatting
29
30
  def format_line(line)
30
31
  @added_bullets = false
31
32
  line = escape_wiki_markers(line)
32
- line = format_wiki_markup(line)
33
+ line = format_tags(line)
34
+ line = format_bullets(line)
35
+ line = format_markup(line)
33
36
  line = format_table(line)
34
37
  line = remove_markers(line)
35
38
  if !@added_bullets then
36
39
  emit_bullets
37
40
  end
38
-
41
+
39
42
  return formatted_output(line)
40
43
  end
41
-
44
+
45
+ # Call when the last line has been formatted. We may need to close lists.
42
46
  def formatting_done
43
47
  emit_bullets
44
48
  result =@pre_line
45
49
  @pre_line = ''
46
50
  result
47
51
  end
48
-
52
+
49
53
  # Return the path to the script verb, with the right extension and parameters
50
54
  # * verb = name of the verb (view, edit,...)
51
55
  # * parameters = further parameters: web.name, web.current_page, ...
52
56
  def make_verb_url(verb,*parameters)
53
57
  make_url(@web.script_prefix,verb + @web.script_extension,*parameters)
54
58
  end
55
-
59
+
60
+ # Return the path to the script verb, with the right extension and parameters
61
+ # * verb = name of the verb (view, edit,...)
62
+ # Adds current subwiki and page name
63
+ def verb_url(verb)
64
+ return make_verb_url(verb,@web.name,@web.current_page)
65
+ end
66
+
56
67
  # Return the path to the given resource. Nil and empty parameters are ignored
57
68
  # The generated url is relative to the root of the site
58
69
  def make_url(*parameters)
@@ -65,15 +76,30 @@ module Wiki2Go
65
76
  end
66
77
  result.squeeze('/')
67
78
  end
68
-
79
+
80
+ # Return an <a> tag filled in.
81
+ def link_to(url,label,follow=true)
82
+ nofollow = (follow ? '' : " rel=\"nofollow\"")
83
+ return "<a href=\"#{url}\"#{nofollow}>#{label}</a>"
84
+ end
85
+
86
+ # Return an <a target="_blank"> tag filled in.
87
+ def link_to_new_page(url,label)
88
+ return "<a href=\"#{url}\" target=\"_blank\">#{label}</a>"
89
+ end
90
+
91
+ # Return absolute URL to current page
69
92
  def absolute_url
70
93
  absolute_url_of_topic(@web.current_page)
71
94
  end
72
-
95
+
96
+ # Return absolute URL of given page
73
97
  def absolute_url_of_topic(topic)
74
98
  return @web.base_url.chop + view_page_url(@web.name,topic)
75
99
  end
76
-
100
+
101
+ # Return a link suitable for creating a new page with the rich editor, if editing is allowed
102
+ # Return the name of the page, otherwise
77
103
  def edit_link(subwiki,page,name)
78
104
  if @editable then
79
105
  return name + edit_this_link(subwiki,page,"?")
@@ -81,51 +107,115 @@ module Wiki2Go
81
107
  return name
82
108
  end
83
109
  end
84
-
110
+
111
+ # Return a link suitable for editing a page with the rich editor, if editing is allowed
112
+ # Return empty string, otherwise
85
113
  def edit_this_link(subwiki,page,name)
86
114
  if @editable then
87
- return "<a href=\"#{make_verb_url('edit',subwiki,page)}\">#{name}</a>"
115
+ return link_to(make_verb_url('edit',subwiki,page),name,false)
88
116
  else
89
117
  return ""
90
118
  end
91
119
  end
92
-
93
- def save_this_link(subwiki,page)
120
+
121
+ # Return a link suitable for creating a new page with the wiki editor, if editing is allowed
122
+ # Return the name of the page, otherwise
123
+ def wikiedit_link(subwiki,page,name)
94
124
  if @editable then
95
- return make_verb_url('save',subwiki,page)
125
+ return name + wikiedit_this_link(subwiki,page,"?")
96
126
  else
97
- return page
127
+ return name
98
128
  end
99
129
  end
100
-
101
- def verb_url(verb)
102
- return make_verb_url(verb,@web.name,@web.current_page)
130
+
131
+ # Return a link suitable for editing a page with the wiki editor, if editing is allowed
132
+ # Return empty string, otherwise
133
+ def wikiedit_this_link(subwiki,page,name)
134
+ if @editable then
135
+ return link_to(make_verb_url('wikiedit',subwiki,page),name,false)
136
+ else
137
+ return ""
138
+ end
103
139
  end
104
-
105
- def removespam_url(user)
106
- return make_verb_url('removespam',@web.name,'') + '?user=' + user
140
+
141
+ # Return a link suitable for creating a new page with the confgured editor, if editing is allowed
142
+ # Return the name of the page, otherwise
143
+ def editor_link(subwiki,page,name)
144
+ if @editable then
145
+ return editor_this_link(subwiki,page,name)
146
+ else
147
+ return name
148
+ end
107
149
  end
108
-
109
- def version_url(page)
110
- return make_verb_url('versions',@web.name,page)
150
+
151
+ # Return a link suitable for creating a new page with the confgured editor, if editing is allowed
152
+ # Return the name of the page, otherwise
153
+ def editor_link2(subwiki,page,name)
154
+ if @editable then
155
+ return name + editor_this_link(subwiki,page,"?")
156
+ else
157
+ return name
158
+ end
111
159
  end
112
-
160
+
161
+ # Return a link suitable for editing a page with the configured editor, if editing is allowed
162
+ # Return empty string, otherwise
163
+ def editor_this_link(subwiki,page,name)
164
+ if @editable then
165
+ return link_to(make_verb_url(@config.editor,subwiki,page),name,false)
166
+ else
167
+ return ""
168
+ end
169
+ end
170
+
171
+ # URL to save current page in current subwiki
113
172
  def save_url
114
- verb_url('save')
173
+ make_verb_url('save',@web.name,@web.current_page)
115
174
  end
116
-
117
- def search_link(desc)
118
- return "<a href=\"#{search_url + "?text="+desc}\">#{desc}</a>"
175
+
176
+ # Return a link suitable for saving a page, if editing is allowed
177
+ # Return page name, otherwise
178
+ # def save_this_link(subwiki,page)
179
+ # if @editable then
180
+ # return make_verb_url('save',subwiki,page)
181
+ #else
182
+ #return page
183
+ #end
184
+ #end
185
+
186
+ # URL to remove spam by user
187
+ def removespam_url(user)
188
+ return make_verb_url('removespam',@web.name,'')
119
189
  end
120
-
121
- def search_link2(desc,name)
122
- return "<a href=\"#{search_url + "?text="+desc}\">#{name}</a>"
190
+
191
+ # URL to display the different versions of a page
192
+ def versions_url(page)
193
+ return make_verb_url('versions',@web.name,page)
123
194
  end
124
-
125
- def search_url
126
- return make_verb_url('search',@web.name)
195
+
196
+ # Link to display the different versions of a page
197
+ def versions_link(page,label)
198
+ return link_to(versions_url(page),label,false)
127
199
  end
128
-
200
+
201
+ alias :version_url :versions_url
202
+ alias :version_link :versions_link
203
+
204
+ # URL to search for (optional) text
205
+ def search_url(for_text=nil)
206
+ parameter = for_text.nil? ? '' : '?text=' + CGI::escape(for_text)
207
+ return make_verb_url('search',@web.name) + parameter
208
+ end
209
+
210
+ # Link to search for given text, with (optional) label to display within link
211
+ def search_link(for_text,label=nil)
212
+ label ||= for_text
213
+ return link_to(search_url(for_text),label,false)
214
+ end
215
+
216
+ alias :search_link2 :search_link
217
+
218
+ # URL of 'recent changes' page
129
219
  def changes_url
130
220
  if @generate_html then
131
221
  return make_url(@web.name,'recent_changes.html')
@@ -133,114 +223,159 @@ module Wiki2Go
133
223
  return make_verb_url('changes',@web.name)
134
224
  end
135
225
  end
136
-
137
- def changes_link(desc)
138
- return "<a href=\"#{changes_url}\">#{desc}</a>"
139
- end
140
-
141
- def view_page_url(subwiki,page)
142
- if @generate_html then
143
- return make_url(subwiki,page + ".html")
144
- else
145
- return make_verb_url('view',subwiki,page)
146
- end
226
+
227
+ # Link to 'recent changes' page
228
+ def changes_link(label)
229
+ return link_to(changes_url,label,false)
147
230
  end
148
-
149
- def view_url(subwiki,page)
231
+
232
+ # URL to the given page in the given subwiki
233
+ # URL is relative or absolute depending on @absolute_urls setting
234
+ def view_url(subwiki,page)
150
235
  if @absolute_urls then
151
236
  return @web.base_url.chop + view_page_url(subwiki,page)
152
237
  else
153
238
  return view_page_url(subwiki,page)
154
239
  end
155
240
  end
156
-
157
241
 
158
-
242
+ # Link to view a page
159
243
  def view_link(subwiki,page,name)
160
244
  if subwiki == @web.name then
161
- return "<a href=\"#{view_url(subwiki,page)}\">#{name}</a>"
245
+ return link_to(view_url(subwiki,page),name)
162
246
  else
163
- return "<a href=\"#{view_url(subwiki,page)}\">#{subwiki}:#{name}</a>"
247
+ if page == name then
248
+ return link_to(view_url(subwiki,page),"#{subwiki}:#{name}")
249
+ else
250
+ return link_to(view_url(subwiki,page),name)
251
+ end
164
252
  end
165
253
  end
166
-
167
- def perform_link(subwiki,page,name)
168
- if @storage.exists?(File.join(subwiki,page)) then
169
- url = make_verb_url('view',subwiki,page)
170
- if subwiki == @web.name then
171
- return "<a href=\"#{url}\">#{name}</a>"
254
+
255
+ # Link to a non-wikipages
256
+ # Images are rendered inline
257
+ # .rbl pages are performed
258
+ # HTML files are linked to
259
+ # Other files are opened in a new browser window
260
+ def resource_link(subwiki,page,name)
261
+ if page =~ /^(.+)\.(gif|jpg|jpeg|png)$/i then
262
+ filename = $1
263
+ alt_label = name
264
+ if page == name || url?(name) then
265
+ alt_label = filename
266
+ end
267
+ image_link = "<img src=\"#{resource_url(page)}\" border=0 alt=\"#{alt_label}\" >"
268
+ if url?(name) then
269
+ return redirect_link(image_link,name)
172
270
  else
173
- return "<a href=\"#{url}\">#{subwiki}:#{name}</a>"
271
+ return image_link
174
272
  end
175
- else
176
- return edit_link(subwiki,page,name)
273
+ elsif page =~ /^(.*)\.rbl$/i then
274
+ page_name = $1
275
+ if page == name then
276
+ name = page_name
277
+ end
278
+ return perform_link(subwiki,page,name)
279
+ elsif page =~ /^(.+)\.html?$/i then
280
+ return link_to(resource_url(page),name)
281
+ else
282
+ return link_to_new_page(resource_url(page),name)
177
283
  end
178
284
  end
179
285
 
180
- def view_version_link(subwiki,page,name,parameters=nil)
181
- return "<a href=\"#{view_version_url(subwiki,page)+query_string(parameters)}\">#{name}</a>"
286
+ # URL to a specific version of a page
287
+ def view_version_url(subwiki,page,version)
288
+ return make_verb_url('view',subwiki,page)+query_string( 'version' => version )
182
289
  end
183
-
184
- def view_version_url(subwiki,page)
185
- return make_verb_url('view',subwiki,page)
290
+
291
+ # Link to a specific version of a page
292
+ def view_version_link(subwiki,page,name,version)
293
+ return link_to(view_version_url(subwiki,page,version),name)
186
294
  end
187
-
188
- def query_string(parameters)
189
- return "" if parameters.nil?
190
- return "?" + parameters.collect { |key,value| key + '=' + value}.sort.join('&')
295
+
296
+ # URL to diff page versions
297
+ def diff_url(subwiki,page,from,to)
298
+ params = Hash.new
299
+ params['from'] = from if from >= 0
300
+ params['to'] = to if to >= 0
301
+ return make_verb_url('diff',subwiki,page)+query_string( params )
191
302
  end
192
-
193
- def version_link(page,name)
194
- return "<a href=\"#{version_url(page)}\">#{name}</a>"
303
+
304
+ # Link to page version
305
+ def diff_link(subwiki,page,name,from,to)
306
+ return link_to(diff_url(subwiki,page,from,to),name,false) if from == -1 && to == -1
307
+ return '' if from < 0
308
+ return '' if from >= to
309
+
310
+ return link_to(diff_url(subwiki,page,from,to),name,false)
195
311
  end
196
-
312
+
313
+ # URL to side by side view of two page versions
314
+ def sidebyside_url(subwiki,page,from,to)
315
+ params = Hash.new
316
+ params['from'] = from if from >= 0
317
+ params['to'] = to if to >= 0
318
+ return make_verb_url('sidebyside',subwiki,page)+query_string( params )
319
+ end
320
+
321
+ # Link to side by side view of two page versions
322
+ def sidebyside_link(subwiki,page,name,from,to)
323
+ return link_to(sidebyside_url(subwiki,page,from,to),name,false) if from == -1 && to == -1
324
+ return '' if from < 0
325
+ return '' if from >= to
326
+
327
+ return link_to(sidebyside_url(subwiki,page,from,to),name,false)
328
+ end
329
+
330
+ # Link to admin page
197
331
  def admin_link(page,name)
198
- return "<a href=\"#{make_verb_url('admin',page)}\">#{name}</a>"
332
+ return link_to(make_verb_url('admin',page),name)
199
333
  end
200
-
201
-
334
+
335
+
202
336
  def redirect_url(url)
203
337
  if @config.redirect_url?(@web,url) then
204
- redirected_url = make_verb_url('redirect',@web.name) + "?url=" + CGI::escape(url)
205
- return redirected_url
338
+ return make_verb_url('redirect',@web.name) + "?url=" + CGI::escape(url)
206
339
  else
207
340
  return url
208
341
  end
209
342
  end
210
-
343
+
211
344
  def redirect_link(label,url)
212
345
  if @config.redirect_url?(@web,url) then
213
- redirected_url = redirect_url(url)
214
- return "<a href=\"#{redirected_url}\" rel=\"nofollow\" target=\"_blank\">#{label}</a>"
346
+ return "<a href=\"#{redirect_url(url)}\" rel=\"nofollow\" target=\"_blank\">#{label}</a>"
215
347
  else
216
- return "<a href=\"#{url}\" target=\"_blank\">#{label}</a>"
348
+ return link_to_new_page(url,label)
217
349
  end
218
-
350
+
351
+ end
352
+
353
+ def escape_spaces(name)
354
+ name.gsub(/ /,'%20')
219
355
  end
220
356
 
221
-
357
+ # URL to a static resource (under the html subdirectory of the site)
222
358
  def resource_url(name)
223
359
  if @absolute_urls then
224
- @web.base_url.chop + make_url('html',@web.name,name)
360
+ @web.base_url.chop + make_url('html',@web.name,escape_spaces(name))
225
361
  else
226
- make_url('html',@web.name,name)
362
+ make_url('html',@web.name,escape_spaces(name))
227
363
  end
228
364
  end
229
-
365
+
366
+ # Encode a mail address with javascript, so that it isn't harvestable
230
367
  def encode_mail_to(addr)
231
-
232
368
  addr =~ /(.*)@(.*)/ ;
233
369
  name = $1 ;
234
370
  site = $2 ;
235
-
236
- return "<a href=\"#{view_url(@web.name,"MailFormattingRules")}\" onmouseover=\"this.href='mai' + 'lto:' + '#{name}' + '&#64;' + '#{site}'\">#{name}</a>"
371
+ return "<a href=\"#{view_url(@web.name,"MailFormattingRules")}\" rel=\"nofollow\" onmouseover=\"this.href='mai' + 'lto:' + '#{name}' + '&#64;' + '#{site}'\">#{name}</a>"
237
372
  end
238
-
373
+
239
374
  alias :encodeMailTo :encode_mail_to
240
-
375
+
241
376
  private
242
-
243
-
377
+
378
+
244
379
  def append(before,match,after)
245
380
  result = ''
246
381
  result += before if !before.nil?
@@ -248,21 +383,67 @@ module Wiki2Go
248
383
  result += after if !after.nil?
249
384
  result
250
385
  end
251
-
386
+
387
+ def format_tags(text)
388
+ original = text.dup
389
+ fragments = []
390
+ while ! text.nil? && text.length > 0
391
+ if text =~ /<(\S[^>]*)\>/ then
392
+ before,match,text = $`,$1,$'
393
+ fragments << format_wiki_markup(before)
394
+ fragments << escape_url_markers(format_tag(match))
395
+ else
396
+ fragments << format_wiki_markup(text)
397
+ break
398
+ end
399
+ end
400
+
401
+ fragments.join
402
+ end
403
+
252
404
  def format_tag(text)
253
- text = text.gsub(/"((http|ftp|gopher|news|https)\:[^"]*)"/) { externalUrl($1) }
254
-
405
+ text = text.gsub(/ target="_blank"/,'')
406
+ text = text.gsub(/^a (.*)"((http|ftp|gopher|news|https)\:[^"]*)"(.*)/i) { "a " + $1 + external_url($2) + $4 }
407
+
255
408
  return '<' + text + '>'
256
409
  end
257
-
258
-
410
+
411
+ # Relative URL to the given page in the given subwiki
412
+ def view_page_url(subwiki,page)
413
+ if @generate_html && !Page.is_dynamic?(page) then
414
+ return make_url(subwiki,page + ".html")
415
+ else
416
+ return make_verb_url('view',subwiki,page)
417
+ end
418
+ end
419
+
420
+ def perform_link(subwiki,page,name)
421
+ if @storage.exists?(File.join(subwiki,page)) then
422
+ url = make_verb_url('view',subwiki,page)
423
+ if subwiki == @web.name then
424
+ return link_to(url,name)
425
+ else
426
+ return link_to(url,"#{subwiki}:#{name}")
427
+ end
428
+ else
429
+ return editor_link2(subwiki,page,name)
430
+ end
431
+ end
432
+
433
+ def query_string(parameters)
434
+ return "" if parameters.nil? || parameters.size == 0
435
+ return "?" + parameters.collect { |key,value| key.to_s + '=' + CGI::escape(value.to_s)}.sort.join('&amp;')
436
+ end
437
+
438
+
439
+
259
440
  def format_wiki_markup(line)
260
441
  if line =~ /^(.*)\{\!(.*)\!\}(.*)$/im then
261
442
  before,match,after = $1,$2,$3
262
443
  return append(format_wiki_markup(before),match,format_wiki_markup(after))
263
- elsif line =~ /^(.*)<(\S.*)\>(.*)$/ then
264
- before,match,after = $1,$2,$3
265
- line = append(format_wiki_markup(before),escape_url_markers(format_tag(match)),format_wiki_markup(after))
444
+ # elsif line =~ /^(.*)<(\S.*)\>(.*)$/ then
445
+ # before,match,after = $1,$2,$3
446
+ # line = append(format_wiki_markup(before),escape_url_markers(format_tag(match)),format_wiki_markup(after))
266
447
  elsif line =~ /^(.*)\{\%([^\}]*)\%\}(.*)$/ then
267
448
  before,match,after = $1,$2,$3
268
449
  line = append(format_wiki_markup(before),escape_url_markers(format_dynamic_link(match)),format_wiki_markup(after))
@@ -274,34 +455,32 @@ module Wiki2Go
274
455
  line = append(format_wiki_markup(before),escape_url_markers(format_forced_link(match)),format_wiki_markup(after))
275
456
  elsif line =~ /^(.*)((http|ftp|gopher|news|https)\:\/\/(\w|\/|\.|_|-|\?|\=|&|;|\~|#|,)+)(.*)$/ then
276
457
  before,match,after = $1,$2,$5
277
- line = append(format_wiki_markup(before),escape_url_markers(external_link(match)),format_wiki_markup(after))
458
+ line = append(format_wiki_markup(before),escape_url_markers(external_link(nil,match)),format_wiki_markup(after))
278
459
  elsif line =~ /^(.*)mailto\:([a-zA-Z0-9\-\_\.]+@[a-zA-Z0-9\-\_\.]+)(.*)$/ then
279
460
  before,match,after = $1,$2,$3
280
461
  line = append(format_wiki_markup(before),escape_url_markers(encode_mail_to(match)),format_wiki_markup(after))
281
462
  else
282
463
  line = format_brackets(line)
283
464
  line = format_entities(line)
284
- line = recognize_wiki_words(line)
465
+ line = format_wiki_words(line)
285
466
  end
286
- line = format_bullets(line)
287
- line = format_markup(line)
288
467
  return line
289
468
  end
290
-
469
+
291
470
  def formatted_output(line)
292
471
  output = @pre_line + line + @post_line
293
472
  @pre_line = ""
294
473
  @post_line = ""
295
474
  return output
296
475
  end
297
-
298
-
476
+
477
+
299
478
  def escape_wiki_markers(line)
300
479
  line = line.gsub(/%%/,"&percent;")
301
480
  line = line.gsub(/\{\{/,"&openingbrace;")
302
481
  line = line.gsub(/\}\}/,"&closingbrace;")
303
482
  end
304
-
483
+
305
484
  def escape_url_markers(line)
306
485
  line = line.gsub(/%/ ,'&percent;')
307
486
  line = line.gsub(/\{/,'&openingbrace;')
@@ -311,7 +490,7 @@ module Wiki2Go
311
490
  line = line.gsub(/_/ ,'&underscore;')
312
491
  return line
313
492
  end
314
-
493
+
315
494
  def remove_markers(line)
316
495
  line = line.gsub(/&percent;/,"%")
317
496
  line = line.gsub(/&openingbrace;/,"{")
@@ -321,14 +500,14 @@ module Wiki2Go
321
500
  line = line.gsub(/&underscore;/,"_")
322
501
  return line
323
502
  end
324
-
325
-
503
+
504
+
326
505
  def format_brackets(line)
327
506
  line = line.gsub(/</,"&lt\;") ;
328
507
  line = line.gsub(/>/,"&gt\;") ;
329
508
  return line
330
509
  end
331
-
510
+
332
511
  def format_entities(line)
333
512
  line = line.gsub(/\~/,"&tilde;") ;
334
513
  line = line.gsub(/&(\w+)\;/,"~\\1\;") ;
@@ -338,7 +517,7 @@ module Wiki2Go
338
517
  line = line.gsub(/\t/," ") ;
339
518
  return line
340
519
  end
341
-
520
+
342
521
  def format_markup(line)
343
522
  line = line.gsub(/\*\*([^\*]*)\*\*/,"<h2>\\1<\/h2>")
344
523
  line = line.gsub(/\*([^\*]+)\*/,"<STRONG>\\1<\/STRONG>")
@@ -346,13 +525,13 @@ module Wiki2Go
346
525
  line = line.gsub(/^---+/,"<hr>")
347
526
  return line
348
527
  end
349
-
528
+
350
529
  def format_bullets(line)
351
530
  line = line.gsub(/^([\s]{3,99})\*(.*)$/) { add_bullet($1,$2,'u') }
352
531
  line = line.gsub(/^([\s]{3,99})(\d)+\.?(.*)$/) { add_bullet($1,$3,'o') }
353
532
  return line
354
533
  end
355
-
534
+
356
535
  def format_table(line)
357
536
  if @in_table then
358
537
  replacement = "</table>"
@@ -370,59 +549,52 @@ module Wiki2Go
370
549
  line = line.gsub(/\|/,"<\/td><td>")
371
550
  end
372
551
  return line
373
-
552
+
374
553
  end
375
-
376
- def recognize_wiki_words(line)
377
- line = line.gsub(/(^|[^\w\.])([A-Z]+[a-z0-9]+[A-Z]+[a-zA-Z0-9]*)/) { $1 + internalLink($2) }
378
-
554
+
555
+ def format_wiki_words(line)
556
+ line = line.gsub(/(^|[^\w\.])([A-Z]+[a-z0-9]+[A-Z]+[a-zA-Z0-9]*)/) { $1 + format_wiki_word($2) }
557
+
379
558
  end
380
-
381
- def external_link(url)
559
+
560
+ def external_link(label,url)
382
561
  if url =~ /([^\/]+)\.(gif|jpg|jpeg|png)$/i then
383
- alt = $1
562
+ alt = label || $1
384
563
  return "<img src=\"#{url}\" alt=\"#{alt}\">"
385
564
  else
386
- return redirect_link(url,url)
565
+ return redirect_link(label || url,url)
387
566
  end
388
567
  end
389
-
390
- def externalUrl(url)
568
+
569
+ def external_url(url)
391
570
  return '"' + redirect_url(url) + (@config.redirect_url?(@web,url) ? '" rel="nofollow"' : '"') +' target="_blank"'
392
571
  end
393
-
572
+
394
573
  def format_forced_link(link)
395
- if ! link.gsub!(/^([^%@]+)@(http[^%]+)$/) { labelLink($1,$2) } then
396
- link.gsub!(/^(([^\%@]+)@)?(([^\%:]+):)?([^%]+)$/) { mega_link($2,$4,$5,@web.name) }
574
+ if ! link.gsub!(/^([^@]+)@(http.+)$/) { external_link($1,$2) } then
575
+ link.gsub!(/^(([^@]+)@)?(([^:]+):)?(.+)$/) { internal_link($2,$4,$5) }
397
576
  end
398
577
  link
399
578
  end
400
-
401
- def format_dynamic_link(link)
402
- return link.gsub(/^(([^\%@]+)@)?(([^\%:]+):)?([^%]+)$/) { dynamic_link($2,$4,$5,@web.name) }
403
- end
404
-
405
- def labelLink(label,url)
406
- return redirect_link(label,url)
407
- end
408
-
409
- def internalLink(page)
410
- return internalSubwikiNamedLink(@web.name,page,page)
579
+
580
+ def format_wiki_word(word)
581
+ internal_link(word,@web.name,word)
411
582
  end
412
-
413
- def mega_link(name,subwiki,page,default_wiki)
414
- name = page if name.nil? || name.empty?
415
- subwiki = default_wiki if subwiki.nil? || subwiki.empty?
416
- internalSubwikiNamedLink(subwiki,page,name)
583
+
584
+ def format_dynamic_link(link)
585
+ return link.gsub(/^(([^\%@]+)@)?(([^\%:]+):)?([^%]+)$/) { dynamic_link($2,$4,$5) }
417
586
  end
418
-
419
- def dynamic_link(name,subwiki,page,default_wiki)
420
- name = page if name.nil? || name.empty?
421
- subwiki = default_wiki if subwiki.nil? || subwiki.empty?
422
- perform_link(subwiki,page+'.rbl',name)
587
+
588
+ def dynamic_link(label,subwiki,page)
589
+ label = page if label.nil? || label.empty?
590
+ subwiki = @web.name if subwiki.nil? || subwiki.empty?
591
+ perform_link(subwiki,page+'.rbl',label)
423
592
  end
424
-
425
- def internalSubwikiNamedLink(subwiki,page,name)
593
+
594
+ def internal_link(label,subwiki,page)
595
+ label = page if label.nil? || label.empty?
596
+ subwiki = @web.name if subwiki.nil? || subwiki.empty?
597
+
426
598
  if subwiki == "xpnl" then
427
599
  return "<a href=\"http://www.xpnl.org/Wiki/#{page}\" target=\"_blank\">xpnl:#{page}</a>"
428
600
  elsif subwiki == 'xpbe' then
@@ -431,49 +603,25 @@ module Wiki2Go
431
603
  return "<a href=\"http://c2.com/cgi/wiki?#{page}\" target=\"_blank\">wiki:#{page}</a>"
432
604
  elsif subwiki == "book" then
433
605
  return "<a href=\"http://bookshelved.org/cgi-bin/wiki.pl?#{page}\" target=\"_blank\">book:#{page}</a>"
606
+ elsif subwiki == 'technorati' then
607
+ return "<a href=\"http://technorati.com/tag/#{page}\" target=\"_blank\" rel=\"tag\">#{label}</a>"
434
608
  elsif subwiki == "wiki2go" then
435
609
  return "<a href=\"http://wiki2go.nayima.be/Wiki2Go/#{page}.html\" target=\"_blank\">wiki2go:#{page}</a>"
436
610
  elsif subwiki =~ /^isbn$/i then
437
- name = "ISBN " + page if page == name
438
- return "<a href=\"http://www.amazon.co.uk/exec/obidos/ASIN/#{page}/#{@config.amazon_affiliate}\" target=\"_blank\">#{name}</a>"
611
+ label = "ISBN " + page if page == label
612
+ return "<a href=\"http://www.amazon.co.uk/exec/obidos/ASIN/#{page}/#{@config.amazon_affiliate}\" target=\"_blank\">#{label}</a>"
439
613
  elsif page =~ /^isbn(.+)$/i then
440
- name = "ISBN " + $1 if page == name
441
- return "<a href=\"http://www.amazon.co.uk/exec/obidos/ASIN/#{$1}/#{@config.amazon_affiliate}\" target=\"_blank\">#{name}</a>"
614
+ label = "ISBN " + $1 if page == label
615
+ return "<a href=\"http://www.amazon.co.uk/exec/obidos/ASIN/#{$1}/#{@config.amazon_affiliate}\" target=\"_blank\">#{label}</a>"
442
616
  elsif page =~ /\./ then
443
- return resource_link(subwiki,page,name)
617
+ return resource_link(subwiki,page,label)
444
618
  elsif @storage.exists?(File.join(subwiki,page)) then
445
- return view_link(subwiki,page,name)
446
- else
447
- return edit_link(subwiki,page,name)
448
- end
449
- end
450
-
451
- def resource_link(subwiki,page,name)
452
- if page =~ /^(.+)\.(gif|jpg|jpeg|png)$/i then
453
- filename = $1
454
- alt_label = name
455
- if page == name || url?(name) then
456
- alt_label = filename
457
- end
458
- image_link = "<img src=\"#{resource_url(page)}\" border=0 alt=\"#{alt_label}\" >"
459
- if url?(name) then
460
- return redirect_link(image_link,name)
461
- else
462
- return image_link
463
- end
464
- elsif page =~ /^(.*)\.rbl$/i then
465
- page_name = $1
466
- if page == name then
467
- name = page_name
468
- end
469
- return perform_link(subwiki,page,name)
470
- elsif page =~ /^(.+)\.html?$/i then
471
- return "<a href=\"#{resource_url(page)}\">#{name}</a>"
619
+ return view_link(subwiki,page,label)
472
620
  else
473
- return "<a href=\"#{resource_url(page)}\" target=\"_blank\">#{name}</a>"
621
+ return editor_link2(subwiki,page,label)
474
622
  end
475
623
  end
476
-
624
+
477
625
  def add_bullet(prefix,text,code)
478
626
  @added_bullets = true
479
627
  depth = prefix.length / 3
@@ -497,18 +645,18 @@ module Wiki2Go
497
645
  end
498
646
  return result + "<li>#{text}"
499
647
  end
500
-
648
+
501
649
  def emit_bullets
502
650
  while ! @bullets.empty?
503
651
  bullet = @bullets.pop
504
652
  @pre_line += "</#{bullet}l>"
505
653
  end
506
654
  end
507
-
655
+
508
656
  def url?(name)
509
657
  name =~ /(http|ftp|gopher|news|https)\:(\w|\/|\.|_|-|\?|\=|&|;|\~|#|,)+/
510
658
  end
511
-
659
+
512
660
  end
513
-
661
+
514
662
  end