Page MenuHomePhabricator

page.botMayEdit should return the correct value even if the bot has not logged in.
Closed, ResolvedPublic

Description

Currently the method expects the bot to be logged in, or otherwise it always returns True:

$ python /shared/pywikipedia/core/pwb.py shell -user:SignBot
Welcome to the Pywikibot interactive shell!
>>> site = pywikibot.Site(user="SignBot")
>>> page = pywikibot.Page(site, 'User_talk:CommonsDelinker/commands/Category_moves')
>>> page.botMayEdit()
True
>>> page.site.user()
>>> page.site.login()
Logging in to commons:commons as SignBot
>>> page.site.user()
'SignBot'
>>> page.botMayEdit()
False
>>>

Event Timeline

Restricted Application added subscribers: pywikibot-bugs-list, Aklapper. · View Herald TranscriptDec 17 2016, 12:12 PM
Dvorapa added a subscriber: Dvorapa.EditedJun 7 2018, 11:44 AM

The fix is relatively easy, but I'm not sure what should it return instead. Should it return just for the current username (even if it is not logged in? can not-logged-in bot edit a page?) Or should it always return False if bot not logged in?

Because bots using OAUTH are not considered logged-in by Pywikibot, those bots will always ignore bot-specific exclusion templates. However, site.username() will return the username. page.botMayEdit should fail safe, which means that it should return False when the username matches, even if the bot is not logged in. That's a very easy fix, and I'll put a patch in momentarily.

Change 609277 had a related patch set uploaded (by AntiCompositeNumber; owner: AntiCompositeNumber):
[pywikibot/core@master] page.botMayEdit: Use site.username() instead of site.user()

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

JJMC89 claimed this task.Jul 3 2020, 2:45 AM
JJMC89 reassigned this task from JJMC89 to AntiCompositeNumber.
JJMC89 added a subscriber: JJMC89.
JJMC89 removed a subscriber: JJMC89.
Xqt triaged this task as Low priority.Jul 3 2020, 4:33 AM

Change 609277 merged by jenkins-bot:
[pywikibot/core@master] page.botMayEdit: Use site.username() instead of site.user()

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

Xqt closed this task as Resolved.Sat, Jul 4, 7:36 PM