diff --git a/ContactPage.i18n.de.php b/ContactPage.i18n.de.php
index 0a8770a..839a1ec 100644
--- a/ContactPage.i18n.de.php
+++ b/ContactPage.i18n.de.php
@@ -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]])';
+
diff --git a/ContactPage.i18n.php b/ContactPage.i18n.php
index faafb29..1e4d0f6 100644
--- a/ContactPage.i18n.php
+++ b/ContactPage.i18n.php
@@ -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]])';
diff --git a/README b/README
index dc99db9..729f725 100644
--- a/README
+++ b/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;
+
diff --git a/SpecialContact.php b/SpecialContact.php
index 9be9171..b14e18a 100644
--- a/SpecialContact.php
+++ b/SpecialContact.php
@@ -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 {
" . wfCheckLabel( $emc, 'wpCCMe', 'wpCCMe', $wgUser->getBoolOption( 'ccmeonemails' ) ) . "
+" . $this->getCaptcha() . "
\n" );
}
+ function getCaptcha() {
+ global $wgCaptcha, $wgCaptchaTriggers;
+ if ( !$wgCaptcha ) return ""; //no captcha installed
+ if ( !@$wgCaptchaTriggers['contactpage'] ) return ""; //don't trigger on contact form
+
+ return "