cewebs-didaktiki 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/AUTHORS +1 -0
- data/LICENSE.GPL +674 -0
- data/README.md +15 -0
- data/Rakefile +25 -0
- data/cewebs-didaktiki.gemspec +26 -0
- data/lib/cewebs-didaktiki/administration.rb +48 -0
- data/lib/cewebs-didaktiki/delivery.rb +253 -0
- data/lib/cewebs-didaktiki/helpers/access.rb +67 -0
- data/lib/cewebs-didaktiki/helpers/encoding.rb +24 -0
- data/lib/cewebs-didaktiki/helpers/export.rb +73 -0
- data/lib/cewebs-didaktiki/helpers/grammar_didaktiki.rb +426 -0
- data/lib/cewebs-didaktiki/helpers/grammar_rename.rb +30 -0
- data/lib/cewebs-didaktiki/helpers/output_latex.rb +294 -0
- data/lib/cewebs-didaktiki/helpers/output_rename.rb +19 -0
- data/lib/cewebs-didaktiki/helpers/output_xhtml.rb +423 -0
- data/lib/cewebs-didaktiki/helpers/parser.rb +8 -0
- data/lib/cewebs-didaktiki/helpers/views.rb +306 -0
- data/lib/cewebs-didaktiki/helpers/wiki_storage.rb +334 -0
- data/lib/cewebs-didaktiki/implementation.rb +21 -0
- data/lib/cewebs-didaktiki/implementation.xml +14 -0
- data/server/data/Default/aman.xml +35 -0
- data/server/data/Default/custom.rng +134 -0
- data/server/data/Default/custom.xml +10 -0
- data/server/data/Default/persons.rng +106 -0
- data/server/data/Default/persons.xml +1 -0
- data/server/data/Default/strings.rng +88 -0
- data/server/data/Default/strings.xml +148 -0
- data/server/data/repositories.xml +3 -0
- data/server/didaktiki +15 -0
- data/server/service.xml +14 -0
- data/test/tc_html.rb +88 -0
- data/tools/cewebs-didaktiki +24 -0
- metadata +117 -0
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
# Please see the LICENSE.GPL file for copyright and distribution information
|
|
2
|
+
module Didaktiki
|
|
3
|
+
# Names of pages and objects are markup, so they are always returned from blocks.
|
|
4
|
+
class View < CEWebS::View
|
|
5
|
+
def initialize(c)
|
|
6
|
+
@c = c
|
|
7
|
+
@strings = c.strings
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def s(name); @strings.sfind(name); end
|
|
11
|
+
|
|
12
|
+
def message(name); div_ s(name); end
|
|
13
|
+
|
|
14
|
+
# pages that contain links to the current one, most important first
|
|
15
|
+
def backlink_names #{{{
|
|
16
|
+
doc = XML::Smart.open(File.join(@c.path,'linking.xml'))
|
|
17
|
+
doc.find("/main/page[link/@name=\"#{@c.storage.subject}\"]").map { |e|
|
|
18
|
+
[e.find('count(*)').to_i,Time.parse(e.attributes['modified']).to_i,e.attributes['name']]
|
|
19
|
+
}.sort.reverse.map { |e| Wiki::Encoding::unescape(e[2]) }
|
|
20
|
+
end #}}}
|
|
21
|
+
|
|
22
|
+
def show(content,text,conflict) #{{{
|
|
23
|
+
div_ s('conflict'), :class => 'urgent' if conflict
|
|
24
|
+
links = backlink_names
|
|
25
|
+
if links.any? || @c.compartment != ''
|
|
26
|
+
max = @c.custom.find('number(/custom/backlinks/@count)').to_i
|
|
27
|
+
size = @c.custom.find('number(/custom/backlinks/@size)').to_i
|
|
28
|
+
div_ :class => 'align-right border-bottom margin-bottom-huge' do
|
|
29
|
+
text_ @c.compartment + ' '
|
|
30
|
+
links.first(max).each do |name|
|
|
31
|
+
short = ReDel::XHTML::unweb(name)
|
|
32
|
+
short = "#{short[0,size-7]}...#{short[-3..-1]}" if short.length > size && size > 7
|
|
33
|
+
a_peg_ short, :href => @c.link('show',name)
|
|
34
|
+
end
|
|
35
|
+
a_peg_ '...', :href => @c.link('backlinks') if links.length > max
|
|
36
|
+
nil
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
text_ content
|
|
40
|
+
div_ :class => 'float-off'
|
|
41
|
+
words = text.scan(/[[:alnum:]]+/).length
|
|
42
|
+
div_(:class => 'margin-top-huge border-top didaktiki-page-stats') do
|
|
43
|
+
@strings.sffind('status') % [@c.storage.get_modified.strftime(s('statusdate')), words]
|
|
44
|
+
end
|
|
45
|
+
discuss_script
|
|
46
|
+
end #}}}
|
|
47
|
+
|
|
48
|
+
# the form is moved to whatever is discussed
|
|
49
|
+
def discuss_script #{{{
|
|
50
|
+
div_ :id => 'discuss_form', :class => 'invisible' do
|
|
51
|
+
form_ :id => 'CEWebS_discuss', :action => @c.link('discuss'), :method => 'post' do
|
|
52
|
+
input_ :type => 'hidden', :name => 'CEWebS_id', :value => ''
|
|
53
|
+
div_ { input_ :class => 'size-max border', :type => 'text', :name => 'CEWebS_comment', :value => '' }
|
|
54
|
+
div_ { input_ :type => 'submit', :value => h(s('submit')) }
|
|
55
|
+
nil
|
|
56
|
+
end
|
|
57
|
+
nil
|
|
58
|
+
end
|
|
59
|
+
javascript_ <<~end
|
|
60
|
+
function discuss(id) {
|
|
61
|
+
var form = document.getElementById('CEWebS_discuss');
|
|
62
|
+
form.elements['CEWebS_id'].value = id;
|
|
63
|
+
document.getElementById('discuss_' + id).appendChild(form);
|
|
64
|
+
form.elements['CEWebS_comment'].focus();
|
|
65
|
+
}
|
|
66
|
+
end
|
|
67
|
+
end #}}}
|
|
68
|
+
|
|
69
|
+
def diff(changes) #{{{
|
|
70
|
+
classes = { :add => 'background-baseB', :del => 'background-baseA line-through' }
|
|
71
|
+
changes.each do |type,text|
|
|
72
|
+
type == :same ? lines(text) : span_(:class => classes[type]) { lines(text) }
|
|
73
|
+
end
|
|
74
|
+
nil
|
|
75
|
+
end #}}}
|
|
76
|
+
def lines(text) #{{{
|
|
77
|
+
text.split("\n",-1).each_with_index do |line,i|
|
|
78
|
+
br_ if i > 0
|
|
79
|
+
text_ line
|
|
80
|
+
end
|
|
81
|
+
nil
|
|
82
|
+
end #}}}
|
|
83
|
+
|
|
84
|
+
def backlinks #{{{
|
|
85
|
+
h1_ { h(s('backlinks')) % capture { a_(:href => @c.link('show')) { @c.what } } }
|
|
86
|
+
links = backlink_names
|
|
87
|
+
return div_(s('backlinksempty')) if links.empty?
|
|
88
|
+
ul_ do
|
|
89
|
+
links.each { |name| li_ { a_(:href => @c.link('show',name)) { name }; nil } }
|
|
90
|
+
nil
|
|
91
|
+
end
|
|
92
|
+
end #}}}
|
|
93
|
+
|
|
94
|
+
def pages #{{{
|
|
95
|
+
doc = XML::Smart.open(File.join(@c.path,'linking.xml'))
|
|
96
|
+
exceptions = @c.custom.find('/custom/exceptions/exception').map { |e| Wiki::Encoding::escape(e.to_s) }
|
|
97
|
+
linked = doc.find('/main/page/link/@name').map(&:to_s)
|
|
98
|
+
cell = { :class => 'margin-left-big margin-right-big' }
|
|
99
|
+
|
|
100
|
+
div_(:class => 'margin-top-huge') { @strings.sffind('pagesintro') }
|
|
101
|
+
div_ { a_ s('exportwiki'), :href => @c.link('exportwiki',nil,'file'); nil }
|
|
102
|
+
table_ :id => 'pages', :class => 'margin-top-huge' do
|
|
103
|
+
thead_ do
|
|
104
|
+
tr_ do
|
|
105
|
+
['header_name','header_author','header_changed','plock_short','alock_short','header_orphan'].each { |n| th_ s(n), :class => 'border' }
|
|
106
|
+
nil
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
tbody_ do
|
|
110
|
+
list = doc.find('/main/page').sort_by { |e| Wiki::Encoding::unescape(e.attributes['name']).downcase }
|
|
111
|
+
list.each do |ele|
|
|
112
|
+
name = Wiki::Encoding::unescape(ele.attributes['name'])
|
|
113
|
+
page = @c.storage(name).get_page
|
|
114
|
+
tr_ do
|
|
115
|
+
td_ cell do
|
|
116
|
+
page ? a_(:href => @c.link('show',name)) { name } : text_(name)
|
|
117
|
+
nil
|
|
118
|
+
end
|
|
119
|
+
td_ ele.attributes['user'].to_s, cell
|
|
120
|
+
td_ Time.parse(ele.attributes['modified']).strftime(s('pagesmodified')), cell
|
|
121
|
+
td_ page && page.meta['plock'] ? 'X' : '', cell
|
|
122
|
+
td_ page && page.meta['alock'] ? 'X' : '', cell
|
|
123
|
+
td_ cell do
|
|
124
|
+
unless linked.include?(ele.attributes['name']) || exceptions.include?(ele.attributes['name'])
|
|
125
|
+
span_ s('orphan'), :class => 'urgent'
|
|
126
|
+
space_
|
|
127
|
+
a_peg_ s('delete'), :onclick => "return confirm('#{h(s('deletewarn'))}');", :href => @c.link('delete',name), :'data-post' => 'true'
|
|
128
|
+
end
|
|
129
|
+
nil
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
tr_ { td_ { em_ s('pagesempty'); nil }; nil } if list.empty?
|
|
134
|
+
nil
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end #}}}
|
|
138
|
+
|
|
139
|
+
def versions #{{{
|
|
140
|
+
div_(:class => 'margin-bottom-huge') { @strings.sffind('versionsintro') }
|
|
141
|
+
div_(:class => 'margin-bottom-big') { @strings.sffind('diffdesc') }
|
|
142
|
+
current = @c.storage.current
|
|
143
|
+
cell = { :class => 'margin-left-huge' }
|
|
144
|
+
form_ :action => @c.link('diff'), :method => 'post' do
|
|
145
|
+
div_(:class => 'margin-bottom-huge') { input_ :type => 'submit', :value => s('diff') }
|
|
146
|
+
table_ do
|
|
147
|
+
thead_ do
|
|
148
|
+
tr_ do
|
|
149
|
+
td_
|
|
150
|
+
td_ s('difffrom'), cell
|
|
151
|
+
td_ s('diffto'), cell
|
|
152
|
+
td_
|
|
153
|
+
td_
|
|
154
|
+
nil
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
tbody_ do
|
|
158
|
+
@c.storage.get_history(@c.custom.find('number(/custom/revisions)').to_i).reverse_each do |ele|
|
|
159
|
+
tr_ do
|
|
160
|
+
td_(:class => 'margin-left-huge nowrap') do
|
|
161
|
+
text_ h(s('revision')) + ' '
|
|
162
|
+
a_ ele.rev, :href => @c.link('versionshow') + "&CEWebS_rev=#{ele.rev}"
|
|
163
|
+
end
|
|
164
|
+
td_(cell) { input_ :type => 'radio', :name => 'CEWebS_from', :value => ele.rev, :checked => (ele.rev == current ? 'checked' : nil) }
|
|
165
|
+
td_(cell) { input_ :type => 'radio', :name => 'CEWebS_to', :value => ele.rev, :checked => (ele.rev == current-1 || current == 1 ? 'checked' : nil) }
|
|
166
|
+
td_ Time.parse(ele.modified).strftime(s('statusdate')), cell
|
|
167
|
+
td_(cell) do
|
|
168
|
+
text_ h("#{ele.user} - #{ele.comment} ")
|
|
169
|
+
span_ "(#{ele.action})", :class => 'urgent' if ele.action
|
|
170
|
+
nil
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
nil
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
end #}}}
|
|
179
|
+
|
|
180
|
+
def edit(text,active) #{{{
|
|
181
|
+
storage = @c.storage
|
|
182
|
+
page = storage.get_page
|
|
183
|
+
meta = page ? page.meta : { 'plock' => @c.compartment != '' }
|
|
184
|
+
text = page ? page.data : "== #{@c.what}\n\n\n" if text.to_s == ''
|
|
185
|
+
eid = @c.r.raw('eid').to_s =~ /\A\h{32}\z/ ? @c.r.raw('eid') : CEWebS::key
|
|
186
|
+
|
|
187
|
+
hidden = lambda do |*names|
|
|
188
|
+
input_ :type => 'hidden', :name => 'CEWebS_rev', :value => storage.current
|
|
189
|
+
input_ :type => 'hidden', :name => 'CEWebS_eid', :value => eid
|
|
190
|
+
names.each { |n| input_ :type => 'hidden', :name => "CEWebS_#{n}", :value => '' }
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
div_ :id => 'icontent' do
|
|
194
|
+
form_ :id => 'CEWebSEdit', :action => @c.link('save'), :method => 'post' do
|
|
195
|
+
hidden.call
|
|
196
|
+
# browsers drop the first newline
|
|
197
|
+
textarea_(:id => 'CEWebS_text', :name => 'CEWebS_text', :class => 'monospace border size-max', :rows => '30', :cols => '45') { "\n" + text }
|
|
198
|
+
div_(:class => 'margin-bottom-big') { input_ :type => 'submit', :value => s('submit') }
|
|
199
|
+
div_ :class => 'margin-bottom-small' do
|
|
200
|
+
%w{help configuration images files}.each { |t| a_peg_ s(t), :href => "javascript:activate('#{t}')"; space_ }
|
|
201
|
+
nil
|
|
202
|
+
end
|
|
203
|
+
div_ :id => 'configuration', :class => 'border' do
|
|
204
|
+
{ 'plock' => 'plock', 'alock' => 'alock', 'notexport' => 'exportnotpossible', 'discussion' => 'discussion' }.each do |name,string|
|
|
205
|
+
div_ do
|
|
206
|
+
input_ :type => 'checkbox', :name => "CEWebS_#{name}", :value => 'true', :checked => (meta[name] ? 'checked' : nil)
|
|
207
|
+
text_ ' ' + h(s(string))
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
div_ :class => 'border-top' do
|
|
211
|
+
text_ h(s('name')) + ': '
|
|
212
|
+
input_ :type => 'text', :name => 'CEWebS_name', :value => @c.what
|
|
213
|
+
text_ ' ' + h(s('name_exp'))
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
width = @c.custom.find('number(/custom/object/@maxwidth)').to_i
|
|
219
|
+
objects('images','CEWebSImage','image',hidden) do
|
|
220
|
+
select_ :name => 'CEWebS_max' do
|
|
221
|
+
0.upto(7) { |i| option_ "#{width-i*width/10}#{s('imagespx')}", :value => i }
|
|
222
|
+
nil
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
objects('files','CEWebSFile','file',hidden) do
|
|
226
|
+
select_ :name => 'CEWebS_lock' do
|
|
227
|
+
option_ s('fileslocked'), :value => 'true'
|
|
228
|
+
option_ s('filesunlocked'), :value => 'false'
|
|
229
|
+
nil
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
div_(:id => 'help', :class => 'border') { @strings.sffind('helptext') }
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
javascript_ <<~end
|
|
236
|
+
function activate(on) {
|
|
237
|
+
['images','files','help','configuration'].forEach(function(id) { document.getElementById(id).style.display = (id == on ? 'block' : 'none'); });
|
|
238
|
+
}
|
|
239
|
+
function submitObject(form) {
|
|
240
|
+
document.forms[form].CEWebS_text.value = document.forms['CEWebSEdit'].CEWebS_text.value;
|
|
241
|
+
}
|
|
242
|
+
function delObject(what,form) {
|
|
243
|
+
document.forms[form].CEWebS_del.value = what;
|
|
244
|
+
submitObject(form);
|
|
245
|
+
document.forms[form].submit();
|
|
246
|
+
}
|
|
247
|
+
function changeLock(what,form,lock) {
|
|
248
|
+
document.forms[form].CEWebS_meta.value = what;
|
|
249
|
+
document.forms[form].CEWebS_meta_lock.value = lock;
|
|
250
|
+
submitObject(form);
|
|
251
|
+
document.forms[form].submit();
|
|
252
|
+
}
|
|
253
|
+
activate("#{active}");
|
|
254
|
+
end
|
|
255
|
+
end #}}}
|
|
256
|
+
|
|
257
|
+
# form for uploading something, and everything that has been uploaded
|
|
258
|
+
def objects(type,form,command,hidden) #{{{
|
|
259
|
+
cell = { :class => 'align-bottom margin-right-big' }
|
|
260
|
+
div_ :id => type do
|
|
261
|
+
form_ :id => form, :action => @c.link(command), :method => 'post', :onsubmit => "submitObject('#{form}');", :enctype => 'multipart/form-data' do
|
|
262
|
+
hidden.call('text','del','meta','meta_lock')
|
|
263
|
+
div_ :class => 'border-bottom' do
|
|
264
|
+
input_ :type => 'file', :name => 'CEWebS_file'
|
|
265
|
+
space_
|
|
266
|
+
yield
|
|
267
|
+
space_
|
|
268
|
+
input_ :type => 'submit', :value => s('submit')
|
|
269
|
+
end
|
|
270
|
+
end
|
|
271
|
+
table_ do
|
|
272
|
+
@c.storage.get_object_list(type.to_sym).each do |ele|
|
|
273
|
+
name = Wiki::Encoding::unescape(ele.data)
|
|
274
|
+
id = ele.data.gsub("'","\\\\'")
|
|
275
|
+
tr_ do
|
|
276
|
+
if type == 'files'
|
|
277
|
+
td_ cell do
|
|
278
|
+
a_(:href => "javascript:changeLock('#{id}','#{form}','#{!ele.meta['lock']}')") { small_img_ ele.meta['lock'] ? 'locked' : 'unlocked' }
|
|
279
|
+
nil
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
td_(cell) { name }
|
|
283
|
+
td_ "#{ele.meta['width']}x#{ele.meta['height']}", cell if type == 'images'
|
|
284
|
+
td_(cell) { a_peg_ s('delete'), :href => "javascript:delObject('#{id}','#{form}')" }
|
|
285
|
+
td_(:class => 'align-bottom important') { "[#{command}:#{name}|#{h(s("#{type}description"))}]" }
|
|
286
|
+
end
|
|
287
|
+
end
|
|
288
|
+
nil
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
end #}}}
|
|
292
|
+
|
|
293
|
+
def export(style,content) #{{{
|
|
294
|
+
text_ "<!DOCTYPE html>\n"
|
|
295
|
+
html_ do
|
|
296
|
+
head_ do
|
|
297
|
+
meta_ :charset => 'utf-8'
|
|
298
|
+
title_ { @c.what }
|
|
299
|
+
link_ :rel => 'stylesheet', :href => style, :type => 'text/css' if style != ''
|
|
300
|
+
nil
|
|
301
|
+
end
|
|
302
|
+
body_(:id => 'content') { content }
|
|
303
|
+
end
|
|
304
|
+
end #}}}
|
|
305
|
+
end
|
|
306
|
+
end
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
# Please see the LICENSE.GPL file for copyright and distribution information
|
|
2
|
+
require 'time'
|
|
3
|
+
require 'digest/md5'
|
|
4
|
+
require 'fileutils'
|
|
5
|
+
require 'open3'
|
|
6
|
+
require 'tmpdir'
|
|
7
|
+
require 'diff/lcs'
|
|
8
|
+
require 'xml/smart'
|
|
9
|
+
require_relative 'parser'
|
|
10
|
+
|
|
11
|
+
module Wiki
|
|
12
|
+
module Storage
|
|
13
|
+
StorageObject = Struct.new(:data,:meta,:modified)
|
|
14
|
+
RevisionObject = Struct.new(:rev,:modified,:user,:comment,:action)
|
|
15
|
+
|
|
16
|
+
# Same layout on disk as before:
|
|
17
|
+
# linking.xml, references.xml, Data/{page}/{revision}, Data/{page}/revisions.xml
|
|
18
|
+
# Data/{page}/{images|files|applets|graphs}/{name}/{revision}
|
|
19
|
+
class Simple
|
|
20
|
+
attr_reader :path, :current, :subject, :name, :cpath
|
|
21
|
+
|
|
22
|
+
def self::words(text)
|
|
23
|
+
text.scan(/[^.,()='"\[\]:;!?{}&\t\n\r ]+|[.,()='"\[\]:;!?{}&\t\n\r ]/)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def initialize(path,subject) #{{{
|
|
27
|
+
@path = path.to_s
|
|
28
|
+
FileUtils.mkdir_p(File.join(@path,'Data'))
|
|
29
|
+
File.write(linking,'<main/>') unless File.exist?(linking)
|
|
30
|
+
|
|
31
|
+
@name = subject.to_s
|
|
32
|
+
@subject = Wiki::Encoding::escape(@name)
|
|
33
|
+
@cpath = File.join(@path,'Data',@subject) + '/'
|
|
34
|
+
@current = File.exist?(revisions) ? XML::Smart.open(revisions).find('count(/revisions/revision)').to_i : 0
|
|
35
|
+
end #}}}
|
|
36
|
+
|
|
37
|
+
def new?; @current == 0; end
|
|
38
|
+
|
|
39
|
+
### pages
|
|
40
|
+
|
|
41
|
+
def get_page(rev=@current) #{{{
|
|
42
|
+
fname = @cpath + rev.to_i.to_s
|
|
43
|
+
return nil unless File.exist?(fname)
|
|
44
|
+
node = revision(rev)
|
|
45
|
+
StorageObject.new(
|
|
46
|
+
File.read(fname),
|
|
47
|
+
node ? meta_of(node) : {},
|
|
48
|
+
node ? Time.parse(node.attributes['modified']) : nil
|
|
49
|
+
)
|
|
50
|
+
end #}}}
|
|
51
|
+
|
|
52
|
+
def del_page #{{{
|
|
53
|
+
return false unless File.exist?(@cpath)
|
|
54
|
+
XML::Smart.modify(linking) do |doc|
|
|
55
|
+
touch doc.find("/main/page[link/@name=\"#{@subject}\"]/@name")
|
|
56
|
+
touch doc.find("/main/page[@name=\"#{@subject}\"]/*/@name")
|
|
57
|
+
doc.find("/main/page[@name=\"#{@subject}\"]").delete_all!
|
|
58
|
+
end
|
|
59
|
+
FileUtils.rm_rf(@cpath)
|
|
60
|
+
true
|
|
61
|
+
end #}}}
|
|
62
|
+
|
|
63
|
+
def move_page(new,user) #{{{
|
|
64
|
+
subject = Wiki::Encoding::escape(new)
|
|
65
|
+
npath = File.join(@path,'Data',subject) + '/'
|
|
66
|
+
return @name if File.exist?(npath) || !File.exist?(@cpath)
|
|
67
|
+
|
|
68
|
+
# no modify, because add_page writes linking.xml
|
|
69
|
+
doc = XML::Smart.open(linking)
|
|
70
|
+
doc.find("/main/page[link/@name=\"#{@subject}\"]/@name").map(&:to_s).each do |par|
|
|
71
|
+
storage = Simple.new(@path,Wiki::Encoding::unescape(par))
|
|
72
|
+
page = storage.get_page or next
|
|
73
|
+
rename = Wiki::Parser::ORename.new(storage,@name,new)
|
|
74
|
+
text = Wiki::Parser::PRename.parse(page.data).prepare(rename).output(rename)
|
|
75
|
+
storage.add_page(text,'','Links renamed',page.meta,user)
|
|
76
|
+
touch [par]
|
|
77
|
+
end
|
|
78
|
+
touch doc.find("/main/page[@name=\"#{@subject}\"]/*/@name")
|
|
79
|
+
|
|
80
|
+
XML::Smart.modify(linking) do |mdoc|
|
|
81
|
+
mdoc.find("/main/page/link[@name=\"#{@subject}\"]").each { |ele| ele.attributes['name'] = subject }
|
|
82
|
+
mdoc.find("/main/page[@name=\"#{@subject}\"]").each do |ele|
|
|
83
|
+
ele.attributes['name'] = subject
|
|
84
|
+
ele.attributes['user'] = user
|
|
85
|
+
ele.attributes['modified'] = Time.now.to_s
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
FileUtils.mv(@cpath,npath)
|
|
89
|
+
@subject = subject
|
|
90
|
+
@name = new
|
|
91
|
+
@cpath = npath
|
|
92
|
+
@name
|
|
93
|
+
end #}}}
|
|
94
|
+
|
|
95
|
+
def get_meta(meta,rev=@current) #{{{
|
|
96
|
+
node = revision(rev) or return nil
|
|
97
|
+
value(node.find(meta).first)
|
|
98
|
+
end #}}}
|
|
99
|
+
|
|
100
|
+
def get_modified(rev=@current) #{{{
|
|
101
|
+
node = revision(rev)
|
|
102
|
+
node ? Time.parse(node.attributes['modified']) : Time.at(0)
|
|
103
|
+
end #}}}
|
|
104
|
+
|
|
105
|
+
# eid identifies an editing session, rev_base is the revision the text is based on
|
|
106
|
+
def add_page(text,eid,comment,meta,user,rev_base=@current) #{{{
|
|
107
|
+
FileUtils.mkdir_p(@cpath)
|
|
108
|
+
success = false
|
|
109
|
+
meta = (meta || {}).dup
|
|
110
|
+
XML::Smart.modify(revisions,'<revisions/>') do |doc|
|
|
111
|
+
new = doc.find('count(/revisions/revision)').to_i + 1
|
|
112
|
+
last = doc.find('/revisions/revision[last()]').first
|
|
113
|
+
if last && File.read(@cpath + (new-1).to_s) == text
|
|
114
|
+
node = last
|
|
115
|
+
else
|
|
116
|
+
attrs = { :eid => eid, :user => user, :modified => Time.now.to_s, :comment => comment }
|
|
117
|
+
if rev_base + 1 != new && !(last && eid != '' && last.attributes['eid'] == eid)
|
|
118
|
+
text, conflict = merge(text,rev_base,new-1)
|
|
119
|
+
attrs[:action] = "Merged#{conflict ? ' with conflict' : ''} #{rev_base}->#{new-1},#{new}"
|
|
120
|
+
meta['conflict'] = 'true' if conflict
|
|
121
|
+
end
|
|
122
|
+
File.write(@cpath + new.to_s,text)
|
|
123
|
+
node = doc.root.add('revision',attrs)
|
|
124
|
+
@current = new
|
|
125
|
+
success = true
|
|
126
|
+
end
|
|
127
|
+
node.children.delete_all!
|
|
128
|
+
meta.each { |k,v| node.add(k.to_s,v.to_s) }
|
|
129
|
+
end
|
|
130
|
+
XML::Smart.modify(linking) do |doc|
|
|
131
|
+
node = doc.find("/main/page[@name=\"#{@subject}\"]").first || doc.root.add('page')
|
|
132
|
+
node.attributes['name'] = @subject
|
|
133
|
+
node.attributes['user'] = user
|
|
134
|
+
node.attributes['modified'] = Time.now.to_s
|
|
135
|
+
# first revision: links in other pages have to appear active
|
|
136
|
+
touch doc.find("/main/page[link/@name=\"#{@subject}\"]/@name") if @current == 1
|
|
137
|
+
end if success
|
|
138
|
+
success
|
|
139
|
+
end #}}}
|
|
140
|
+
|
|
141
|
+
def add_links(names) #{{{
|
|
142
|
+
names = names.map { |n| Wiki::Encoding::escape(n) }
|
|
143
|
+
# called whenever a page is shown, so only write when necessary
|
|
144
|
+
return if names == XML::Smart.open(linking).find("/main/page[@name=\"#{@subject}\"]/link/@name").map(&:to_s)
|
|
145
|
+
XML::Smart.modify(linking) do |doc|
|
|
146
|
+
doc.find("/main/page[@name=\"#{@subject}\"]").each do |node|
|
|
147
|
+
old = node.find('link/@name').map(&:to_s)
|
|
148
|
+
touch((old - names) + (names - old))
|
|
149
|
+
node.children.delete_all!
|
|
150
|
+
names.each { |n| node.add('link',{'name' => n}) }
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end #}}}
|
|
154
|
+
|
|
155
|
+
def get_links #{{{
|
|
156
|
+
XML::Smart.open(linking).find("/main/page[@name=\"#{@subject}\"]/link/@name").map { |e| Wiki::Encoding::unescape(e.to_s) }
|
|
157
|
+
end #}}}
|
|
158
|
+
|
|
159
|
+
def exist?(name); !Simple.new(@path,name).new?; end
|
|
160
|
+
|
|
161
|
+
# returns the pages that contain the references: cite => page
|
|
162
|
+
def update_references(references,cites) #{{{
|
|
163
|
+
fname = File.join(@path,'references.xml')
|
|
164
|
+
new = { 'reference' => references, 'cite' => cites }.transform_values { |l| l.map { |n| Wiki::Encoding::escape(n) }.uniq }
|
|
165
|
+
doc = File.exist?(fname) ? XML::Smart.open(fname) : XML::Smart.string('<main/>')
|
|
166
|
+
old = new.keys.to_h { |k| [k,doc.find("/main/page[@name=\"#{@subject}\"]/#{k}/@name").map(&:to_s)] }
|
|
167
|
+
# called whenever a page is shown, so only write when necessary
|
|
168
|
+
if old != new
|
|
169
|
+
XML::Smart.modify(fname,'<main/>') do |mdoc|
|
|
170
|
+
node = mdoc.find("/main/page[@name=\"#{@subject}\"]").first || mdoc.root.add('page',{ 'name' => @subject })
|
|
171
|
+
node.children.delete_all!
|
|
172
|
+
new.each { |k,l| l.each { |n| node.add(k,{ 'name' => n }) } }
|
|
173
|
+
changed = (old['reference'] - new['reference']) + (new['reference'] - old['reference'])
|
|
174
|
+
changed.each { |n| touch mdoc.find("/main/page[@name!=\"#{@subject}\" and cite[@name=\"#{n}\"]]/@name") }
|
|
175
|
+
end
|
|
176
|
+
doc = XML::Smart.open(fname)
|
|
177
|
+
end
|
|
178
|
+
new['cite'].to_h { |n| [n,doc.find("string(/main/page[reference[@name=\"#{n}\"]]/@name)")] }.reject { |_,page| page == '' }
|
|
179
|
+
end #}}}
|
|
180
|
+
|
|
181
|
+
### objects: images, files, applets, graphs
|
|
182
|
+
|
|
183
|
+
def get_object(name,type,rev=@current) #{{{
|
|
184
|
+
node = object_revision(name,type,rev) or return nil
|
|
185
|
+
fname = File.join(object_path(name,type),node.attributes['rev'])
|
|
186
|
+
StorageObject.new(
|
|
187
|
+
File.exist?(fname) ? File.binread(fname) : nil,
|
|
188
|
+
meta_of(node),
|
|
189
|
+
Time.parse(node.attributes['time'])
|
|
190
|
+
)
|
|
191
|
+
end #}}}
|
|
192
|
+
|
|
193
|
+
def get_object_id(name,type,rev=@current) #{{{
|
|
194
|
+
node = object_revision(name,type,rev) or return nil
|
|
195
|
+
Digest::MD5.hexdigest("#{object_path(name,type)}/#{node.attributes['rev']}/#{node.attributes['time']}")
|
|
196
|
+
end #}}}
|
|
197
|
+
|
|
198
|
+
def get_object_modified(name,type,rev=@current) #{{{
|
|
199
|
+
node = object_revision(name,type,rev)
|
|
200
|
+
node ? Time.parse(node.attributes['time']) : Time.at(0)
|
|
201
|
+
end #}}}
|
|
202
|
+
|
|
203
|
+
def get_object_meta(name,meta,type,rev=@current) #{{{
|
|
204
|
+
node = object_revision(name,type,rev) or return nil
|
|
205
|
+
value(node.find(meta).first)
|
|
206
|
+
end #}}}
|
|
207
|
+
|
|
208
|
+
def get_object_list(type,rev=@current) #{{{
|
|
209
|
+
Dir.glob(File.join(@cpath.gsub(/[\[\]{}*?\\]/) { |m| "\\#{m}" },type.to_s,'*')).filter_map do |d|
|
|
210
|
+
name = File.basename(d)
|
|
211
|
+
node = object_revision(Wiki::Encoding::unescape(name),type,rev) or next
|
|
212
|
+
StorageObject.new(name,meta_of(node),Time.parse(node.attributes['time']))
|
|
213
|
+
end.sort_by { |e| Wiki::Encoding::unescape(e.data) }
|
|
214
|
+
end #}}}
|
|
215
|
+
|
|
216
|
+
def add_object(name,data,meta,type,rev=@current) #{{{
|
|
217
|
+
opath = object_path(name,type)
|
|
218
|
+
FileUtils.mkdir_p(opath)
|
|
219
|
+
XML::Smart.modify(opath + '/revisions.xml','<revisions/>') do |doc|
|
|
220
|
+
node = doc.find("/revisions/revision[@text-rev='#{rev.to_i}']").first
|
|
221
|
+
if node.nil?
|
|
222
|
+
node = doc.root.add('revision',{ 'rev' => doc.find('count(/revisions/revision)').to_i + 1, 'text-rev' => rev.to_i })
|
|
223
|
+
end
|
|
224
|
+
node.attributes['state'] = 'active'
|
|
225
|
+
node.attributes['time'] = Time.now.iso8601(6)
|
|
226
|
+
unless meta.nil?
|
|
227
|
+
node.children.delete_all!
|
|
228
|
+
meta.each { |k,v| node.add(k.to_s,v.to_s) }
|
|
229
|
+
end
|
|
230
|
+
File.binwrite(File.join(opath,node.attributes['rev']),data)
|
|
231
|
+
end
|
|
232
|
+
end #}}}
|
|
233
|
+
|
|
234
|
+
def add_object_meta(name,meta,type,rev=@current) #{{{
|
|
235
|
+
change_object(name,type,rev) do |node|
|
|
236
|
+
node.attributes['time'] = Time.now.iso8601(6)
|
|
237
|
+
node.children.delete_all!
|
|
238
|
+
meta.each { |k,v| node.add(k.to_s,v.to_s) }
|
|
239
|
+
end
|
|
240
|
+
end #}}}
|
|
241
|
+
|
|
242
|
+
def del_object(name,type,rev=@current) #{{{
|
|
243
|
+
change_object(name,type,rev) { |node| node.attributes['state'] = 'deleted' }
|
|
244
|
+
end #}}}
|
|
245
|
+
|
|
246
|
+
### history
|
|
247
|
+
|
|
248
|
+
def get_history(last=20) #{{{
|
|
249
|
+
return [] unless File.exist?(revisions)
|
|
250
|
+
counter = [@current-last,0].max
|
|
251
|
+
XML::Smart.open(revisions).find("/revisions/revision[position()>#{counter}]").map do |ele|
|
|
252
|
+
a = ele.attributes
|
|
253
|
+
RevisionObject.new(counter += 1,a['modified'],a['user'],a['comment'],a['action'])
|
|
254
|
+
end
|
|
255
|
+
end #}}}
|
|
256
|
+
|
|
257
|
+
def has_diff(rev_from,rev_to)
|
|
258
|
+
get_page(rev_from).data.strip != get_page(rev_to).data.strip
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
# list of [:same|:del|:add,text]
|
|
262
|
+
def get_diff(rev_from,rev_to) #{{{
|
|
263
|
+
rev_from, rev_to = [rev_from.to_i,rev_to.to_i].minmax
|
|
264
|
+
old, new = [rev_from,rev_to].map { |r| Simple.words(get_page(r).data) }
|
|
265
|
+
::Diff::LCS.sdiff(old,new).chunk_while { |a,b| a.action == b.action }.flat_map do |chunk|
|
|
266
|
+
del = chunk.map(&:old_element).join
|
|
267
|
+
add = chunk.map(&:new_element).join
|
|
268
|
+
chunk.first.action == '=' ? [[:same,del]] : [[:del,del],[:add,add]].reject { |_,text| text == '' }
|
|
269
|
+
end
|
|
270
|
+
end #}}}
|
|
271
|
+
|
|
272
|
+
private
|
|
273
|
+
|
|
274
|
+
def linking; File.join(@path,'linking.xml'); end
|
|
275
|
+
def revisions; @cpath + 'revisions.xml'; end
|
|
276
|
+
|
|
277
|
+
def revision(rev)
|
|
278
|
+
File.exist?(revisions) ? XML::Smart.open(revisions).find("/revisions/revision[#{rev.to_i}]").first : nil
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
def object_path(name,type)
|
|
282
|
+
File.join(@cpath,type.to_s,Wiki::Encoding::escape(name))
|
|
283
|
+
end
|
|
284
|
+
def object_xpath(rev)
|
|
285
|
+
"/revisions/revision[@text-rev<=#{rev.to_i}][position()=last() and @state='active']"
|
|
286
|
+
end
|
|
287
|
+
def object_revision(name,type,rev)
|
|
288
|
+
fname = object_path(name,type) + '/revisions.xml'
|
|
289
|
+
File.exist?(fname) ? XML::Smart.open(fname).find(object_xpath(rev)).first : nil
|
|
290
|
+
end
|
|
291
|
+
def change_object(name,type,rev,&blk)
|
|
292
|
+
fname = object_path(name,type) + '/revisions.xml'
|
|
293
|
+
XML::Smart.modify(fname) { |doc| doc.find(object_xpath(rev)).each(&blk) } if File.exist?(fname)
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
def value(node)
|
|
297
|
+
case node.to_s
|
|
298
|
+
when 'true'; true
|
|
299
|
+
when 'false'; false
|
|
300
|
+
else node.nil? ? nil : node.to_s
|
|
301
|
+
end
|
|
302
|
+
end
|
|
303
|
+
def meta_of(node)
|
|
304
|
+
node.find('*').to_h { |e| [e.qname.name,value(e)] }
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
# pages are cached by the engine as long as revisions.xml is not changed
|
|
308
|
+
def touch(names)
|
|
309
|
+
names.map(&:to_s).each do |n|
|
|
310
|
+
f = File.join(@path,'Data',n,'revisions.xml')
|
|
311
|
+
FileUtils.touch(f) if File.exist?(f)
|
|
312
|
+
end
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
def merge(text,base,last) #{{{
|
|
316
|
+
out, status = Dir.mktmpdir do |dir|
|
|
317
|
+
# pages don't end with a newline, but diff3 needs it
|
|
318
|
+
# no get_page, because revisions.xml is locked
|
|
319
|
+
old = lambda { |rev| File.exist?(@cpath + rev.to_i.to_s) ? File.read(@cpath + rev.to_i.to_s) : '' }
|
|
320
|
+
{ 'mine' => text, 'base' => old.call(base), 'last' => old.call(last) }.each do |name,data|
|
|
321
|
+
File.write(File.join(dir,name),data + "\n")
|
|
322
|
+
end
|
|
323
|
+
Open3.capture2('diff3','-a','-m','-L','MINE','-L','BASE','-L','LAST','mine','base','last',:chdir => dir)
|
|
324
|
+
end
|
|
325
|
+
out = out.force_encoding('UTF-8').chomp
|
|
326
|
+
return [out,false] if status.exitstatus == 0
|
|
327
|
+
out = out.gsub(/^\|{7} BASE\n.*?^=======\n/m,"\n-----\n!!Version 2:!!\n")
|
|
328
|
+
out = out.gsub(/^<{7} MINE\n/,"\n-----\n!!Version 1:!!\n")
|
|
329
|
+
out = out.gsub(/^>{7} LAST(\n|\z)/,"\n-----\n")
|
|
330
|
+
[out,true]
|
|
331
|
+
end #}}}
|
|
332
|
+
end
|
|
333
|
+
end
|
|
334
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Please see the LICENSE.GPL file for copyright and distribution information
|
|
2
|
+
require 'cewebs-servicesbase/service'
|
|
3
|
+
require_relative 'helpers/wiki_storage'
|
|
4
|
+
require_relative 'helpers/access'
|
|
5
|
+
require_relative 'helpers/views'
|
|
6
|
+
require_relative 'helpers/export'
|
|
7
|
+
require_relative 'delivery'
|
|
8
|
+
require_relative 'administration'
|
|
9
|
+
|
|
10
|
+
module Didaktiki
|
|
11
|
+
SERVER = CEWebS::declaration(File.join(__dir__,'implementation.xml'))
|
|
12
|
+
|
|
13
|
+
def self::implementation(opts) #{{{
|
|
14
|
+
CEWebS::data_dir = File.expand_path(opts[:data_dir] || 'data',opts[:basepath])
|
|
15
|
+
|
|
16
|
+
Proc.new do
|
|
17
|
+
interface 'delivery', &CEWebS::delivery(Didaktiki::Delivery.new)
|
|
18
|
+
interface 'administration', &CEWebS::administration(Didaktiki::Administration.new)
|
|
19
|
+
end
|
|
20
|
+
end #}}}
|
|
21
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<declaration xmlns="http://riddl.org/ns/declaration/1.0" xmlns:xi="http://www.w3.org/2001/XInclude">
|
|
2
|
+
<interface name="delivery">
|
|
3
|
+
<xi:include href="contracts/delivery.xml"/>
|
|
4
|
+
</interface>
|
|
5
|
+
<interface name="administration">
|
|
6
|
+
<xi:include href="contracts/administration.xml"/>
|
|
7
|
+
</interface>
|
|
8
|
+
<facade>
|
|
9
|
+
<tile>
|
|
10
|
+
<layer name="delivery"><apply-to>/delivery</apply-to></layer>
|
|
11
|
+
<layer name="administration"><apply-to>/administration</apply-to></layer>
|
|
12
|
+
</tile>
|
|
13
|
+
</facade>
|
|
14
|
+
</declaration>
|