Skip to content

Dependency injection and raw error refactor#19

Merged
jeffw16 merged 9 commits intomainfrom
jeffw16/2026-march-improvements
Mar 27, 2026
Merged

Dependency injection and raw error refactor#19
jeffw16 merged 9 commits intomainfrom
jeffw16/2026-march-improvements

Conversation

@jeffw16
Copy link
Copy Markdown
Member

@jeffw16 jeffw16 commented Mar 27, 2026

Closes #16

Copilot AI review requested due to automatic review settings March 27, 2026 20:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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) and ResponseFactory (denial response strategies), and delegate hook handling to the service.
  • Add service wiring (includes/ServiceWiring.php) and update extension.json to 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.

@jeffw16 jeffw16 changed the title March 2026 improvements Dependency injection and raw error refactor Mar 27, 2026
@jeffw16 jeffw16 merged commit 1f516e8 into main Mar 27, 2026
14 checks passed
@jeffw16 jeffw16 deleted the jeffw16/2026-march-improvements branch March 27, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants