Mpaa has uploaded a new change for review.

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

Change subject: Fetch patrol token for MW < 1.20
......................................................................

Fetch patrol token for MW < 1.20

Get patrol token for versions < MW 1.20.

Since patrol was added in v1.14, until v1.16, the patrol token is the
same as the edit token.

For MW 1.17-19, the patrol token must be obtained from the query list
recentchanges.

Bug: TT85727
Change-Id: Ibbba1f8e0093f28d8cefd86a71f225938bc4a8a1
---
M pywikibot/site.py
1 file changed, 32 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/90/182690/1

diff --git a/pywikibot/site.py b/pywikibot/site.py
index 973edaf..c87d42c 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -2608,6 +2608,12 @@
         _version = MediaWikiVersion(self.version())
         if _version < MediaWikiVersion('1.20'):
             valid_types = [token for token in types if token in self.TOKENS_0]
+
+            # Pre 1.17, preload token was was the same as the edit token.
+            if _version < MediaWikiVersion('1.17'):
+                if 'patrol' in types and 'edit' not in valid_types:
+                    valid_types.append('edit')
+
         elif _version < MediaWikiVersion('1.24wmf19'):
             valid_types = [token for token in types if token in self.TOKENS_1]
         else:
@@ -2630,13 +2636,19 @@
         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 will default to the 'csrf' token.
+
         The other token types available are:
          - deleteglobalaccount
-         - patrol
+         - patrol (*)
          - rollback
          - setglobalaccountstatus
          - userrights
          - watch
+
+         (*) Patrol was added in v1.14.
+             Until v1.16, the patrol token is same as the edit token.
+             For v1.17-19, the patrol token must be obtained from the query
+             list recentchanges.
 
         @param types: the types of token (e.g., "edit", "move", "delete");
             see API documentation for full list of types
@@ -2670,6 +2682,25 @@
                     if (tokentype + 'token') in item:
                         user_tokens[tokentype] = item[tokentype + 'token']
 
+            # patrol token require special handling.
+            # TODO: try to catch exceptions?
+            if 'patrol' in types:
+                if MediaWikiVersion('1.14') <= _version < 
MediaWikiVersion('1.17'):
+                    user_tokens['patrol'] = user_tokens['edit']
+                else:
+                    req = api.Request(site=self, action='query',
+                                      list='recentchanges',
+                                      rctoken='patrol', rclimit=1)
+
+                    req._warning_handler = warn_handler
+                    data = req.submit()
+
+                    if 'query' in data:
+                        data = data['query']
+                        if 'recentchanges' in data:
+                            item = data['recentchanges'][0]
+                            user_tokens['patrol'] = item.get('patroltoken', 
None)
+
         else:
             if _version < MediaWikiVersion('1.24wmf19'):
                 if all is not False:

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibbba1f8e0093f28d8cefd86a71f225938bc4a8a1
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <mpaa.w...@gmail.com>

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

Reply via email to