Captchas for ContactPage
This commit is contained in:
parent
49c9c7a035
commit
5ebf35a965
|
@ -25,3 +25,6 @@ $messages['contactpage-formfootnotes']= '
|
|||
** optional, wird aber benötigt um Ihnen antworten zu können
|
||||
';
|
||||
|
||||
$messages['contactpage-captcha']= 'Um die Nachricht senden zu können, lösen Sie bitte das Captcha ([[Special:Captcha/help|weitere Informationen]])';
|
||||
$messages['contactpage-captcha-failed']= 'Captcha-Test nicht bestanden! ([[Special:Captcha/help|weitere Informationen]])';
|
||||
|
||||
|
|
|
@ -25,3 +25,5 @@ $messages['contactpage-formfootnotes']= '
|
|||
** optional but needed if you want an answer
|
||||
';
|
||||
|
||||
$messages['contactpage-captcha']= 'To send the message, please solve the captcha ([[Special:Captcha/help|more info]])';
|
||||
$messages['contactpage-captcha-failed']= 'Captcha test failed! ([[Special:Captcha/help|more info]])';
|
||||
|
|
5
README
5
README
|
@ -46,3 +46,8 @@ be an existing mail account.
|
|||
$wgContactSenderName is the name associated with the contact sender.
|
||||
This will be shown in the recipient's email program.
|
||||
|
||||
If you are using the ConfirmEdit extension (captchas), you can require
|
||||
a captcha test for sending contact messages by using the following:
|
||||
|
||||
$wgCaptchaTriggers['contactpage'] = true;
|
||||
|
||||
|
|
|
@ -71,13 +71,17 @@ class SpecialContact extends SpecialPage {
|
|||
$tokenOk = $wgUser->matchEditToken( $token );
|
||||
}
|
||||
|
||||
if ( $tokenOk ) {
|
||||
wfDebug( "$fname: submit\n" );
|
||||
$f->doSubmit();
|
||||
} else {
|
||||
if ( !$tokenOk ) {
|
||||
wfDebug( "$fname: bad token (".($wgUser->isAnon()?'anon':'user')."): $token\n" );
|
||||
$wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
|
||||
$f->showForm();
|
||||
} else if ( !$f->passCaptcha() ) {
|
||||
wfDebug( "$fname: captcha failed" );
|
||||
$wgOut->addWikiText( wfMsg( 'contactpage-captcha-failed' ) ); //TODO: provide a message for this!
|
||||
$f->showForm();
|
||||
} else {
|
||||
wfDebug( "$fname: submit\n" );
|
||||
$f->doSubmit();
|
||||
}
|
||||
} else {
|
||||
wfDebug( "$fname: form\n" );
|
||||
|
@ -101,6 +105,8 @@ class EmailContactForm {
|
|||
*/
|
||||
function EmailContactForm( $target ) {
|
||||
global $wgRequest, $wgUser;
|
||||
global $wgCaptcha, $wgCaptchaTriggers;
|
||||
|
||||
$this->target = $target;
|
||||
$this->text = $wgRequest->getText( 'wpText' );
|
||||
$this->subject = $wgRequest->getText( 'wpSubject' );
|
||||
|
@ -113,6 +119,12 @@ class EmailContactForm {
|
|||
if (!$this->fromname) $this->fromname = $wgUser->getName();
|
||||
if (!$this->fromaddress) $this->fromaddress = $wgUser->getEmail();
|
||||
}
|
||||
|
||||
//prepare captcha if applicable
|
||||
if ( $wgCaptcha && @$wgCaptchaTriggers['contactpage'] ) {
|
||||
$wgCaptcha->trigger = 'contactpage';
|
||||
$wgCaptcha->action = 'contact';
|
||||
}
|
||||
}
|
||||
|
||||
function showForm() {
|
||||
|
@ -176,12 +188,32 @@ class EmailContactForm {
|
|||
<textarea name=\"wpText\" rows='20' cols='80' wrap='virtual' style=\"width: 100%;\">" . htmlspecialchars( $this->text ) .
|
||||
"</textarea>
|
||||
" . wfCheckLabel( $emc, 'wpCCMe', 'wpCCMe', $wgUser->getBoolOption( 'ccmeonemails' ) ) . "<br />
|
||||
" . $this->getCaptcha() . "
|
||||
<input type='submit' name=\"wpSend\" value=\"{$ems}\" />
|
||||
<input type='hidden' name='wpEditToken' value=\"$token\" />
|
||||
</form>\n" );
|
||||
|
||||
}
|
||||
|
||||
function getCaptcha() {
|
||||
global $wgCaptcha, $wgCaptchaTriggers;
|
||||
if ( !$wgCaptcha ) return ""; //no captcha installed
|
||||
if ( !@$wgCaptchaTriggers['contactpage'] ) return ""; //don't trigger on contact form
|
||||
|
||||
return "<div class='captcha'>" .
|
||||
$wgCaptcha->getForm() .
|
||||
wfMsgWikiHtml( 'contactpage-captcha' ) .
|
||||
"</div>\n";
|
||||
}
|
||||
|
||||
function passCaptcha() {
|
||||
global $wgCaptcha, $wgCaptchaTriggers;
|
||||
if ( !$wgCaptcha ) return true; //no captcha installed
|
||||
if ( !@$wgCaptchaTriggers['contactpage'] ) return true; //don't trigger on contact form
|
||||
|
||||
return $wgCaptcha->passCaptcha();
|
||||
}
|
||||
|
||||
function doSubmit( ) {
|
||||
global $wgOut, $wgContactSender, $wgContactSenderName;
|
||||
|
||||
|
|
Loading…
Reference in New Issue