Index: trunk/extensions/UserFunctions/UserFunctions_body.php |
— | — | @@ -2,134 +2,193 @@ |
3 | 3 | |
4 | 4 | class ExtUserFunctions { |
5 | 5 | |
| 6 | + /** |
| 7 | + * @param $parser Parser |
| 8 | + * @return bool |
| 9 | + */ |
6 | 10 | function clearState(&$parser) { |
7 | 11 | $parser->pf_ifexist_breakdown = array(); |
8 | 12 | return true; |
9 | 13 | } |
10 | 14 | |
| 15 | + /** |
| 16 | + * @param $parser Parser |
| 17 | + * @param $then string |
| 18 | + * @param $else string |
| 19 | + * @return string |
| 20 | + */ |
11 | 21 | function ifanon( &$parser, $then = '', $else = '' ) { |
12 | 22 | global $wgUser; |
13 | 23 | $parser->disableCache(); |
14 | | - |
15 | 24 | if($wgUser->isAnon()){ |
16 | 25 | return $then; |
17 | 26 | } |
18 | 27 | return $else; |
19 | 28 | } |
20 | | - |
| 29 | + |
| 30 | + /** |
| 31 | + * @param $parser Parser |
| 32 | + * @param $frame PPFrame |
| 33 | + * @param $args array |
| 34 | + * @return string |
| 35 | + */ |
21 | 36 | function ifanonObj( &$parser, $frame, $args ) { |
22 | 37 | global $wgUser; |
23 | | - |
24 | 38 | if($wgUser->isAnon()){ |
25 | 39 | return isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : ''; |
26 | 40 | } else { |
27 | 41 | return isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : ''; |
28 | 42 | } |
29 | | - } |
30 | | - |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * @param $parser Parser |
| 47 | + * @param $then string |
| 48 | + * @param $else string |
| 49 | + * @return string |
| 50 | + */ |
31 | 51 | function ifblocked( &$parser, $then = '', $else = '' ) { |
32 | | - global $wgUser; |
| 52 | + global $wgUser; |
33 | 53 | $parser->disableCache(); |
34 | | - |
| 54 | + |
35 | 55 | if($wgUser->isBlocked()) { |
36 | | - return $then; |
37 | | - } |
38 | | - return $else; |
| 56 | + return $then; |
| 57 | + } |
| 58 | + return $else; |
39 | 59 | } |
40 | | - |
| 60 | + |
| 61 | + /** |
| 62 | + * @param $parser Parser |
| 63 | + * @param $frame PPFrame |
| 64 | + * @param $args array |
| 65 | + * @return string |
| 66 | + */ |
41 | 67 | function ifblockedObj( &$parser, $frame, $args ) { |
42 | 68 | global $wgUser; |
43 | | - |
44 | 69 | if($wgUser->isBlocked()){ |
45 | 70 | return isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : ''; |
46 | 71 | } else { |
47 | 72 | return isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : ''; |
48 | 73 | } |
49 | | - } |
50 | | - |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * @param $parser Parser |
| 78 | + * @param $then string |
| 79 | + * @param $else string |
| 80 | + * @return string |
| 81 | + */ |
51 | 82 | function ifsysop( &$parser, $then = '', $else = '' ) { |
52 | | - global $wgUser; |
53 | | - $parser->disableCache(); |
54 | | - |
55 | | - if($wgUser->isAllowed('protect')) { |
| 83 | + global $wgUser; |
| 84 | + $parser->disableCache(); |
| 85 | + if($wgUser->isAllowed('protect')) { |
56 | 86 | return $then; |
57 | | - } |
58 | | - return $else; |
| 87 | + } |
| 88 | + return $else; |
59 | 89 | } |
60 | | - |
| 90 | + |
| 91 | + /** |
| 92 | + * @param $parser Parser |
| 93 | + * @param $frame PPFrame |
| 94 | + * @param $args array |
| 95 | + * @return string |
| 96 | + */ |
61 | 97 | function ifsysopObj( &$parser, $frame, $args ) { |
62 | 98 | global $wgUser; |
63 | | - |
64 | 99 | if($wgUser->isAllowed('protect')){ |
65 | 100 | return isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : ''; |
66 | 101 | } else { |
67 | 102 | return isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : ''; |
68 | 103 | } |
| 104 | + } |
69 | 105 | |
70 | | - } |
71 | | - |
| 106 | + /** |
| 107 | + * @param $parser Parser |
| 108 | + * @param $grp string |
| 109 | + * @param $then string |
| 110 | + * @param $else string |
| 111 | + * @return string |
| 112 | + */ |
72 | 113 | function ifingroup( &$parser, $grp = '', $then = '', $else = '' ) { |
73 | 114 | global $wgUser; |
74 | 115 | $parser->disableCache(); |
75 | 116 | |
76 | | - if($grp!==''){ |
77 | | - if(in_array($grp,$wgUser->getEffectiveGroups())) { |
78 | | - return $then; |
79 | | - } |
80 | | - return $else; |
81 | | - } else { |
82 | | - return $else; |
| 117 | + if($grp!=='' && in_array($grp,$wgUser->getEffectiveGroups())){ |
| 118 | + return $then; |
83 | 119 | } |
| 120 | + return $else; |
84 | 121 | } |
85 | 122 | |
| 123 | + /** |
| 124 | + * @param $parser Parser |
| 125 | + * @param $frame PPFrame |
| 126 | + * @param $args array |
| 127 | + * @return string |
| 128 | + */ |
86 | 129 | function ifingroupObj( &$parser, $frame, $args ) { |
87 | 130 | global $wgUser; |
88 | 131 | $grp = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : ''; |
89 | | - |
90 | | - if($grp!==''){ |
91 | | - if(in_array($grp,$wgUser->getEffectiveGroups())) { |
92 | | - return isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : ''; |
93 | | - } |
94 | | - return isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : ''; |
95 | | - } else { |
96 | | - return isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : ''; |
| 132 | + |
| 133 | + if($grp!=='' && in_array($grp,$wgUser->getEffectiveGroups())){ |
| 134 | + return isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : ''; |
97 | 135 | } |
98 | | - } |
99 | | - |
| 136 | + return isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : ''; |
| 137 | + } |
| 138 | + |
| 139 | + /** |
| 140 | + * @param $parser Parser |
| 141 | + * @param $alt string |
| 142 | + * @return String |
| 143 | + */ |
100 | 144 | function realname( &$parser, $alt = '' ) { |
101 | 145 | global $wgUser; |
102 | 146 | $parser->disableCache(); |
103 | | - |
| 147 | + |
104 | 148 | if($wgUser->isAnon() && $alt!=='') { |
105 | 149 | return $alt; |
106 | 150 | } |
107 | 151 | return $wgUser->getRealName(); |
108 | 152 | } |
109 | | - |
| 153 | + |
| 154 | + /** |
| 155 | + * @param $parser Parser |
| 156 | + * @param $alt string |
| 157 | + * @return String |
| 158 | + */ |
110 | 159 | function username( &$parser, $alt = '' ) { |
111 | 160 | global $wgUser; |
112 | 161 | $parser->disableCache(); |
113 | | - |
| 162 | + |
114 | 163 | if($wgUser->isAnon() && $alt!=='') { |
115 | 164 | return $alt; |
116 | 165 | } |
117 | 166 | return $wgUser->getName(); |
118 | 167 | } |
119 | | - |
| 168 | + |
| 169 | + /** |
| 170 | + * @param $parser Parser |
| 171 | + * @param $alt string |
| 172 | + * @return String |
| 173 | + */ |
120 | 174 | function useremail( &$parser, $alt = '' ) { |
121 | 175 | global $wgUser; |
122 | 176 | $parser->disableCache(); |
123 | | - |
| 177 | + |
124 | 178 | if($wgUser->isAnon() && $alt!=='') { |
125 | 179 | return $alt; |
126 | 180 | } |
127 | 181 | return $wgUser->getEmail(); |
128 | 182 | } |
129 | | - |
| 183 | + |
| 184 | + /** |
| 185 | + * @param $parser Parser |
| 186 | + * @param $alt string |
| 187 | + * @return String |
| 188 | + */ |
130 | 189 | function nickname( &$parser, $alt = '' ) { |
131 | 190 | global $wgUser; |
132 | 191 | $parser->disableCache(); |
133 | | - |
| 192 | + |
134 | 193 | if($wgUser->isAnon()) { |
135 | 194 | if ( $alt!=='') { |
136 | 195 | return $alt; |
— | — | @@ -140,7 +199,11 @@ |
141 | 200 | $nickname = $nickname === '' ? $wgUser->getName() : $nickname; |
142 | 201 | return $nickname; |
143 | 202 | } |
144 | | - |
| 203 | + |
| 204 | + /** |
| 205 | + * @param $parser Parser |
| 206 | + * @return string |
| 207 | + */ |
145 | 208 | function ip( &$parser ) { |
146 | 209 | $parser->disableCache(); |
147 | 210 | return wfGetIP(); |
Index: trunk/extensions/UserFunctions/UserFunctions.php |
— | — | @@ -55,6 +55,10 @@ |
56 | 56 | class UserFunctions_HookStub { |
57 | 57 | var $realObj; |
58 | 58 | |
| 59 | + /** |
| 60 | + * @param $parser Parser |
| 61 | + * @return bool |
| 62 | + */ |
59 | 63 | function registerParser( &$parser ) { |
60 | 64 | |
61 | 65 | if ( defined( get_class( $parser ) . '::SFH_OBJECT_ARGS' ) ) { |
— | — | @@ -68,8 +72,8 @@ |
69 | 73 | $parser->setFunctionHook( 'ifblocked', array( &$this, 'ifblocked' ) ); |
70 | 74 | $parser->setFunctionHook( 'ifsysop', array( &$this, 'ifsysop' ) ); |
71 | 75 | $parser->setFunctionHook( 'ifingroup', array( &$this, 'ifingroup' ) ); |
72 | | - } |
73 | | - |
| 76 | + } |
| 77 | + |
74 | 78 | $parser->setFunctionHook( 'realname', array( &$this, 'realname' ) ); |
75 | 79 | $parser->setFunctionHook( 'username', array( &$this, 'username' ) ); |
76 | 80 | $parser->setFunctionHook( 'useremail', array( &$this, 'useremail' ) ); |
— | — | @@ -79,7 +83,9 @@ |
80 | 84 | return true; |
81 | 85 | } |
82 | 86 | |
83 | | - /** Defer ParserClearState */ |
| 87 | + /** |
| 88 | + * Defer ParserClearState |
| 89 | + */ |
84 | 90 | function clearState( &$parser ) { |
85 | 91 | if ( !is_null( $this->realObj ) ) { |
86 | 92 | $this->realObj->clearState( $parser ); |
— | — | @@ -87,7 +93,9 @@ |
88 | 94 | return true; |
89 | 95 | } |
90 | 96 | |
91 | | - /** Pass through function call */ |
| 97 | + /** |
| 98 | + * Pass through function call |
| 99 | + */ |
92 | 100 | function __call( $name, $args ) { |
93 | 101 | if ( is_null( $this->realObj ) ) { |
94 | 102 | $this->realObj = new ExtUserFunctions; |