From 0813c46daaa7ca1b52008633a5eb8a769df67137 Mon Sep 17 00:00:00 2001 From: David Barratt Date: Mon, 27 Aug 2018 18:19:37 -0400 Subject: Update Special:Block to set Partial Blocks Make the necessary UI changes to Special:Block in order to set/update partial blocks. Bug: T197109 Change-Id: Ib3067824b5dcbdd893ab1f165d169a35d0716cb2 --- includes/api/ApiBlock.php | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'includes/api/ApiBlock.php') diff --git a/includes/api/ApiBlock.php b/includes/api/ApiBlock.php index 8f4028310a79..3581ac851490 100644 --- a/includes/api/ApiBlock.php +++ b/includes/api/ApiBlock.php @@ -54,6 +54,30 @@ class ApiBlock extends ApiBase { } } + $editingRestriction = 'sitewide'; + $pageRestrictions = ''; + if ( $this->getConfig()->get( 'EnablePartialBlocks' ) ) { + if ( $params['pagerestrictions'] ) { + $count = count( $params['pagerestrictions'] ); + if ( $count > 10 ) { + $this->dieWithError( + $this->msg( + 'apierror-integeroutofrange-abovebotmax', + 'pagerestrictions', + 10, + $count + ) + ); + } + } + + if ( $params['partial'] ) { + $editingRestriction = 'partial'; + } + + $pageRestrictions = implode( "\n", $params['pagerestrictions'] ); + } + if ( $params['userid'] !== null ) { $username = User::whoIs( $params['userid'] ); @@ -107,6 +131,8 @@ class ApiBlock extends ApiBase { 'Watch' => $params['watchuser'], 'Confirm' => true, 'Tags' => $params['tags'], + 'EditingRestriction' => $editingRestriction, + 'PageRestrictions' => $pageRestrictions, ]; $retval = SpecialBlock::processForm( $data, $this->getContext() ); @@ -137,6 +163,11 @@ class ApiBlock extends ApiBase { $res['allowusertalk'] = $params['allowusertalk']; $res['watchuser'] = $params['watchuser']; + if ( $this->getConfig()->get( 'EnablePartialBlocks' ) ) { + $res['partial'] = $params['partial']; + $res['pagerestrictions'] = $params['pagerestrictions']; + } + $this->getResult()->addValue( null, $this->getModuleName(), $res ); } @@ -149,7 +180,7 @@ class ApiBlock extends ApiBase { } public function getAllowedParams() { - return [ + $params = [ 'user' => [ ApiBase::PARAM_TYPE => 'user', ], @@ -171,6 +202,15 @@ class ApiBlock extends ApiBase { ApiBase::PARAM_ISMULTI => true, ], ]; + + if ( $this->getConfig()->get( 'EnablePartialBlocks' ) ) { + $params['partial'] = false; + $params['pagerestrictions'] = [ + ApiBase::PARAM_ISMULTI => true, + ]; + } + + return $params; } public function needsToken() { -- cgit v1.2.3