X-Git-Url: http://git.cyclocoop.org/%28?a=blobdiff_plain;f=includes%2FBlock.php;h=85fa3415ce6ca3a5e8ef2fdd041da26f2f4c8c34;hb=4d5a6ab95157f97cb8faffcfa7ce0b0eb0194900;hp=7138301d94df603961ace0fe015e8ffb09895633;hpb=734a969d5506a80ceabfa2bc61bda79f76d73d5f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Block.php b/includes/Block.php index 7138301d94..85fa3415ce 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -24,6 +24,8 @@ use Wikimedia\Rdbms\Database; use Wikimedia\Rdbms\IDatabase; use MediaWiki\Block\BlockRestriction; use MediaWiki\Block\Restriction\Restriction; +use MediaWiki\Block\Restriction\NamespaceRestriction; +use MediaWiki\Block\Restriction\PageRestriction; use MediaWiki\MediaWikiServices; class Block { @@ -725,6 +727,7 @@ class Block { 'ipb_create_account' => $this->prevents( 'createaccount' ), 'ipb_deleted' => (int)$this->mHideName, // typecast required for SQLite 'ipb_allow_usertalk' => !$this->prevents( 'editownusertalk' ), + 'ipb_sitewide' => $this->isSitewide(), ] + CommentStore::getStore()->insert( $dbw, 'ipb_reason', $this->mReason ) + ActorMigration::newMigration()->getInsertValues( $dbw, 'ipb_by', $this->getBlocker() ); } @@ -1183,6 +1186,9 @@ class Block { case 'read': $res = false; break; + case 'purge': + $res = false; + break; } if ( !$res && $blockDisablesLogin ) { // If a block would disable login, then it should @@ -1827,4 +1833,77 @@ class Block { return false; } + + /** + * Checks if a block applies to a particular namespace + * + * @since 1.33 + * + * @param int $ns + * @return bool + */ + public function appliesToNamespace( $ns ) { + if ( $this->isSitewide() ) { + return true; + } + + // Blocks do not apply to virtual namespaces. + if ( $ns < 0 ) { + return false; + } + + $restriction = $this->findRestriction( NamespaceRestriction::TYPE, $ns ); + + return (bool)$restriction; + } + + /** + * Checks if a block applies to a particular page + * + * This check does not consider whether `$this->prevents( 'editownusertalk' )` + * returns false, as the identity of the user making the hypothetical edit + * isn't known here (particularly in the case of IP hardblocks, range + * blocks, and auto-blocks). + * + * @since 1.33 + * + * @param int $pageId + * @return bool + */ + public function appliesToPage( $pageId ) { + if ( $this->isSitewide() ) { + return true; + } + + // If the pageId is not over zero, the block cannot apply to it. + if ( $pageId <= 0 ) { + return false; + } + + $restriction = $this->findRestriction( PageRestriction::TYPE, $pageId ); + + return (bool)$restriction; + } + + /** + * Find Restriction by type and value. + * + * @param string $type + * @param int $value + * @return Restriction|null + */ + private function findRestriction( $type, $value ) { + $restrictions = $this->getRestrictions(); + foreach ( $restrictions as $restriction ) { + if ( $restriction->getType() !== $type ) { + continue; + } + + if ( $restriction->getValue() === $value ) { + return $restriction; + } + } + + return null; + } }