summaryrefslogtreecommitdiff
path: root/includes/api/ApiProtect.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/api/ApiProtect.php')
-rw-r--r--includes/api/ApiProtect.php62
1 files changed, 39 insertions, 23 deletions
diff --git a/includes/api/ApiProtect.php b/includes/api/ApiProtect.php
index fb225d86..b3ca67e6 100644
--- a/includes/api/ApiProtect.php
+++ b/includes/api/ApiProtect.php
@@ -4,7 +4,7 @@
*
* Created on Sep 1, 2007
*
- * Copyright © 2007 Roan Kattouw <Firstname>.<Lastname>@gmail.com
+ * Copyright © 2007 Roan Kattouw "<Firstname>.<Lastname>@gmail.com"
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -37,10 +37,8 @@ class ApiProtect extends ApiBase {
global $wgRestrictionLevels;
$params = $this->extractRequestParams();
- $titleObj = Title::newFromText( $params['title'] );
- if ( !$titleObj ) {
- $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
- }
+ $pageObj = $this->getTitleOrPageId( $params, 'fromdbmaster' );
+ $titleObj = $pageObj->getTitle();
$errors = $titleObj->getUserPermissionsErrors( 'protect', $this->getUser() );
if ( $errors ) {
@@ -58,7 +56,7 @@ class ApiProtect extends ApiBase {
}
$restrictionTypes = $titleObj->getRestrictionTypes();
- $dbr = wfGetDB( DB_SLAVE );
+ $db = $this->getDB();
$protections = array();
$expiryarray = array();
@@ -82,7 +80,7 @@ class ApiProtect extends ApiBase {
}
if ( in_array( $expiry[$i], array( 'infinite', 'indefinite', 'never' ) ) ) {
- $expiryarray[$p[0]] = $dbr->getInfinity();
+ $expiryarray[$p[0]] = $db->getInfinity();
} else {
$exp = strtotime( $expiry[$i] );
if ( $exp < 0 || !$exp ) {
@@ -96,7 +94,7 @@ class ApiProtect extends ApiBase {
$expiryarray[$p[0]] = $exp;
}
$resultProtections[] = array( $p[0] => $protections[$p[0]],
- 'expiry' => ( $expiryarray[$p[0]] == $dbr->getInfinity() ?
+ 'expiry' => ( $expiryarray[$p[0]] == $db->getInfinity() ?
'infinite' :
wfTimestamp( TS_ISO_8601, $expiryarray[$p[0]] ) ) );
}
@@ -106,7 +104,6 @@ class ApiProtect extends ApiBase {
$watch = $params['watch'] ? 'watch' : $params['watchlist'];
$this->setWatch( $watch, $titleObj );
- $pageObj = WikiPage::factory( $titleObj );
$status = $pageObj->doUpdateRestrictions( $protections, $expiryarray, $cascade, $params['reason'], $this->getUser() );
if ( !$status->isOK() ) {
@@ -138,9 +135,14 @@ class ApiProtect extends ApiBase {
return array(
'title' => array(
ApiBase::PARAM_TYPE => 'string',
+ ),
+ 'pageid' => array(
+ ApiBase::PARAM_TYPE => 'integer',
+ ),
+ 'token' => array(
+ ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true
),
- 'token' => null,
'protections' => array(
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_REQUIRED => true,
@@ -169,13 +171,15 @@ 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)',
+ 'protections' => '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.',
'Use \'infinite\', \'indefinite\' or \'never\', for a neverexpiring protection.' ),
- 'reason' => 'Reason for (un)protecting (optional)',
+ 'reason' => 'Reason for (un)protecting',
'cascade' => array( 'Enable cascading protection (i.e. protect pages included in this page)',
'Ignored if not all protection levels are \'sysop\' or \'protect\'' ),
'watch' => 'If set, add the page being (un)protected to your watchlist',
@@ -183,21 +187,33 @@ class ApiProtect extends ApiBase {
);
}
+ public function getResultProperties() {
+ return array(
+ '' => array(
+ 'title' => 'string',
+ 'reason' => 'string',
+ 'cascade' => 'boolean'
+ )
+ );
+ }
+
public function getDescription() {
return 'Change the protection level of a page';
}
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->getTitleOrPageIdErrorMessage(),
+ array(
+ 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() {