diff options
author | Thalia <thalia.e.chan@googlemail.com> | 2021-04-29 17:21:50 +0100 |
---|---|---|
committer | Thalia <thalia.e.chan@googlemail.com> | 2021-05-04 17:48:21 +0100 |
commit | 6cb10165943dec3bf5f706a3439cfd9e0da62961 (patch) | |
tree | ed36fb1a3b8d15708668df91aed01e3a3f3dd76f /includes/api | |
parent | c8736c949c1662cac2b89b2dfc43d4dacc8eb07d (diff) | |
download | mediawikicore-6cb10165943dec3bf5f706a3439cfd9e0da62961.tar.gz mediawikicore-6cb10165943dec3bf5f706a3439cfd9e0da62961.zip |
Allow partial action blocks to be made via ApiBlock
Bug: T280522
Change-Id: I114e3c76cfb6dd2f79b5217aee4b3da34df00850
Diffstat (limited to 'includes/api')
-rw-r--r-- | includes/api/ApiBlock.php | 35 | ||||
-rw-r--r-- | includes/api/ApiMain.php | 3 | ||||
-rw-r--r-- | includes/api/i18n/en.json | 1 | ||||
-rw-r--r-- | includes/api/i18n/qqq.json | 1 |
4 files changed, 37 insertions, 3 deletions
diff --git a/includes/api/ApiBlock.php b/includes/api/ApiBlock.php index b5ac55b7a07f..53a9105c6acb 100644 --- a/includes/api/ApiBlock.php +++ b/includes/api/ApiBlock.php @@ -21,10 +21,12 @@ */ use MediaWiki\Block\AbstractBlock; +use MediaWiki\Block\BlockActionInfo; use MediaWiki\Block\BlockPermissionCheckerFactory; use MediaWiki\Block\BlockUserFactory; use MediaWiki\Block\BlockUtils; use MediaWiki\Block\DatabaseBlock; +use MediaWiki\Block\Restriction\ActionRestriction; use MediaWiki\Block\Restriction\NamespaceRestriction; use MediaWiki\Block\Restriction\PageRestriction; use MediaWiki\ParamValidator\TypeDef\UserDef; @@ -61,6 +63,9 @@ class ApiBlock extends ApiBase { /** @var BlockUtils */ private $blockUtils; + /** @var BlockActionInfo */ + private $blockActionInfo; + /** * @param ApiMain $main * @param string $action @@ -70,6 +75,7 @@ class ApiBlock extends ApiBase { * @param UserFactory $userFactory * @param WatchedItemStoreInterface $watchedItemStore * @param BlockUtils $blockUtils + * @param BlockActionInfo $blockActionInfo */ public function __construct( ApiMain $main, @@ -79,7 +85,8 @@ class ApiBlock extends ApiBase { TitleFactory $titleFactory, UserFactory $userFactory, WatchedItemStoreInterface $watchedItemStore, - BlockUtils $blockUtils + BlockUtils $blockUtils, + BlockActionInfo $blockActionInfo ) { parent::__construct( $main, $action ); @@ -91,6 +98,7 @@ class ApiBlock extends ApiBase { $this->watchlistExpiryEnabled = $this->getConfig()->get( 'WatchlistExpiry' ); $this->watchlistMaxDuration = $this->getConfig()->get( 'WatchlistExpiryMaxDuration' ); $this->blockUtils = $blockUtils; + $this->blockActionInfo = $blockActionInfo; } /** @@ -139,6 +147,13 @@ class ApiBlock extends ApiBase { return new NamespaceRestriction( 0, $id ); }, (array)$params['namespacerestrictions'] ); $restrictions = array_merge( $pageRestrictions, $namespaceRestrictions ); + + if ( $this->getConfig()->get( 'EnablePartialActionBlocks' ) ) { + $actionRestrictions = array_map( function ( $action ) { + return new ActionRestriction( 0, $this->blockActionInfo->getIdFromAction( $action ) ); + }, (array)$params['actionrestrictions'] ); + $restrictions = array_merge( $restrictions, $actionRestrictions ); + } } $status = $this->blockUserFactory->newBlockUser( @@ -209,6 +224,9 @@ class ApiBlock extends ApiBase { $res['partial'] = $params['partial']; $res['pagerestrictions'] = $params['pagerestrictions']; $res['namespacerestrictions'] = $params['namespacerestrictions']; + if ( $this->getConfig()->get( 'EnablePartialActionBlocks' ) ) { + $res['actionrestrictions'] = $params['actionrestrictions']; + } $this->getResult()->addValue( null, $this->getModuleName(), $res ); } @@ -256,7 +274,7 @@ class ApiBlock extends ApiBase { ]; } - return $params + [ + $params += [ 'tags' => [ ApiBase::PARAM_TYPE => 'tags', ApiBase::PARAM_ISMULTI => true, @@ -272,6 +290,19 @@ class ApiBlock extends ApiBase { ApiBase::PARAM_TYPE => 'namespace', ], ]; + + if ( $this->getConfig()->get( 'EnablePartialActionBlocks' ) ) { + $params += [ + 'actionrestrictions' => [ + ApiBase::PARAM_ISMULTI => true, + ApiBase::PARAM_TYPE => array_keys( + $this->blockActionInfo->getAllBlockActions() + ), + ], + ]; + } + + return $params; } public function needsToken() { diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 4b7cf27dd960..7b022ec9d840 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -137,7 +137,8 @@ class ApiMain extends ApiBase { 'TitleFactory', 'UserFactory', 'WatchedItemStore', - 'BlockUtils' + 'BlockUtils', + 'BlockActionInfo', ] ], 'unblock' => [ diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json index 0c26a0d07ee2..3e0fef1719f5 100644 --- a/includes/api/i18n/en.json +++ b/includes/api/i18n/en.json @@ -43,6 +43,7 @@ "apihelp-block-param-partial": "Block user from specific pages or namespaces rather than the entire site.", "apihelp-block-param-pagerestrictions": "List of titles to block the user from editing. Only applies when <var>partial</var> is set to true.", "apihelp-block-param-namespacerestrictions": "List of namespace IDs to block the user from editing. Only applies when <var>partial</var> is set to true.", + "apihelp-block-param-actionrestrictions": "List of actions to block the user from performing. Only applies when <var>partial</var> is set to true.", "apihelp-block-example-ip-simple": "Block IP address <kbd>192.0.2.5</kbd> for three days with a reason.", "apihelp-block-example-user-complex": "Block user <kbd>Vandal</kbd> indefinitely with a reason, and prevent new account creation and email sending.", diff --git a/includes/api/i18n/qqq.json b/includes/api/i18n/qqq.json index eb1f3631bd3c..b7ecf87ec80a 100644 --- a/includes/api/i18n/qqq.json +++ b/includes/api/i18n/qqq.json @@ -58,6 +58,7 @@ "apihelp-block-param-partial": "{{doc-apihelp-param|block|partial}}", "apihelp-block-param-pagerestrictions": "{{doc-apihelp-param|block|pagerestrictions}}", "apihelp-block-param-namespacerestrictions": "{{doc-apihelp-param|block|namespacerestrictions}}", + "apihelp-block-param-actionrestrictions": "{{doc-apihelp-param|block|actionrestrictions}}", "apihelp-block-example-ip-simple": "{{doc-apihelp-example|block}}", "apihelp-block-example-user-complex": "{{doc-apihelp-example|block}}", "apihelp-changeauthenticationdata-summary": "{{doc-apihelp-summary|changeauthenticationdata}}", |