Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions includes/ResponseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,23 @@ 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' ),
$this->options->get( 'CrawlerProtectionRawDenialText' )
);
}
} else {
$output->clearHTML();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is logic which directly interacts with MediaWiki, so this should be moved back to denyAccessPretty. But, the question remains: why is this necessary?

$this->denyAccessPretty( $output );
$output->returnToMain();
}
}

/**
* 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.
*
Expand All @@ -120,15 +115,16 @@ protected function denyAccessRaw( string $header, string $message ): void {
*/
protected function denyAccessPretty( $output ): void {
$output->setStatusCode( 403 );
Comment on lines 116 to 117
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New calls to OutputPage::clearHTML() (and later returnToMain()) will break the unit-test environment that relies on tests/phpunit/namespaced-stubs.php: its OutputPage stub doesn’t define these methods, so createMock() will fail. Update the stub to include clearHTML() and returnToMain(), and (optionally) add expectations in ResponseFactoryTest so the behavior is covered.

Copilot uses AI. Check for mistakes.
$output->addWikiTextAsInterface(
wfMessage( 'crawlerprotection-accessdenied-text' )->plain()
);

if ( version_compare( MW_VERSION, '1.41', '<' ) ) {
$output->setPageTitle( wfMessage( 'crawlerprotection-accessdenied-title' ) );
} else {
// @phan-suppress-next-line PhanUndeclaredMethod Exists in 1.41+
$output->setPageTitleMsg( wfMessage( 'crawlerprotection-accessdenied-title' ) );
}

$output->addWikiTextAsInterface(
wfMessage( 'crawlerprotection-accessdenied-text' )->plain()
);
}
}
Loading