Dependency injection and raw error refactor#19
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors CrawlerProtection to use dependency-injected service classes for request blocking and response generation, adds a configurable “raw denial” strategy, and updates the unit tests accordingly.
Changes:
- Introduce
CrawlerProtectionService(business logic) andResponseFactory(denial response strategies), and delegate hook handling to the service. - Add service wiring (
includes/ServiceWiring.php) and updateextension.jsonto inject services + expose new raw-denial config options. - Add/adjust PHPUnit unit tests and test stubs to cover the new service and response factory behavior.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
includes/Hooks.php |
Converts hook handler into a thin delegator using injected CrawlerProtectionService. |
includes/CrawlerProtectionService.php |
New service encapsulating “should block?” checks for actions and special pages. |
includes/ResponseFactory.php |
New response strategy class (pretty 403, raw denial, optional 418). |
includes/ServiceWiring.php |
Registers ResponseFactory and CrawlerProtectionService in MediaWiki service container. |
extension.json |
Adds service injection for the hook handler, registers ServiceWiring, adds raw-denial config keys, bumps version. |
tests/phpunit/unit/HooksTest.php |
Updates tests to validate Hooks delegates to the injected service. |
tests/phpunit/unit/CrawlerProtectionServiceTest.php |
New tests covering service decisions for action params and protected special pages. |
tests/phpunit/unit/ResponseFactoryTest.php |
New tests verifying denial strategy selection and pretty 403 behavior. |
tests/phpunit/namespaced-stubs.php |
Extends stubs with a ServiceOptions test double and adjusts config stubbing. |
.github/instructions/mediawiki-extensions-clean-code.instructions.md |
Adds repository guidance doc for DI/service container patterns. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #16