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

Change subject: [FEAT] Support new token system
......................................................................


[FEAT] Support new token system

With fdddf94570efc33fd06f16c72d41636a45cf203a the token system was
overhauled. This queries with the new token system if the version
is new enough (>= 1.24wmf19).

If the token type is not one of the listed in the api help it is
defaulting to 'csrf'.

Bug: 70060
Change-Id: I54fc1d7ad083f12b80ef52ddb7be592fa82b6b2a
---
M pywikibot/site.py
1 file changed, 26 insertions(+), 3 deletions(-)

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



diff --git a/pywikibot/site.py b/pywikibot/site.py
index 07a280c..7216d7e 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -2191,7 +2191,17 @@
         """Preload one or multiple tokens.
 
         For all MediaWiki versions prior to 1.20, only one token can be
-        retrieved at once.
+        retrieved at once. For MediaWiki versions since 1.24wmfXXX a new token
+        system was introduced which reduced the amount of tokens available.
+        Most of them were merged into the 'csrf' token. If the token type in
+        the parameter is not known it'll default to the 'csrf' token. The other
+        token types available are:
+        - deleteglobalaccount
+        - patrol
+        - rollback
+        - setglobalaccountstatus
+        - userrights
+        - watch
 
         @param types: the types of token (e.g., "edit", "move", "delete");
             see API documentation for full list of types
@@ -2209,8 +2219,21 @@
                     if (tokentype + 'token') in item:
                         storage[tokentype] = item[tokentype + 'token']
         else:
-            data = api.Request(site=self, action='tokens',
-                               type='|'.join(types)).submit()
+            if LV(self.version()) < LV('1.24wmf19'):
+                data = api.Request(site=self, action='tokens',
+                                   type='|'.join(types)).submit()
+            else:
+                # TODO: Fetch that from the API with paraminfo
+                special_names = set('deleteglobalaccount', 'patrol', 
'rollback',
+                                    'setglobalaccountstatus', 'userrights',
+                                    'watch')
+                new_tokens = [token if token in special_names else 'csrf'
+                              for token in types]
+                data = api.Request(action='query',
+                                   tokens='|'.join(new_tokens)).submit()
+                if 'query' in data:
+                    data = data['query']
+
             if 'tokens' in data and data['tokens']:
                 storage.update(dict((key[:-5], val)
                                     for key, val in data['tokens'].items()))

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I54fc1d7ad083f12b80ef52ddb7be592fa82b6b2a
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <commodorefabia...@gmx.de>
Gerrit-Reviewer: John Vandenberg <jay...@gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhall...@arctus.nl>
Gerrit-Reviewer: Ricordisamoa <ricordisa...@openmailbox.org>
Gerrit-Reviewer: XZise <commodorefabia...@gmx.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to