(bug 32497) API now allows changing of protection level using pageid
authorAlex Monk <krenair@gmail.com>
Sat, 7 Apr 2012 19:31:27 +0000 (20:31 +0100)
committerAlex Monk <krenair@gmail.com>
Sat, 7 Apr 2012 20:00:55 +0000 (21:00 +0100)
Change-Id: I01802dde2fba9510cbdf23522ddac59f36a93960

RELEASE-NOTES-1.20
includes/api/ApiEditPage.php
includes/api/ApiProtect.php

index c6b2756..92e8367 100644 (file)
@@ -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 ===
 
index 608f815..796b049 100644 (file)
@@ -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' ),
index fb225d8..ec7b560 100644 (file)
@@ -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() {