jenkins-bot has submitted this change and it was merged.
Change subject: Verifies tokens from paraminfo
......................................................................
Verifies tokens from paraminfo
Resolves the API warnings due to tokens which only concern global accounts.
Instead of hard coded variables TOKENS_[012] , now using the following:
For mwVersion < 1.20 gets the tokens from action=paraminfo&querymodules=info
For mwVersion < 1.24wmf19 and >= 1.20 from action=paraminfo&modules=tokens
For mwVersion > 1.24wmf19 from action=paraminfo&querymodules=tokens
and replacing those required and present in action=paraminfo&querymodules=info
or action=paraminfo&modules=tokens by 'csrf'
Bug: T72965
Bug: T85725
Change-Id: I3ff70dd8b9ee33fde15bd13d7af15db408aefc7d
---
M pywikibot/site.py
1 file changed, 27 insertions(+), 56 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 222145d..fdecbe0 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -1492,50 +1492,6 @@
# Pages; see method docs for details) --
#
- # Constants for token management.
- # For all MediaWiki versions prior to 1.20.
- # 'patrol' is indirectly supported via 'edit' token or
recentchanges.
- # It will be converted in site.validate_tokens()/site.get_tokens().
- TOKENS_0 = set(['edit',
- 'delete',
- 'protect',
- 'move',
- 'block',
- 'unblock',
- 'email',
- 'import',
- 'watch',
- 'patrol',
- ])
-
- # For all MediaWiki versions, with 1.20 <= version < 1.24wmf19
- TOKENS_1 = set(['block',
- 'centralauth',
- 'delete',
- 'deleteglobalaccount',
- 'undelete',
- 'edit',
- 'email',
- 'import',
- 'move',
- 'options',
- 'patrol',
- 'protect',
- 'setglobalaccountstatus',
- 'unblock',
- 'watch',
- ])
-
- # For all MediaWiki versions >= 1.24wmf19
- TOKENS_2 = set(['csrf',
- 'deleteglobalaccount',
- 'patrol',
- 'rollback',
- 'setglobalaccountstatus',
- 'userrights',
- 'watch',
- ])
-
def __init__(self, code, fam=None, user=None, sysop=None):
"""Constructor."""
BaseSite.__init__(self, code, fam, user, sysop)
@@ -2646,7 +2602,10 @@
"""
_version = MediaWikiVersion(self.version())
if _version < MediaWikiVersion('1.20'):
- valid_types = [token for token in types if token in self.TOKENS_0]
+ types_wiki = self._paraminfo.parameter('query+info',
+ 'token')['type']
+ types_wiki.append('patrol')
+ valid_types = [token for token in types if token in types_wiki]
# Pre 1.17, preload token was the same as the edit token.
if _version < MediaWikiVersion('1.17'):
@@ -2654,16 +2613,22 @@
valid_types.append('edit')
elif _version < MediaWikiVersion('1.24wmf19'):
- valid_types = [token for token in types if token in self.TOKENS_1]
+ types_wiki = self._paraminfo.parameter('tokens',
+ 'type')['type']
+ valid_types = [token for token in types if token in types_wiki]
else:
- valid_types = []
+ types_wiki_old = self._paraminfo.parameter('query+info',
+ 'token')['type']
+ types_wiki_action = self._paraminfo.parameter('tokens',
+
'type')['type']
+ types_wiki = self._paraminfo.parameter('query+tokens',
+ 'type')['type']
+ valid_types = [token for token in types if token in types_wiki]
for token in types:
- if ((token in self.TOKENS_0 or token in self.TOKENS_1) and
- token not in self.TOKENS_2):
- token = 'csrf'
- if token in self.TOKENS_2:
- valid_types.append(token)
-
+ if (token not in valid_types and
+ (token in types_wiki_old or
+ token in types_wiki_action)):
+ valid_types.append('csrf')
return valid_types
def get_tokens(self, types, all=False):
@@ -2708,7 +2673,9 @@
_version = MediaWikiVersion(self.version())
if _version < MediaWikiVersion('1.20'):
if all:
- types.extend(self.TOKENS_0)
+ types_wiki = self._paraminfo.parameter('query+info',
+ 'token')['type']
+ types.extend(types_wiki)
valid_tokens = set(self.validate_tokens(types))
# don't request patrol
query = api.PropertyGenerator('info',
@@ -2746,12 +2713,16 @@
else:
if _version < MediaWikiVersion('1.24wmf19'):
if all is not False:
- types.extend(self.TOKENS_1)
+ types_wiki = self._paraminfo.parameter('action+tokens',
+
'type')['type']
+ types.extend(types_wiki)
req = api.Request(site=self, action='tokens',
type='|'.join(self.validate_tokens(types)))
else:
if all is not False:
- types.extend(self.TOKENS_2)
+ types_wiki = self._paraminfo.parameter('query+tokens',
+
'type')['type']
+ types.extend(types_wiki)
req = api.Request(site=self, action='query',
meta='tokens',
type='|'.join(self.validate_tokens(types)))
--
To view, visit
https://gerrit.wikimedia.org/r/196450
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3ff70dd8b9ee33fde15bd13d7af15db408aefc7d
Gerrit-PatchSet: 11
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Akashagarwal <akashslg(a)gmail.com>
Gerrit-Reviewer: Akashagarwal <akashslg(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>