MediaWiki
REL1_32
OATHUserRepository.php
Go to the documentation of this file.
1
<?php
19
use
Wikimedia\Rdbms\ILoadBalancer
;
20
use
Wikimedia\Rdbms\DBConnRef
;
21
22
class
OATHUserRepository
{
24
protected
$lb
;
25
27
protected
$cache
;
28
34
public
function
__construct
(
ILoadBalancer
$lb
,
BagOStuff
$cache
) {
35
$this->lb =
$lb
;
36
$this->
cache
=
$cache
;
37
}
38
43
public
function
findByUser
(
User
$user ) {
44
$oathUser = $this->
cache
->get( $user->
getName
() );
45
if
( !$oathUser ) {
46
$oathUser =
new
OATHUser
( $user,
null
);
47
48
$uid = CentralIdLookup::factory()->centralIdFromLocalUser( $user );
49
$res
= $this->
getDB
(
DB_REPLICA
)->selectRow(
50
'oathauth_users'
,
51
'*'
,
52
[
'id'
=> $uid ],
53
__METHOD__
54
);
55
if
(
$res
) {
56
$key =
new
OATHAuthKey
(
$res
->secret, explode(
','
,
$res
->scratch_tokens ) );
57
$oathUser->setKey( $key );
58
}
59
60
$this->
cache
->set( $user->
getName
(), $oathUser );
61
}
62
return
$oathUser;
63
}
64
68
public
function
persist
(
OATHUser
$user ) {
69
$this->
getDB
(
DB_MASTER
)->replace(
70
'oathauth_users'
,
71
[
'id'
],
72
[
73
'id'
=> CentralIdLookup::factory()->centralIdFromLocalUser( $user->getUser() ),
74
'secret'
=> $user->getKey()->getSecret(),
75
'scratch_tokens'
=> implode(
','
, $user->getKey()->getScratchTokens() ),
76
],
77
__METHOD__
78
);
79
$this->
cache
->set( $user->
getUser
()->getName(), $user );
80
}
81
85
public
function
remove
(
OATHUser
$user
) {
86
$this->
getDB
(
DB_MASTER
)->delete(
87
'oathauth_users'
,
88
[
'id'
=> CentralIdLookup::factory()->centralIdFromLocalUser( $user->getUser() ) ],
89
__METHOD__
90
);
91
$this->
cache
->delete( $user->getUser()->getName() );
92
}
93
98
private
function
getDB
( $index ) {
99
global $wgOATHAuthDatabase;
100
101
return
$this->lb->getConnectionRef( $index, [], $wgOATHAuthDatabase );
102
}
103
}
BagOStuff
Class representing a cache/ephemeral data store.
Definition
BagOStuff.php:58
OATHAuthKey
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
Definition
OATHAuthKey.php:26
OATHUserRepository
Definition
OATHUserRepository.php:22
OATHUserRepository\persist
persist(OATHUser $user)
Definition
OATHUserRepository.php:68
OATHUserRepository\findByUser
findByUser(User $user)
Definition
OATHUserRepository.php:43
OATHUserRepository\getDB
getDB( $index)
Definition
OATHUserRepository.php:98
OATHUserRepository\$cache
BagOStuff $cache
Definition
OATHUserRepository.php:27
OATHUserRepository\$lb
ILoadBalancer $lb
Definition
OATHUserRepository.php:24
OATHUserRepository\__construct
__construct(ILoadBalancer $lb, BagOStuff $cache)
OATHUserRepository constructor.
Definition
OATHUserRepository.php:34
OATHUser
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
Definition
OATHUser.php:24
OATHUser\getUser
getUser()
Definition
OATHUser.php:44
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition
User.php:47
User\getName
getName()
Get the user name, or the IP of an anonymous user.
Definition
User.php:2462
Wikimedia\Rdbms\DBConnRef
Helper class to handle automatically marking connections as reusable (via RAII pattern) as well handl...
Definition
DBConnRef.php:15
$res
$res
Definition
database.txt:21
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition
hooks.txt:247
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition
ILoadBalancer.php:78
cache
you have access to all of the normal MediaWiki so you can get a DB use the cache
Definition
maintenance.txt:55
DB_REPLICA
const DB_REPLICA
Definition
defines.php:25
DB_MASTER
const DB_MASTER
Definition
defines.php:26
extensions
OATHAuth
includes
OATHUserRepository.php
Generated on Mon Nov 25 2024 15:56:39 for MediaWiki by
1.10.0