Class: Wiki2Go::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/Wiki2Go/Wiki2GoConfig.rb

Overview

Base class for configurations

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory = nil) ⇒ Config

directory = base directory of the wiki. Current directory by default



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 46

def initialize(directory=nil)
  directory ||= Dir.getwd

  @root_directory = directory
  @site_directory = File.join(directory,'site')

  @server        = 'localhost'
  @port          = 8081
  @default_web   = 'Wiki2go'
  @default_page  = 'FrontPage'  
  @generate_html = true 
  @storage       = nil
  @processors    = { }
  @debug         = false
  @multi_wiki    = true
  @site_admin    = '[email protected]'
  @amazon_affiliate = 'agilesystems-21'
  @allow_dynamic_pages = false
  @subsite             = ''
  @blog_style    = false
  @maximum_urls  = 5
  
  @pages_in_recent_changes = 20 
  @pages_in_rss = 20
  @editor       = 'wikiedit'
  @delete_spam  = false
  
  @checksum_required = false
  @checksum_salt = '^$%wiki#§}'
  @blacklist_when_no_checksum = false
  
  @logger = nil

  @user  = nil
  @group = nil
  
  @banned_users = nil
  @banned_urls = nil
  @chonqed_urls = nil
  @greylist = nil 
end

Instance Attribute Details

#allow_dynamic_pagesObject

Returns the value of attribute allow_dynamic_pages.



30
31
32
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 30

def allow_dynamic_pages
  @allow_dynamic_pages
end

#amazon_affiliateObject

Returns the value of attribute amazon_affiliate.



29
30
31
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 29

def amazon_affiliate
  @amazon_affiliate
end

#blacklist_when_no_checksumObject

When a document is submitted without a checksum, blacklist the sender (default = false)



43
44
45
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 43

def blacklist_when_no_checksum
  @blacklist_when_no_checksum
end

#blog_styleObject

Returns the value of attribute blog_style.



32
33
34
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 32

def blog_style
  @blog_style
end

#checksum_requiredObject

User must submit a checksum of the original page when saving



39
40
41
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 39

def checksum_required
  @checksum_required
end

#checksum_saltObject

Salt to make checksum unique and unguessable



41
42
43
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 41

def checksum_salt
  @checksum_salt
end

#debugObject

Returns the value of attribute debug.



26
27
28
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 26

def debug
  @debug
end

#default_pageObject

Returns the value of attribute default_page.



17
18
19
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 17

def default_page
  @default_page
end

#default_webObject

Returns the value of attribute default_web.



16
17
18
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 16

def default_web
  @default_web
end

#delete_spamObject

Returns the value of attribute delete_spam.



37
38
39
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 37

def delete_spam
  @delete_spam
end

#editorObject

Returns the value of attribute editor.



36
37
38
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 36

def editor
  @editor
end

#generate_htmlObject

Returns the value of attribute generate_html.



25
26
27
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 25

def generate_html
  @generate_html
end

#groupObject

Returns the value of attribute group.



23
24
25
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 23

def group
  @group
end

#maximum_urlsObject

Returns the value of attribute maximum_urls.



33
34
35
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 33

def maximum_urls
  @maximum_urls
end

#multi_wikiObject

Returns the value of attribute multi_wiki.



27
28
29
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 27

def multi_wiki
  @multi_wiki
end

#pages_in_recent_changesObject

Returns the value of attribute pages_in_recent_changes.



34
35
36
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 34

def pages_in_recent_changes
  @pages_in_recent_changes
end

#pages_in_rssObject

Returns the value of attribute pages_in_rss.



35
36
37
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 35

def pages_in_rss
  @pages_in_rss
end

#portObject

Returns the value of attribute port.



15
16
17
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 15

def port
  @port
end

#root_directoryObject

Returns the value of attribute root_directory.



19
20
21
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 19

def root_directory
  @root_directory
end

#serverObject

Returns the value of attribute server.



14
15
16
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 14

def server
  @server
end

#site_adminObject

Returns the value of attribute site_admin.



28
29
30
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 28

def site_admin
  @site_admin
end

#site_directoryObject

