jenkins-bot has submitted this change and it was merged.
Change subject: Adding a bunch of actions to block on simulate mode ......................................................................
Adding a bunch of actions to block on simulate mode
There were several actions that weren't listed in actions_to_block, but also perform modifications on the server.
Since there was also a list of write actions in api.py, I've merged them on that file, and left actions_to_block empty as an additional list of actions to add for wiki families with more extensions, etc
Repurposed the list of actions in api.py so that they're also checked when we've specified the -simulate option
I went to https://www.mediawiki.org/w/api.php and added all of them that are part of core and the description contains "This module requires write rights"
Bug: 69896 Change-Id: Ibbd05e86bf585e3c9f21670fd2be1978dbe27ebd --- M pywikibot/config2.py M pywikibot/data/api.py M pywikibot/site.py 3 files changed, 20 insertions(+), 12 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved XZise: Looks good to me, but someone else must approve jenkins-bot: Verified
diff --git a/pywikibot/config2.py b/pywikibot/config2.py index 4b31fc1..6ea3c45 100644 --- a/pywikibot/config2.py +++ b/pywikibot/config2.py @@ -638,11 +638,11 @@
# Simulate settings
-# Defines what actions the bots are NOT allowed to do (e.g. 'edit') on wikipedia -# servers. Allows simulation runs of bots to be carried out without changing any -# page on the server side. This setting may be overridden in user_config.py. -actions_to_block = ['edit', 'watch', 'move', 'delete', 'undelete', 'protect', - 'emailuser'] +# Defines what additional actions the bots are NOT allowed to do (e.g. 'edit') +# on the wiki server. Allows simulation runs of bots to be carried out without +# changing any page on the server side. Use this setting to add more actions +# in user-config.py for wikis with extra write actions. +actions_to_block = []
# Set simulate to True or use -simulate option to block all actions given above. simulate = False diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index 643369c..bdb39a3 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -137,14 +137,19 @@ if "action" not in kwargs: raise ValueError("'action' specification missing from Request.") self.update(**kwargs) + # Actions that imply database updates on the server, used for various + # things like throttling or skipping actions when we're in simulation + # mode self.write = self.params["action"] in ( "edit", "move", "rollback", "delete", "undelete", "protect", "block", "unblock", "watch", "patrol", - "import", "userrights", "upload", "wbeditentity", - "wbsetlabel", "wbsetdescription", "wbsetaliases", - "wblinktitles", "wbsetsitelink", "wbcreateclaim", - "wbremoveclaims", "wbsetclaimvalue", "wbsetreference", - "wbremovereferences" + "import", "userrights", "upload", "emailuser", + "createaccount", "setnotificationtimestamp", + "filerevert", "options", "purge", "revisiondelete", + "wbeditentity", "wbsetlabel", "wbsetdescription", + "wbsetaliases", "wblinktitles", "wbsetsitelink", + "wbcreateclaim", "wbremoveclaims", "wbsetclaimvalue", + "wbsetreference", "wbremovereferences" ) # MediaWiki 1.23 allows assertion for any action, # whereas earlier WMF wikis and others used an extension which @@ -251,7 +256,7 @@ return "%s.%s<%s->%r>" % (self.__class__.__module__, self.__class__.__name__, self.site, str(self))
def _simulate(self, action): - if action and config.simulate and action in config.actions_to_block: + if action and config.simulate and (self.write or action in config.actions_to_block): pywikibot.output( u'\03{lightyellow}SIMULATION: %s action blocked.\03{default}' % action) diff --git a/pywikibot/site.py b/pywikibot/site.py index befcf3a..698be2d 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -3950,7 +3950,10 @@ pywikibot.output(u"Upload: unrecognized response: %s" % result) if result["result"] == "Success": pywikibot.output(u"Upload successful.") - filepage._imageinfo = result["imageinfo"] + # If we receive a nochange, that would mean we're in simulation + # mode, don't attempt to access imageinfo + if "nochange" not in result: + filepage._imageinfo = result["imageinfo"] return
@deprecate_arg("number", "step")