jenkins-bot has submitted this change and it was merged.
Change subject: [Bugfix] Revision.timestamp is a pwb Timestamp not ISOformat string ......................................................................
[Bugfix] Revision.timestamp is a pwb Timestamp not ISOformat string
- rewrite UserEditFilterGenerator - use page revisions generator instead of getLatestEditors - introduce max_revision_depth parameter for further extensions - remember Revision.timestamp is already a pywikibot.Timestamp - "found and not skip or not found and skip" is a xor operation. We can simplify it with "found ^ skip" or better with "found != skip" - We stop iteration after time limit is exceeded
Change-Id: I525f9ed1c71cb502514afe388dc05b8f1dc3c205 --- M scripts/template.py 1 file changed, 15 insertions(+), 14 deletions(-)
Approvals: XZise: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/template.py b/scripts/template.py index de98b32..f82d097 100755 --- a/scripts/template.py +++ b/scripts/template.py @@ -100,8 +100,8 @@ # # (C) Daniel Herding, 2004 # (C) Rob W.W. Hooft, 2003-2005 -# (C) xqt, 2009-2014 -# (C) Pywikibot team, 2004-2014 +# (C) xqt, 2009-2015 +# (C) Pywikibot team, 2004-2015 # # Distributed under the terms of the MIT license. # @@ -114,31 +114,31 @@ from scripts import replace
-def UserEditFilterGenerator(generator, username, timestamp=None, skip=False): +def UserEditFilterGenerator(generator, username, timestamp=None, skip=False, + max_revision_depth=None): """ Generator which will yield Pages modified by username.
- It only looks at the last 100 editors. + It only looks at the last editors given by max_revision_depth. If timestamp is set in MediaWiki format JJJJMMDDhhmmss, older edits are - ignored + ignored. If skip is set, pages edited by the given user are ignored otherwise only - pages edited by this user are given back - + pages edited by this user are given back. """ if timestamp: ts = pywikibot.Timestamp.fromtimestampformat(timestamp) + else: + ts = pywikibot.Timestamp.min for page in generator: - editors = page.getLatestEditors(limit=100) found = False - for ed in editors: - uts = pywikibot.Timestamp.fromISOformat(ed['timestamp']) - if not timestamp or uts >= ts: - if username == ed['user']: + for ed in page.revisions(total=max_revision_depth): + if ed.timestamp >= ts: + if username == ed.user: found = True break else: break - if found and not skip or not found and skip: + if found != bool(skip): # xor operation yield page else: pywikibot.output(u'Skipping %s' % page.title(asLink=True)) @@ -378,7 +378,8 @@ gen = pagegenerators.CombinedPageGenerator(gens) gen = pagegenerators.DuplicateFilterPageGenerator(gen) if user: - gen = UserEditFilterGenerator(gen, user, timestamp, skip) + gen = UserEditFilterGenerator(gen, user, timestamp, skip, + max_revision_depth=100)
if not genFactory.gens: # make sure that proper namespace filtering etc. is handled
pywikibot-commits@lists.wikimedia.org