Returns the value of attribute site_directory.



20
21
22
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 20

def site_directory
  @site_directory
end

#subsiteObject

Returns the value of attribute subsite.



31
32
33
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 31

def subsite
  @subsite
end

#userObject

Returns the value of attribute user.



22
23
24
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 22

def user
  @user
end

Instance Method Details

#accept_edit?(web, old_page, checksum) ⇒ Boolean

Check if the edit is correct (not by a spammer, no editing clash)

old_page

the page as it is on disk

checksum

the checksum submitted with the edit

Returns:

  • (Boolean)


190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 190

def accept_edit?(web,old_page,checksum)
  checksum = checksum.strip
  if @checksum_required then
    check = old_page.checksum(@checksum_salt)
    if check != checksum then
      author   = web.user
      pagename = web.name.length > 0 ? "#{web.name}/#{web.current_page}" : web.current_page 

      log("User #{author} gave wrong checksum when editing '#{pagename}': #{checksum} vs #{check}.")
    end
    return check == checksum
  end
  true
end

#accept_page?(web, content) ⇒ Boolean

Check if the submitted content can be accepted. Default=true

web

a Web object describing the request

content

a String with the submitted page content

Returns:

  • (Boolean)


176
177
178
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 176

def accept_page?(web,content)
  true
end

#accept_user?(web) ⇒ Boolean

Check if we want to accept calls from the user before doing anything

web

a Web object describing the request

true by default, subclasses can override

Returns:

  • (Boolean)


183
184
185
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 183

def accept_user?(web)
  true
end

#add_processor(type, proc) ⇒ Object



214
215
216
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 214

def add_processor(type,proc)
  @processors[type] =  proc
end

#banned_urlsObject



107
108
109
110
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 107

def banned_urls
  @banned_urls ||= storage.load_blacklist('url',true)
  @banned_urls
end

#banned_usersObject



102
103
104
105
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 102

def banned_users
  @banned_users ||= storage.load_blacklist('user')
  @banned_users
end

#blacklist_user(spammer) ⇒ Object

Add the spammer IP address to the blacklist



206
207
208
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 206

def blacklist_user(spammer)
  
end

#chonqed_urlsObject



112
113
114
115
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 112

def chonqed_urls
  @chonqed_urls ||= storage.load_blacklist('chonqed')
  @chonqed_urls
end

#closeObject

Discard configuration. Closes logger object, if present



123
124
125
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 123

def close
  @logger.close unless @logger.nil? 
end

#commit_to_repository(comment = 'No Comment') ⇒ Object

Put changes in the repository Call #use_repository to enable.



244
245
246
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 244

def commit_to_repository(comment='No Comment')
  [ "Commit not implemented" ]
end

#default_wikiObject

Default Web object based on the following fields.

@server

hostname. Default = localhost

@port

server port. Default = 8081

@default_web

subwiki. Default = ‘Wiki2Go’. Empty unless @multi_wiki

@default_page

first page. Default = ‘FrontPage’



147
148
149
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 147

def default_wiki
  return Wiki2Go::Web.new(@server,@port.to_s,'','','view',(@multi_wiki ? @default_web : ''),@default_page)
end

#editable?(web) ⇒ Boolean

Is this request one for an editable page? Subclasses should override to do security checking (if necessary) Default = true

Returns:

  • (Boolean)


154
155
156
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 154

def editable?(web)
  true
end

#enable_dot_graphics(dot_executable_path) ⇒ Object

Call dot enable ‘dot’ graphics. Graphviz must be installed. See www.graphviz.org

dot_executable_path

path where ‘dot’ command is installed



299
300
301
302
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 299

def enable_dot_graphics(dot_executable_path)
  require 'Wiki2Go/DotGraphics'
  add_processor('GRAPH',Wiki2Go::DotGraphics.new(dot_executable_path))
end

#enable_syntax_highlightingObject

Call to enable Syntax plugin. ‘Syntax’ gem must be installed. See rubyforge.org/projects/syntax/



291
292
293
294
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 291

def enable_syntax_highlighting
  require 'Wiki2Go/SyntaxHighlighter'
  add_processor('Syntax',Wiki2Go::SyntaxHighlighter.new)
