ContactPage:
*$fname => __METHOD__ *change some double quotes to single quotes *mark visibility of some functions *addWikiText(wfMsg()) => addWikiMsg() whenever possible *doxygen doc tweaks *tweak Finnish special page alias name
This commit is contained in:
parent
a3a3ab305a
commit
246bd92718
|
@ -2,7 +2,8 @@
|
|||
/**
|
||||
* Aliases for Special:Contact
|
||||
*
|
||||
* @addtogroup Extensions
|
||||
* @file
|
||||
* @ingroup Extensions
|
||||
*/
|
||||
|
||||
$aliases = array();
|
||||
|
@ -55,7 +56,7 @@ $aliases['el'] = array(
|
|||
|
||||
/** Finnish (Suomi) */
|
||||
$aliases['fi'] = array(
|
||||
'Contact' => array( 'Yhteystiedot' ),
|
||||
'Contact' => array( 'Ota yhteyttä' ),
|
||||
);
|
||||
|
||||
/** Galician (Galego) */
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
/**
|
||||
* Internationalisation file for extension ContactPage.
|
||||
* Internationalisation file for ContactPage extension.
|
||||
*
|
||||
* @addtogroup Extensions
|
||||
* @file
|
||||
* @ingroup Extensions
|
||||
* @author Daniel Kinzler, brightbyte.de
|
||||
* @copyright © 2007 Daniel Kinzler
|
||||
* @license GNU General Public Licence 2.0 or later
|
||||
|
@ -10,6 +11,9 @@
|
|||
|
||||
$messages = array();
|
||||
|
||||
/** English
|
||||
* @author Daniel Kinzler
|
||||
*/
|
||||
$messages['en'] = array(
|
||||
'contact' => 'Contact page',
|
||||
'contactpage' => 'Contact page',
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
* Setup for ContactPage extension, a special page that implements a contact form
|
||||
* for use by anonymous visitors.
|
||||
*
|
||||
* @package MediaWiki
|
||||
* @subpackage Extensions
|
||||
* @file
|
||||
* @ingroup Extensions
|
||||
* @author Daniel Kinzler, brightbyte.de
|
||||
* @copyright © 2007 Daniel Kinzler
|
||||
* @licence GNU General Public Licence 2.0 or later
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
* Speclial:Contact, a contact form for visitors.
|
||||
* Based on SpecialEmailUser.php
|
||||
*
|
||||
* @addtogroup SpecialPage
|
||||
* @file
|
||||
* @ingroup SpecialPage
|
||||
* @author Daniel Kinzler, brightbyte.de
|
||||
* @copyright © 2007 Daniel Kinzler
|
||||
* @license GNU General Public Licence 2.0 or later
|
||||
|
@ -18,30 +19,30 @@ global $IP; #needed when called from the autoloader
|
|||
require_once("$IP/includes/UserMailer.php");
|
||||
|
||||
/**
|
||||
*
|
||||
* Provides the contact form
|
||||
* @ingroup SpecialPage
|
||||
*/
|
||||
class SpecialContact extends SpecialPage {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
function __construct() {
|
||||
global $wgOut;
|
||||
SpecialPage::SpecialPage( 'Contact', '', true );
|
||||
public function __construct() {
|
||||
parent::__construct( 'Contact' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Main execution function
|
||||
* @param $par Parameters passed to the page
|
||||
*
|
||||
* @param $par Mixed: Parameters passed to the page
|
||||
*/
|
||||
function execute( $par ) {
|
||||
public function execute( $par ) {
|
||||
global $wgUser, $wgOut, $wgRequest, $wgEnableEmail, $wgContactUser;
|
||||
|
||||
wfLoadExtensionMessages( 'ContactPage' );
|
||||
$fname = "SpecialContact::execute";
|
||||
|
||||
if( !$wgEnableEmail || !$wgContactUser ) {
|
||||
$wgOut->showErrorPage( "nosuchspecialpage", "nospecialpagetext" );
|
||||
$wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -50,16 +51,16 @@ class SpecialContact extends SpecialPage {
|
|||
$nu = User::newFromName( $wgContactUser );
|
||||
if( is_null( $nu ) || !$nu->canReceiveEmail() ) {
|
||||
wfDebug( "Target is invalid user or can't receive.\n" );
|
||||
$wgOut->showErrorPage( "noemailtitle", "noemailtext" );
|
||||
$wgOut->showErrorPage( 'noemailtitle', 'noemailtext' );
|
||||
return;
|
||||
}
|
||||
|
||||
$f = new EmailContactForm( $nu );
|
||||
|
||||
if ( "success" == $action ) {
|
||||
wfDebug( "$fname: success.\n" );
|
||||
$f->showSuccess( );
|
||||
} else if ( "submit" == $action && $wgRequest->wasPosted() && $f->hasAllInfo() ) {
|
||||
if ( 'success' == $action ) {
|
||||
wfDebug( __METHOD__ . ": success.\n" );
|
||||
$f->showSuccess();
|
||||
} else if ( 'submit' == $action && $wgRequest->wasPosted() && $f->hasAllInfo() ) {
|
||||
$token = $wgRequest->getVal( 'wpEditToken' );
|
||||
|
||||
if( $wgUser->isAnon() ) {
|
||||
|
@ -71,19 +72,19 @@ class SpecialContact extends SpecialPage {
|
|||
}
|
||||
|
||||
if ( !$tokenOk ) {
|
||||
wfDebug( "$fname: bad token (".($wgUser->isAnon()?'anon':'user')."): $token\n" );
|
||||
$wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
|
||||
wfDebug( __METHOD__ . ": bad token (".( $wgUser->isAnon() ? 'anon' : 'user' )."): $token\n" );
|
||||
$wgOut->addWikiMsg( 'sessionfailure' );
|
||||
$f->showForm();
|
||||
} else if ( !$f->passCaptcha() ) {
|
||||
wfDebug( "$fname: captcha failed" );
|
||||
$wgOut->addWikiText( wfMsg( 'contactpage-captcha-failed' ) ); //TODO: provide a message for this!
|
||||
wfDebug( __METHOD__ . ": captcha failed" );
|
||||
$wgOut->addWikiMsg( 'contactpage-captcha-failed' );
|
||||
$f->showForm();
|
||||
} else {
|
||||
wfDebug( "$fname: submit\n" );
|
||||
wfDebug( __METHOD__ . ": submit\n" );
|
||||
$f->doSubmit();
|
||||
}
|
||||
} else {
|
||||
wfDebug( "$fname: form\n" );
|
||||
wfDebug( __METHOD__ . ": form\n" );
|
||||
$f->showForm();
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +92,7 @@ class SpecialContact extends SpecialPage {
|
|||
|
||||
/**
|
||||
* @todo document
|
||||
* @addtogroup SpecialPage
|
||||
* @ingroup SpecialPage
|
||||
*/
|
||||
class EmailContactForm {
|
||||
|
||||
|
@ -114,12 +115,12 @@ class EmailContactForm {
|
|||
$this->fromname = $wgRequest->getText( 'wpFromName' );
|
||||
$this->fromaddress = $wgRequest->getText( 'wpFromAddress' );
|
||||
|
||||
if ($wgUser->isLoggedIn()) {
|
||||
if (!$this->fromname) $this->fromname = $wgUser->getName();
|
||||
if (!$this->fromaddress) $this->fromaddress = $wgUser->getEmail();
|
||||
if( $wgUser->isLoggedIn() ) {
|
||||
if( !$this->fromname ) $this->fromname = $wgUser->getName();
|
||||
if( !$this->fromaddress ) $this->fromaddress = $wgUser->getEmail();
|
||||
}
|
||||
|
||||
//prepare captcha if applicable
|
||||
// prepare captcha if applicable
|
||||
if ( $this->useCaptcha() ) {
|
||||
$captcha = ConfirmEditHooks::getInstance();
|
||||
$captcha->trigger = 'contactpage';
|
||||
|
@ -152,11 +153,11 @@ class EmailContactForm {
|
|||
|
||||
#TODO: show captcha
|
||||
|
||||
$wgOut->setPagetitle( wfMsg( "contactpage-title" ) );
|
||||
$wgOut->addWikiText( wfMsg( "contactpage-pagetext" ) );
|
||||
$wgOut->setPageTitle( wfMsg( 'contactpage-title' ) );
|
||||
$wgOut->addWikiMsg( 'contactpage-pagetext' );
|
||||
|
||||
if ( $this->subject === "" ) {
|
||||
$this->subject = wfMsgForContent( "contactpage-defsubject" );
|
||||
if ( $this->subject === '' ) {
|
||||
$this->subject = wfMsgForContent( 'contactpage-defsubject' );
|
||||
}
|
||||
|
||||
$msgSuffix = $wgContactRequireAll ? '-required' : '';
|
||||
|
@ -230,8 +231,8 @@ class EmailContactForm {
|
|||
|
||||
function useCaptcha() {
|
||||
global $wgCaptchaClass, $wgCaptchaTriggers, $wgUser;
|
||||
if ( !$wgCaptchaClass ) return false; //no captcha installed
|
||||
if ( !@$wgCaptchaTriggers['contactpage'] ) return false; //don't trigger on contact form
|
||||
if ( !$wgCaptchaClass ) return false; // no captcha installed
|
||||
if ( !@$wgCaptchaTriggers['contactpage'] ) return false; // don't trigger on contact form
|
||||
|
||||
if( $wgUser->isAllowed( 'skipcaptcha' ) ) {
|
||||
wfDebug( "EmailContactForm::useCaptcha: user group allows skipping captcha\n" );
|
||||
|
@ -243,7 +244,7 @@ class EmailContactForm {
|
|||
|
||||
function getCaptcha() {
|
||||
global $wgCaptcha;
|
||||
if ( !$this->useCaptcha() ) return "";
|
||||
if ( !$this->useCaptcha() ) return '';
|
||||
|
||||
wfSetupSession(); #NOTE: make sure we have a session. May be required for captchas to work.
|
||||
|
||||
|
@ -260,7 +261,7 @@ class EmailContactForm {
|
|||
return $wgCaptcha->passCaptcha();
|
||||
}
|
||||
|
||||
function doSubmit( ) {
|
||||
function doSubmit() {
|
||||
global $wgOut;
|
||||
global $wgEnableEmail, $wgUserEmailUseReplyTo, $wgEmergencyContact;
|
||||
global $wgContactUser, $wgContactSender, $wgContactSenderName;
|
||||
|
@ -268,40 +269,35 @@ class EmailContactForm {
|
|||
$csender = $wgContactSender ? $wgContactSender : $wgEmergencyContact;
|
||||
$cname = $wgContactSenderName;
|
||||
|
||||
$fname = 'EmailContactForm::doSubmit';
|
||||
|
||||
wfDebug( "$fname: start\n" );
|
||||
wfDebug( __METHOD__ . ": start\n" );
|
||||
|
||||
$to = new MailAddress( $this->target );
|
||||
$replyto = NULL;
|
||||
|
||||
if ( !$this->fromaddress ) {
|
||||
$from = new MailAddress( $csender, $cname );
|
||||
}
|
||||
else if ( $wgUserEmailUseReplyTo ) {
|
||||
} else if ( $wgUserEmailUseReplyTo ) {
|
||||
$from = new MailAddress( $csender, $cname );
|
||||
$replyto = new MailAddress( $this->fromaddress, $this->fromname );
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$from = new MailAddress( $this->fromaddress, $this->fromname );
|
||||
}
|
||||
|
||||
$subject = trim( $this->subject );
|
||||
|
||||
if ( $subject === "" ) {
|
||||
$subject = wfMsgForContent( "contactpage-defsubject" );
|
||||
if ( $subject === '' ) {
|
||||
$subject = wfMsgForContent( 'contactpage-defsubject' );
|
||||
}
|
||||
|
||||
if ( $this->fromname !== "" ) {
|
||||
$subject = wfMsgForContent( "contactpage-subject-and-sender", $subject, $this->fromname );
|
||||
}
|
||||
else if ( $this->fromaddress !== "" ) {
|
||||
$subject = wfMsgForContent( "contactpage-subject-and-sender", $subject, $this->fromaddress );
|
||||
if ( $this->fromname !== '' ) {
|
||||
$subject = wfMsgForContent( 'contactpage-subject-and-sender', $subject, $this->fromname );
|
||||
} else if ( $this->fromaddress !== '' ) {
|
||||
$subject = wfMsgForContent( 'contactpage-subject-and-sender', $subject, $this->fromaddress );
|
||||
}
|
||||
|
||||
if( wfRunHooks( 'ContactForm', array( &$to, &$replyto, &$subject, &$this->text ) ) ) {
|
||||
|
||||
wfDebug( "$fname: sending mail from ".$from->toString()." to ".$to->toString()." replyto ".($replyto==null?'-/-':$replyto->toString())."\n" );
|
||||
wfDebug( __METHOD__ . ": sending mail from ".$from->toString()." to ".$to->toString()." replyto ".( $replyto == null ? '-/-' : $replyto->toString() )."\n" );
|
||||
|
||||
#HACK: in MW 1.9, replyto must be a string, in MW 1.10 it must be an object!
|
||||
$ver = preg_replace( '![^\d._+]!', '', $GLOBALS['wgVersion'] );
|
||||
|
@ -312,15 +308,14 @@ class EmailContactForm {
|
|||
$mailResult = userMailer( $to, $from, $subject, $this->text, $replyaddr );
|
||||
|
||||
if( WikiError::isError( $mailResult ) ) {
|
||||
$wgOut->addWikiText( wfMsg( "usermailererror" ) . $mailResult->getMessage());
|
||||
$wgOut->addWikiMsg( 'usermailererror' ) . $mailResult->getMessage();
|
||||
} else {
|
||||
|
||||
// if the user requested a copy of this mail, do this now,
|
||||
// unless they are emailing themselves, in which case one copy of the message is sufficient.
|
||||
if ($this->cc_me && $replyto) {
|
||||
if( $this->cc_me && $replyto ) {
|
||||
$cc_subject = wfMsg('emailccsubject', $this->target->getName(), $subject);
|
||||
if( wfRunHooks( 'ContactForm', array( &$from, &$replyto, &$cc_subject, &$this->text ) ) ) {
|
||||
wfDebug( "$fname: sending cc mail from ".$from->toString()." to ".$replyto->toString()."\n" );
|
||||
wfDebug( __METHOD__ . ": sending cc mail from ".$from->toString()." to ".$replyto->toString()."\n" );
|
||||
$ccResult = userMailer( $replyto, $from, $cc_subject, $this->text );
|
||||
if( WikiError::isError( $ccResult ) ) {
|
||||
// At this stage, the user's CC mail has failed, but their
|
||||
|
@ -328,28 +323,28 @@ class EmailContactForm {
|
|||
// We can either show them an error, or we can say everything was fine,
|
||||
// or we can say we sort of failed AND sort of succeeded. Of these options,
|
||||
// simply saying there was an error is probably best.
|
||||
$wgOut->addWikiText( wfMsg( "usermailererror" ) . $ccResult);
|
||||
$wgOut->addWikiText( wfMsg( 'usermailererror' ) . $ccResult );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wfDebug( "$fname: success\n" );
|
||||
wfDebug( __METHOD__ . ": success\n" );
|
||||
|
||||
$titleObj = SpecialPage::getTitleFor( "Contact" );
|
||||
$titleObj = SpecialPage::getTitleFor( 'Contact' );
|
||||
$wgOut->redirect( $titleObj->getFullURL( "action=success" ) );
|
||||
wfRunHooks( 'ContactFromComplete', array( $to, $replyto, $subject, $this->text ) );
|
||||
}
|
||||
}
|
||||
|
||||
wfDebug( "$fname: end\n" );
|
||||
wfDebug( __METHOD__ . ": end\n" );
|
||||
}
|
||||
|
||||
function showSuccess( ) {
|
||||
function showSuccess() {
|
||||
global $wgOut;
|
||||
|
||||
$wgOut->setPagetitle( wfMsg( "emailsent" ) );
|
||||
$wgOut->addWikiText( wfMsg( "emailsenttext" ) );
|
||||
$wgOut->setPageTitle( wfMsg( 'emailsent' ) );
|
||||
$wgOut->addWikiMsg( 'emailsenttext' );
|
||||
|
||||
$wgOut->returnToMain( false );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue