Index: trunk/extensions/UserFunctions/UserFunctions_body.php |
— | — | @@ -11,19 +11,13 @@ |
12 | 12 | return true; |
13 | 13 | } |
14 | 14 | |
15 | | - /** |
16 | | - * @param $parser Parser |
17 | | - * @param $then string |
18 | | - * @param $else string |
19 | | - * @return string |
20 | | - */ |
21 | | - function ifanon( &$parser, $then = '', $else = '' ) { |
22 | | - global $wgUser; |
23 | | - $parser->disableCache(); |
24 | | - if($wgUser->isAnon()){ |
25 | | - return $then; |
26 | | - } |
27 | | - return $else; |
| 15 | + /** |
| 16 | + * @param $parser Parser |
| 17 | + * @return $obj User |
| 18 | + */ |
| 19 | + private function getUserObj($parser) { |
| 20 | + $obj = $parser->getOptions()->mUser; |
| 21 | + return $obj; |
28 | 22 | } |
29 | 23 | |
30 | 24 | /** |
— | — | @@ -33,8 +27,8 @@ |
34 | 28 | * @return string |
35 | 29 | */ |
36 | 30 | function ifanonObj( &$parser, $frame, $args ) { |
37 | | - global $wgUser; |
38 | | - if($wgUser->isAnon()){ |
| 31 | + $myuser = $this->getUserObj($parser); |
| 32 | + if($myuser->isAnon()){ |
39 | 33 | return isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : ''; |
40 | 34 | } else { |
41 | 35 | return isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : ''; |
— | — | @@ -43,29 +37,13 @@ |
44 | 38 | |
45 | 39 | /** |
46 | 40 | * @param $parser Parser |
47 | | - * @param $then string |
48 | | - * @param $else string |
49 | | - * @return string |
50 | | - */ |
51 | | - function ifblocked( &$parser, $then = '', $else = '' ) { |
52 | | - global $wgUser; |
53 | | - $parser->disableCache(); |
54 | | - |
55 | | - if($wgUser->isBlocked()) { |
56 | | - return $then; |
57 | | - } |
58 | | - return $else; |
59 | | - } |
60 | | - |
61 | | - /** |
62 | | - * @param $parser Parser |
63 | 41 | * @param $frame PPFrame |
64 | 42 | * @param $args array |
65 | 43 | * @return string |
66 | 44 | */ |
67 | 45 | function ifblockedObj( &$parser, $frame, $args ) { |
68 | | - global $wgUser; |
69 | | - if($wgUser->isBlocked()){ |
| 46 | + $myuser = $this->getUserObj($parser); |
| 47 | + if($myuser->isBlocked()){ |
70 | 48 | return isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : ''; |
71 | 49 | } else { |
72 | 50 | return isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : ''; |
— | — | @@ -74,28 +52,13 @@ |
75 | 53 | |
76 | 54 | /** |
77 | 55 | * @param $parser Parser |
78 | | - * @param $then string |
79 | | - * @param $else string |
80 | | - * @return string |
81 | | - */ |
82 | | - function ifsysop( &$parser, $then = '', $else = '' ) { |
83 | | - global $wgUser; |
84 | | - $parser->disableCache(); |
85 | | - if($wgUser->isAllowed('protect')) { |
86 | | - return $then; |
87 | | - } |
88 | | - return $else; |
89 | | - } |
90 | | - |
91 | | - /** |
92 | | - * @param $parser Parser |
93 | 56 | * @param $frame PPFrame |
94 | 57 | * @param $args array |
95 | 58 | * @return string |
96 | 59 | */ |
97 | 60 | function ifsysopObj( &$parser, $frame, $args ) { |
98 | | - global $wgUser; |
99 | | - if($wgUser->isAllowed('protect')){ |
| 61 | + $myuser = $this->getUserObj($parser); |
| 62 | + if($myuser->isAllowed('protect')){ |
100 | 63 | return isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : ''; |
101 | 64 | } else { |
102 | 65 | return isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : ''; |
— | — | @@ -104,32 +67,15 @@ |
105 | 68 | |
106 | 69 | /** |
107 | 70 | * @param $parser Parser |
108 | | - * @param $grp string |
109 | | - * @param $then string |
110 | | - * @param $else string |
111 | | - * @return string |
112 | | - */ |
113 | | - function ifingroup( &$parser, $grp = '', $then = '', $else = '' ) { |
114 | | - global $wgUser; |
115 | | - $parser->disableCache(); |
116 | | - |
117 | | - if($grp!=='' && in_array($grp,$wgUser->getEffectiveGroups())){ |
118 | | - return $then; |
119 | | - } |
120 | | - return $else; |
121 | | - } |
122 | | - |
123 | | - /** |
124 | | - * @param $parser Parser |
125 | 71 | * @param $frame PPFrame |
126 | 72 | * @param $args array |
127 | 73 | * @return string |
128 | 74 | */ |
129 | 75 | function ifingroupObj( &$parser, $frame, $args ) { |
130 | | - global $wgUser; |
| 76 | + $myuser = $this->getUserObj($parser); |
131 | 77 | $grp = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : ''; |
132 | 78 | |
133 | | - if($grp!=='' && in_array($grp,$wgUser->getEffectiveGroups())){ |
| 79 | + if($grp!=='' && in_array($grp,$myuser->getEffectiveGroups())){ |
134 | 80 | return isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : ''; |
135 | 81 | } |
136 | 82 | return isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : ''; |
— | — | @@ -141,13 +87,13 @@ |
142 | 88 | * @return String |
143 | 89 | */ |
144 | 90 | function realname( &$parser, $alt = '' ) { |
145 | | - global $wgUser; |
| 91 | + $myuser = $this->getUserObj($parser); |
146 | 92 | $parser->disableCache(); |
147 | 93 | |
148 | | - if($wgUser->isAnon() && $alt!=='') { |
| 94 | + if($myuser->isAnon() && $alt!=='') { |
149 | 95 | return $alt; |
150 | 96 | } |
151 | | - return $wgUser->getRealName(); |
| 97 | + return $myuser->getRealName(); |
152 | 98 | } |
153 | 99 | |
154 | 100 | /** |
— | — | @@ -156,13 +102,13 @@ |
157 | 103 | * @return String |
158 | 104 | */ |
159 | 105 | function username( &$parser, $alt = '' ) { |
160 | | - global $wgUser; |
| 106 | + $myuser = $this->getUserObj($parser); |
161 | 107 | $parser->disableCache(); |
162 | 108 | |
163 | | - if($wgUser->isAnon() && $alt!=='') { |
| 109 | + if($myuser->isAnon() && $alt!=='') { |
164 | 110 | return $alt; |
165 | 111 | } |
166 | | - return $wgUser->getName(); |
| 112 | + return $myuser->getName(); |
167 | 113 | } |
168 | 114 | |
169 | 115 | /** |
— | — | @@ -171,13 +117,13 @@ |
172 | 118 | * @return String |
173 | 119 | */ |
174 | 120 | function useremail( &$parser, $alt = '' ) { |
175 | | - global $wgUser; |
| 121 | + $myuser = $this->getUserObj($parser); |
176 | 122 | $parser->disableCache(); |
177 | 123 | |
178 | | - if($wgUser->isAnon() && $alt!=='') { |
| 124 | + if($myuser->isAnon() && $alt!=='') { |
179 | 125 | return $alt; |
180 | 126 | } |
181 | | - return $wgUser->getEmail(); |
| 127 | + return $myuser->getEmail(); |
182 | 128 | } |
183 | 129 | |
184 | 130 | /** |
— | — | @@ -186,17 +132,17 @@ |
187 | 133 | * @return String |
188 | 134 | */ |
189 | 135 | function nickname( &$parser, $alt = '' ) { |
190 | | - global $wgUser; |
| 136 | + $myuser = $this->getUserObj($parser); |
191 | 137 | $parser->disableCache(); |
192 | 138 | |
193 | | - if($wgUser->isAnon()) { |
| 139 | + if($myuser->isAnon()) { |
194 | 140 | if ( $alt!=='') { |
195 | 141 | return $alt; |
196 | 142 | } |
197 | | - return $wgUser->getName(); |
| 143 | + return $myuser->getName(); |
198 | 144 | } |
199 | | - $nickname = $wgUser->getOption( 'nickname' ); |
200 | | - $nickname = $nickname === '' ? $wgUser->getName() : $nickname; |
| 145 | + $nickname = $myuser->getOption( 'nickname' ); |
| 146 | + $nickname = $nickname === '' ? $myuser->getName() : $nickname; |
201 | 147 | return $nickname; |
202 | 148 | } |
203 | 149 | |
Index: trunk/extensions/UserFunctions/UserFunctions.php |
— | — | @@ -22,6 +22,15 @@ |
23 | 23 | die( 'This file is a MediaWiki extension, it is not a valid entry point' ); |
24 | 24 | } |
25 | 25 | |
| 26 | +/** |
| 27 | + * Enable Personal Data Functions |
| 28 | + * Set this to true if you want your users to be able to use the following functions: |
| 29 | + * realname, username, useremail, nickname, ip |
| 30 | + * WARNING: These functions can be used to leak your user's email addresses and real names. |
| 31 | + * If unsure, don't activate these features. |
| 32 | +**/ |
| 33 | +$wgUFEnablePersonalDataFunctions = false; |
| 34 | + |
26 | 35 | $wgExtensionFunctions[] = 'wfSetupUserFunctions'; |
27 | 36 | $wgExtensionCredits['parserhook'][] = array( |
28 | 37 | 'path' => __FILE__, |
— | — | @@ -58,6 +67,7 @@ |
59 | 68 | * @return bool |
60 | 69 | */ |
61 | 70 | function registerParser( &$parser ) { |
| 71 | + global $wgUFEnablePersonalDataFunctions; |
62 | 72 | |
63 | 73 | // These functions accept DOM-style arguments |
64 | 74 | $parser->setFunctionHook( 'ifanon', array( &$this, 'ifanonObj' ), SFH_OBJECT_ARGS ); |
— | — | @@ -65,12 +75,14 @@ |
66 | 76 | $parser->setFunctionHook( 'ifsysop', array( &$this, 'ifsysopObj' ), SFH_OBJECT_ARGS ); |
67 | 77 | $parser->setFunctionHook( 'ifingroup', array( &$this, 'ifingroupObj' ), SFH_OBJECT_ARGS ); |
68 | 78 | |
69 | | - $parser->setFunctionHook( 'realname', array( &$this, 'realname' ) ); |
70 | | - $parser->setFunctionHook( 'username', array( &$this, 'username' ) ); |
71 | | - $parser->setFunctionHook( 'useremail', array( &$this, 'useremail' ) ); |
72 | | - $parser->setFunctionHook( 'nickname', array( &$this, 'nickname' ) ); |
73 | | - $parser->setFunctionHook( 'ip', array( &$this, 'ip' ) ); |
74 | | - |
| 79 | + if ($wgUFEnablePersonalDataFunctions) { |
| 80 | + $parser->setFunctionHook( 'realname', array( &$this, 'realname' ) ); |
| 81 | + $parser->setFunctionHook( 'username', array( &$this, 'username' ) ); |
| 82 | + $parser->setFunctionHook( 'useremail', array( &$this, 'useremail' ) ); |
| 83 | + $parser->setFunctionHook( 'nickname', array( &$this, 'nickname' ) ); |
| 84 | + $parser->setFunctionHook( 'ip', array( &$this, 'ip' ) ); |
| 85 | + } |
| 86 | + |
75 | 87 | return true; |
76 | 88 | } |
77 | 89 | |