-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathCustomHooks.php
50 lines (40 loc) · 1.7 KB
/
CustomHooks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
use Exception;
use IMSGlobal\Caliper\entities\agent\Person;
use CaliperExtension\caliper\CaliperSensor;
if (filter_var( getenv( 'UBC_AUTH_ENABLED' ), FILTER_VALIDATE_BOOLEAN )) {
# if Caliper is setup, use a custom actor with puid
if (getenv('CALIPER_HOST') && getenv('CALIPER_API_KEY')) {
$wgHooks['SetCaliperActorObject'][] = 'SetCaliperActor';
// This is the username MediaWiki will use.
function SetCaliperActor(&$actor, &$user) {
global $wgDBprefix;
if ($actor !== null) {
return true;
} else if (!$user->isRegistered() || !$user->getId()) {
return false;
}
$puid = null;
$userId = $user->getId();
$dbr = wfGetDB(DB_REPLICA);
$res = $dbr->select(
array('ucead' => $wgDBprefix.'user_cwl_extended_account_data'), // tables
array('ucead.puid'), // fields
array('ucead.user_id' => $userId, 'ucead.account_status' => 1), // where clause
__METHOD__, // caller function name
array('LIMIT' => 1) // options. fetch first row only
);
foreach ($res as $row) {
$puid = $row->puid;
}
if (!$puid) {
return false;
}
$caliperLDAPActorHomepage = rtrim(loadenv('CALIPER_LDAP_ACTOR_HOMEPAGE', ''), '/');
$actor = (new Person( $caliperLDAPActorHomepage . "/" . $puid ))
->setName($user->getName())
->setDateCreated(CaliperSensor::mediawikiTimestampToDateTime($user->getRegistration()));
return true;
}
}
}