Configurable protected special pages list and optional quick request halting#10
Configurable protected special pages list and optional quick request halting#10vedmaka wants to merge 9 commits intomywikis:mainfrom
Conversation
…roves fast deny logic
| "CrawlerProtectedSpecialPages": { | ||
| "value": [ | ||
| "recentchangeslinked", | ||
| "whatlinkshere" |
| || in_array( 'Special:' . $special->getName(), $protectedSpecialPages, true ) | ||
| ) { | ||
| $out = $special->getContext()->getOutput(); | ||
| if ( $denyFast ) { |
There was a problem hiding this comment.
Please add unit tests to test this branch
| // allow forgiving entries in the setting array for Special pages names | ||
| in_array( $special->getName(), $protectedSpecialPages, true ) | ||
| || in_array( $name, $protectedSpecialPages, true ) | ||
| || in_array( 'Special:' . $special->getName(), $protectedSpecialPages, true ) |
There was a problem hiding this comment.
Please refactor magic word "Special:" to a constant variable at the top of the file
| $config = MediaWikiServices::getInstance()->getMainConfig(); | ||
| $protectedSpecialPages = $config->get( 'CrawlerProtectedSpecialPages' ); | ||
| $denyFast = $config->get( 'CrawlerProtectedSpecialPages' ); | ||
|
|
There was a problem hiding this comment.
Rather than having multiple checks, please add a line to get a version of $protectedSpecialPages which has been tolowercaseed and had Special: stripped from it.
For example:
$result = array_map(
fn($p) => ($p = strtolower($p)) && strpos($p, NS_SPECIAL_NAME) === 0
? substr($p, 8)
: $p,
$protectedSpecialPages
);| if ( in_array( $name, [ 'recentchangeslinked', 'whatlinkshere' ], true ) ) { | ||
| if ( | ||
| // allow forgiving entries in the setting array for Special pages names | ||
| in_array( $special->getName(), $protectedSpecialPages, true ) |
There was a problem hiding this comment.
These 3 lines will be redundant once the transformation is applied. Please remove the two extra lines
| * @return void | ||
| * @suppress PhanPluginNeverReturnMethod | ||
| */ | ||
| protected function denyAccessFast() { |
There was a problem hiding this comment.
"Deny access fast" is a subjective name which I don't think properly addresses why one might choose to use this. Naming is a hard problem to solve, so I do empathize. How about we change the 403 vs. 418 preference variable to $wgCrawlerProtectionUse418, and this function's name to denyAccessWith418()?
|
Also, could we use this PR to incorporate the per-feature blocking options in #6? |
|
This PR has been superseded by #12 |
This pull request introduces the following improvements:
$wgCrawlerProtectedSpecialPages$wgCrawlerProtectionDenyFasttoggle (turned off by default)