jenkins-bot has submitted this change and it was merged.

Change subject: use API assert for supported 'write' actions
......................................................................


use API assert for supported 'write' actions

For MediaWiki 1.23+ extend the existing assertion, that the bot is logged in,
to cover all write operations.

Also add check that the AssertEdit extension is present before asserting
for MediaWiki versions 1.14 to 1.22.  Prior versions do not provide a
list of running extensions.

If the first operation to the site is a edit operation, before server
capabilities have been determined, do the assertion unconditionally
as the api module doesnt know check.  If the server doesnt understand
the assert, it will issue a warning but others behave properly.

Bug: 55068
Change-Id: I80971cde07651a042ef6472dc1a81cb4a1704742
---
M pywikibot/data/api.py
1 file changed, 15 insertions(+), 1 deletion(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 7102074..e25c996 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -26,6 +26,7 @@
 import re
 import traceback
 import time
+from distutils.version import LooseVersion as LV
 
 import pywikibot
 from pywikibot import config, login
@@ -141,7 +142,20 @@
             "wbremoveclaims", "wbsetclaimvalue", "wbsetreference",
             "wbremovereferences"
         )
-        if self.params["action"] == "edit":
+        # MediaWiki 1.23 allows assertion for any action,
+        # whereas earlier WMF wikis and others used an extension which
+        # could only allow assert for action=edit.  Do not look up
+        # the extension info if the siteinfo has not been loaded,
+        # otherwise cyclic recursion will occur.
+
+        # Check siteinfo has not been loaded to avoid infinite loop
+        if hasattr(self.site, "_siteinfo"):
+            use_assert_edit_extension = self.site.hasExtension('AssertEdit', 
False)
+        else:
+            use_assert_edit_extension = True
+
+        if (self.write and LV(self.site.version()) >= LV("1.23") or
+                self.params["action"] == "edit" and use_assert_edit_extension):
             pywikibot.debug(u"Adding user assertion", _logger)
             self.params["assert"] = "user"  # make sure user is logged in
 

-- 
To view, visit https://gerrit.wikimedia.org/r/147837
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I80971cde07651a042ef6472dc1a81cb4a1704742
Gerrit-PatchSet: 7
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: Ricordisamoa <[email protected]>
Gerrit-Reviewer: Russell Blau <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to