From c6e693cb9883b710e3aa9963b1f44bb77389bf6b Mon Sep 17 00:00:00 2001 From: Alex Monk Date: Sat, 7 Apr 2012 20:31:27 +0100 Subject: [PATCH] (bug 32497) API now allows changing of protection level using pageid Change-Id: I01802dde2fba9510cbdf23522ddac59f36a93960 --- RELEASE-NOTES-1.20 | 1 + includes/api/ApiEditPage.php | 2 +- includes/api/ApiProtect.php | 47 ++++++++++++++++++++++++------------ 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20 index c6b275663a..92e836755d 100644 --- a/RELEASE-NOTES-1.20 +++ b/RELEASE-NOTES-1.20 @@ -84,6 +84,7 @@ production. * (bug 32384) Allow descending order for list=watchlistraw. * (bug 31883) Limit of bkusers of list=blocks and titles of action=query is not documented in API help. * (bug 32492) API now allows editing using pageid +* (bug 32497) API now allows changing of protection level using pageid === Languages updated in 1.20 === diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 608f815f63..796b049746 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -381,7 +381,7 @@ class ApiEditPage extends ApiBase { global $wgMaxArticleSize; return array_merge( parent::getPossibleErrors(), - $this->getRequireOnlyOneParameterErrorMessages( 'title', 'pageid' ), + $this->getRequireOnlyOneParameterErrorMessages( array( 'title', 'pageid' ) ), array( array( 'nosuchpageid', 'pageid' ), array( 'missingtext' ), diff --git a/includes/api/ApiProtect.php b/includes/api/ApiProtect.php index fb225d86b6..ec7b560b88 100644 --- a/includes/api/ApiProtect.php +++ b/includes/api/ApiProtect.php @@ -37,9 +37,18 @@ class ApiProtect extends ApiBase { global $wgRestrictionLevels; $params = $this->extractRequestParams(); - $titleObj = Title::newFromText( $params['title'] ); - if ( !$titleObj ) { - $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); + $this->requireOnlyOneParameter( $params, 'title', 'pageid' ); + + if ( isset( $params['title'] ) ) { + $titleObj = Title::newFromText( $params['title'] ); + if ( !$titleObj ) { + $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); + } + } elseif ( isset( $params['pageid'] ) ) { + $titleObj = Title::newFromID( $params['pageid'] ); + if ( !$titleObj ) { + $this->dieUsageMsg( array( 'nosuchpageid', $params['pageid'] ) ); + } } $errors = $titleObj->getUserPermissionsErrors( 'protect', $this->getUser() ); @@ -138,7 +147,9 @@ class ApiProtect extends ApiBase { return array( 'title' => array( ApiBase::PARAM_TYPE => 'string', - ApiBase::PARAM_REQUIRED => true + ), + 'pageid' => array( + ApiBase::PARAM_TYPE => 'integer', ), 'token' => null, 'protections' => array( @@ -169,8 +180,10 @@ class ApiProtect extends ApiBase { } public function getParamDescription() { + $p = $this->getModulePrefix(); return array( - 'title' => 'Title of the page you want to (un)protect', + 'title' => "Title of the page you want to (un)protect. Cannot be used together with {$p}pageid", + 'pageid' => "ID of the page you want to (un)protect. Cannot be used together with {$p}title", 'token' => 'A protect token previously retrieved through prop=info', 'protections' => 'Pipe-separated list of protection levels, formatted action=group (e.g. edit=sysop)', 'expiry' => array( 'Expiry timestamps. If only one timestamp is set, it\'ll be used for all protections.', @@ -188,16 +201,20 @@ class ApiProtect extends ApiBase { } public function getPossibleErrors() { - return array_merge( parent::getPossibleErrors(), array( - array( 'invalidtitle', 'title' ), - array( 'toofewexpiries', 'noofexpiries', 'noofprotections' ), - array( 'create-titleexists' ), - array( 'missingtitle-createonly' ), - array( 'protect-invalidaction', 'action' ), - array( 'protect-invalidlevel', 'level' ), - array( 'invalidexpiry', 'expiry' ), - array( 'pastexpiry', 'expiry' ), - ) ); + return array_merge( parent::getPossibleErrors(), + $this->getRequireOnlyOneParameterErrorMessages( array( 'title', 'pageid' ) ), + array( + array( 'invalidtitle', 'title' ), + array( 'nosuchpageid', 'pageid' ), + array( 'toofewexpiries', 'noofexpiries', 'noofprotections' ), + array( 'create-titleexists' ), + array( 'missingtitle-createonly' ), + array( 'protect-invalidaction', 'action' ), + array( 'protect-invalidlevel', 'level' ), + array( 'invalidexpiry', 'expiry' ), + array( 'pastexpiry', 'expiry' ), + ) + ); } public function needsToken() { -- 2.20.1