Revision: 7967
Author: xqt
Date: 2010-02-26 16:20:35 +0000 (Fri, 26 Feb 2010)
Log Message:
-----------
enable logpagesPageGenerator for special:log entries
Modified Paths:
--------------
trunk/pywikipedia/interwiki.py
trunk/pywikipedia/pagegenerators.py
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/interwiki.py
===================================================================
--- trunk/pywikipedia/interwiki.py 2010-02-26 09:20:14 UTC (rev 7966)
+++ trunk/pywikipedia/interwiki.py 2010-02-26 16:20:35 UTC (rev 7967)
@@ -190,8 +190,9 @@
(note: without ending colon)
-initialredirect work on its target if a redirect or category redirect is
- entered on the command line or by a generator.
- (note: without ending colon)
+ entered on the command line or by a generator (note: without
+ ending colon). It is recommended to use this option with
+ -movelog pagegenerator.
-neverlink: used as -neverlink:xx where xx is a language code:
Disregard any links found to language xx. You can also
Modified: trunk/pywikipedia/pagegenerators.py
===================================================================
--- trunk/pywikipedia/pagegenerators.py 2010-02-26 09:20:14 UTC (rev 7966)
+++ trunk/pywikipedia/pagegenerators.py 2010-02-26 16:20:35 UTC (rev 7967)
@@ -115,6 +115,19 @@
delimited with ";"
Example: -usercontribs:DumZiBoT;500
returns 500 distinct pages to work on.
+
+-<mode>log Work on articles that were on a specified special:log.
+ You have options for every type of logs given by the
+ <mode> parameter which could be one of the following:
+ block, protect, rights, delete, upload, move, import,
+ patrol, merge, suppress, review, stable, gblblock,
+ renameuser, globalauth, gblrights, abusefilter, newusers
+ Examples:
+ -movelog gives 500 pages from move log (should be redirects)
+ -deletelog:10 gives 10 pages from deletion log
+ -protect:Dummy gives 500 pages from protect by user Dummy
+ -patrol:Dummy;20 gives 20 pages patroled by user Dummy
+ In some cases this must be written as -patrol:"Dummy;20"
-weblink Work on all articles that contain an external link to
a given URL; may be given as "-weblink:url"
@@ -286,6 +299,12 @@
for page in site.prefixindex(prefix = title, namespace = namespace, includeredirects = includeredirects):
yield page
+def LogpagesPageGenerator(number = 500, mode='', user=None, repeat = False, site = None, namespace=[]):
+ if site is None:
+ site = pywikibot.getSite()
+ for page in site.logpages(number=number, mode=mode, user=user, repeat=repeat, namespace=namespace):
+ yield page[0]
+
def NewpagesPageGenerator(number = 100, get_redirect = False, repeat = False, site = None, namespace = 0):
if site is None:
site = pywikibot.getSite()
@@ -1145,7 +1164,7 @@
limit = arg[11:] or pywikibot.input(
u'How many images do you want to load?')
gen = NewimagesPageGenerator(number = int(limit))
- elif arg.startswith('-new'):
+ elif arg == ('-new') or arg.startswith('-new:'):
if len(arg) >=5:
gen = NewpagesPageGenerator(number = int(arg[5:]))
else:
@@ -1175,7 +1194,25 @@
elif arg.startswith('-yahoo'):
gen = YahooSearchPageGenerator(arg[7:])
else:
- pass
+ mode, log, user = arg.partition('log')
+ if log == 'log':
+ number = 500
+ if not user:
+ user = None
+ else:
+ try:
+ number = int(user[1:])
+ user = None
+ except ValueError:
+ user = user[1:]
+ if user:
+ result = user.split(';')
+ user = result[0]
+ try:
+ number = int(result[1])
+ except:
+ pass
+ gen = LogpagesPageGenerator(number, mode[1:], user)
if gen:
self.gens.append(gen)
return self.getCombinedGenerator()
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2010-02-26 09:20:14 UTC (rev 7966)
+++ trunk/pywikipedia/wikipedia.py 2010-02-26 16:20:35 UTC (rev 7967)
@@ -5928,6 +5928,59 @@
yield page, '', '', '', '', ''
# TODO: avoid code duplication for the following methods
+
+ def logpages(self, number=50, mode='', user=None, repeat=False, namespace=[], offset=-1):
+ if config.use_api:
+ apiURL = self.api_address()
+ del apiURL
+ else:
+ raise NotImplementedError
+ if mode not in ('block', 'protect', 'rights', 'delete', 'upload',
+ 'move', 'import', 'patrol', 'merge', 'suppress',
+ 'review', 'stable', 'gblblock', 'renameuser',
+ 'globalauth', 'gblrights', 'abusefilter', 'newusers'):
+ raise NotImplementedError
+ params = {
+ 'action' : 'query',
+ 'list' : 'logevents',
+ 'letype' : mode,
+ 'lelimit' : int(number),
+ }
+
+ if number > config.special_page_limit:
+ params['lelimit'] = config.special_page_limit
+ if number > 5000 and self.site().isAllowed('apihighlimits'):
+ params['lelimit'] = 5000
+ if user:
+ params['leuser'] = user
+ nbresults = 0
+ while True:
+ result = query.GetData(params, self)
+ if 'error' in result or 'warnings' in result:
+ output('%s' % result)
+ raise Error
+ for c in result['query']['logevents']:
+ if not namespace or c['ns'] in namespace:
+ yield (Page(self, c['title'], defaultNamespace=c['ns']),
+ c['user'],
+ parsetime2stamp(c['timestamp']),
+ c['comment'],
+ )
+
+ nbresults += 1
+ if nbresults >= number:
+ break
+ if 'query-continue' in result and nbresults < number:
+ params['ucstart'] = result['query-continue']['logevents']['ucstart']
+ elif repeat:
+ nbresults = 0
+ try:
+ params.pop('ucstart')
+ except KeyError:
+ pass
+ else:
+ break
+ return
def newpages(self, number = 10, get_redirect = False, repeat = False, namespace = 0):
"""Yield new articles (as Page objects) from Special:Newpages.