-
Notifications
You must be signed in to change notification settings - Fork 8
Add configurable action protection via $wgCrawlerProtectedActions #14
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -43,7 +43,7 @@ class Hooks implements MediaWikiPerformActionHook, SpecialPageBeforeExecuteHook | |
| * Block sensitive page views for anonymous users via MediaWikiPerformAction. | ||
| * Handles: | ||
| * - ?type=revision | ||
| * - ?action=history | ||
| * - ?action=<configurable actions> | ||
| * - ?diff=1234 | ||
| * - ?oldid=1234 | ||
| * | ||
|
|
@@ -70,11 +70,14 @@ public function onMediaWikiPerformAction( | |
| $diffId = (int)$request->getVal( 'diff' ); | ||
| $oldId = (int)$request->getVal( 'oldid' ); | ||
|
|
||
| $config = MediaWikiServices::getInstance()->getMainConfig(); | ||
| $protectedActions = $config->get( 'CrawlerProtectedActions' ); | ||
|
|
||
| if ( | ||
| !$user->isRegistered() | ||
| && ( | ||
| $type === 'revision' | ||
| || $action === 'history' | ||
| || in_array( $action, $protectedActions, true ) | ||
|
Comment on lines
+73
to
+80
|
||
| || $diffId > 0 | ||
| || $oldId > 0 | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -130,6 +130,9 @@ public function getMainConfig() { | |
| * @return mixed | ||
| */ | ||
| public function get( $name ) { | ||
| if ( $name === 'CrawlerProtectedActions' ) { | ||
| return [ 'history' ]; | ||
| } | ||
|
Comment on lines
+133
to
+135
|
||
| if ( $name === 'CrawlerProtectedSpecialPages' ) { | ||
| return [ | ||
| 'RecentChangesLinked', | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -160,6 +160,128 @@ public function testNonRevisionTypeAlwaysAllowed() { | |||||||||||||
| $this->assertTrue( $result ); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * @covers ::onMediaWikiPerformAction | ||||||||||||||
| */ | ||||||||||||||
| public function testHistoryActionBlocksAnonymous() { | ||||||||||||||
| // Skip this test in MediaWiki environment - it requires service container | ||||||||||||||
| if ( !property_exists( '\MediaWiki\MediaWikiServices', 'testUse418' ) ) { | ||||||||||||||
| $this->markTestSkipped( | ||||||||||||||
| 'Test requires stub MediaWikiServices. Skipped in MediaWiki unit test environment.' | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
Comment on lines
+167
to
+173
|
||||||||||||||
| // Skip this test in MediaWiki environment - it requires service container | |
| if ( !property_exists( '\MediaWiki\MediaWikiServices', 'testUse418' ) ) { | |
| $this->markTestSkipped( | |
| 'Test requires stub MediaWikiServices. Skipped in MediaWiki unit test environment.' | |
| ); | |
| } |
Copilot
AI
Feb 19, 2026
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.
The getVal() mocks use willReturnMap entries with two parameters ([ 'action', null, 'history' ]), but Hooks::onMediaWikiPerformAction() calls $request->getVal( 'action' ) with a single argument. That means the map entry won’t match and the mock will return null, so this test won’t actually exercise the history-action branch. Update the mock to match the one-arg call (or provide map entries for both 1-arg and 2-arg invocations).
| [ 'action', null, 'history' ], | |
| [ 'action', 'history' ], |
Copilot
AI
Feb 19, 2026
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.
Same issue as above: the getVal() mock map includes a null default parameter, but the code under test calls getVal( 'action' ) with one argument. As written, this will likely return null and not test the intended behavior.
| [ 'action', null, 'history' ], | |
| [ 'action', 'history' ], |
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.
The README says setting
$wgCrawlerProtectedActions = []will "allow all actions for anonymous users", but anonymous users will still be blocked by the other checks inonMediaWikiPerformAction(type=revision,diff,oldid). Consider rewording to clarify that this only disables theaction=-based restriction.