-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCSHUserSig.php
More file actions
62 lines (55 loc) · 2.3 KB
/
CSHUserSig.php
File metadata and controls
62 lines (55 loc) · 2.3 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
<?php
// Tweaked 03/23/2011 by Grantovich to use CN instead of givenName + SN
// PHP 7 Compatability ~ <3 mbillow 03/14/2017
// MediaWiki 1.36 compat ~ <3 mstrodl 2023-01-25
global $wgHooks, $wgOut;
$wgHooks['ParserBeforeInternalParse'][] = 'parseUserSignatures';
$wgExtensionCredits['parserhook'][] = array(
'version' => '0.0.1',
'name' => 'CSH Usersig',
'author' => 'Computer Science House',
'email' => 'webmaster@csh.rit.edu',
'url' => 'https://csh.rit.edu/',
'description' => 'provides the ability to add user names using ^^^user^^^ syntax',
'descriptionmsg' => 'cshuserlink-desc',
);
function parseUserSignatures( &$parser, &$text, &$strip_state ) {
while (preg_match('/\^\^\^(.+?)\^\^\^/', $text, $matches)) {
$user = getUserInfoFromText($matches[1]);
if($user != 0){
$text = str_replace("^^^$matches[1]^^^", "[[:user:" . $user['uid'] . "|" . $user['name'] . "]]", $text);
}else{
$text = str_replace("^^^$matches[1]^^^", $matches[1], $text);
}
}
while (preg_match('/\^\^(.+?)\^\^/', $text, $matches)) {
$user = getUserInfoFromUID($matches[1]);
if($user != 0){
$text = str_replace("^^$matches[1]^^", "[[:user:" . $user['uid'] . "|" . $user['name'] . "]]", $text);
}else{
$text = str_replace("^^$matches[1]^^", "[[:user:".$matches[1]."]]", $text);
}
}
return true;
}
function getLdapClient() {
if(!isset($GLOBALS['ldap_ds'])){
$GLOBALS['ldap_ds'] = ldap_connect('ldaps://ipa11-nrh.csh.rit.edu');
$bind = ldap_bind($GLOBALS['ldap_ds'],'krbprincipalname=wiki/yasuko.csh.rit.edu@CSH.RIT.EDU,cn=services,cn=accounts,dc=csh,dc=rit,dc=edu',$GLOBALS['csh_wiki_ldap_password']);
}
}
function getUserInfoFromText($name) {
getLdapClient();
$sr = ldap_list($GLOBALS['ldap_ds'],'cn=users,cn=accounts,dc=csh,dc=rit,dc=edu',"(displayName=*$name*)",array('uid','cn'));
$results = ldap_get_entries($GLOBALS['ldap_ds'],$sr);
if(!isset($results[0])) return 0;
return array('uid'=>$results[0]['uid'][0],'name'=>$results[0]['cn'][0]);
}
function getUserInfoFromUID($name) {
getLdapClient();
$sr = ldap_list($GLOBALS['ldap_ds'],'cn=users,cn=accounts,dc=csh,dc=rit,dc=edu',"(uid=$name)",array('uid','cn'));
$results = ldap_get_entries($GLOBALS['ldap_ds'],$sr);
if(!isset($results[0])) return 0;
return array('uid'=>$results[0]['uid'][0],'name'=>$results[0]['cn'][0]);
}
?>