<?php
/**
- *
- *
- * Created on Sep 4, 2007
- *
* Copyright © 2007 Roan Kattouw "<Firstname>.<Lastname>@gmail.com"
*
* This program is free software; you can redistribute it and/or modify
$this->requireOnlyOneParameter( $params, 'user', 'userid' );
- # bug 15810: blocked admins should have limited access here
+ # T17810: blocked admins should have limited access here
if ( $user->isBlocked() ) {
$status = SpecialBlock::checkUnblockSelf( $params['user'], $user );
if ( $status !== true ) {
}
}
+ $editingRestriction = 'sitewide';
+ $pageRestrictions = '';
+ $namespaceRestrictions = '';
+ if ( $this->getConfig()->get( 'EnablePartialBlocks' ) ) {
+ if ( $params['partial'] ) {
+ $editingRestriction = 'partial';
+ }
+
+ $pageRestrictions = implode( "\n", (array)$params['pagerestrictions'] );
+ $namespaceRestrictions = implode( "\n", (array)$params['namespacerestrictions'] );
+ }
+
if ( $params['userid'] !== null ) {
$username = User::whoIs( $params['userid'] );
$params['user'] = $username;
}
} else {
- $target = User::newFromName( $params['user'] );
+ list( $target, $type ) = SpecialBlock::getTargetAndType( $params['user'] );
- // Bug 38633 - if the target is a user (not an IP address), but it
+ // T40633 - if the target is a user (not an IP address), but it
// doesn't exist or is unusable, error.
- if ( $target instanceof User &&
- ( $target->isAnon() /* doesn't exist */ || !User::isUsableName( $target->getName() ) )
+ if ( $type === Block::TYPE_USER &&
+ ( $target->isAnon() /* doesn't exist */ || !User::isUsableName( $params['user'] ) )
) {
$this->dieWithError( [ 'nosuchusershort', $params['user'] ], 'nosuchuser' );
}
'Watch' => $params['watchuser'],
'Confirm' => true,
'Tags' => $params['tags'],
+ 'EditingRestriction' => $editingRestriction,
+ 'PageRestrictions' => $pageRestrictions,
+ 'NamespaceRestrictions' => $namespaceRestrictions,
];
$retval = SpecialBlock::processForm( $data, $this->getContext() );
$res['id'] = $block->getId();
} else {
# should be unreachable
- $res['expiry'] = '';
- $res['id'] = '';
+ $res['expiry'] = ''; // @codeCoverageIgnore
+ $res['id'] = ''; // @codeCoverageIgnore
}
$res['reason'] = $params['reason'];
$res['allowusertalk'] = $params['allowusertalk'];
$res['watchuser'] = $params['watchuser'];
+ if ( $this->getConfig()->get( 'EnablePartialBlocks' ) ) {
+ $res['partial'] = $params['partial'];
+ $res['pagerestrictions'] = $params['pagerestrictions'];
+ $res['namespacerestrictions'] = $params['namespacerestrictions'];
+ }
+
$this->getResult()->addValue( null, $this->getModuleName(), $res );
}
}
public function getAllowedParams() {
- return [
+ $params = [
'user' => [
ApiBase::PARAM_TYPE => 'user',
],
ApiBase::PARAM_ISMULTI => true,
],
];
+
+ if ( $this->getConfig()->get( 'EnablePartialBlocks' ) ) {
+ $params['partial'] = false;
+ $params['pagerestrictions'] = [
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_ISMULTI_LIMIT1 => 10,
+ ApiBase::PARAM_ISMULTI_LIMIT2 => 10,
+ ];
+ $params['namespacerestrictions'] = [
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_TYPE => 'namespace',
+ ];
+ }
+
+ return $params;
}
public function needsToken() {
}
protected function getExamplesMessages() {
- // @codingStandardsIgnoreStart Generic.Files.LineLength
+ // phpcs:disable Generic.Files.LineLength
return [
'action=block&user=192.0.2.5&expiry=3%20days&reason=First%20strike&token=123ABC'
=> 'apihelp-block-example-ip-simple',
'action=block&user=Vandal&expiry=never&reason=Vandalism&nocreate=&autoblock=&noemail=&token=123ABC'
=> 'apihelp-block-example-user-complex',
];
- // @codingStandardsIgnoreEnd
+ // phpcs:enable
}
public function getHelpUrls() {
- return 'https://www.mediawiki.org/wiki/API:Block';
+ return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Block';
}
}