jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/517604 )

Change subject: feat(APISite.purgepages): raise error on invalid arguments
......................................................................

feat(APISite.purgepages): raise error on invalid arguments

Also add param info to the docstrings of BasePage.purge and purgepages.

Bug: T225993
Change-Id: I1b59d9749c5668a54be8c86dfaedbdce98f810f2
---
M pywikibot/page.py
M pywikibot/site.py
2 files changed, 42 insertions(+), 13 deletions(-)

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



diff --git a/pywikibot/page.py b/pywikibot/page.py
index fb7507d..f93dbd9 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -1412,6 +1412,17 @@
         """
         Purge the server's cache for this page.

+        @keyword redirects: Automatically resolve redirects.
+        @type redirects: bool
+        @keyword converttitles: Convert titles to other variants if necessary.
+            Only works if the wiki's content language supports variant
+            conversion.
+        @type converttitles: bool
+        @keyword forcelinkupdate: Update the links tables.
+        @type forcelinkupdate: bool
+        @keyword forcerecursivelinkupdate: Update the links table, and update
+            the links tables for any page that uses this page as a template.
+        @type forcerecursivelinkupdate: bool
         @rtype: bool
         """
         self.clear_cache()
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 04e0e87..ee2c84c 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -6049,32 +6049,50 @@
         return ('unwatched' if unwatch else 'watched') in result['watch']

     @must_be(group='user')
-    def purgepages(self, pages, **kwargs):
+    def purgepages(
+        self, pages, forcelinkupdate=False, forcerecursivelinkupdate=False,
+        converttitles=False, redirects=False
+    ):
         """
         Purge the server's cache for one or multiple pages.

-        @see: U{https://www.mediawiki.org/wiki/API:Purge}
-
         @param pages: list of Page objects
+        @param redirects: Automatically resolve redirects.
+        @type redirects: bool
+        @param converttitles: Convert titles to other variants if necessary.
+            Only works if the wiki's content language supports variant
+            conversion.
+        @type converttitles: bool
+        @param forcelinkupdate: Update the links tables.
+        @type forcelinkupdate: bool
+        @param forcerecursivelinkupdate: Update the links table, and update the
+            links tables for any page that uses this page as a template.
+        @type forcerecursivelinkupdate: bool
         @return: True if API returned expected response; False otherwise
         @rtype: bool
         """
         req = self._simple_request(action='purge',
                                    titles=[page for page in set(pages)])
-        linkupdate_args = ['forcelinkupdate', 'forcerecursivelinkupdate']
-        for arg in kwargs:
-            if arg in linkupdate_args + ['redirects', 'converttitles']:
-                req[arg] = kwargs[arg]
+        if converttitles:
+            req['converttitles'] = True
+        if redirects:
+            req['redirects'] = True
+        if forcelinkupdate:
+            req['forcelinkupdate'] = True
+        if forcerecursivelinkupdate:
+            req['forcerecursivelinkupdate'] = True
         result = req.submit()
-        if 'purge' not in result:
+        try:
+            result = result['purge']
+        except KeyError:
             pywikibot.error(
                 'purgepages: Unexpected API response:\n%s' % result)
             return False
-        result = result['purge']
-        purged = ['purged' in page for page in result]
-        if any(kwargs.get(arg) for arg in linkupdate_args):
-            purged += ['linkupdate' in page for page in result]
-        return all(purged)
+        if not all('purged' in page for page in result):
+            return False
+        if forcelinkupdate or forcerecursivelinkupdate:
+            return all('linkupdate' in page for page in result)
+        return True

     @deprecated('Site().exturlusage', since='20090529')
     def linksearch(self, siteurl, limit=None, euprotocol=None):

--
To view, visit https://gerrit.wikimedia.org/r/517604
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I1b59d9749c5668a54be8c86dfaedbdce98f810f2
Gerrit-Change-Number: 517604
Gerrit-PatchSet: 5
Gerrit-Owner: Dalba <[email protected]>
Gerrit-Reviewer: Dalba <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot (75)
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to