summaryrefslogtreecommitdiff
path: root/includes/api/ApiProtect.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2014-12-27 15:41:37 +0100
committerPierre Schmitz <pierre@archlinux.de>2014-12-31 11:43:28 +0100
commitc1f9b1f7b1b77776192048005dcc66dcf3df2bfb (patch)
tree2b38796e738dd74cb42ecd9bfd151803108386bc /includes/api/ApiProtect.php
parentb88ab0086858470dd1f644e64cb4e4f62bb2be9b (diff)
Update to MediaWiki 1.24.1
Diffstat (limited to 'includes/api/ApiProtect.php')
-rw-r--r--includes/api/ApiProtect.php99
1 files changed, 44 insertions, 55 deletions
diff --git a/includes/api/ApiProtect.php b/includes/api/ApiProtect.php
index 7830c8b4..a3d12b7f 100644
--- a/includes/api/ApiProtect.php
+++ b/includes/api/ApiProtect.php
@@ -28,9 +28,7 @@
* @ingroup API
*/
class ApiProtect extends ApiBase {
-
public function execute() {
- global $wgRestrictionLevels;
$params = $this->extractRequestParams();
$pageObj = $this->getTitleOrPageId( $params, 'fromdbmaster' );
@@ -47,7 +45,11 @@ class ApiProtect extends ApiBase {
if ( count( $expiry ) == 1 ) {
$expiry = array_fill( 0, count( $params['protections'] ), $expiry[0] );
} else {
- $this->dieUsageMsg( array( 'toofewexpiries', count( $expiry ), count( $params['protections'] ) ) );
+ $this->dieUsageMsg( array(
+ 'toofewexpiries',
+ count( $expiry ),
+ count( $params['protections'] )
+ ) );
}
}
@@ -71,11 +73,11 @@ class ApiProtect extends ApiBase {
if ( !in_array( $p[0], $restrictionTypes ) && $p[0] != 'create' ) {
$this->dieUsageMsg( array( 'protect-invalidaction', $p[0] ) );
}
- if ( !in_array( $p[1], $wgRestrictionLevels ) && $p[1] != 'all' ) {
+ if ( !in_array( $p[1], $this->getConfig()->get( 'RestrictionLevels' ) ) && $p[1] != 'all' ) {
$this->dieUsageMsg( array( 'protect-invalidlevel', $p[1] ) );
}
- if ( in_array( $expiry[$i], array( 'infinite', 'indefinite', 'never' ) ) ) {
+ if ( in_array( $expiry[$i], array( 'infinite', 'indefinite', 'infinity', 'never' ) ) ) {
$expiryarray[$p[0]] = $db->getInfinity();
} else {
$exp = strtotime( $expiry[$i] );
@@ -89,18 +91,30 @@ class ApiProtect extends ApiBase {
}
$expiryarray[$p[0]] = $exp;
}
- $resultProtections[] = array( $p[0] => $protections[$p[0]],
- 'expiry' => ( $expiryarray[$p[0]] == $db->getInfinity() ?
- 'infinite' :
- wfTimestamp( TS_ISO_8601, $expiryarray[$p[0]] ) ) );
+ $resultProtections[] = array(
+ $p[0] => $protections[$p[0]],
+ 'expiry' => ( $expiryarray[$p[0]] == $db->getInfinity()
+ ? 'infinite'
+ : wfTimestamp( TS_ISO_8601, $expiryarray[$p[0]] )
+ )
+ );
}
$cascade = $params['cascade'];
+ if ( $params['watch'] ) {
+ $this->logFeatureUsage( 'action=protect&watch' );
+ }
$watch = $params['watch'] ? 'watch' : $params['watchlist'];
- $this->setWatch( $watch, $titleObj );
-
- $status = $pageObj->doUpdateRestrictions( $protections, $expiryarray, $cascade, $params['reason'], $this->getUser() );
+ $this->setWatch( $watch, $titleObj, 'watchdefault' );
+
+ $status = $pageObj->doUpdateRestrictions(
+ $protections,
+ $expiryarray,
+ $cascade,
+ $params['reason'],
+ $this->getUser()
+ );
if ( !$status->isOK() ) {
$this->dieStatus( $status );
@@ -134,10 +148,6 @@ class ApiProtect extends ApiBase {
'pageid' => array(
ApiBase::PARAM_TYPE => 'integer',
),
- 'token' => array(
- ApiBase::PARAM_TYPE => 'string',
- ApiBase::PARAM_REQUIRED => true
- ),
'protections' => array(
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_REQUIRED => true,
@@ -167,62 +177,41 @@ class ApiProtect extends ApiBase {
public function getParamDescription() {
$p = $this->getModulePrefix();
+
return array(
'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' => '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 never-expiring protection.' ),
+ 'expiry' => array(
+ 'Expiry timestamps. If only one timestamp is ' .
+ 'set, it\'ll be used for all protections.',
+ 'Use \'infinite\', \'indefinite\', \'infinity\' or \'never\', for a never-expiring protection.'
+ ),
'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\'' ),
+ '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',
- 'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch',
- );
- }
-
- public function getResultProperties() {
- return array(
- '' => array(
- 'title' => 'string',
- 'reason' => 'string',
- 'cascade' => 'boolean'
- )
+ 'watchlist' => 'Unconditionally add or remove the page from your ' .
+ 'watchlist, use preferences or do not change watch',
);
}
public function getDescription() {
- return 'Change the protection level of a page';
- }
-
- public function getPossibleErrors() {
- 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' ),
- )
- );
+ return 'Change the protection level of a page.';
}
public function needsToken() {
- return true;
- }
-
- public function getTokenSalt() {
- return '';
+ return 'csrf';
}
public function getExamples() {
return array(
- 'api.php?action=protect&title=Main%20Page&token=123ABC&protections=edit=sysop|move=sysop&cascade=&expiry=20070901163000|never',
- 'api.php?action=protect&title=Main%20Page&token=123ABC&protections=edit=all|move=all&reason=Lifting%20restrictions'
+ 'api.php?action=protect&title=Main%20Page&token=123ABC&' .
+ 'protections=edit=sysop|move=sysop&cascade=&expiry=20070901163000|never',
+ 'api.php?action=protect&title=Main%20Page&token=123ABC&' .
+ 'protections=edit=all|move=all&reason=Lifting%20restrictions'
);
}