Index: trunk/extensions/ContactPage/ContactPage_body.php |
— | — | @@ -1,442 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Speclial:Contact, a contact form for visitors. |
5 | | - * Based on SpecialEmailUser.php |
6 | | - * |
7 | | - * @file |
8 | | - * @ingroup SpecialPage |
9 | | - * @author Daniel Kinzler, brightbyte.de |
10 | | - * @copyright © 2007 Daniel Kinzler |
11 | | - * @license GNU General Public Licence 2.0 or later |
12 | | - */ |
13 | | - |
14 | | -/** |
15 | | - * Provides the contact form |
16 | | - * @ingroup SpecialPage |
17 | | - */ |
18 | | -class SpecialContact extends SpecialPage { |
19 | | - /** |
20 | | - * Constructor |
21 | | - */ |
22 | | - public function __construct() { |
23 | | - parent::__construct( 'Contact' ); |
24 | | - } |
25 | | - |
26 | | - /** |
27 | | - * @see SpecialPage::getDescription |
28 | | - */ |
29 | | - function getDescription() { |
30 | | - return wfMsg( 'contactpage' ); |
31 | | - } |
32 | | - |
33 | | - /** |
34 | | - * Main execution function |
35 | | - * |
36 | | - * @param $par Mixed: Parameters passed to the page |
37 | | - */ |
38 | | - public function execute( $par ) { |
39 | | - global $wgUser, $wgOut, $wgRequest, $wgEnableEmail, $wgContactUser; |
40 | | - |
41 | | - if( !$wgEnableEmail || !$wgContactUser ) { |
42 | | - $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' ); |
43 | | - return; |
44 | | - } |
45 | | - |
46 | | - $action = $wgRequest->getVal( 'action' ); |
47 | | - |
48 | | - $nu = User::newFromName( $wgContactUser ); |
49 | | - if( is_null( $nu ) || !$nu->canReceiveEmail() ) { |
50 | | - wfDebug( "Target is invalid user or can't receive.\n" ); |
51 | | - $wgOut->showErrorPage( 'noemailtitle', 'noemailtext' ); |
52 | | - return; |
53 | | - } |
54 | | - |
55 | | - // Blocked users cannot use the contact form if they're disabled from sending email. |
56 | | - if ( $wgUser->isBlockedFromEmailuser() ) { |
57 | | - $wgOut->blockedPage(); |
58 | | - |
59 | | - return; |
60 | | - } |
61 | | - |
62 | | - $f = new EmailContactForm( $nu, $par ); |
63 | | - |
64 | | - if ( 'success' == $action ) { |
65 | | - wfDebug( __METHOD__ . ": success.\n" ); |
66 | | - $f->showSuccess(); |
67 | | - } elseif ( 'submit' == $action && $wgRequest->wasPosted() && $f->hasAllInfo() ) { |
68 | | - $token = $wgRequest->getVal( 'wpEditToken' ); |
69 | | - |
70 | | - if( $wgUser->isAnon() ) { |
71 | | - # Anonymous users may not have a session |
72 | | - # open. Check for suffix anyway. |
73 | | - $tokenOk = ( EDIT_TOKEN_SUFFIX == $token ); |
74 | | - } else { |
75 | | - $tokenOk = $wgUser->matchEditToken( $token ); |
76 | | - } |
77 | | - |
78 | | - if ( !$tokenOk ) { |
79 | | - wfDebug( __METHOD__ . ": bad token (" . ( $wgUser->isAnon() ? 'anon' : 'user' ) . "): $token\n" ); |
80 | | - $wgOut->addWikiMsg( 'sessionfailure' ); |
81 | | - $f->showForm(); |
82 | | - } elseif ( !$f->passCaptcha() ) { |
83 | | - wfDebug( __METHOD__ . ": captcha failed" ); |
84 | | - $wgOut->addWikiMsg( 'contactpage-captcha-failed' ); |
85 | | - $f->showForm(); |
86 | | - } else { |
87 | | - wfDebug( __METHOD__ . ": submit\n" ); |
88 | | - $f->doSubmit(); |
89 | | - } |
90 | | - } else { |
91 | | - wfDebug( __METHOD__ . ": form\n" ); |
92 | | - $f->showForm(); |
93 | | - } |
94 | | - } |
95 | | -} |
96 | | - |
97 | | -/** |
98 | | - * @todo document |
99 | | - * @ingroup SpecialPage |
100 | | - */ |
101 | | -class EmailContactForm { |
102 | | - |
103 | | - var $target; |
104 | | - var $text, $subject; |
105 | | - var $cc_me; // Whether user requested to be sent a separate copy of their email. |
106 | | - |
107 | | - /** |
108 | | - * @param User $target |
109 | | - */ |
110 | | - function __construct( $target, $par ) { |
111 | | - global $wgRequest, $wgUser; |
112 | | - |
113 | | - $this->wasPosted = $wgRequest->wasPosted(); |
114 | | - $this->formType = $wgRequest->getText( 'formtype', $par ); |
115 | | - |
116 | | - # Check for type in [[Special:Contact/type]]: change pagetext and prefill form fields |
117 | | - if ( $this->formType != '' ) { |
118 | | - $message = 'contactpage-pagetext-' . $this->formType; |
119 | | - $text = wfMsgExt( $message, 'parse' ); |
120 | | - if ( !wfEmptyMsg( $message, $text ) ) { |
121 | | - $this->formularText = $text; |
122 | | - } else { |
123 | | - $this->formularText = wfMsgExt( 'contactpage-pagetext', 'parse' ); |
124 | | - } |
125 | | - |
126 | | - $message = 'contactpage-subject-' . $this->formType; |
127 | | - $text = wfMsgForContentNoTrans( $message ); |
128 | | - if ( !wfEmptyMsg( $message, $text ) ) { |
129 | | - $this->subject = $wgRequest->getText( 'wpSubject', $text ); |
130 | | - } else { |
131 | | - $this->subject = $wgRequest->getText( 'wpSubject' ); |
132 | | - } |
133 | | - |
134 | | - $message = 'contactpage-text-' . $this->formType; |
135 | | - $text = wfMsgForContentNoTrans( $message ); |
136 | | - if ( !wfEmptyMsg( $message, $text ) ) { |
137 | | - $this->text = $wgRequest->getText( 'wpText', $text ); |
138 | | - } else { |
139 | | - $this->text = $wgRequest->getText( 'wpText' ); |
140 | | - } |
141 | | - } else { |
142 | | - $this->formularText = wfMsgExt( 'contactpage-pagetext', 'parse' ); |
143 | | - $this->text = $wgRequest->getText( 'wpText' ); |
144 | | - $this->subject = $wgRequest->getText( 'wpSubject' ); |
145 | | - } |
146 | | - |
147 | | - $this->target = $target; |
148 | | - $this->cc_me = $wgRequest->getBool( 'wpCCMe' ); |
149 | | - $this->includeIP = $wgRequest->getBool( 'wpIncludeIP' ); |
150 | | - |
151 | | - $this->fromname = $wgRequest->getText( 'wpFromName' ); |
152 | | - $this->fromaddress = $wgRequest->getText( 'wpFromAddress' ); |
153 | | - |
154 | | - if( $wgUser->isLoggedIn() ) { |
155 | | - if( !$this->fromname ) { |
156 | | - $this->fromname = $wgUser->getName(); |
157 | | - } |
158 | | - if( !$this->fromaddress ) { |
159 | | - $this->fromaddress = $wgUser->getEmail(); |
160 | | - } |
161 | | - } |
162 | | - |
163 | | - // prepare captcha if applicable |
164 | | - if ( $this->useCaptcha() ) { |
165 | | - $captcha = ConfirmEditHooks::getInstance(); |
166 | | - $captcha->trigger = 'contactpage'; |
167 | | - $captcha->action = 'contact'; |
168 | | - } |
169 | | - } |
170 | | - |
171 | | - function hasAllInfo() { |
172 | | - global $wgContactRequireAll; |
173 | | - |
174 | | - if ( $this->text === null ) { |
175 | | - return false; |
176 | | - } else { |
177 | | - $this->text = trim( $this->text ); |
178 | | - } |
179 | | - if ( $this->text === '' ) { |
180 | | - return false; |
181 | | - } |
182 | | - |
183 | | - if ( $wgContactRequireAll ) { |
184 | | - if ( $this->fromname === null ) { |
185 | | - return false; |
186 | | - } else { |
187 | | - $this->fromname = trim( $this->fromname ); |
188 | | - } |
189 | | - if ( $this->fromname === '' ) { |
190 | | - return false; |
191 | | - } |
192 | | - |
193 | | - if ( $this->fromaddress === null ) { |
194 | | - return false; |
195 | | - } else { |
196 | | - $this->fromaddress = trim( $this->fromaddress ); |
197 | | - } |
198 | | - if ( $this->fromaddress === '' ) { |
199 | | - return false; |
200 | | - } |
201 | | - } |
202 | | - |
203 | | - return true; |
204 | | - } |
205 | | - |
206 | | - function showForm() { |
207 | | - global $wgOut, $wgUser, $wgContactRequireAll, $wgContactIncludeIP, $wgRequest; |
208 | | - |
209 | | - #TODO: show captcha |
210 | | - |
211 | | - $wgOut->setPageTitle( wfMsg( 'contactpage-title' ) ); |
212 | | - $wgOut->addHTML( $this->formularText ); |
213 | | - |
214 | | - if ( $this->subject === '' ) { |
215 | | - $this->subject = wfMsgForContent( 'contactpage-defsubject' ); |
216 | | - } |
217 | | - |
218 | | - $msgSuffix = $wgContactRequireAll ? '-required' : ''; |
219 | | - |
220 | | - $titleObj = SpecialPage::getTitleFor( 'Contact' ); |
221 | | - $action = $titleObj->getLocalURL( 'action=submit' ); |
222 | | - $token = $wgUser->isAnon() ? EDIT_TOKEN_SUFFIX : $wgUser->editToken(); //this kind of sucks, really... |
223 | | - |
224 | | - $form = |
225 | | - Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'emailuser' ) ) . |
226 | | - Xml::openElement( 'fieldset' ) . |
227 | | - Xml::element( 'legend', null, wfMsg( 'contactpage-legend' ) ) . |
228 | | - Xml::openElement( 'table', array( 'id' => 'mailheader' ) ) . |
229 | | - '<tr> |
230 | | - <td class="mw-label">' . |
231 | | - Xml::label( wfMsg( 'emailsubject' ), 'wpSubject' ) . |
232 | | - '</td> |
233 | | - <td class="mw-input" id="mw-contactpage-subject">' . |
234 | | - Xml::input( 'wpSubject', 60, $this->subject, array( 'type' => 'text', 'maxlength' => 200 ) ) . |
235 | | - '</td> |
236 | | - </tr> |
237 | | - <tr> |
238 | | - <td class="mw-label">' . |
239 | | - Xml::label( wfMsg( "contactpage-fromname$msgSuffix" ), 'wpFromName' ) . |
240 | | - '</td> |
241 | | - <td class="mw-input" id="mw-contactpage-from">' . |
242 | | - Xml::input( 'wpFromName', 60, $this->fromname, array( 'type' => 'text', 'maxlength' => 200 ) ) . |
243 | | - '</td> |
244 | | - </tr> |
245 | | - <tr> |
246 | | - <td class="mw-label">' . |
247 | | - Xml::label( wfMsg( "contactpage-fromaddress$msgSuffix" ), 'wpFromAddress' ) . |
248 | | - '</td> |
249 | | - <td class="mw-input" id="mw-contactpage-address">' . |
250 | | - Xml::input( 'wpFromAddress', 60, $this->fromaddress, array( 'type' => 'text', 'maxlength' => 200 ) ) . |
251 | | - '</td> |
252 | | - </tr>'; |
253 | | - |
254 | | - // Allow other extensions to add more fields into Special:Contact |
255 | | - wfRunHooks( 'ContactFormBeforeMessage', array( $this, &$form ) ); |
256 | | - |
257 | | - $form .= '<tr> |
258 | | - <td></td> |
259 | | - <td class="mw-input" id="mw-contactpage-formfootnote"> |
260 | | - <small>' . wfMsg( "contactpage-formfootnotes$msgSuffix" ) . '</small> |
261 | | - </td> |
262 | | - </tr> |
263 | | - <tr> |
264 | | - <td class="mw-label">' . |
265 | | - Xml::label( wfMsg( 'emailmessage' ), 'wpText' ) . |
266 | | - '</td> |
267 | | - <td class="mw-input">' . |
268 | | - Xml::textarea( 'wpText', $this->text, 80, 20, array( 'id' => 'wpText' ) ) . |
269 | | - '</td> |
270 | | - </tr>'; |
271 | | - if ( $wgContactIncludeIP && $wgUser->isLoggedIn() ) { |
272 | | - $form .= '<tr> |
273 | | - <td></td> |
274 | | - <td class="mw-input">' . |
275 | | - Xml::checkLabel( wfMsg( 'contactpage-includeip' ), 'wpIncludeIP', 'wpIncludeIP', false ) . |
276 | | - '</td> |
277 | | - </tr>'; |
278 | | - } |
279 | | - |
280 | | - $ccme = $this->wasPosted ? $this->cc_me : $wgUser->getBoolOption( 'ccmeonemails' ); |
281 | | - $form .= '<tr> |
282 | | - <td></td> |
283 | | - <td class="mw-input">' . |
284 | | - Xml::checkLabel( wfMsg( 'emailccme' ), 'wpCCMe', 'wpCCMe', $ccme ) . |
285 | | - '<br />' . $this->getCaptcha() . |
286 | | - '</td> |
287 | | - </tr> |
288 | | - <tr> |
289 | | - <td></td> |
290 | | - <td class="mw-submit">' . |
291 | | - Xml::submitButton( wfMsg( 'emailsend' ), array( 'name' => 'wpSend', 'accesskey' => 's' ) ) . |
292 | | - '</td> |
293 | | - </tr>' . |
294 | | - Html::hidden( 'wpEditToken', $token ) . |
295 | | - Html::hidden( 'formtype', $this->formType ) . |
296 | | - Xml::closeElement( 'table' ) . |
297 | | - Xml::closeElement( 'fieldset' ) . |
298 | | - Xml::closeElement( 'form' ); |
299 | | - $wgOut->addHTML( $form ); |
300 | | - } |
301 | | - |
302 | | - function useCaptcha() { |
303 | | - global $wgCaptchaClass, $wgCaptchaTriggers, $wgUser; |
304 | | - if ( !$wgCaptchaClass ) { |
305 | | - return false; // no captcha installed |
306 | | - } |
307 | | - if ( !@$wgCaptchaTriggers['contactpage'] ) { |
308 | | - return false; // don't trigger on contact form |
309 | | - } |
310 | | - |
311 | | - if( $wgUser->isAllowed( 'skipcaptcha' ) ) { |
312 | | - wfDebug( "EmailContactForm::useCaptcha: user group allows skipping captcha\n" ); |
313 | | - return false; |
314 | | - } |
315 | | - |
316 | | - return true; |
317 | | - } |
318 | | - |
319 | | - function getCaptcha() { |
320 | | - global $wgCaptcha; |
321 | | - if ( !$this->useCaptcha() ) { |
322 | | - return ''; |
323 | | - } |
324 | | - |
325 | | - wfSetupSession(); #NOTE: make sure we have a session. May be required for captchas to work. |
326 | | - |
327 | | - return '<div class="captcha">' . |
328 | | - $wgCaptcha->getForm() . |
329 | | - wfMsgWikiHtml( 'contactpage-captcha' ) . |
330 | | - "</div>\n"; |
331 | | - } |
332 | | - |
333 | | - function passCaptcha() { |
334 | | - global $wgCaptcha; |
335 | | - if ( !$this->useCaptcha() ) { |
336 | | - return true; |
337 | | - } |
338 | | - |
339 | | - return $wgCaptcha->passCaptcha(); |
340 | | - } |
341 | | - |
342 | | - function doSubmit() { |
343 | | - global $wgOut, $wgUser; |
344 | | - global $wgUserEmailUseReplyTo, $wgPasswordSender; |
345 | | - global $wgContactSender, $wgContactSenderName, $wgContactIncludeIP; |
346 | | - |
347 | | - $csender = $wgContactSender ? $wgContactSender : $wgPasswordSender; |
348 | | - $cname = $wgContactSenderName; |
349 | | - $senderIP = wfGetIP(); |
350 | | - |
351 | | - wfDebug( __METHOD__ . ": start\n" ); |
352 | | - |
353 | | - $targetAddress = new MailAddress( $this->target ); |
354 | | - $replyto = null; |
355 | | - $contactSender = new MailAddress( $csender, $cname ); |
356 | | - |
357 | | - if ( !$this->fromaddress ) { |
358 | | - $submitterAddress = $contactSender; |
359 | | - } else { |
360 | | - $submitterAddress = new MailAddress( $this->fromaddress, $this->fromname ); |
361 | | - if ( $wgUserEmailUseReplyTo ) { |
362 | | - $replyto = $submitterAddress; |
363 | | - } |
364 | | - } |
365 | | - |
366 | | - $subject = trim( $this->subject ); |
367 | | - |
368 | | - if ( $subject === '' ) { |
369 | | - $subject = wfMsgForContent( 'contactpage-defsubject' ); |
370 | | - } |
371 | | - |
372 | | - $includeIP = $wgContactIncludeIP && ( $this->includeIP || $wgUser->isAnon() ); |
373 | | - if ( $this->fromname !== '' ) { |
374 | | - if ( $includeIP ) { |
375 | | - $subject = wfMsgForContent( 'contactpage-subject-and-sender-withip', $subject, $this->fromname, $senderIP ); |
376 | | - } else { |
377 | | - $subject = wfMsgForContent( 'contactpage-subject-and-sender', $subject, $this->fromname ); |
378 | | - } |
379 | | - } elseif ( $this->fromaddress !== '' ) { |
380 | | - if ( $includeIP ) { |
381 | | - $subject = wfMsgForContent( 'contactpage-subject-and-sender-withip', $subject, $this->fromaddress, $senderIP ); |
382 | | - } else { |
383 | | - $subject = wfMsgForContent( 'contactpage-subject-and-sender', $subject, $this->fromaddress ); |
384 | | - } |
385 | | - } elseif ( $includeIP ) { |
386 | | - $subject = wfMsgForContent( 'contactpage-subject-and-sender', $subject, $senderIP ); |
387 | | - } |
388 | | - |
389 | | - if( !wfRunHooks( 'ContactForm', array( &$targetAddress, &$replyto, &$subject, &$this->text, $this->formType ) ) ) { |
390 | | - wfDebug( __METHOD__ . ": aborted by hook\n" ); |
391 | | - return; |
392 | | - } |
393 | | - |
394 | | - wfDebug( __METHOD__ . ": sending mail from " . $submitterAddress->toString() . |
395 | | - " to " . $targetAddress->toString(). |
396 | | - " replyto " . ( $replyto == null ? '-/-' : $replyto->toString() ) . "\n" ); |
397 | | - |
398 | | - $mailResult = UserMailer::send( $targetAddress, $submitterAddress, $subject, $this->text, $replyto ); |
399 | | - |
400 | | - if( WikiError::isError( $mailResult ) ) { |
401 | | - $wgOut->addWikiMsg( 'usermailererror' ) . $mailResult->getMessage(); |
402 | | - wfDebug( __METHOD__ . ": got error from UserMailer: " . $mailResult->getMessage() . "\n" ); |
403 | | - return; |
404 | | - } |
405 | | - |
406 | | - // if the user requested a copy of this mail, do this now, |
407 | | - // unless they are emailing themselves, in which case one copy of the message is sufficient. |
408 | | - if( $this->cc_me && $this->fromaddress ) { |
409 | | - $cc_subject = wfMsg( 'emailccsubject', $this->target->getName(), $subject ); |
410 | | - if( wfRunHooks( 'ContactForm', array( &$submitterAddress, &$contactSender, &$cc_subject, &$this->text, $this->formType ) ) ) { |
411 | | - wfDebug( __METHOD__ . ": sending cc mail from " . $contactSender->toString() . |
412 | | - " to " . $submitterAddress->toString() . "\n" ); |
413 | | - $ccResult = UserMailer::send( $submitterAddress, $contactSender, $cc_subject, $this->text ); |
414 | | - if( WikiError::isError( $ccResult ) ) { |
415 | | - // At this stage, the user's CC mail has failed, but their |
416 | | - // original mail has succeeded. It's unlikely, but still, what to do? |
417 | | - // We can either show them an error, or we can say everything was fine, |
418 | | - // or we can say we sort of failed AND sort of succeeded. Of these options, |
419 | | - // simply saying there was an error is probably best. |
420 | | - $wgOut->addWikiText( wfMsg( 'usermailererror' ) . $ccResult ); |
421 | | - return; |
422 | | - } |
423 | | - } |
424 | | - } |
425 | | - |
426 | | - wfDebug( __METHOD__ . ": success\n" ); |
427 | | - |
428 | | - $titleObj = SpecialPage::getTitleFor( 'Contact' ); |
429 | | - $wgOut->redirect( $titleObj->getFullURL( 'action=success' ) ); |
430 | | - wfRunHooks( 'ContactFromComplete', array( $targetAddress, $replyto, $subject, $this->text ) ); |
431 | | - |
432 | | - wfDebug( __METHOD__ . ": end\n" ); |
433 | | - } |
434 | | - |
435 | | - function showSuccess() { |
436 | | - global $wgOut; |
437 | | - |
438 | | - $wgOut->setPageTitle( wfMsg( 'emailsent' ) ); |
439 | | - $wgOut->addWikiMsg( 'emailsenttext' ); |
440 | | - |
441 | | - $wgOut->returnToMain( false ); |
442 | | - } |
443 | | -} |
Index: trunk/extensions/ContactPage/SpecialContact.php |
— | — | @@ -0,0 +1,442 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Speclial:Contact, a contact form for visitors. |
| 5 | + * Based on SpecialEmailUser.php |
| 6 | + * |
| 7 | + * @file |
| 8 | + * @ingroup SpecialPage |
| 9 | + * @author Daniel Kinzler, brightbyte.de |
| 10 | + * @copyright © 2007 Daniel Kinzler |
| 11 | + * @license GNU General Public Licence 2.0 or later |
| 12 | + */ |
| 13 | + |
| 14 | +/** |
| 15 | + * Provides the contact form |
| 16 | + * @ingroup SpecialPage |
| 17 | + */ |
| 18 | +class SpecialContact extends SpecialPage { |
| 19 | + /** |
| 20 | + * Constructor |
| 21 | + */ |
| 22 | + public function __construct() { |
| 23 | + parent::__construct( 'Contact' ); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @see SpecialPage::getDescription |
| 28 | + */ |
| 29 | + function getDescription() { |
| 30 | + return wfMsg( 'contactpage' ); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Main execution function |
| 35 | + * |
| 36 | + * @param $par Mixed: Parameters passed to the page |
| 37 | + */ |
| 38 | + public function execute( $par ) { |
| 39 | + global $wgUser, $wgOut, $wgRequest, $wgEnableEmail, $wgContactUser; |
| 40 | + |
| 41 | + if( !$wgEnableEmail || !$wgContactUser ) { |
| 42 | + $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' ); |
| 43 | + return; |
| 44 | + } |
| 45 | + |
| 46 | + $action = $wgRequest->getVal( 'action' ); |
| 47 | + |
| 48 | + $nu = User::newFromName( $wgContactUser ); |
| 49 | + if( is_null( $nu ) || !$nu->canReceiveEmail() ) { |
| 50 | + wfDebug( "Target is invalid user or can't receive.\n" ); |
| 51 | + $wgOut->showErrorPage( 'noemailtitle', 'noemailtext' ); |
| 52 | + return; |
| 53 | + } |
| 54 | + |
| 55 | + // Blocked users cannot use the contact form if they're disabled from sending email. |
| 56 | + if ( $wgUser->isBlockedFromEmailuser() ) { |
| 57 | + $wgOut->blockedPage(); |
| 58 | + |
| 59 | + return; |
| 60 | + } |
| 61 | + |
| 62 | + $f = new EmailContactForm( $nu, $par ); |
| 63 | + |
| 64 | + if ( 'success' == $action ) { |
| 65 | + wfDebug( __METHOD__ . ": success.\n" ); |
| 66 | + $f->showSuccess(); |
| 67 | + } elseif ( 'submit' == $action && $wgRequest->wasPosted() && $f->hasAllInfo() ) { |
| 68 | + $token = $wgRequest->getVal( 'wpEditToken' ); |
| 69 | + |
| 70 | + if( $wgUser->isAnon() ) { |
| 71 | + # Anonymous users may not have a session |
| 72 | + # open. Check for suffix anyway. |
| 73 | + $tokenOk = ( EDIT_TOKEN_SUFFIX == $token ); |
| 74 | + } else { |
| 75 | + $tokenOk = $wgUser->matchEditToken( $token ); |
| 76 | + } |
| 77 | + |
| 78 | + if ( !$tokenOk ) { |
| 79 | + wfDebug( __METHOD__ . ": bad token (" . ( $wgUser->isAnon() ? 'anon' : 'user' ) . "): $token\n" ); |
| 80 | + $wgOut->addWikiMsg( 'sessionfailure' ); |
| 81 | + $f->showForm(); |
| 82 | + } elseif ( !$f->passCaptcha() ) { |
| 83 | + wfDebug( __METHOD__ . ": captcha failed" ); |
| 84 | + $wgOut->addWikiMsg( 'contactpage-captcha-failed' ); |
| 85 | + $f->showForm(); |
| 86 | + } else { |
| 87 | + wfDebug( __METHOD__ . ": submit\n" ); |
| 88 | + $f->doSubmit(); |
| 89 | + } |
| 90 | + } else { |
| 91 | + wfDebug( __METHOD__ . ": form\n" ); |
| 92 | + $f->showForm(); |
| 93 | + } |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +/** |
| 98 | + * @todo document |
| 99 | + * @ingroup SpecialPage |
| 100 | + */ |
| 101 | +class EmailContactForm { |
| 102 | + |
| 103 | + var $target; |
| 104 | + var $text, $subject; |
| 105 | + var $cc_me; // Whether user requested to be sent a separate copy of their email. |
| 106 | + |
| 107 | + /** |
| 108 | + * @param User $target |
| 109 | + */ |
| 110 | + function __construct( $target, $par ) { |
| 111 | + global $wgRequest, $wgUser; |
| 112 | + |
| 113 | + $this->wasPosted = $wgRequest->wasPosted(); |
| 114 | + $this->formType = $wgRequest->getText( 'formtype', $par ); |
| 115 | + |
| 116 | + # Check for type in [[Special:Contact/type]]: change pagetext and prefill form fields |
| 117 | + if ( $this->formType != '' ) { |
| 118 | + $message = 'contactpage-pagetext-' . $this->formType; |
| 119 | + $text = wfMsgExt( $message, 'parse' ); |
| 120 | + if ( !wfEmptyMsg( $message, $text ) ) { |
| 121 | + $this->formularText = $text; |
| 122 | + } else { |
| 123 | + $this->formularText = wfMsgExt( 'contactpage-pagetext', 'parse' ); |
| 124 | + } |
| 125 | + |
| 126 | + $message = 'contactpage-subject-' . $this->formType; |
| 127 | + $text = wfMsgForContentNoTrans( $message ); |
| 128 | + if ( !wfEmptyMsg( $message, $text ) ) { |
| 129 | + $this->subject = $wgRequest->getText( 'wpSubject', $text ); |
| 130 | + } else { |
| 131 | + $this->subject = $wgRequest->getText( 'wpSubject' ); |
| 132 | + } |
| 133 | + |
| 134 | + $message = 'contactpage-text-' . $this->formType; |
| 135 | + $text = wfMsgForContentNoTrans( $message ); |
| 136 | + if ( !wfEmptyMsg( $message, $text ) ) { |
| 137 | + $this->text = $wgRequest->getText( 'wpText', $text ); |
| 138 | + } else { |
| 139 | + $this->text = $wgRequest->getText( 'wpText' ); |
| 140 | + } |
| 141 | + } else { |
| 142 | + $this->formularText = wfMsgExt( 'contactpage-pagetext', 'parse' ); |
| 143 | + $this->text = $wgRequest->getText( 'wpText' ); |
| 144 | + $this->subject = $wgRequest->getText( 'wpSubject' ); |
| 145 | + } |
| 146 | + |
| 147 | + $this->target = $target; |
| 148 | + $this->cc_me = $wgRequest->getBool( 'wpCCMe' ); |
| 149 | + $this->includeIP = $wgRequest->getBool( 'wpIncludeIP' ); |
| 150 | + |
| 151 | + $this->fromname = $wgRequest->getText( 'wpFromName' ); |
| 152 | + $this->fromaddress = $wgRequest->getText( 'wpFromAddress' ); |
| 153 | + |
| 154 | + if( $wgUser->isLoggedIn() ) { |
| 155 | + if( !$this->fromname ) { |
| 156 | + $this->fromname = $wgUser->getName(); |
| 157 | + } |
| 158 | + if( !$this->fromaddress ) { |
| 159 | + $this->fromaddress = $wgUser->getEmail(); |
| 160 | + } |
| 161 | + } |
| 162 | + |
| 163 | + // prepare captcha if applicable |
| 164 | + if ( $this->useCaptcha() ) { |
| 165 | + $captcha = ConfirmEditHooks::getInstance(); |
| 166 | + $captcha->trigger = 'contactpage'; |
| 167 | + $captcha->action = 'contact'; |
| 168 | + } |
| 169 | + } |
| 170 | + |
| 171 | + function hasAllInfo() { |
| 172 | + global $wgContactRequireAll; |
| 173 | + |
| 174 | + if ( $this->text === null ) { |
| 175 | + return false; |
| 176 | + } else { |
| 177 | + $this->text = trim( $this->text ); |
| 178 | + } |
| 179 | + if ( $this->text === '' ) { |
| 180 | + return false; |
| 181 | + } |
| 182 | + |
| 183 | + if ( $wgContactRequireAll ) { |
| 184 | + if ( $this->fromname === null ) { |
| 185 | + return false; |
| 186 | + } else { |
| 187 | + $this->fromname = trim( $this->fromname ); |
| 188 | + } |
| 189 | + if ( $this->fromname === '' ) { |
| 190 | + return false; |
| 191 | + } |
| 192 | + |
| 193 | + if ( $this->fromaddress === null ) { |
| 194 | + return false; |
| 195 | + } else { |
| 196 | + $this->fromaddress = trim( $this->fromaddress ); |
| 197 | + } |
| 198 | + if ( $this->fromaddress === '' ) { |
| 199 | + return false; |
| 200 | + } |
| 201 | + } |
| 202 | + |
| 203 | + return true; |
| 204 | + } |
| 205 | + |
| 206 | + function showForm() { |
| 207 | + global $wgOut, $wgUser, $wgContactRequireAll, $wgContactIncludeIP, $wgRequest; |
| 208 | + |
| 209 | + #TODO: show captcha |
| 210 | + |
| 211 | + $wgOut->setPageTitle( wfMsg( 'contactpage-title' ) ); |
| 212 | + $wgOut->addHTML( $this->formularText ); |
| 213 | + |
| 214 | + if ( $this->subject === '' ) { |
| 215 | + $this->subject = wfMsgForContent( 'contactpage-defsubject' ); |
| 216 | + } |
| 217 | + |
| 218 | + $msgSuffix = $wgContactRequireAll ? '-required' : ''; |
| 219 | + |
| 220 | + $titleObj = SpecialPage::getTitleFor( 'Contact' ); |
| 221 | + $action = $titleObj->getLocalURL( 'action=submit' ); |
| 222 | + $token = $wgUser->isAnon() ? EDIT_TOKEN_SUFFIX : $wgUser->editToken(); //this kind of sucks, really... |
| 223 | + |
| 224 | + $form = |
| 225 | + Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'emailuser' ) ) . |
| 226 | + Xml::openElement( 'fieldset' ) . |
| 227 | + Xml::element( 'legend', null, wfMsg( 'contactpage-legend' ) ) . |
| 228 | + Xml::openElement( 'table', array( 'id' => 'mailheader' ) ) . |
| 229 | + '<tr> |
| 230 | + <td class="mw-label">' . |
| 231 | + Xml::label( wfMsg( 'emailsubject' ), 'wpSubject' ) . |
| 232 | + '</td> |
| 233 | + <td class="mw-input" id="mw-contactpage-subject">' . |
| 234 | + Xml::input( 'wpSubject', 60, $this->subject, array( 'type' => 'text', 'maxlength' => 200 ) ) . |
| 235 | + '</td> |
| 236 | + </tr> |
| 237 | + <tr> |
| 238 | + <td class="mw-label">' . |
| 239 | + Xml::label( wfMsg( "contactpage-fromname$msgSuffix" ), 'wpFromName' ) . |
| 240 | + '</td> |
| 241 | + <td class="mw-input" id="mw-contactpage-from">' . |
| 242 | + Xml::input( 'wpFromName', 60, $this->fromname, array( 'type' => 'text', 'maxlength' => 200 ) ) . |
| 243 | + '</td> |
| 244 | + </tr> |
| 245 | + <tr> |
| 246 | + <td class="mw-label">' . |
| 247 | + Xml::label( wfMsg( "contactpage-fromaddress$msgSuffix" ), 'wpFromAddress' ) . |
| 248 | + '</td> |
| 249 | + <td class="mw-input" id="mw-contactpage-address">' . |
| 250 | + Xml::input( 'wpFromAddress', 60, $this->fromaddress, array( 'type' => 'text', 'maxlength' => 200 ) ) . |
| 251 | + '</td> |
| 252 | + </tr>'; |
| 253 | + |
| 254 | + // Allow other extensions to add more fields into Special:Contact |
| 255 | + wfRunHooks( 'ContactFormBeforeMessage', array( $this, &$form ) ); |
| 256 | + |
| 257 | + $form .= '<tr> |
| 258 | + <td></td> |
| 259 | + <td class="mw-input" id="mw-contactpage-formfootnote"> |
| 260 | + <small>' . wfMsg( "contactpage-formfootnotes$msgSuffix" ) . '</small> |
| 261 | + </td> |
| 262 | + </tr> |
| 263 | + <tr> |
| 264 | + <td class="mw-label">' . |
| 265 | + Xml::label( wfMsg( 'emailmessage' ), 'wpText' ) . |
| 266 | + '</td> |
| 267 | + <td class="mw-input">' . |
| 268 | + Xml::textarea( 'wpText', $this->text, 80, 20, array( 'id' => 'wpText' ) ) . |
| 269 | + '</td> |
| 270 | + </tr>'; |
| 271 | + if ( $wgContactIncludeIP && $wgUser->isLoggedIn() ) { |
| 272 | + $form .= '<tr> |
| 273 | + <td></td> |
| 274 | + <td class="mw-input">' . |
| 275 | + Xml::checkLabel( wfMsg( 'contactpage-includeip' ), 'wpIncludeIP', 'wpIncludeIP', false ) . |
| 276 | + '</td> |
| 277 | + </tr>'; |
| 278 | + } |
| 279 | + |
| 280 | + $ccme = $this->wasPosted ? $this->cc_me : $wgUser->getBoolOption( 'ccmeonemails' ); |
| 281 | + $form .= '<tr> |
| 282 | + <td></td> |
| 283 | + <td class="mw-input">' . |
| 284 | + Xml::checkLabel( wfMsg( 'emailccme' ), 'wpCCMe', 'wpCCMe', $ccme ) . |
| 285 | + '<br />' . $this->getCaptcha() . |
| 286 | + '</td> |
| 287 | + </tr> |
| 288 | + <tr> |
| 289 | + <td></td> |
| 290 | + <td class="mw-submit">' . |
| 291 | + Xml::submitButton( wfMsg( 'emailsend' ), array( 'name' => 'wpSend', 'accesskey' => 's' ) ) . |
| 292 | + '</td> |
| 293 | + </tr>' . |
| 294 | + Html::hidden( 'wpEditToken', $token ) . |
| 295 | + Html::hidden( 'formtype', $this->formType ) . |
| 296 | + Xml::closeElement( 'table' ) . |
| 297 | + Xml::closeElement( 'fieldset' ) . |
| 298 | + Xml::closeElement( 'form' ); |
| 299 | + $wgOut->addHTML( $form ); |
| 300 | + } |
| 301 | + |
| 302 | + function useCaptcha() { |
| 303 | + global $wgCaptchaClass, $wgCaptchaTriggers, $wgUser; |
| 304 | + if ( !$wgCaptchaClass ) { |
| 305 | + return false; // no captcha installed |
| 306 | + } |
| 307 | + if ( !@$wgCaptchaTriggers['contactpage'] ) { |
| 308 | + return false; // don't trigger on contact form |
| 309 | + } |
| 310 | + |
| 311 | + if( $wgUser->isAllowed( 'skipcaptcha' ) ) { |
| 312 | + wfDebug( "EmailContactForm::useCaptcha: user group allows skipping captcha\n" ); |
| 313 | + return false; |
| 314 | + } |
| 315 | + |
| 316 | + return true; |
| 317 | + } |
| 318 | + |
| 319 | + function getCaptcha() { |
| 320 | + global $wgCaptcha; |
| 321 | + if ( !$this->useCaptcha() ) { |
| 322 | + return ''; |
| 323 | + } |
| 324 | + |
| 325 | + wfSetupSession(); #NOTE: make sure we have a session. May be required for captchas to work. |
| 326 | + |
| 327 | + return '<div class="captcha">' . |
| 328 | + $wgCaptcha->getForm() . |
| 329 | + wfMsgWikiHtml( 'contactpage-captcha' ) . |
| 330 | + "</div>\n"; |
| 331 | + } |
| 332 | + |
| 333 | + function passCaptcha() { |
| 334 | + global $wgCaptcha; |
| 335 | + if ( !$this->useCaptcha() ) { |
| 336 | + return true; |
| 337 | + } |
| 338 | + |
| 339 | + return $wgCaptcha->passCaptcha(); |
| 340 | + } |
| 341 | + |
| 342 | + function doSubmit() { |
| 343 | + global $wgOut, $wgUser; |
| 344 | + global $wgUserEmailUseReplyTo, $wgPasswordSender; |
| 345 | + global $wgContactSender, $wgContactSenderName, $wgContactIncludeIP; |
| 346 | + |
| 347 | + $csender = $wgContactSender ? $wgContactSender : $wgPasswordSender; |
| 348 | + $cname = $wgContactSenderName; |
| 349 | + $senderIP = wfGetIP(); |
| 350 | + |
| 351 | + wfDebug( __METHOD__ . ": start\n" ); |
| 352 | + |
| 353 | + $targetAddress = new MailAddress( $this->target ); |
| 354 | + $replyto = null; |
| 355 | + $contactSender = new MailAddress( $csender, $cname ); |
| 356 | + |
| 357 | + if ( !$this->fromaddress ) { |
| 358 | + $submitterAddress = $contactSender; |
| 359 | + } else { |
| 360 | + $submitterAddress = new MailAddress( $this->fromaddress, $this->fromname ); |
| 361 | + if ( $wgUserEmailUseReplyTo ) { |
| 362 | + $replyto = $submitterAddress; |
| 363 | + } |
| 364 | + } |
| 365 | + |
| 366 | + $subject = trim( $this->subject ); |
| 367 | + |
| 368 | + if ( $subject === '' ) { |
| 369 | + $subject = wfMsgForContent( 'contactpage-defsubject' ); |
| 370 | + } |
| 371 | + |
| 372 | + $includeIP = $wgContactIncludeIP && ( $this->includeIP || $wgUser->isAnon() ); |
| 373 | + if ( $this->fromname !== '' ) { |
| 374 | + if ( $includeIP ) { |
| 375 | + $subject = wfMsgForContent( 'contactpage-subject-and-sender-withip', $subject, $this->fromname, $senderIP ); |
| 376 | + } else { |
| 377 | + $subject = wfMsgForContent( 'contactpage-subject-and-sender', $subject, $this->fromname ); |
| 378 | + } |
| 379 | + } elseif ( $this->fromaddress !== '' ) { |
| 380 | + if ( $includeIP ) { |
| 381 | + $subject = wfMsgForContent( 'contactpage-subject-and-sender-withip', $subject, $this->fromaddress, $senderIP ); |
| 382 | + } else { |
| 383 | + $subject = wfMsgForContent( 'contactpage-subject-and-sender', $subject, $this->fromaddress ); |
| 384 | + } |
| 385 | + } elseif ( $includeIP ) { |
| 386 | + $subject = wfMsgForContent( 'contactpage-subject-and-sender', $subject, $senderIP ); |
| 387 | + } |
| 388 | + |
| 389 | + if( !wfRunHooks( 'ContactForm', array( &$targetAddress, &$replyto, &$subject, &$this->text, $this->formType ) ) ) { |
| 390 | + wfDebug( __METHOD__ . ": aborted by hook\n" ); |
| 391 | + return; |
| 392 | + } |
| 393 | + |
| 394 | + wfDebug( __METHOD__ . ": sending mail from " . $submitterAddress->toString() . |
| 395 | + " to " . $targetAddress->toString(). |
| 396 | + " replyto " . ( $replyto == null ? '-/-' : $replyto->toString() ) . "\n" ); |
| 397 | + |
| 398 | + $mailResult = UserMailer::send( $targetAddress, $submitterAddress, $subject, $this->text, $replyto ); |
| 399 | + |
| 400 | + if( WikiError::isError( $mailResult ) ) { |
| 401 | + $wgOut->addWikiMsg( 'usermailererror' ) . $mailResult->getMessage(); |
| 402 | + wfDebug( __METHOD__ . ": got error from UserMailer: " . $mailResult->getMessage() . "\n" ); |
| 403 | + return; |
| 404 | + } |
| 405 | + |
| 406 | + // if the user requested a copy of this mail, do this now, |
| 407 | + // unless they are emailing themselves, in which case one copy of the message is sufficient. |
| 408 | + if( $this->cc_me && $this->fromaddress ) { |
| 409 | + $cc_subject = wfMsg( 'emailccsubject', $this->target->getName(), $subject ); |
| 410 | + if( wfRunHooks( 'ContactForm', array( &$submitterAddress, &$contactSender, &$cc_subject, &$this->text, $this->formType ) ) ) { |
| 411 | + wfDebug( __METHOD__ . ": sending cc mail from " . $contactSender->toString() . |
| 412 | + " to " . $submitterAddress->toString() . "\n" ); |
| 413 | + $ccResult = UserMailer::send( $submitterAddress, $contactSender, $cc_subject, $this->text ); |
| 414 | + if( WikiError::isError( $ccResult ) ) { |
| 415 | + // At this stage, the user's CC mail has failed, but their |
| 416 | + // original mail has succeeded. It's unlikely, but still, what to do? |
| 417 | + // We can either show them an error, or we can say everything was fine, |
| 418 | + // or we can say we sort of failed AND sort of succeeded. Of these options, |
| 419 | + // simply saying there was an error is probably best. |
| 420 | + $wgOut->addWikiText( wfMsg( 'usermailererror' ) . $ccResult ); |
| 421 | + return; |
| 422 | + } |
| 423 | + } |
| 424 | + } |
| 425 | + |
| 426 | + wfDebug( __METHOD__ . ": success\n" ); |
| 427 | + |
| 428 | + $titleObj = SpecialPage::getTitleFor( 'Contact' ); |
| 429 | + $wgOut->redirect( $titleObj->getFullURL( 'action=success' ) ); |
| 430 | + wfRunHooks( 'ContactFromComplete', array( $targetAddress, $replyto, $subject, $this->text ) ); |
| 431 | + |
| 432 | + wfDebug( __METHOD__ . ": end\n" ); |
| 433 | + } |
| 434 | + |
| 435 | + function showSuccess() { |
| 436 | + global $wgOut; |
| 437 | + |
| 438 | + $wgOut->setPageTitle( wfMsg( 'emailsent' ) ); |
| 439 | + $wgOut->addWikiMsg( 'emailsenttext' ); |
| 440 | + |
| 441 | + $wgOut->returnToMain( false ); |
| 442 | + } |
| 443 | +} |
Property changes on: trunk/extensions/ContactPage/SpecialContact.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 444 | + native |
Index: trunk/extensions/ContactPage/ContactPage.php |
— | — | @@ -29,7 +29,7 @@ |
30 | 30 | $wgExtensionMessagesFiles['ContactPage'] = $dir . 'ContactPage.i18n.php'; |
31 | 31 | $wgExtensionMessagesFiles['ContactPageAliases'] = $dir . 'ContactPage.alias.php'; |
32 | 32 | |
33 | | -$wgAutoloadClasses['SpecialContact'] = $dir . 'ContactPage_body.php'; |
| 33 | +$wgAutoloadClasses['SpecialContact'] = $dir . 'SpecialContact.php'; |
34 | 34 | $wgSpecialPages['Contact'] = 'SpecialContact'; |
35 | 35 | |
36 | 36 | # Configuration |
Index: trunk/extensions/DisableAccount/DisableAccount_body.php |
— | — | @@ -1,65 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -class SpecialDisableAccount extends SpecialPage { |
5 | | - function __construct() { |
6 | | - parent::__construct( 'DisableAccount', 'disableaccount', |
7 | | - true, array( $this, 'show' ) ); |
8 | | - } |
9 | | - |
10 | | - public function show( $par ) { |
11 | | - $formFields = array( |
12 | | - 'account' => array( |
13 | | - 'type' => 'text', |
14 | | - 'validation-callback' => array( __CLASS__, 'validateUser' ), |
15 | | - 'label-message' => 'disableaccount-user', |
16 | | - ), |
17 | | - 'confirm' => array( |
18 | | - 'type' => 'toggle', |
19 | | - 'validation-callback' => array( __CLASS__, 'checkConfirmation' ), |
20 | | - 'label-message' => 'disableaccount-confirm', |
21 | | - ), |
22 | | - ); |
23 | | - |
24 | | - $htmlForm = new HTMLForm( $formFields, 'disableaccount' ); |
25 | | - |
26 | | - $htmlForm->setSubmitCallback( array( __CLASS__, 'submit' ) ); |
27 | | - $htmlForm->setTitle( $this->getTitle() ); |
28 | | - |
29 | | - $htmlForm->show(); |
30 | | - } |
31 | | - |
32 | | - static function validateUser( $field, $allFields ) { |
33 | | - $u = User::newFromName( $field ); |
34 | | - |
35 | | - if ( $u && $u->getID() != 0 ) { |
36 | | - return true; |
37 | | - } else { |
38 | | - return wfMsgExt( 'disableaccount-nosuchuser', 'parseinline', array( $field ) ); |
39 | | - } |
40 | | - } |
41 | | - |
42 | | - static function checkConfirmation( $field, $allFields ) { |
43 | | - if ( $field ) { |
44 | | - return true; |
45 | | - } else { |
46 | | - return wfMsgExt( 'disableaccount-mustconfirm', 'parseinline' ); |
47 | | - } |
48 | | - } |
49 | | - |
50 | | - static function submit( $fields ) { |
51 | | - $user = User::newFromName( $fields['account'] ); |
52 | | - |
53 | | - $user->setPassword( null ); |
54 | | - $user->setEmail( null ); |
55 | | - $user->setToken(); |
56 | | - $user->addGroup( 'inactive' ); |
57 | | - |
58 | | - $user->saveSettings(); |
59 | | - $user->invalidateCache(); |
60 | | - |
61 | | - global $wgOut; |
62 | | - $wgOut->addWikiMsg( 'disableaccount-success', $user->getName() ); |
63 | | - |
64 | | - return true; |
65 | | - } |
66 | | -} |
\ No newline at end of file |
Index: trunk/extensions/DisableAccount/DisableAccount.php |
— | — | @@ -17,7 +17,7 @@ |
18 | 18 | $wgExtensionMessagesFiles['DisableAccountAliases'] = $dir . 'DisableAccount.alias.php'; |
19 | 19 | |
20 | 20 | // Special page classes |
21 | | -$wgAutoloadClasses['SpecialDisableAccount'] = $dir . 'DisableAccount_body.php'; |
| 21 | +$wgAutoloadClasses['SpecialDisableAccount'] = $dir . 'SpecialDisableAccount.php'; |
22 | 22 | $wgSpecialPages['DisableAccount'] = 'SpecialDisableAccount'; |
23 | 23 | |
24 | 24 | // Add permission required to use Special:DisableAccount |
Index: trunk/extensions/DisableAccount/SpecialDisableAccount.php |
— | — | @@ -0,0 +1,65 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class SpecialDisableAccount extends SpecialPage { |
| 5 | + function __construct() { |
| 6 | + parent::__construct( 'DisableAccount', 'disableaccount', |
| 7 | + true, array( $this, 'show' ) ); |
| 8 | + } |
| 9 | + |
| 10 | + public function show( $par ) { |
| 11 | + $formFields = array( |
| 12 | + 'account' => array( |
| 13 | + 'type' => 'text', |
| 14 | + 'validation-callback' => array( __CLASS__, 'validateUser' ), |
| 15 | + 'label-message' => 'disableaccount-user', |
| 16 | + ), |
| 17 | + 'confirm' => array( |
| 18 | + 'type' => 'toggle', |
| 19 | + 'validation-callback' => array( __CLASS__, 'checkConfirmation' ), |
| 20 | + 'label-message' => 'disableaccount-confirm', |
| 21 | + ), |
| 22 | + ); |
| 23 | + |
| 24 | + $htmlForm = new HTMLForm( $formFields, 'disableaccount' ); |
| 25 | + |
| 26 | + $htmlForm->setSubmitCallback( array( __CLASS__, 'submit' ) ); |
| 27 | + $htmlForm->setTitle( $this->getTitle() ); |
| 28 | + |
| 29 | + $htmlForm->show(); |
| 30 | + } |
| 31 | + |
| 32 | + static function validateUser( $field, $allFields ) { |
| 33 | + $u = User::newFromName( $field ); |
| 34 | + |
| 35 | + if ( $u && $u->getID() != 0 ) { |
| 36 | + return true; |
| 37 | + } else { |
| 38 | + return wfMsgExt( 'disableaccount-nosuchuser', 'parseinline', array( $field ) ); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + static function checkConfirmation( $field, $allFields ) { |
| 43 | + if ( $field ) { |
| 44 | + return true; |
| 45 | + } else { |
| 46 | + return wfMsgExt( 'disableaccount-mustconfirm', 'parseinline' ); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + static function submit( $fields ) { |
| 51 | + $user = User::newFromName( $fields['account'] ); |
| 52 | + |
| 53 | + $user->setPassword( null ); |
| 54 | + $user->setEmail( null ); |
| 55 | + $user->setToken(); |
| 56 | + $user->addGroup( 'inactive' ); |
| 57 | + |
| 58 | + $user->saveSettings(); |
| 59 | + $user->invalidateCache(); |
| 60 | + |
| 61 | + global $wgOut; |
| 62 | + $wgOut->addWikiMsg( 'disableaccount-success', $user->getName() ); |
| 63 | + |
| 64 | + return true; |
| 65 | + } |
| 66 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/DisableAccount/SpecialDisableAccount.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 67 | + native |
Index: trunk/extensions/BatchUserRights/BatchUserRights_body.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | * @file |
7 | 7 | * @ingroup SpecialPage |
8 | 8 | */ |
9 | | -class SpecialBatchUserRights extends SpecialPage { |
| 9 | +class BatchUserRights extends SpecialPage { |
10 | 10 | protected $isself = false; |
11 | 11 | |
12 | 12 | /** |
Index: trunk/extensions/BatchUserRights/BatchUserRights.php |
— | — | @@ -35,5 +35,5 @@ |
36 | 36 | $dir = dirname( __FILE__ ) . '/'; |
37 | 37 | $wgExtensionMessagesFiles['BatchUserRights'] = $dir . 'BatchUserRights.i18n.php'; |
38 | 38 | $wgExtensionMessagesFiles['BatchUserRightsAliases'] = $dir . 'BatchUserRights.alias.php'; |
39 | | -$wgAutoloadClasses['SpecialBatchUserRights'] = $dir . 'BatchUserRights_body.php'; |
40 | | -$wgSpecialPages['BatchUserRights'] = 'SpecialBatchUserRights'; |
| 39 | +$wgAutoloadClasses['BatchUserRights'] = $dir . 'BatchUserRights_body.php'; |
| 40 | +$wgSpecialPages['BatchUserRights'] = 'BatchUserRights'; |