Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4037835
Hooks.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
Hooks.php
View Options
<?php
/**
* @file
* @ingroup Extensions
*/
// phpcs:disable MediaWiki.NamingConventions.LowerCamelFunctionsName
namespace
LoginNotify
;
use
MediaWiki\Auth\AuthenticationResponse
;
use
MediaWiki\Auth\Hook\AuthManagerLoginAuthenticateAuditHook
;
use
MediaWiki\Auth\Hook\LocalUserCreatedHook
;
use
MediaWiki\Hook\RecentChange_saveHook
;
use
MediaWiki\RecentChanges\RecentChange
;
use
MediaWiki\User\User
;
use
MediaWiki\User\UserFactory
;
class
Hooks
implements
AuthManagerLoginAuthenticateAuditHook
,
LocalUserCreatedHook
,
RecentChange_saveHook
{
private
UserFactory
$userFactory
;
public
function
__construct
(
UserFactory
$userFactory
)
{
$this
->
userFactory
=
$userFactory
;
}
/**
* Hook for login auditing
*
* @param AuthenticationResponse $ret Is login successful?
* @param User|null $user User object on successful auth
* @param string|null $username Username for failed attempts.
* @param string[] $extraData
*/
public
function
onAuthManagerLoginAuthenticateAudit
(
$ret
,
$user
,
$username
,
$extraData
)
{
if
(
!
$user
&&
$username
!==
null
)
{
$user
=
$this
->
userFactory
->
newFromName
(
$username
,
UserFactory
::
RIGOR_USABLE
);
}
if
(
!
$user
)
{
return
;
}
if
(
$ret
->
status
===
AuthenticationResponse
::
PASS
)
{
self
::
doSuccessfulLogin
(
$user
);
}
elseif
(
$ret
->
status
===
AuthenticationResponse
::
FAIL
&&
$ret
->
message
->
getKey
()
!==
'login-throttled'
)
{
self
::
doFailedLogin
(
$user
);
}
// Other statuses include Abstain, Redirect, or UI. We ignore such
// statuses.
}
/**
* Handle a successful login (clear the attempt counter, send a notice, and record the
* current IP address as known).
*
* @param User $user The user who logged in.
*/
public
static
function
doSuccessfulLogin
(
User
$user
)
{
$loginNotify
=
LoginNotify
::
getInstance
();
$loginNotify
->
clearCounters
(
$user
);
$loginNotify
->
sendSuccessNotice
(
$user
);
$loginNotify
->
recordKnownWithCookie
(
$user
);
}
/**
* Handle a failed login (record the failure).
*
* @param User $user The user that failed to log in.
*/
public
static
function
doFailedLogin
(
User
$user
)
{
$loginNotify
=
LoginNotify
::
getInstance
();
$loginNotify
->
recordFailure
(
$user
);
}
/**
* Hook handler for new account creation.
*
* Called immediately after a local user has been created and saved to the database
*
* @todo This still sets cookies if user creates account well logged in as someone else.
* @param User $user User created
* @param bool $autocreated Whether this was an auto-created account
*/
public
function
onLocalUserCreated
(
$user
,
$autocreated
)
{
if
(
!
$autocreated
)
{
$loginNotify
=
LoginNotify
::
getInstance
();
$loginNotify
->
recordKnownWithCookie
(
$user
);
}
}
/**
* @param RecentChange $recentChange
*/
public
function
onRecentChange_save
(
$recentChange
)
{
$loginNotify
=
LoginNotify
::
getInstance
();
$user
=
$this
->
userFactory
->
newFromUserIdentity
(
$recentChange
->
getPerformerIdentity
()
);
$loginNotify
->
recordKnown
(
$user
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Aug 15 2026, 03:56 (13 w, 3 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
57/b1/854aa25e5ef6e5ba5a2d6de60fd3
Default Alt Text
Hooks.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment