jenkins-bot has submitted this change and it was merged.
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. For APISite.protect(), the prototype of the function is completely changed. However, the function is used internally, so there should be no problem. For Page.protect(), although it might be considered a breaking change since parameter "create" and "upload" are inserted between the old parameters, it is unlikely anyone will be affected negatively because most people would call this function by specifying keyword argument. 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, 40 insertions(+), 22 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
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..33bfb51 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 unprotect: If true, unprotect the page (equivalent to setting - all protection levels to '') + @param create: Level of create protection + @param upload: Level of upload protection + @param unprotect: If true, unprotect page editing and moving + (equivalent to set both edit and move 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. If None, 'infinite', 'indefinite', 'never', or '' + is given, there is no expiry. + @type expiry: pywikibot.Timestamp, string in GNU timestamp format + (including ISO 8601). """ if reason is None: if unprotect: @@ -1483,6 +1489,9 @@ reason = pywikibot.input(u'Please enter a reason for the action:') if unprotect: edit = move = "" + # Apply to only edit and move for backward compatibility. + # To unprotect article creation, for example, + # create must be set to '' and the rest must be None answer = 'y' if prompt and not hasattr(self.site, '_noProtectPrompt'): answer = pywikibot.inputChoice( @@ -1495,7 +1504,13 @@ answer = 'y' self.site._noProtectPrompt = True if answer in ['y', 'Y']: - return self.site.protect(self, edit, move, reason, expiry) + protections = { + 'edit': edit, + 'move': move, + 'create': create, + 'upload': upload, + } + return self.site.protect(self, protections, 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 7e621a3..c171f7a 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -3078,26 +3078,29 @@ }
@must_be(group='sysop') - def protect(self, page, edit, move, summary, expiry=None): + def protect(self, page, protections, 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'. - - @param edit: Level of edit protection - @param move: Level of move 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 protections: A dict mapping type of protection to protection + level of that type. Valid types of protection are 'edit', 'move', + 'create', and 'upload'. Valid protection levels (in MediaWiki 1.12) + are '' (equivalent to 'none'), 'autoconfirmed', and 'sysop'. + If None is given, however, that protection will be skipped. + @param summary: Edit summary. + @param expiry: When the block should expire. This expiry will be applied + to all protections. If None, 'infinite', 'indefinite', 'never', or '' + is given, there is no expiry. + @type expiry: pywikibot.Timestamp, string in GNU timestamp format + (including ISO 8601). """ token = self.token(page, "protect") self.lock_page(page) + + protectList = [type + '=' + level for type, level in protections.items() + if level is not None] req = api.Request(site=self, action="protect", token=token, title=page.title(withSection=False), - protections="edit=" + edit + "|" + "move=" + move, + protections=protectList, reason=summary) if isinstance(expiry, pywikibot.Timestamp): expiry = expiry.toISOformat()
pywikibot-commits@lists.wikimedia.org