Module: MediaWiki::Query::Lists::Log

Includes:
Block, Delete, Import, Merge, Move, NewUsers, Patrol, Protect, Rights, Upload
Included in:
MediaWiki::Query::Lists
Defined in:
lib/mediawiki/query/lists/log/log.rb,
lib/mediawiki/query/lists/log/move.rb,
lib/mediawiki/query/lists/log/block.rb,
lib/mediawiki/query/lists/log/merge.rb,
lib/mediawiki/query/lists/log/delete.rb,
lib/mediawiki/query/lists/log/import.rb,
lib/mediawiki/query/lists/log/patrol.rb,
lib/mediawiki/query/lists/log/rights.rb,
lib/mediawiki/query/lists/log/upload.rb,
lib/mediawiki/query/lists/log/protect.rb,
lib/mediawiki/query/lists/log/newusers.rb

Defined Under Namespace

Modules: Block, Delete, Import, Merge, Move, NewUsers, Patrol, Protect, Rights, Upload

Instance Method Summary collapse

Methods included from Upload

#get_upload_log, #get_upload_overwrite_log

Methods included from Rights

#get_autopromotion_log, #get_rights_log

Methods included from Protect

#get_modify_protection_log, #get_move_protected_log, #get_protect_log, #get_unprotect_log

Methods included from Patrol

#get_patrol_log

Methods included from NewUsers

#get_autocreate_users_log, #get_user_create2_log, #get_user_create_log

Methods included from Move

#get_move_log, #get_move_redirect_log

Methods included from Merge

#get_merge_log

Methods included from Import

#get_interwiki_import_log, #get_upload_import_log

Methods included from Delete

#get_delete_log, #get_deletion_restore_log

Methods included from Block

#get_block_log, #get_reblock_log, #get_unblock_log

Instance Method Details

#get_log(action, user = nil, title = nil, start = nil, stop = nil, limit = @query_limit_default) ⇒ Hash (private)

Gets log events.

Parameters:

  • action (String)

    The action, e.g., block/block.

  • user (String) (defaults to: nil)

    The user to filter by.

  • title (String) (defaults to: nil)

    The title to filter by.

  • start (DateTime) (defaults to: nil)

    Where to start the log events at.

  • stop (DateTime) (defaults to: nil)

    Where to end the log events.

  • limit (Fixnum) (defaults to: @query_limit_default)

    The limit, maximum 500 for users or 5000 for bots.

Returns:

  • (Hash)

    The response.

See Also:

Since:

  • 0.10.0



138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/mediawiki/query/lists/log/log.rb', line 138

def get_log(action, user = nil, title = nil, start = nil, stop = nil, limit = @query_limit_default)
  params = {
    action: 'query',
    list: 'logevents',
    leaction: action,
    lelimit: get_limited(limit)
  }
  params[:leuser] = user unless user.nil?
  params[:letitle] = title unless title.nil?
  params[:lestart] = start.xmlschema unless start.nil?
  params[:leend] = stop.xmlschema unless stop.nil?
  post(params)
end

#get_overall_log(user = nil, title = nil, start = nil, stop = nil, limit = @query_limit_default) ⇒ Array<Hash>

Gets the general log as seen in Special:Log. Since not every single log type possible can be supported, non-default MW logs will be represented exactly as provided by the API, with the :skipped key as true.

Parameters:

  • user (String) (defaults to: nil)

    The user to filter by.

  • title (String) (defaults to: nil)

    The title to filter by.

  • start (DateTime) (defaults to: nil)

    Where to start the log events at.

  • stop (DateTime) (defaults to: nil)

    Where to end the log events.

  • limit (Fixnum) (defaults to: @query_limit_default)

    The limit, maximum 500 for users or 5000 for bots.

Returns:

  • (Array<Hash>)

    All the log events.

See Also:

Since:

  • 0.10.0



40
41
42
43
44
45
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/mediawiki/query/lists/log/log.rb', line 40

