From a98249d8f750658e96449831f23f67b7c6165d28 Mon Sep 17 00:00:00 2001 From: Reedy Date: Sat, 5 Oct 2024 22:52:24 +0100 Subject: [PATCH] Blocked Domains: Minor tweaks Change-Id: I424726677910911094ec28b152be267a7f494469 --- includes/BlockedDomainFilter.php | 2 +- includes/BlockedDomainStorage.php | 19 ++++++++++++------- includes/Special/BlockedExternalDomains.php | 7 ++++--- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/includes/BlockedDomainFilter.php b/includes/BlockedDomainFilter.php index 368771ef3..86cba0415 100644 --- a/includes/BlockedDomainFilter.php +++ b/includes/BlockedDomainFilter.php @@ -78,7 +78,7 @@ class BlockedDomainFilter { continue; } // Given that we block subdomains of blocked domains too - // pretend that all of higher-level domains are added as well + // pretend that all the higher-level domains are added as well // so for foo.bar.com, you will have three domains to check: // foo.bar.com, bar.com, and com // This saves string search in the large list of blocked domains diff --git a/includes/BlockedDomainStorage.php b/includes/BlockedDomainStorage.php index 30bc82ebc..ebce0755e 100644 --- a/includes/BlockedDomainStorage.php +++ b/includes/BlockedDomainStorage.php @@ -28,11 +28,13 @@ use MediaWiki\Content\JsonContent; use MediaWiki\Json\FormatJson; use MediaWiki\Message\Message; use MediaWiki\Page\WikiPageFactory; +use MediaWiki\Permissions\Authority; use MediaWiki\Revision\RevisionLookup; use MediaWiki\Revision\RevisionRecord; use MediaWiki\Revision\SlotRecord; use MediaWiki\Title\TitleValue; use MediaWiki\User\UserFactory; +use MediaWiki\User\UserIdentity; use MediaWiki\Utils\UrlUtils; use RecentChange; use StatusValue; @@ -108,7 +110,7 @@ class BlockedDomainStorage implements IDBAccessObject { } /** - * Load the computed domain block list + * Load the computed domain blocklist * * @return array Flipped for performance reasons */ @@ -164,7 +166,7 @@ class BlockedDomainStorage implements IDBAccessObject { /** * Fetch the contents of the configuration page, without caching. * - * Result is not validated with a config validator. + * The result is not validated with a config validator. * * @param int $flags bit field, see IDBAccessObject::READ_XXX; do NOT pass READ_UNCACHED * @return StatusValue Status object, with the configuration (as JSON data) on success. @@ -173,7 +175,7 @@ class BlockedDomainStorage implements IDBAccessObject { $revision = $this->revisionLookup->getRevisionByTitle( $this->getBlockedDomainPage(), 0, $flags ); if ( !$revision ) { // The configuration page does not exist. Pretend it does not configure anything - // specific (failure mode and empty-page behavior is equal). + // specific (failure mode and empty-page behaviors are equal). return StatusValue::newGood( [] ); } $content = $revision->getContent( SlotRecord::MAIN ); @@ -191,7 +193,8 @@ class BlockedDomainStorage implements IDBAccessObject { * * @param string $domain domain to be blocked * @param string $notes User provided notes - * @param \MediaWiki\Permissions\Authority|\MediaWiki\User\UserIdentity $user Performer + * @param Authority|UserIdentity $user Performer + * * @return RevisionRecord|null Null on failure */ public function addDomain( string $domain, string $notes, $user ): ?RevisionRecord { @@ -211,7 +214,8 @@ class BlockedDomainStorage implements IDBAccessObject { * * @param string $domain domain to be removed from the blocked list * @param string $notes User provided notes - * @param \MediaWiki\Permissions\Authority|\MediaWiki\User\UserIdentity $user Performer + * @param Authority|UserIdentity $user Performer + * * @return RevisionRecord|null Null on failure */ public function removeDomain( string $domain, string $notes, $user ): ?RevisionRecord { @@ -255,8 +259,9 @@ class BlockedDomainStorage implements IDBAccessObject { * Save the provided content into the page * * @param array[] $content To be turned into JSON - * @param \MediaWiki\Permissions\Authority|\MediaWiki\User\UserIdentity $user Performer + * @param Authority|UserIdentity $user Performer * @param string $comment Save comment + * * @return RevisionRecord|null */ private function saveContent( array $content, $user, string $comment ): ?RevisionRecord { @@ -275,7 +280,7 @@ class BlockedDomainStorage implements IDBAccessObject { } /** - * @return TitleValue TitleValue of the config json page + * @return TitleValue TitleValue of the config JSON page */ private function getBlockedDomainPage(): TitleValue { return new TitleValue( NS_MEDIAWIKI, self::TARGET_PAGE ); diff --git a/includes/Special/BlockedExternalDomains.php b/includes/Special/BlockedExternalDomains.php index c3d2dc1c9..7d5969737 100644 --- a/includes/Special/BlockedExternalDomains.php +++ b/includes/Special/BlockedExternalDomains.php @@ -166,8 +166,7 @@ class BlockedExternalDomains extends SpecialPage { * @return string HTML for the row */ private function doDomainRow( $domain, $showManageActions ) { - $newRow = ''; - $newRow .= Html::rawElement( 'td', [], Html::element( 'code', [], $domain['domain'] ) ); + $newRow = Html::rawElement( 'td', [], Html::element( 'code', [], $domain['domain'] ) ); $newRow .= Html::rawElement( 'td', [], $this->getOutput()->parseInlineAsInterface( $domain['notes'] ) ); @@ -186,7 +185,8 @@ class BlockedExternalDomains extends SpecialPage { $this->getPageTitle( 'remove' ), $this->msg( 'abusefilter-blocked-domains-remove' )->text(), [], - [ 'domain' => $domain['domain'] ] ); + [ 'domain' => $domain['domain'] ] + ); $newRow .= Html::rawElement( 'td', [], $actionLink ); } @@ -343,6 +343,7 @@ class BlockedExternalDomains extends SpecialPage { return 'spam'; } + /** @inheritDoc */ public function isListed() { return $this->getConfig()->get( 'AbuseFilterEnableBlockedExternalDomain' ); }