rwikibot 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/CHANGELOG +6 -1
  2. data/lib/rwikibot.rb +15 -11
  3. data/sample-config.yaml +6 -0
  4. metadata +4 -2
data/CHANGELOG CHANGED
@@ -1,7 +1,12 @@
1
1
  RWikiBot ChangeLog
2
2
 
3
3
  1.0.4
4
- - Small code change for config operations
4
+ - Changed config.yaml to sample-config.yaml
5
+ - Had rake include the sample-config.yaml file
6
+ - Fixed broken cookie code to ask for wikicookieprefix, which is usually dbname+tableprefix
7
+
8
+ 1.0.3
9
+ - Bugfix in config file
5
10
 
6
11
  1.0.2
7
12
  - Changed initialize to ask for a configuration to use, defaulting to 'default'
data/lib/rwikibot.rb CHANGED
@@ -26,7 +26,7 @@ class RWikiBot
26
26
  # New bots hope for three attributes, but require none. The first is simply the name of the bot for logging purposes. The second is the debug level constant, and third is the logfile.
27
27
  #
28
28
  # Example: bot = RWikiBot.new("My Neat Bot", Logger::DEBUG, "./rwikibot.log")
29
- def initialize (name = "Unnamed Bot", config = 'default', debuglevel = Logger::INFO, log_location = "./rwikibot.log" )
29
+ def initialize (name = "Unnamed Bot", config = 'default', debuglevel = Logger::DEBUG, log_location = "./rwikibot.log" )
30
30
 
31
31
  @botname = name
32
32
 
@@ -41,11 +41,9 @@ class RWikiBot
41
41
  # Load the configuration!! (saved the file based, because I liked it too much.)
42
42
  @wikibotlogger.debug "Loading configuration..."
43
43
  config_file = YAML.load_file('config.yaml')
44
- use_config = config
45
- @wikibotlogger.debug "Config loaded. Using settings: #{use_config}"
46
44
 
47
45
  #now, the hash that will hold the config options
48
- @config = config_file.fetch(use_config)
46
+ @config = config_file.fetch(config)
49
47
  @config['logged_in'] = FALSE
50
48
  @config['uri'] = URI.parse(@config.fetch('api_path'))
51
49
 
@@ -287,7 +285,7 @@ class RWikiBot
287
285
 
288
286
  # This will get all pages. Limits vary based on user rights of the Bot. Set to bot.
289
287
  @wikibotlogger.debug "ALL PAGES - Preparing request information..."
290
- post_me = {'list' => 'allpages', 'apnamespace' => '0', 'aplimit' => '5000'}
288
+ post_me = {'list' => 'allpages', 'apnamespace' => '0', 'aplimit' => '500'}
291
289
 
292
290
  #make the request
293
291
  @wikibotlogger.debug "ALL PAGES - Asking make_request to get all pages..."
@@ -458,7 +456,7 @@ class RWikiBot
458
456
 
459
457
  #Send the actual request
460
458
  @wikibotlogger.debug "MAKE REQUEST - Sending request..."
461
- resp = @http.post( @config.fetch('uri').path , post_string , {'User-agent' => 'RWikiBot/0.1','Cookie' => bake(@config.fetch('cookie'))})
459
+ resp = @http.post( @config.fetch('uri').path , post_string , {'User-agent' => 'RWikiBot/0.1','Cookie' => bake(@config.fetch('cookie')) } )
462
460
  @wikibotlogger.info "MAKE REQUEST - Response: "
463
461
  @wikibotlogger.info resp.body
464
462
  @wikibotlogger.debug "MAKE REQUEST - End Response "
@@ -470,7 +468,7 @@ class RWikiBot
470
468
 
471
469
  # A small check to make sure we don't need to save cookie data. Because usually, we don't
472
470
  if @config.fetch('logged_in') == FALSE
473
- @config['cookie'] = resp.header['set-cookie']
471
+ @config['cookie'] = resp.header['set-cookie'] if @config.fetch('cookie').nil?
474
472
  @wikibotlogger.debug "MAKE REQUEST - Received login cookie. Cookie is: #{resp.header['set-cookie']}"
475
473
  end
476
474
 
@@ -491,14 +489,20 @@ class RWikiBot
491
489
  def bake(cookie)
492
490
 
493
491
  # Make some dough. Let CGI parse set-cookie, since there's multiple set-cookies and this is hard
494
- dough = CGI::Cookie::parse(cookie)
492
+ dough = CGI::Cookie::parse(cookie)
493
+ dough.each do |key, value|
494
+ puts "#{key} => #{value}"
495
+ end
495
496
 
496
497
  # Take the dough and get my three elements out
497
- # wikidb_wiki_UserID wikidb_wiki_UserName wikidb_wiki_Token
498
498
 
499
- if cookie != nil
500
- return "#{dough.fetch(@config.fetch('wikidbprefix')+'UserID')}; #{dough.fetch(@config.fetch('wikidbprefix')+'UserName')}; #{dough.fetch(@config.fetch('wikidbprefix')+'Token')}"
499
+ if @config.fetch('logged_in') == TRUE
500
+ @wikibotlogger.debug "BAKE - Baking a cookie... Smells like wiki."
501
+ return "#{dough.fetch(@config.fetch('wikicookieprefix')+'UserID')}; #{dough.fetch(@config.fetch('wikicookieprefix')+'UserName')}; #{dough.fetch(@config.fetch('wikicookieprefix')+'Token')}"
502
+ # return "#{dough.fetch('wikidb_UserID')}; #{dough.fetch('wikidb_UserName')}; #{dough.fetch('wikidb_Token')}"
503
+
501
504
  else
505
+ @wikibotlogger.debug "BAKE - No cookies to bake this time."
502
506
  return ""
503
507
  end
504
508
 
@@ -0,0 +1,6 @@
1
+ default:
2
+ username: "RWikiBot"
3
+ password: "rwikibot"
4
+ domain: 'en'
5
+ api_path: "http://localhost:8888/wiki/api.php"
6
+ wikicookieprefix: 'wikidb_wiki_' #this is the MediaWiki default
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: rwikibot
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.3
7
- date: 2007-02-28 00:00:00 -06:00
6
+ version: 1.0.4
7
+ date: 2007-03-01 00:00:00 -06:00
8
8
  summary: A library for creating MediaWiki bots.
9
9
  require_paths:
10
10
  - lib
@@ -29,6 +29,7 @@ authors:
29
29
  - Eddie Roger
30
30
  files:
31
31
  - lib/rwikibot.rb
32
+ - sample-config.yaml
32
33
  - README
33
34
  - CHANGELOG
34
35
  test_files: []
@@ -38,6 +39,7 @@ rdoc_options:
38
39
  extra_rdoc_files:
39
40
  - README
40
41
  - CHANGELOG
42
+ - sample-config.yaml
41
43
  executables: []
42
44
 
43
45
  extensions: []