def get_overall_log(user = nil, title = nil, start = nil, stop = nil, limit = @query_limit_default)
  params = {
    action: 'query',
    list: 'logevents',
    lelimit: get_limited(limit)
  }
  params[:leuser] = user unless user.nil?
  params[:letitle] = title unless title.nil?
  params[:lestart] = start.xmlschema unless start.nil?
  params[:leend] = stop.xmlschema unless stop.nil?
  response = post(params)

  ret = []
  response['query']['logevents'].each do |log|
    case log['type']
    when 'block'
      case log['action']
      when 'block', 'reblock'
        hash = loghash_block(log)
      when 'unblock'
        hash = loghash_unblock(log)
      end
    when 'delete'
      case log['action']
      when 'delete', 'restore'
        hash = loghash_general(log)
      end
    when 'import'
      case log['action']
      when 'interwiki'
        hash = loghash_importinterwiki(log)
      when 'upload'
        hash = loghash_importupload(log)
      end
    when 'merge'
      case log['action']
      when 'merge'
        hash = loghash_merge(log)
      end
    when 'move'
      case log['action']
      when 'move', 'move_redir'
        hash = loghash_move(log)
      end
    when 'newusers'
      case log['action']
      when 'autocreate', 'create', 'create2'
        hash = loghash_user(log)
      end
    when 'patrol'
      case log['action']
      when 'patrol'
        hash = loghash_patrol(log)
      end
    when 'protect'
      case log['action']
      when 'modify', 'protect'
        hash = loghash_protect(log)
      when 'move_prot'
        hash = loghash_protectmoveprot(log)
      when 'unprotect'
        hash = loghash_protectunprotect(log)
      end
    when 'rights'
      case log['action']
      when 'autopromote'
        hash = loghash_rightsautopromote(log)
      when 'rights'
        hash = loghash_rightsrights(log)
      end
    when 'upload'
      case log['action']
      when 'overwrite', 'upload'
        hash = loghash_upload(log)
      end
    end

    hash = log if hash.nil?

    type = "#{log['type']}/#{log['action']}"

    hash[:type] = type
    hash[:skipped] = false unless hash.key(:skipped)

    ret << hash
  end

  ret
end

#loghash_block(log) ⇒ Object (private)



152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/mediawiki/query/lists/log/log.rb', line 152

def loghash_block(log)
  hash = {
    id: log['logid'],
    blocked: log['title'],
    flags: log['params']['flags'],
    duration: log['params']['duration'],
    blocker: log['user'],
    comment: log['comment'],
    timestamp: DateTime.xmlschema(log['timestamp'])
  }
  hash[:expiry] = DateTime.xmlschema(log['params']['expiry']) if log['params'].key?('expiry')

  hash
end

#loghash_general(log) ⇒ Object (private)



200
201
202
203
204
205
206
207
208
# File 'lib/mediawiki/query/lists/log/log.rb', line 200

def loghash_general(log)
  {
    id: log['logid'],
    title: log['title'],
    user: log['user'],
    timestamp: DateTime.xmlschema(log['timestamp']),
    comment: log['comment']
  }
end

#loghash_importinterwiki(log) ⇒ Object (private)



177
178
179
180
181
182
183
184
185
186
187
# File 'lib/mediawiki/query/lists/log/log.rb', line 177

def loghash_importinterwiki(log)
  {
    id: log['logid'],
    title: log['title'],
    user: log['user'],
    comment: log['comment'],
    timestamp: DateTime.xmlschema(log['timestamp']),
    count: log['params']['count'],
    interwiki_title: log['params']['interwiki_title']
  }
end

#loghash_importupload(log) ⇒ Object (private)



189
190
191
192
193
194
195
196
197
198
# File 'lib/mediawiki/query/lists/log/log.rb', line 189

def loghash_importupload(log)
  {
    id: log['logid'],
    title: log['title'],
    user: log['user'],
    comment: log['comment'],
    timestamp: DateTime.xmlschema(log['timestamp']),
    count: log['params']['count']
  }
end

#loghash_merge(log) ⇒ Object (private)



210
211
212
213
214
215
216
217
218
219
220
# File 'lib/mediawiki/query/lists/log/log.rb', line 210

def loghash_merge(log)
  {
    id: log['logid'],
    title: log['title'],
    user: log['user'],
    comment: log['comment'],
    destination_title: log['params']['dest_title'],
    mergepoint: DateTime.xmlschema(log['params']['mergepoint']),
    timestamp: DateTime.xmlschema(log['timestamp'])
  }
end

#loghash_move(log) ⇒ Object (private)



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/mediawiki/query/lists/log/log.rb', line 222

def loghash_move(log)
  hash = {
    id: log['logid'],
    timestamp: DateTime.xmlschema(log['timestamp'])
  }

  if log.key?('actionhidden')
    hash[:hidden] = true
    hash[:old_title] = nil
    hash[:comment] = nil
    hash[:suppressedredirect] = log.key('suppressed')
  else
    hash[:old_title] = log['title']
    hash[:new_title] = log['params']['target_title']
    hash[:user] = log['user']
    hash[:comment] = log['comment']

    hash[:suppressedredirect] = log['params'].key?('suppressedredirect')
  end

  hash
