From 929552dab5ae4a16f303c2d03c58ffcadb6e2bf8 Mon Sep 17 00:00:00 2001 From: WikiMANNia <55834825+WikiMANNia@users.noreply.github.com> Date: Sun, 29 Mar 2026 04:08:12 +0200 Subject: [PATCH 1/3] Refactor denyAccessPretty to clear HTML and return to main --- includes/ResponseFactory.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/includes/ResponseFactory.php b/includes/ResponseFactory.php index 9da0abb..e4a1a02 100644 --- a/includes/ResponseFactory.php +++ b/includes/ResponseFactory.php @@ -119,10 +119,8 @@ protected function denyAccessRaw( string $header, string $message ): void { * @return void */ protected function denyAccessPretty( $output ): void { + $output->clearHTML(); $output->setStatusCode( 403 ); - $output->addWikiTextAsInterface( - wfMessage( 'crawlerprotection-accessdenied-text' )->plain() - ); if ( version_compare( MW_VERSION, '1.41', '<' ) ) { $output->setPageTitle( wfMessage( 'crawlerprotection-accessdenied-title' ) ); @@ -130,5 +128,10 @@ protected function denyAccessPretty( $output ): void { // @phan-suppress-next-line PhanUndeclaredMethod Exists in 1.41+ $output->setPageTitleMsg( wfMessage( 'crawlerprotection-accessdenied-title' ) ); } + + $output->addWikiTextAsInterface( + wfMessage( 'crawlerprotection-accessdenied-text' )->plain() + ); + $output->returnToMain(); } } From 31131123e02ef5c58a00b5c8dd2c79ee93d6cacb Mon Sep 17 00:00:00 2001 From: WikiMANNia <55834825+WikiMANNia@users.noreply.github.com> Date: Sun, 29 Mar 2026 05:33:57 +0200 Subject: [PATCH 2/3] Update ResponseFactory.php prevent breaking the unit-test environment --- includes/ResponseFactory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/ResponseFactory.php b/includes/ResponseFactory.php index e4a1a02..7b6bb88 100644 --- a/includes/ResponseFactory.php +++ b/includes/ResponseFactory.php @@ -85,7 +85,9 @@ public function denyAccess( $output ): void { ); } } else { + $output->clearHTML(); $this->denyAccessPretty( $output ); + $output->returnToMain(); } } @@ -119,7 +121,6 @@ protected function denyAccessRaw( string $header, string $message ): void { * @return void */ protected function denyAccessPretty( $output ): void { - $output->clearHTML(); $output->setStatusCode( 403 ); if ( version_compare( MW_VERSION, '1.41', '<' ) ) { @@ -132,6 +133,5 @@ protected function denyAccessPretty( $output ): void { $output->addWikiTextAsInterface( wfMessage( 'crawlerprotection-accessdenied-text' )->plain() ); - $output->returnToMain(); } } From 35d97ea11793ec44dc5525624aa479e3f89de798 Mon Sep 17 00:00:00 2001 From: WikiMANNia <55834825+WikiMANNia@users.noreply.github.com> Date: Sun, 29 Mar 2026 05:37:14 +0200 Subject: [PATCH 3/3] Replace 418 response method with raw denial Simplify code --- includes/ResponseFactory.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/includes/ResponseFactory.php b/includes/ResponseFactory.php index 7b6bb88..6431638 100644 --- a/includes/ResponseFactory.php +++ b/includes/ResponseFactory.php @@ -77,7 +77,10 @@ public function __construct( ServiceOptions $options ) { public function denyAccess( $output ): void { if ( $this->options->get( 'CrawlerProtectionRawDenial' ) ) { if ( $this->options->get( 'CrawlerProtectionUse418' ) ) { - $this->denyAccessWith418(); + $this->denyAccessRaw( + self::TEAPOT_HEADER, + self::TEAPOT_BODY + ); } else { $this->denyAccessRaw( $this->options->get( 'CrawlerProtectionRawDenialHeader' ), @@ -91,16 +94,6 @@ public function denyAccess( $output ): void { } } - /** - * Output a 418 "I'm a teapot" response and halt. - * - * @return void - * @suppress PhanPluginNeverReturnMethod - */ - protected function denyAccessWith418(): void { - $this->denyAccessRaw( self::TEAPOT_HEADER, self::TEAPOT_BODY ); - } - /** * Output a raw HTTP response and halt. *