-
Notifications
You must be signed in to change notification settings - Fork 11
Refactor denyAccessPretty to clear HTML and return to main #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(); | ||
| $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. | ||
| * | ||
|
|
@@ -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
|
||
| $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() | ||
| ); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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?