Typehint against IDatabase in special pages
[lhc/web/wiklou.git] / includes / specials / SpecialBlock.php
index b558d5e..b79a482 100644 (file)
@@ -21,9 +21,9 @@
  * @ingroup SpecialPage
  */
 
-use MediaWiki\Block\BlockRestriction;
 use MediaWiki\Block\Restriction\PageRestriction;
 use MediaWiki\Block\Restriction\NamespaceRestriction;
+use MediaWiki\MediaWikiServices;
 
 /**
  * A special page that allows users with 'block' right to block users from
@@ -141,7 +141,9 @@ class SpecialBlock extends FormSpecialPage {
         * @return array
         */
        protected function getFormFields() {
-               global $wgBlockAllowsUTEdit;
+               $conf = $this->getConfig();
+               $enablePartialBlocks = $conf->get( 'EnablePartialBlocks' );
+               $blockAllowsUTEdit = $conf->get( 'BlockAllowsUTEdit' );
 
                $this->getOutput()->enableOOUI();
 
@@ -149,9 +151,6 @@ class SpecialBlock extends FormSpecialPage {
 
                $suggestedDurations = self::getSuggestedDurations();
 
-               $conf = $this->getConfig();
-               $enablePartialBlocks = $conf->get( 'EnablePartialBlocks' );
-
                $a = [];
 
                $a['Target'] = [
@@ -232,7 +231,7 @@ class SpecialBlock extends FormSpecialPage {
                        ];
                }
 
-               if ( $wgBlockAllowsUTEdit ) {
+               if ( $blockAllowsUTEdit ) {
                        $a['DisableUTEdit'] = [
                                'type' => 'check',
                                'label-message' => 'ipb-disableusertalk',
@@ -620,6 +619,7 @@ class SpecialBlock extends FormSpecialPage {
         *     the HTMLForm
         * @param WebRequest|null $request Optionally try and get data from a request too
         * @return array [ User|string|null, Block::TYPE_ constant|null ]
+        * @phan-return array{0:User|string|null,1:int|null}
         */
        public static function getTargetAndType( $par, WebRequest $request = null ) {
                $i = 0;
@@ -949,8 +949,9 @@ class SpecialBlock extends FormSpecialPage {
                                        $currentBlock->isSitewide( $block->isSitewide() );
 
                                        // Set the block id of the restrictions.
+                                       $blockRestrictionStore = MediaWikiServices::getInstance()->getBlockRestrictionStore();
                                        $currentBlock->setRestrictions(
-                                               BlockRestriction::setBlockId( $currentBlock->getId(), $restrictions )
+                                               $blockRestrictionStore->setBlockId( $currentBlock->getId(), $restrictions )
                                        );
                                }
 
@@ -1075,7 +1076,7 @@ class SpecialBlock extends FormSpecialPage {
         *
         * @todo strtotime() only accepts English strings. This means the expiry input
         *       can only be specified in English.
-        * @see https://secure.php.net/manual/en/function.strtotime.php
+        * @see https://www.php.net/manual/en/function.strtotime.php
         *
         * @param string $expiry Whatever was typed into the form
         * @return string|bool Timestamp or 'infinity' or false on error.
@@ -1125,9 +1126,11 @@ class SpecialBlock extends FormSpecialPage {
                } elseif ( is_string( $target ) ) {
                        $target = User::newFromName( $target );
                }
-               if ( $performer->isBlocked() ) {
+               if ( $performer->getBlock() ) {
                        if ( $target instanceof User && $target->getId() == $performer->getId() ) {
                                # User is trying to unblock themselves
+                               // @TODO Ensure that the block does not apply to the `unblockself`
+                               //       right.
                                if ( $performer->isAllowed( 'unblockself' ) ) {
                                        return true;
                                        # User blocked themselves and is now trying to reverse it