end

#loghash_patrol(log) ⇒ Object (private)



255
256
257
258
259
260
261
262
263
264
265
# File 'lib/mediawiki/query/lists/log/log.rb', line 255

def loghash_patrol(log)
  {
    id: log['logid'],
    title: log['title'],
    user: log['user'],
    comment: log['comment'],
    current_revision: log['params']['curid'],
    previous_revision: log['params']['previd'],
    timestamp: DateTime.xmlschema(log['timestamp'])
  }
end

#loghash_protect(log) ⇒ Object (private)



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/mediawiki/query/lists/log/log.rb', line 267

def loghash_protect(log)
  hash = {
    id: log['logid'],
    title: log['title'],
    description: log['params']['description'],
    user: log['user'],
    comment: log['comment'],
    timestamp: DateTime.xmlschema(log['timestamp'])
  }

  hash[:details] = []

  # It appears that older protection logs did not have a details key.
  if log['params'].key?('details')
    log['params']['details'].each do |detail|
      details_hash = {
        type: detail['type'],
        level: detail['level']
      }
      expire = detail['expiry']
      if expire != 'infinite'
        details_hash[:expiry] = DateTime.xmlschema(expire)
      end
      hash[:details] << details_hash
    end
  end

  hash
end

#loghash_protectmoveprot(log) ⇒ Object (private)



297
298
299
300
301
302
303
304
305
306
# File 'lib/mediawiki/query/lists/log/log.rb', line 297

def loghash_protectmoveprot(log)
  {
    id: log['logid'],
    title: log['title'],
    old_title: log['params']['oldtitle_title'],
    user: log['user'],
    comment: log['comment'],
    timestamp: DateTime.xmlschema(log['timestamp'])
  }
end

#loghash_protectunprotect(log) ⇒ Object (private)



308
309
310
311
312
313
314
315
316
# File 'lib/mediawiki/query/lists/log/log.rb', line 308

def loghash_protectunprotect(log)
  {
    id: log['logid'],
    title: log['title'],
    user: log['user'],
    comment: log['comment'],
    timestamp: DateTime.xmlschema(log['timestamp'])
  }
end

#loghash_rightsautopromote(log) ⇒ Object (private)



318
319
320
321
322
323
324
325
326
327
# File 'lib/mediawiki/query/lists/log/log.rb', line 318

def loghash_rightsautopromote(log)
  {
    id: log['logid'],
    user: log['user'],
    new_rights: log['params']['newgroups'],
    old_rights: log['params']['oldgroups'],
    comment: log['comment'],
    timestamp: DateTime.xmlschema(log['timestamp'])
  }
end

#loghash_rightsrights(log) ⇒ Object (private)



329
330
331
332
333
334
335
336
337
338
339
# File 'lib/mediawiki/query/lists/log/log.rb', line 329

def loghash_rightsrights(log)
  {
    id: log['logid'],
    to: log['title'],
    from: log['user'],
    new_rights: log['params']['newgroups'],
    old_rights: log['params']['oldgroups'],
    comment: log['comment'],
    timestamp: DateTime.xmlschema(log['timestamp'])
  }
end

#loghash_unblock(log) ⇒ Object (private)



167
168
169
170
171
172
173
174
175
# File 'lib/mediawiki/query/lists/log/log.rb', line 167

def loghash_unblock(log)
  {
    id: log['logid'],
    blocked: log['title'],
    blocker: log['user'],
    timestamp: DateTime.xmlschema(log['timestamp']),
    comment: log['comment']
  }
end

#loghash_upload(log) ⇒ Object (private)



341
342
343
344
345
346
347
348
349
350
# File 'lib/mediawiki/query/lists/log/log.rb', line 341

def loghash_upload(log)
  {
    id: log['logid'],
    title: log['title'],
    user: log['user'],
    sha: log['img_sha1'],
    comment: log['comment'],
    timestamp: DateTime.xmlschema(log['timestamp'])
  }
end

#loghash_user(log) ⇒ Object (private)



245
246
247
248
249
250
251
252
253
# File 'lib/mediawiki/query/lists/log/log.rb', line 245

def loghash_user(log)
  {
    id: log['logid'],
    new_user: log['title'],
    user: log['user'],
    comment: log['comment'],
    timestamp: DateTime.xmlschema(log['timestamp'])
  }
end