Nullzero has uploaded a new change for review.

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

Change subject: Implement expiry in protect()
......................................................................

Implement expiry in protect()

This patch implements a way to set the duration of protection, like
that in block().

Change-Id: I4981f4f094c082ce75ae2973b581bdc3063b10ee
---
M pywikibot/page.py
M pywikibot/site.py
2 files changed, 9 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/77/115177/1

diff --git a/pywikibot/page.py b/pywikibot/page.py
index b75bbc3..f633cb2 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -1411,7 +1411,7 @@
 
     @deprecate_arg("throttle", None)
     def protect(self, edit='sysop', move='sysop', unprotect=False,
-                reason=None, prompt=True):
+                reason=None, prompt=True, expiry=None):
         """(Un)protect a wiki page. Requires administrator status.
 
         Valid protection levels (in MediaWiki 1.12) are '' (equivalent to
@@ -1423,6 +1423,7 @@
             all protection levels to '')
         @param reason: Edit summary.
         @param prompt: If true, ask user for confirmation.
+        @param expiry: When the block should expire
 
         """
         if reason is None:
@@ -1447,7 +1448,7 @@
                 answer = 'y'
                 self.site._noProtectPrompt = True
         if answer in ['y', 'Y']:
-            return self.site.protect(self, edit, move, reason)
+            return self.site.protect(self, edit, move, reason, expiry)
 
     def change_category(self, oldCat, newCat, comment=None, sortKey=None,
                         inPlace=True):
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 3d85c6b..8824a06 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -3099,7 +3099,7 @@
     }
 
     @must_be(group='sysop')
-    def protect(self, page, edit, move, summary):
+    def protect(self, page, edit, move, summary, expiry=None):
         """(Un)protect a wiki page. Requires administrator status.
 
         Valid protection levels (in MediaWiki 1.12) are '' (equivalent to
@@ -3111,6 +3111,7 @@
             all protection levels to '')
         @param reason: Edit summary.
         @param prompt: If true, ask user for confirmation.
+        @param expiry: When the block should expire
 
         """
         token = self.token(page, "protect")
@@ -3119,6 +3120,10 @@
                           title=page.title(withSection=False),
                           protections="edit=" + edit + "|" + "move=" + move,
                           reason=summary)
+        if isinstance(expiry, pywikibot.Timestamp):
+            expiry = expiry.toISOformat()
+        if expiry:
+            req['expiry'] = expiry
         try:
             result = req.submit()
         except api.APIError as err:

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4981f4f094c082ce75ae2973b581bdc3063b10ee
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Nullzero <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to