ContactPage now supports LoadAllMessages hook
This commit is contained in:
parent
52a8aa5446
commit
97956cb56a
|
@ -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]])';
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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