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/ContactPage.php b/ContactPage.php
index 9876d0f..dc27df5 100644
--- a/ContactPage.php
+++ b/ContactPage.php
@@ -25,6 +25,8 @@ $wgExtensionCredits['specialpage'][] = array(
$wgAutoloadClasses['SpecialContact'] = dirname( __FILE__ ) . '/SpecialContact.php';
$wgSpecialPages['Contact'] = 'SpecialContact';
+$wgHooks['LoadAllMessages'][] = 'loadContactPageI18n';
+
$wgContactUser = NULL;
$wgContactSender = 'apache@' . $wgServerName;
$wgContactSenderName = 'Contact Form on ' . $wgSitename;
@@ -37,7 +39,7 @@ function loadContactPageI18n() {
static $initialized = false;
- if ( $initialized ) return;
+ if ( $initialized ) return true;
$messages= array();
@@ -49,5 +51,7 @@ function loadContactPageI18n() {
$initialized = true;
$wgMessageCache->addMessages( $messages );
+
+ return 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 "