dokuwiki 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +25 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +56 -0
- data/lib/dokuwiki.rb +268 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 063c8012a01a44893ac209de95730fc6c1791544a303790a789d208f0085cbc3
|
4
|
+
data.tar.gz: aa12c6b4182d2dbaf2f7cc14d6aed64260e138775ed9be7fd03098ed54632896
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3dd8743a3a31682f78d436ca2018602e175f49fe0f2365e7accdc4ab82a5de1cfcfe45235f1a3b803659821688ad4ace8dd9b8f6cae9615fff9a42db47de22cd
|
7
|
+
data.tar.gz: f3f401e9630ccc90c75e2a659e9fafe909a4a33ee69faf47fc1e230813c1c1f9e3ff75998f37fb6236fc1ba1dcec74815c63514209865993b635d06a15bc676d
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets.
|
4
|
+
# SupportedStyles: space, no_space, compact
|
5
|
+
# SupportedStylesForEmptyBrackets: space, no_space
|
6
|
+
Layout/SpaceInsideArrayLiteralBrackets:
|
7
|
+
EnforcedStyle: space
|
8
|
+
Exclude:
|
9
|
+
- 'dokuwiki.gemspec'
|
10
|
+
|
11
|
+
# Configuration parameters: EnforcedStyle.
|
12
|
+
# SupportedStyles: space, no_space
|
13
|
+
Layout/SpaceInsideParens:
|
14
|
+
EnforcedStyle: space
|
15
|
+
|
16
|
+
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets.
|
17
|
+
# SupportedStyles: space, no_space
|
18
|
+
# SupportedStylesForEmptyBrackets: space, no_space
|
19
|
+
Layout/SpaceInsideReferenceBrackets:
|
20
|
+
EnforcedStyle: space
|
21
|
+
|
22
|
+
# URISchemes: http, https
|
23
|
+
Metrics/LineLength:
|
24
|
+
Exclude:
|
25
|
+
- 'dokuwiki.gemspec'
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2018-2019 Dirk Meyer
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# DokuWiki
|
2
|
+
|
3
|
+
The DokuWiki library is used for automating interaction with a DokuWiki Server.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's `Gemfile`:
|
8
|
+
|
9
|
+
gem 'dokuwiki'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install dokuwiki
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
########################
|
22
|
+
# Example 1 Download
|
23
|
+
########################
|
24
|
+
|
25
|
+
# Initialize and access the wiki at http://www.example.org/dokuwiki/
|
26
|
+
dokuwiki = DokuWiki::DokuWikiAccess.new( 'www.example.org', '/dokuwiki' )
|
27
|
+
|
28
|
+
# Login at specific Namespace
|
29
|
+
dokuwiki.login( 'dir:index', username, password )
|
30
|
+
|
31
|
+
# Download a specific Namespace
|
32
|
+
dokuwiki.save_wiki_path( 'dir:page' )
|
33
|
+
|
34
|
+
########################
|
35
|
+
# Example 2 Upload
|
36
|
+
########################
|
37
|
+
|
38
|
+
# Initialize and access the wiki at http://www.example.org/
|
39
|
+
dokuwiki = DokuWiki::DokuWikiAccess.new( 'www.example.org' )
|
40
|
+
|
41
|
+
# Login at specific Namespace
|
42
|
+
dokuwiki.login( 'dir:index', username, password )
|
43
|
+
|
44
|
+
# create the cache dir
|
45
|
+
dokuwiki.upload_dir = 'UPLOAD'
|
46
|
+
File.mkdir( dokuwiki.upload_dir )
|
47
|
+
|
48
|
+
# Upload a specific Namespace
|
49
|
+
dokuwiki.upload_file( 'dir:page', 'result.pdf' )
|
50
|
+
|
51
|
+
### File formats
|
52
|
+
|
53
|
+
The extensions decides the Format used.
|
54
|
+
'.wiki': Page in DokuWiki source
|
55
|
+
'.txt', '.css', '.jpg', '.png', 'pdf': MediaManager file.
|
56
|
+
|
data/lib/dokuwiki.rb
ADDED
@@ -0,0 +1,268 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
# = dokuwiki.rb
|
4
|
+
#
|
5
|
+
# Author:: Dirk Meyer
|
6
|
+
# Copyright:: Copyright (c) 2018 - 2019 Dirk Meyer
|
7
|
+
# License:: Distributes under the same terms as Ruby
|
8
|
+
#
|
9
|
+
# == module DokuWiki
|
10
|
+
#
|
11
|
+
# Namespace for accessing DokuWiki
|
12
|
+
#
|
13
|
+
|
14
|
+
require 'rubygems'
|
15
|
+
require 'http-cookie'
|
16
|
+
require 'mechanize'
|
17
|
+
require 'pp'
|
18
|
+
|
19
|
+
# Module for accessing DokuWiki
|
20
|
+
module DokuWiki
|
21
|
+
# === Class Functions
|
22
|
+
#
|
23
|
+
# require 'dokuwiki"
|
24
|
+
#
|
25
|
+
# DokuWiki.new( hostname, urlpath = nil )
|
26
|
+
# DokuWiki.media_dir
|
27
|
+
# DokuWiki.upload_dir
|
28
|
+
# DokuWiki.wait_second
|
29
|
+
# DokuWiki.namespace( wikipath )
|
30
|
+
# DokuWiki.edit_url( wikipath )
|
31
|
+
# DokuWiki.get( url )
|
32
|
+
# DokuWiki.login( wikipath, user, pass )
|
33
|
+
# DokuWiki.downloaded?( filename, buffer )
|
34
|
+
# DokuWiki.file_put_contents( filename, line, mode = 'w+' )
|
35
|
+
# DokuWiki.save_wiki_source( page, filename )
|
36
|
+
# DokuWiki.save_wiki_body( filename, url )
|
37
|
+
# DokuWiki.save_wiki_media( filename, url )
|
38
|
+
# DokuWiki.save_wiki_path( wikipath )
|
39
|
+
# DokuWiki.uploaded?( filename, buffer )
|
40
|
+
# DokuWiki.save_uploaded( filename )
|
41
|
+
# DokuWiki.upload_media_file?( wikipath, filename )
|
42
|
+
# DokuWiki.upload_wiki_file( wikipath, filename )
|
43
|
+
# DokuWiki.upload_file( wikipath, filename )
|
44
|
+
#
|
45
|
+
class DokuWikiAccess
|
46
|
+
# extension for files in dokuwiki syntax
|
47
|
+
EXTENSION = 'wiki'.freeze
|
48
|
+
# filename for cookie cache
|
49
|
+
COOKIES = 'cookies.txt'.freeze
|
50
|
+
|
51
|
+
# directory for media download cache
|
52
|
+
attr_accessor :media_dir
|
53
|
+
# directory for upload cache
|
54
|
+
attr_accessor :upload_dir
|
55
|
+
|
56
|
+
# define server location
|
57
|
+
def initialize( hostname, urlpath = nil )
|
58
|
+
@site = "https://#{hostname}"
|
59
|
+
@site << urlpath unless urlpath.nil?
|
60
|
+
@site.freeze
|
61
|
+
@dokuwiki_page_url = "#{@site}/doku.php?id=".freeze
|
62
|
+
@dokuwiki_css_url = "#{@site}/lib/exe/css.php?t=".freeze
|
63
|
+
@dokuwiki_media_url = "#{@site}/lib/exe/fetch.php?cache=&media=".freeze
|
64
|
+
@dokuwiki_media_upload_url = "#{@site}/lib/exe/ajax.php?" \
|
65
|
+
'tab_files=files&tab_details=view&do=media&ns='.freeze
|
66
|
+
@media_dir = nil
|
67
|
+
@upload_dir = nil
|
68
|
+
@lastpage = nil
|
69
|
+
@cookies = nil
|
70
|
+
@sectok = nil
|
71
|
+
@agent = nil
|
72
|
+
end
|
73
|
+
|
74
|
+
# be nice to the server
|
75
|
+
def wait_second
|
76
|
+
now = Time.now.to_i
|
77
|
+
# p [ 'wait_second', now, $lastpage ]
|
78
|
+
unless @lastpage.nil?
|
79
|
+
if now <= @lastpage + 2
|
80
|
+
sleep 2
|
81
|
+
now = Time.now.to_i
|
82
|
+
end
|
83
|
+
end
|
84
|
+
@lastpage = now
|
85
|
+
end
|
86
|
+
|
87
|
+
# convert path to namesape
|
88
|
+
def namespace( wikipath )
|
89
|
+
wikipath.gsub( ':', '%3A' ).freeze
|
90
|
+
end
|
91
|
+
|
92
|
+
# make edit url
|
93
|
+
def edit_url( wikipath )
|
94
|
+
"#{@dokuwiki_page_url}#{wikipath}&do=edit"
|
95
|
+
end
|
96
|
+
|
97
|
+
# make upload url
|
98
|
+
def upload_url( wikipath, filename )
|
99
|
+
namespace = namespace( wikipath )
|
100
|
+
url = "#{@dokuwiki_media_upload_url}#{namespace}§ok=#{@sectok}"
|
101
|
+
url << '&mediaid=&call=mediaupload'
|
102
|
+
url << "&qqfile=#{filename}&ow=true"
|
103
|
+
url
|
104
|
+
end
|
105
|
+
|
106
|
+
# get url
|
107
|
+
def get( url )
|
108
|
+
p url
|
109
|
+
wait_second
|
110
|
+
@agent.get( url )
|
111
|
+
end
|
112
|
+
|
113
|
+
# login into DokuWiki at given path
|
114
|
+
def login( wikipath, user, pass )
|
115
|
+
Timeout.timeout( 300 ) do
|
116
|
+
@agent = Mechanize.new
|
117
|
+
@agent.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
118
|
+
@agent.agent.http.reuse_ssl_sessions = false
|
119
|
+
# @agent.agent.http.ca_file = ca_path
|
120
|
+
if @cookies.nil?
|
121
|
+
url = @dokuwiki_page_url + wikipath
|
122
|
+
page = get( url )
|
123
|
+
# Submit the login form
|
124
|
+
wait_second
|
125
|
+
page = page.form_with( id: 'dw__login' ) do |f|
|
126
|
+
f.field_with( name: 'u' ).value = user
|
127
|
+
f.field_with( name: 'p' ).value = pass
|
128
|
+
f.checkbox_with( name: 'r' ).check
|
129
|
+
end.click_button
|
130
|
+
f = page.forms[ 1 ]
|
131
|
+
@sectok = f.field_with( name: 'sectok' ).value
|
132
|
+
@agent.cookie_jar.save( COOKIES )
|
133
|
+
else
|
134
|
+
@agent.cookie_jar.load( COOKIES )
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# check if downloaded file has changed
|
140
|
+
def downloaded?( filename, buffer )
|
141
|
+
return false unless File.exist?( filename )
|
142
|
+
|
143
|
+
old = File.read( filename, encoding: buffer.encoding )
|
144
|
+
return true if buffer == old
|
145
|
+
|
146
|
+
false
|
147
|
+
end
|
148
|
+
|
149
|
+
# write buffer to file
|
150
|
+
def file_put_contents( filename, buffer, mode = 'w+' )
|
151
|
+
return if downloaded?( filename, buffer )
|
152
|
+
|
153
|
+
File.open( filename, mode ) do |f|
|
154
|
+
f.write( buffer )
|
155
|
+
f.close
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# save wiki source to file
|
160
|
+
def save_wiki_source( page, filename )
|
161
|
+
f = page.form_with( id: 'dw__editform' )
|
162
|
+
wikitext = f.field_with( name: 'wikitext' ).value.delete( "\r" )
|
163
|
+
file_put_contents( filename, wikitext )
|
164
|
+
button = f.button_with( name: 'do[draftdel]' )
|
165
|
+
@agent.submit( f, button )
|
166
|
+
end
|
167
|
+
|
168
|
+
# save wiki body to file
|
169
|
+
def save_wiki_body( filename, url )
|
170
|
+
page = get( url )
|
171
|
+
file_put_contents( filename, page.body )
|
172
|
+
end
|
173
|
+
|
174
|
+
# save wiki media body to file
|
175
|
+
def save_wiki_media( filename, url )
|
176
|
+
path =
|
177
|
+
if @media_dir.nil?
|
178
|
+
filename
|
179
|
+
else
|
180
|
+
"#{MEDIA_DIR}/#{filename}"
|
181
|
+
end
|
182
|
+
save_wiki_body( path, url )
|
183
|
+
end
|
184
|
+
|
185
|
+
# save wiki path to file
|
186
|
+
def save_wiki_path( wikipath )
|
187
|
+
filename = wikipath.split( ':' ).last
|
188
|
+
case wikipath
|
189
|
+
when /[.]jpe?g$/, /[.]png$/, /[.]pdf$/
|
190
|
+
url = @dokuwiki_media_url + wikipath
|
191
|
+
save_wiki_media( filename, url )
|
192
|
+
when /[.]css$/
|
193
|
+
url = @dokuwiki_css_url + wikipath.sub( /[.]css$/, '' )
|
194
|
+
save_wiki_media( filename, url )
|
195
|
+
when /[.]html$/
|
196
|
+
url = @dokuwiki_page_url + wikipath.sub( /[.]html$/, '' )
|
197
|
+
save_wiki_body( filename, url )
|
198
|
+
else
|
199
|
+
url = edit_url( wikipath )
|
200
|
+
filename << ".#{EXTENSION}"
|
201
|
+
page = get( url )
|
202
|
+
save_wiki_source( page, filename )
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
# check if uploaded file has changed
|
207
|
+
def uploaded?( filename, buffer )
|
208
|
+
return false if @upload_dir.nil?
|
209
|
+
|
210
|
+
savedfile = "#{@upload_dir}/#{filename}"
|
211
|
+
return false unless File.exist?( savedfile )
|
212
|
+
|
213
|
+
old = File.read( savedfile, encoding: buffer.encoding )
|
214
|
+
return true if buffer == old
|
215
|
+
|
216
|
+
false
|
217
|
+
end
|
218
|
+
|
219
|
+
# save content to avoid useless edits
|
220
|
+
def save_uploaded( filename )
|
221
|
+
print system( "cp -pv '#{filename}' '#{@upload_dir}/'" )
|
222
|
+
end
|
223
|
+
|
224
|
+
# upload media file at path
|
225
|
+
def upload_media_file( wikipath, filename, raw )
|
226
|
+
p filename
|
227
|
+
headers = {
|
228
|
+
'Content-Type' => 'application/octet-stream',
|
229
|
+
'X-File-Name' => filename
|
230
|
+
}
|
231
|
+
url = upload_url( wikipath, filename )
|
232
|
+
p url
|
233
|
+
wait_second
|
234
|
+
pp @agent.post( url, raw, headers )
|
235
|
+
save_uploaded( filename )
|
236
|
+
end
|
237
|
+
|
238
|
+
# edit wiki source at path
|
239
|
+
def upload_wiki_file( wikipath, filename )
|
240
|
+
raw = File.read( filename ).gsub( "\n", "\r\n" )
|
241
|
+
basename = filename.sub( /[.]#{EXTENSION}$/, '' )
|
242
|
+
finalpath = "#{wikipath}:#{basename}"
|
243
|
+
page = get( edit_url( finalpath ) )
|
244
|
+
f = page.form_with( id: 'dw__editform' )
|
245
|
+
f.field_with( name: 'wikitext' ).value = raw
|
246
|
+
f.field_with( name: 'summary' ).value = 'automated by qscript'
|
247
|
+
button = f.button_with( name: 'do[save]' )
|
248
|
+
pp @agent.submit( f, button )
|
249
|
+
save_uploaded( filename )
|
250
|
+
end
|
251
|
+
|
252
|
+
# upload a file at given path
|
253
|
+
def upload_file( wikipath, filename )
|
254
|
+
p filename
|
255
|
+
raw = File.read( filename )
|
256
|
+
return if uploaded?( filename, raw )
|
257
|
+
|
258
|
+
case filename
|
259
|
+
when /[.]#{EXTENSION}$/
|
260
|
+
upload_wiki_file( wikipath, filename )
|
261
|
+
else
|
262
|
+
upload_media_file( wikipath, filename, raw )
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
# eof
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dokuwiki
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dirk Meyer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-09-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: http-cookie
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.3
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.3
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: mechanize
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.7'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 2.7.6
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '2.7'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.7.6
|
53
|
+
description: The DokuWiki library is used for automating interaction with a DokuWiki
|
54
|
+
server.
|
55
|
+
email:
|
56
|
+
executables: []
|
57
|
+
extensions: []
|
58
|
+
extra_rdoc_files: []
|
59
|
+
files:
|
60
|
+
- ".rubocop.yml"
|
61
|
+
- CHANGELOG.md
|
62
|
+
- Gemfile
|
63
|
+
- LICENSE.txt
|
64
|
+
- README.md
|
65
|
+
- lib/dokuwiki.rb
|
66
|
+
homepage: https://rubygems.org/gems/dokuwiki
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubygems_version: 3.0.6
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: access DokuWiki server
|
89
|
+
test_files: []
|