XZise has uploaded a new change for review.

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

Change subject: [FIX] Tokens: Return the csrf token, when such a token is 
requested
......................................................................

[FIX] Tokens: Return the csrf token, when such a token is requested

With the new token system, most of the token names are now 'csrf'
tokens. So if the token name is unknown it uses a csrf token, but it
still looks for the original token name, which is of course not
present.

Instead of a warning, it only returns '+\' if the user has not enough
rights with the new token system.

Change-Id: I38e326c0f5382a585fba11bc6cbfba1a3dffaca5
---
M pywikibot/site.py
1 file changed, 10 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/91/159991/1

diff --git a/pywikibot/site.py b/pywikibot/site.py
index eb7cf93..3c0eb42 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -1185,9 +1185,16 @@
     def __init__(self, site):
         self.site = site
         self.site._tokens = {}
+        # TODO: Fetch that from the API with paraminfo
+        self.special_names = set(['deleteglobalaccount', 'patrol', 'rollback',
+                                  'setglobalaccountstatus', 'userrights',
+                                  'watch'])
 
     def __getitem__(self, key):
         storage = self.site._tokens.setdefault(self.site.user(), {})
+        if (LV(self.site.version()) >= LV('1.24wmf19')
+                and key not in self.special_names):
+            key = 'csrf'
         if key not in storage:
             self.site.preload_tokens([key])
         return storage[key]
@@ -2295,11 +2302,7 @@
                 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'
+                new_tokens = [token if token in self.tokens.special_names else 
'csrf'
                               for token in types]
                 data = api.Request(action='query', meta='tokens',
                                    type='|'.join(new_tokens)).submit()
@@ -2308,7 +2311,8 @@
 
             if 'tokens' in data and data['tokens']:
                 storage.update(dict((key[:-5], val)
-                                    for key, val in data['tokens'].items()))
+                                    for key, val in data['tokens'].items()
+                                    if val != '+\\'))
 
     @deprecated("the 'tokens' property")
     def token(self, page, tokentype):

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I38e326c0f5382a585fba11bc6cbfba1a3dffaca5
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <commodorefabia...@gmx.de>

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

Reply via email to