-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetUserInfo_body.php
150 lines (118 loc) · 3.14 KB
/
GetUserInfo_body.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
/*
* 2011-2015
* Provides user email or real name information
*
*/
class ExtGetUserInfo {
/**
* @param $parser Parser
* @return bool
*/
public static function clearState( $parser ) {
$parser->pf_ifexist_breakdown = array();
return true;
}
/**
* Register ParserClearState hook.
* We defer this until needed to avoid the loading of the code of this file
* when no parser function is actually called.
*/
public static function registerClearHook() {
static $done = false;
if( !$done ) {
global $wgHooks;
$wgHooks['ParserClearState'][] = __CLASS__ . '::clearState';
$done = true;
}
}
public static function getUserInfo( $parser, $frame, $args ) {
global $wgUser;
global $wgGUAllowedGroups, $wgGUWhiteListPages, $wgGUWhiteListNS;
global $wgGUOnlyActualUser, $wgGUOnlyUserPage;
$parser->disableCache();
if ( isset( $args[0] ) ) {
$param1 = trim( $frame->expand( $args[0] ) );
} else {
return false;
}
$param2 = "email";
if ( isset( $args[1] ) ) {
$param2 = trim( $frame->expand( $args[1] ) );
// Fix problem with existing values -> Values maybe other place
if ( ! in_array( $param2, array( 'email', 'realname', 'groups' ) ) ) {
$param2 = "email";
}
}
$user = $wgUser;
// TODO: Check for maintenace mode
// Get title and NS of page
$titlepage = $parser->getTitle();
$namespace = $titlepage->getNamespace();
$fulltext = $titlepage->getFullText();
$titletext = $titlepage->getText();
// Can be filtered at the parser level, current user group and page
$cur_gps = $user->getEffectiveGroups();
$ingroup = false;
foreach ( $cur_gps as $cur_gp ) {
if ( in_array( $cur_gp, $wgGUAllowedGroups[ $param2 ] ) ) {
$ingroup = true;
break;
}
}
# Check NS
if ( in_array( $namespace, $wgGUWhiteListNS[ $param2 ] ) ) {
$ingroup = true;
}
# Check pages
if ( in_array( $fulltext, array_map( "self::allWS", $wgGUWhiteListPages[ $param2 ] ) ) ) {
$ingroup = true;
}
// If true show only if the same user
if ( $wgGUOnlyActualUser ) {
if ( str_replace( "_", " ", $param1 ) != $user->getName() ) {
$ingroup = false;
}
}
// If true show only in user page
if ( $wgGUOnlyUserPage ) {
if ( $namespace != NS_USER && $titletext != str_replace( "_", " ", $param1 ) ) {
$ingroup = false;
}
}
if ( !$ingroup ) {
return false;
}
// Let's check if it exists
$userout = User::newFromName( $param1 );
if ( !method_exists( $userout, "getID" ) ) {
return false;
}
else {
if ( $userout->getID() == 0 ) {
return false;
}
//Now do
return( self::userGet( $param1, $param2 ) );
}
}
private static function userGet( $username, $param ) {
$user = User::newFromName( $username );
if ( is_object( $user ) ) {
if ( $param == 'email' ) {
return ( $user->getEmail() );
}
elseif ( $param == 'groups' ) {
return( implode( ",", $user->getGroups() ) );
}
else {
return ( $user->getRealName() ) ;
}
}
return false;
}
/** We allow title to be stored in different ways **/
private static function allWS( $n ) {
return( str_replace( "_", " ", $n ) );
}
}