Skip to content
Closed
Show file tree
Hide file tree
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
3 changes: 0 additions & 3 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
"recentchangeslinked",
"whatlinkshere"
]
},
"CrawlerProtectionUse418": {
"value": false
}
},
"license-name": "MIT",
Expand Down
4 changes: 1 addition & 3 deletions i18n/de.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"@metadata": {
"authors": [ "MyWikis LLC" ]
},
"crawlerprotection-accessdenied-title": "Zugriff verweigert",
"crawlerprotection-accessdenied-text": "Anmeldung erforderlich, um diese Aktion auzuführen oder Spezialseite anzusehen."
}
}
4 changes: 1 addition & 3 deletions i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"@metadata": {
"authors": [ "MyWikis LLC" ]
},
"crawlerprotection-accessdenied-title": "Access denied",
"crawlerprotection-accessdenied-text": "You must be logged in to perform this action or view this special page."
}
}
33 changes: 5 additions & 28 deletions includes/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public function onSpecialPageBeforeExecute( $special, $subPage ) {

$config = MediaWikiServices::getInstance()->getMainConfig();
$protectedSpecialPages = $config->get( 'CrawlerProtectedSpecialPages' );
$denyFast = $config->get( 'CrawlerProtectionUse418' );

// Normalize protected special pages: lowercase and strip 'Special:' prefix
$normalizedProtectedPages = array_map(
Expand All @@ -114,43 +113,21 @@ public function onSpecialPageBeforeExecute( $special, $subPage ) {

$name = strtolower( $special->getName() );
if ( in_array( $name, $normalizedProtectedPages, true ) ) {
$out = $special->getContext()->getOutput();
if ( $denyFast ) {
$this->denyAccessWith418();
}
$this->denyAccess( $out );
$this->denyAccess();
return false;
}

return true;
}

/**
* Helper: output 418 Teapot and halt the processing immediately
*
* @return void
* @suppress PhanPluginNeverReturnMethod
*/
protected function denyAccessWith418() {
header( 'HTTP/1.0 I\'m a teapot' );
die( 'I\'m a teapot' );
}

/**
* Helper: output 403 Access Denied page using i18n messages.
* Output 403 Access Denied page in as lightweight a way as possible.
*
* @param OutputPage $output
* @return void
*/
protected function denyAccess( $output ): void {
$output->setStatusCode( 403 );
$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' ) );
}
protected function denyAccess(): void {
header( 'HTTP/1.1 403 Forbidden' );
die( "You must be logged in to perform this action or view this special page." );
}
}