Xqt has uploaded a new change for review.
https://gerrit.wikimedia.org/r/231859
Change subject: [FEAT] use site.newfiles for uploadimages
......................................................................
[FEAT] use site.newfiles for uploadimages
- Enable a variant tuple yielded by site.newfiles which could be configurated
by prop parameter.
- update doc for newfiles
- return empty string for LogEntry.comment instead of None
Change-Id: Ifd1f3aad6c93b03f5ddab7b71dbc29945dc17b45
---
M pywikibot/logentries.py
M pywikibot/page.py
M pywikibot/site.py
3 files changed, 26 insertions(+), 18 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/59/231859/1
diff --git a/pywikibot/logentries.py b/pywikibot/logentries.py
index e7e560d..b5def89 100644
--- a/pywikibot/logentries.py
+++ b/pywikibot/logentries.py
@@ -121,7 +121,7 @@
return self._timestamp
def comment(self):
- return self.data['comment']
+ return self.data['comment'] or ''
class BlockEntry(LogEntry):
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 470d118..d37df2c 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -3038,21 +3038,22 @@
"""Yield tuples describing files uploaded by this user.
Each tuple is composed of a pywikibot.Page, the timestamp (str in
- ISO8601 format), comment (unicode) and a bool for pageid > 0.
+ ISO8601 format), comment (unicode) and a bool for pageid > 0 which
+ indicates that the page exists on local wiki.
+
Pages returned are not guaranteed to be unique.
@param total: limit result to this number of pages
@type total: int
+ @rtype: generator
"""
if not self.isRegistered():
raise StopIteration
- for item in self.site.logevents(
- logtype='upload', user=self.username, total=total):
- yield (item.page(),
- unicode(item.timestamp()),
- item.comment(),
- item.pageid() > 0
- )
+ return ((page, unicode(timestamp), comment, pageid > 0)
+ for page, timestamp, comment, pageid in
+ self.site.newfiles(
+ user=self.username, total=total,
+ prop=('page', 'timestamp', 'comment', 'pageid')))
class WikibasePage(BasePage):
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 3938d06..4dc5659 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -5439,25 +5439,32 @@
@deprecated_args(lestart='start', leend='end', leuser='user', letitle=None,
repeat=None, number='total')
def newfiles(self, user=None, start=None, end=None, reverse=False,
- step=None, total=None):
+ step=None, total=None, prop=None):
"""Yield information about newly uploaded files.
- Yields a tuple of FilePage, Timestamp, user(unicode), comment(unicode).
+ The yielded tuple may be given by the prop parameter which represents
+ logevent methods.
+ Default tuple is FilePage, Timestamp, user(unicode), comment(unicode).
N.B. the API does not provide direct access to Special:Newimages, so
this is derived from the "upload" log events instead.
+ @param user: only iterate entries that match this user name
+ @param start: only iterate entries from and after this Timestamp
+ @param end: only iterate entries up to and through this Timestamp
+ @param reverse: if True, iterate oldest entries first (default: newest)
+ @param step: request batch size
+ @param total: number of pages to return
+ @param prop: tuple or list of logevent methods
+ @return: tuple of information about uploaded files
+ @rtype: generator
"""
- # TODO: update docstring
+ if prop == None:
+ prop = ('page', 'timestamp', 'user', 'comment')
for event in self.logevents(logtype="upload", user=user,
start=start, end=end, reverse=reverse,
step=step, total=total):
- # event.page() actually returns a FilePage
- filepage = event.page()
- date = event.timestamp()
- user = event.user()
- comment = event.comment() or u''
- yield (filepage, date, user, comment)
+ yield tuple(getattr(event, method)() for method in prop)
@deprecated("Site().newfiles()")
@deprecated_args(number='total', repeat=None)
--
To view, visit https://gerrit.wikimedia.org/r/231859
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifd1f3aad6c93b03f5ddab7b71dbc29945dc17b45
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits