Nullzero has uploaded a new change for review.
https://gerrit.wikimedia.org/r/139792
Change subject: Support protecting action=create/upload
......................................................................
Support protecting action=create/upload
This patch makes it possible to protect creating a page or uploading a file.
Note that it is a breaking change since parameter "create" and "upload" are
inserted between the old parameters. However, for Page.protect(), it is unlikel
anyone will be affected negatively by this patch because most people would call
this function by specifying keyword argument. For APISite.protect(), no one wou
call it directly. This change therefore should not be problematic.
Besides this, I correct/elaborate docstring. I also change my name in CREDITS
to my preferable name.
Change-Id: I595228ea9a61f7e55dc14f8c3682494c8938cb1e
---
M CREDITS
M pywikibot/page.py
M pywikibot/site.py
3 files changed, 36 insertions(+), 14 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/92/139792/1
diff --git a/CREDITS b/CREDITS
index d99b3fe..a87d3e5 100644
--- a/CREDITS
+++ b/CREDITS
@@ -53,7 +53,6 @@
Mpaa
Nicolas Dumazet
notconfusing
-Nullzer0
Philip Tzou
Platonides
Purodha B Blissenbach
@@ -67,6 +66,7 @@
Shinjiman
Shi Zhao
Siebrand Mazeland
+Sorawee Porncharoenwase
Steve Sanbeg
Sumana Harihareswara
Thomas R. Koll
diff --git a/pywikibot/page.py b/pywikibot/page.py
index b19c09a..9267d7d 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -1457,21 +1457,27 @@
return self.site.undelete(self, comment)
@deprecate_arg("throttle", None)
- def protect(self, edit='sysop', move='sysop', unprotect=False,
- reason=None, prompt=True, expiry=None):
+ def protect(self, edit='sysop', move='sysop', create=None, upload=None,
+ unprotect=False, reason=None, prompt=True, expiry=None):
"""(Un)protect a wiki page. Requires administrator status.
Valid protection levels (in MediaWiki 1.12) are '' (equivalent to
- 'none'), 'autoconfirmed', and 'sysop'.
+ 'none'), 'autoconfirmed', and 'sysop'. If None is given, however,
+ that protection will be skipped.
@param edit: Level of edit protection
@param move: Level of move protection
+ @param create: Level of create protection
+ @param upload: Level of upload protection
@param unprotect: If true, unprotect the page (equivalent to setting
all protection levels to '')
@param reason: Edit summary.
@param prompt: If true, ask user for confirmation.
- @param expiry: When the block should expire
-
+ @param expiry: When the block should expire. This expiry will be
applied
+ to all protections. Possible type of value is
+ pywikibot.Timestamp, string in GNU timestamp format
+ (including ISO 8601). If None, "infinite", "indefinite",
+ "never", or empty string is given, there is no expiry.
"""
if reason is None:
if unprotect:
@@ -1482,7 +1488,7 @@
% (un, self.title(asLink=True)))
reason = pywikibot.input(u'Please enter a reason for the action:')
if unprotect:
- edit = move = ""
+ edit = move = create = upload = ""
answer = 'y'
if prompt and not hasattr(self.site, '_noProtectPrompt'):
answer = pywikibot.inputChoice(
@@ -1495,7 +1501,7 @@
answer = 'y'
self.site._noProtectPrompt = True
if answer in ['y', 'Y']:
- return self.site.protect(self, edit, move, reason, expiry)
+ return self.site.protect(self, edit, move, create, upload, reason,
exp
def change_category(self, oldCat, newCat, comment=None, sortKey=None,
inPlace=True):
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 7e621a3..2fc07bb 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -3078,26 +3078,42 @@
}
@must_be(group='sysop')
- def protect(self, page, edit, move, summary, expiry=None):
+ def protect(self, page, edit, move, create, upload, summary, expiry=None):
"""(Un)protect a wiki page. Requires administrator status.
Valid protection levels (in MediaWiki 1.12) are '' (equivalent to
- 'none'), 'autoconfirmed', and 'sysop'.
+ 'none'), 'autoconfirmed', and 'sysop'. If None is given, however,
+ that protection will be skipped.
@param edit: Level of edit protection
@param move: Level of move protection
+ @param create: Level of create protection
+ @param upload: Level of upload protection
@param unprotect: If true, unprotect the page (equivalent to setting
all protection levels to '')
@param reason: Edit summary.
- @param prompt: If true, ask user for confirmation.
- @param expiry: When the block should expire
-
+ @param expiry: When the block should expire. This expiry will be
applied
+ to all protections. Possible type of value is
+ pywikibot.Timestamp, string in GNU timestamp format
+ (including ISO 8601). If None, "infinite", "indefinite",
+ "never", or empty string is given, there is no expiry.
"""
token = self.token(page, "protect")
self.lock_page(page)
+
+ protectList = []
+ protects = {
+ 'edit': edit,
+ 'move': move,
+ 'create': create,
+ 'upload': upload,
+ }
+ for protectType, protectLevel in protects.items():
+ if protectLevel is not None:
+ protectList.append(protectType + "=" + protectLevel)
req = api.Request(site=self, action="protect", token=token,
title=page.title(withSection=False),
- protections="edit=" + edit + "|" + "move=" + move,
+ protections="|".join(protectList),
reason=summary)
if isinstance(expiry, pywikibot.Timestamp):
expiry = expiry.toISOformat()
--
To view, visit https://gerrit.wikimedia.org/r/139792
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I595228ea9a61f7e55dc14f8c3682494c8938cb1e
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