end

#errorlog(msg) ⇒ Object

Log an error message



133
134
135
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 133

def errorlog(msg)
  logger.error(msg)
end

#greylistObject



117
118
119
120
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 117

def greylist
  @greylist ||= storage.load_greylist
  @greylist
end

#instant_commit_to_repository(comment = 'No Comment') ⇒ Object

Put changes in the repository as each file gets added/updated. Call #use_repository to enable.



250
251
252
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 250

def instant_commit_to_repository(comment='No Comment')
  [ "Instant Commit not implemented" ]
end

#log(msg) ⇒ Object

Log an informational message if @debug



128
129
130
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 128

def log(msg)
  logger.info(msg) if @debug
end

#logfileObject

Filename of the log file. Default = ./logs/wiki.log



138
139
140
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 138

def logfile
  File.join( @root_directory,'logs','wiki.log')
end

#loggerObject

return current Logger object. Override #make_logger to make customer Logger object. Object must conform to standard Logger interface



97
98
99
100
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 97

def logger
  @logger ||= make_logger
  @logger
end

#preprocess(web, content) ⇒ Object



218
219
220
221
222
223
224
225
226
227
228
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 218

def preprocess(web,content)
  if content =~ /^<!--([^:]+):(.*)-->$/m then
    type = $1
    value = $2
    processor = @processors[type] 
    if !processor.nil? then
      content = processor.process(self,web,value)
    end
  end
  content
end

#redirect_to_html?(web) ⇒ Boolean

Returns:

  • (Boolean)


210
211
212
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 210

def redirect_to_html?(web)
  @generate_html && !web.secure?
end

#redirect_url?(web, url) ⇒ Boolean

Should this url be redirected, to avoid a direct link? Subclasses should override this to reduce harm by wikispam Default = false

Returns:

  • (Boolean)


161
162
163
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 161

def redirect_url?(web,url)
  false
end

#save(web, page) ⇒ Object



230
231
232
233
234
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 230

def save(web,page)
  process_comment(web,page.content)

  storage.save_page(web.name,page)
end

#static_web(web) ⇒ Object



165
166
167
168
169
170
171
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 165

def static_web(web) 
  copy = web.clone
  copy.server        = web.server.gsub(/^edit\./,"www.")
  copy.script_prefix = web.script_prefix.gsub(/\/secure/,"")
  copy.request       = nil
  return copy
end

#storageObject

return current Storage object. Override #make_storage to make a custom storage object



90
91
92
93
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 90

def storage
  @storage ||= make_storage
  @storage
end

#update_from_repositoryObject

Get changes from the repository Call #use_repository to enable.



238
239
240
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 238

def update_from_repository
  return [] , ["Update not implemented"]
end

#use_repository(root, modulename) ⇒ Object

Call to enable repository integration.

root

CVSROOT of the repository. Must exist and webserver must have commit access.

modulename

name of a module in the repository. Must exist.



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/Wiki2Go/Wiki2GoConfig.rb', line 257

def use_repository(root,modulename)
  @root = root
  @modulename = modulename

  require 'Wiki2Go/Install/make_repository'

  def update_from_repository
    cvs = Wiki2Go::RepositoryMaker.new(@root,logger)
    updated,clashed = cvs.update(@root_directory,@modulename)
    log("UPDATE: Updated files : #{updated.join(', ')}")
    log("UPDATE: Clashed files : #{clashed.join(', ')}")
    return updated,clashed
  end

  def commit_to_repository(comment='No Comment')
    cvs = Wiki2Go::RepositoryMaker.new(@root,logger)
    report = cvs.add_wiki(@root_directory,@modulename,comment)
    log("COMMIT: #{report.join}")
    return report
  end

  def instant_commit_to_repository(comment='No Comment')
    cvs = Wiki2Go::RepositoryMaker.new(@root,logger)
    if cvs.is_local?(@root_directory,@modulename) then
      report = cvs.add_wiki(@root_directory,@modulename,comment)
      log("COMMIT: #{report.join}")
      return report
    end
    return []
  end
end