Page MenuHomePhabricator

Get tags of edit in user.contributions() in Pywikibot
Closed, ResolvedPublicFeature

Description

Feature summary (what you would like to be able to do and where): user.contributions should return tags of an edit as well.

Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution):
I used code like:

from pywikibot import Site, User

user = User(Site("en"), input('Enter user name: '))
counts = {}
for page, oldid, ts, comment in user.contributions(50):
   # do some stuff with contributions here

It would be nice if we could get the tags of the contribution, like in line 5 of the code block above.

Benefits (why should this be implemented?): The Mediawiki API has a method for getting tags of an edit, so it should be possible. Also, this helps count edits better by making it possible to exclude a specific tag (e.g. mw-reverted).

Event Timeline

Xqt triaged this task as Medium priority.May 22 2022, 6:31 PM

Change 803388 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] [WIP] Enable all prop informations with usercontribs

https://gerrit.wikimedia.org/r/803388

The path above is not completed but can be used as follow to get all needed prop informations from API:Usercontribs like:

import pywikibot
site = pywikibot.Site('wikipedia:en')
user = pywikibot.User(site, <your_user_name>)
for uc in site.usercontribs(user=user.username, total=50, prop=['comment', 'ids', 'timestamp', 'title', 'tags']:
    # upcast page and timestamp if necessary
    page = pywikibot.Page(site, uc['title'], uc['ns'])
    timestamp = pywikibot.Timestamp.fromISOformat(uc['timestamp'])
    # get tags
    tags = uc['tags']
    # do other stuff

The User.contribution() method was also changed.

Old style usage:

>>> site = pywikibot.Site('wikipedia:test')
>>> user = pywikibot.User(site, 'Pywikibot-test')
>>> # set reverse=True to get the oldest contributions first
>>> uc = list(user.contributions(total=1, reverse=True))
>>> page, revid, timestamp, comment = uc[0]
>>> page.title()
'User:Unicodesnowman/DeleteMark'
>>> revid
504586
>>> timestamp.totimestampformat()
'20220304173541'
>>> comment
'pywikibot unit test. Do NOT actually delete.'

For new style usage a prop keyword mustbe given even it is None:

>>> site = pywikibot.Site('wikipedia:test')
>>> user = pywikibot.User(site, 'Pywikibot-test')
>>> uc = list(user.contributions(total=1, reverse=True, prop='tags'))
>>> # 'title' prop is always added
>>> page, data = uc[0]
>>> data.title
'User:Unicodesnowman/DeleteMark'
>>> page.title() == data.title
True
>>> data.tags  # attribute access
['mw-manual-revert']
>>> data['tags']  # key access
['mw-manual-revert']
Xqt removed Xqt as the assignee of this task.Oct 11 2024, 4:31 PM
Xqt claimed this task.
Xqt subscribed.
Xqt changed the task status from Open to In Progress.Jul 16 2026, 8:47 AM
Xqt edited projects, added: Patch-For-Review; removed: Patch-Needs-Improvement.
Xqt moved this task from Backlog to Needs Review on the Pywikibot board.

Change #803388 merged by jenkins-bot:

[pywikibot/core@master] [feature] Enable all prop informations with usercontribs and User.contribs

https://gerrit.wikimedia.org/r/803388