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:
Jack Phoenix 2009-01-11 12:16:13 +00:00
parent a3a3ab305a
commit 246bd92718
4 changed files with 67 additions and 67 deletions

View File

@ -2,7 +2,8 @@
/** /**
* Aliases for Special:Contact * Aliases for Special:Contact
* *
* @addtogroup Extensions * @file
* @ingroup Extensions
*/ */
$aliases = array(); $aliases = array();
@ -55,7 +56,7 @@ $aliases['el'] = array(
/** Finnish (Suomi) */ /** Finnish (Suomi) */
$aliases['fi'] = array( $aliases['fi'] = array(
'Contact' => array( 'Yhteystiedot' ), 'Contact' => array( 'Ota yhteyttä' ),
); );
/** Galician (Galego) */ /** Galician (Galego) */

View File

@ -1,8 +1,9 @@
<?php <?php
/** /**
* Internationalisation file for extension ContactPage. * Internationalisation file for ContactPage extension.
* *
* @addtogroup Extensions * @file
* @ingroup Extensions
* @author Daniel Kinzler, brightbyte.de * @author Daniel Kinzler, brightbyte.de
* @copyright © 2007 Daniel Kinzler * @copyright © 2007 Daniel Kinzler
* @license GNU General Public Licence 2.0 or later * @license GNU General Public Licence 2.0 or later
@ -10,6 +11,9 @@
$messages = array(); $messages = array();
/** English
* @author Daniel Kinzler
*/
$messages['en'] = array( $messages['en'] = array(
'contact' => 'Contact page', 'contact' => 'Contact page',
'contactpage' => 'Contact page', 'contactpage' => 'Contact page',

View File

@ -3,8 +3,8 @@
* Setup for ContactPage extension, a special page that implements a contact form * Setup for ContactPage extension, a special page that implements a contact form
* for use by anonymous visitors. * for use by anonymous visitors.
* *
* @package MediaWiki * @file
* @subpackage Extensions * @ingroup Extensions
* @author Daniel Kinzler, brightbyte.de * @author Daniel Kinzler, brightbyte.de
* @copyright © 2007 Daniel Kinzler * @copyright © 2007 Daniel Kinzler
* @licence GNU General Public Licence 2.0 or later * @licence GNU General Public Licence 2.0 or later

View File

@ -3,7 +3,8 @@
* Speclial:Contact, a contact form for visitors. * Speclial:Contact, a contact form for visitors.
* Based on SpecialEmailUser.php * Based on SpecialEmailUser.php
* *
* @addtogroup SpecialPage * @file
* @ingroup SpecialPage
* @author Daniel Kinzler, brightbyte.de * @author Daniel Kinzler, brightbyte.de
* @copyright © 2007 Daniel Kinzler * @copyright © 2007 Daniel Kinzler
* @license GNU General Public Licence 2.0 or later * @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"); require_once("$IP/includes/UserMailer.php");
/** /**
* * Provides the contact form
* @ingroup SpecialPage
*/ */
class SpecialContact extends SpecialPage { class SpecialContact extends SpecialPage {
/** /**
* Constructor * Constructor
*/ */
function __construct() { public function __construct() {
global $wgOut; parent::__construct( 'Contact' );
SpecialPage::SpecialPage( 'Contact', '', true );
} }
/** /**
* Main execution function * 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; global $wgUser, $wgOut, $wgRequest, $wgEnableEmail, $wgContactUser;
wfLoadExtensionMessages( 'ContactPage' ); wfLoadExtensionMessages( 'ContactPage' );
$fname = "SpecialContact::execute";
if( !$wgEnableEmail || !$wgContactUser ) { if( !$wgEnableEmail || !$wgContactUser ) {
$wgOut->showErrorPage( "nosuchspecialpage", "nospecialpagetext" ); $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
return; return;
} }
@ -50,16 +51,16 @@ class SpecialContact extends SpecialPage {
$nu = User::newFromName( $wgContactUser ); $nu = User::newFromName( $wgContactUser );
if( is_null( $nu ) || !$nu->canReceiveEmail() ) { if( is_null( $nu ) || !$nu->canReceiveEmail() ) {
wfDebug( "Target is invalid user or can't receive.\n" ); wfDebug( "Target is invalid user or can't receive.\n" );
$wgOut->showErrorPage( "noemailtitle", "noemailtext" ); $wgOut->showErrorPage( 'noemailtitle', 'noemailtext' );
return; return;
} }
$f = new EmailContactForm( $nu ); $f = new EmailContactForm( $nu );
if ( "success" == $action ) { if ( 'success' == $action ) {
wfDebug( "$fname: success.\n" ); wfDebug( __METHOD__ . ": success.\n" );
$f->showSuccess( ); $f->showSuccess();
} else if ( "submit" == $action && $wgRequest->wasPosted() && $f->hasAllInfo() ) { } else if ( 'submit' == $action && $wgRequest->wasPosted() && $f->hasAllInfo() ) {
$token = $wgRequest->getVal( 'wpEditToken' ); $token = $wgRequest->getVal( 'wpEditToken' );
if( $wgUser->isAnon() ) { if( $wgUser->isAnon() ) {
@ -71,19 +72,19 @@ class SpecialContact extends SpecialPage {
} }
if ( !$tokenOk ) { if ( !$tokenOk ) {
wfDebug( "$fname: bad token (".($wgUser->isAnon()?'anon':'user')."): $token\n" ); wfDebug( __METHOD__ . ": bad token (".( $wgUser->isAnon() ? 'anon' : 'user' )."): $token\n" );
$wgOut->addWikiText( wfMsg( 'sessionfailure' ) ); $wgOut->addWikiMsg( 'sessionfailure' );
$f->showForm(); $f->showForm();
} else if ( !$f->passCaptcha() ) { } else if ( !$f->passCaptcha() ) {
wfDebug( "$fname: captcha failed" ); wfDebug( __METHOD__ . ": captcha failed" );
$wgOut->addWikiText( wfMsg( 'contactpage-captcha-failed' ) ); //TODO: provide a message for this! $wgOut->addWikiMsg( 'contactpage-captcha-failed' );
$f->showForm(); $f->showForm();
} else { } else {
wfDebug( "$fname: submit\n" ); wfDebug( __METHOD__ . ": submit\n" );
$f->doSubmit(); $f->doSubmit();
} }
} else { } else {
wfDebug( "$fname: form\n" ); wfDebug( __METHOD__ . ": form\n" );
$f->showForm(); $f->showForm();
} }
} }
@ -91,13 +92,13 @@ class SpecialContact extends SpecialPage {
/** /**
* @todo document * @todo document
* @addtogroup SpecialPage * @ingroup SpecialPage
*/ */
class EmailContactForm { class EmailContactForm {
var $target; var $target;
var $text, $subject; var $text, $subject;
var $cc_me; // Whether user requested to be sent a separate copy of their email. var $cc_me; // Whether user requested to be sent a separate copy of their email.
/** /**
* @param User $target * @param User $target
@ -114,12 +115,12 @@ class EmailContactForm {
$this->fromname = $wgRequest->getText( 'wpFromName' ); $this->fromname = $wgRequest->getText( 'wpFromName' );
$this->fromaddress = $wgRequest->getText( 'wpFromAddress' ); $this->fromaddress = $wgRequest->getText( 'wpFromAddress' );
if ($wgUser->isLoggedIn()) { if( $wgUser->isLoggedIn() ) {
if (!$this->fromname) $this->fromname = $wgUser->getName(); if( !$this->fromname ) $this->fromname = $wgUser->getName();
if (!$this->fromaddress) $this->fromaddress = $wgUser->getEmail(); if( !$this->fromaddress ) $this->fromaddress = $wgUser->getEmail();
} }
//prepare captcha if applicable // prepare captcha if applicable
if ( $this->useCaptcha() ) { if ( $this->useCaptcha() ) {
$captcha = ConfirmEditHooks::getInstance(); $captcha = ConfirmEditHooks::getInstance();
$captcha->trigger = 'contactpage'; $captcha->trigger = 'contactpage';
@ -152,11 +153,11 @@ class EmailContactForm {
#TODO: show captcha #TODO: show captcha
$wgOut->setPagetitle( wfMsg( "contactpage-title" ) ); $wgOut->setPageTitle( wfMsg( 'contactpage-title' ) );
$wgOut->addWikiText( wfMsg( "contactpage-pagetext" ) ); $wgOut->addWikiMsg( 'contactpage-pagetext' );
if ( $this->subject === "" ) { if ( $this->subject === '' ) {
$this->subject = wfMsgForContent( "contactpage-defsubject" ); $this->subject = wfMsgForContent( 'contactpage-defsubject' );
} }
$msgSuffix = $wgContactRequireAll ? '-required' : ''; $msgSuffix = $wgContactRequireAll ? '-required' : '';
@ -230,8 +231,8 @@ class EmailContactForm {
function useCaptcha() { function useCaptcha() {
global $wgCaptchaClass, $wgCaptchaTriggers, $wgUser; global $wgCaptchaClass, $wgCaptchaTriggers, $wgUser;
if ( !$wgCaptchaClass ) return false; //no captcha installed if ( !$wgCaptchaClass ) return false; // no captcha installed
if ( !@$wgCaptchaTriggers['contactpage'] ) return false; //don't trigger on contact form if ( !@$wgCaptchaTriggers['contactpage'] ) return false; // don't trigger on contact form
if( $wgUser->isAllowed( 'skipcaptcha' ) ) { if( $wgUser->isAllowed( 'skipcaptcha' ) ) {
wfDebug( "EmailContactForm::useCaptcha: user group allows skipping captcha\n" ); wfDebug( "EmailContactForm::useCaptcha: user group allows skipping captcha\n" );
@ -243,7 +244,7 @@ class EmailContactForm {
function getCaptcha() { function getCaptcha() {
global $wgCaptcha; 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. wfSetupSession(); #NOTE: make sure we have a session. May be required for captchas to work.
@ -260,7 +261,7 @@ class EmailContactForm {
return $wgCaptcha->passCaptcha(); return $wgCaptcha->passCaptcha();
} }
function doSubmit( ) { function doSubmit() {
global $wgOut; global $wgOut;
global $wgEnableEmail, $wgUserEmailUseReplyTo, $wgEmergencyContact; global $wgEnableEmail, $wgUserEmailUseReplyTo, $wgEmergencyContact;
global $wgContactUser, $wgContactSender, $wgContactSenderName; global $wgContactUser, $wgContactSender, $wgContactSenderName;
@ -268,40 +269,35 @@ class EmailContactForm {
$csender = $wgContactSender ? $wgContactSender : $wgEmergencyContact; $csender = $wgContactSender ? $wgContactSender : $wgEmergencyContact;
$cname = $wgContactSenderName; $cname = $wgContactSenderName;
$fname = 'EmailContactForm::doSubmit'; wfDebug( __METHOD__ . ": start\n" );
wfDebug( "$fname: start\n" );
$to = new MailAddress( $this->target ); $to = new MailAddress( $this->target );
$replyto = NULL; $replyto = NULL;
if ( !$this->fromaddress ) { if ( !$this->fromaddress ) {
$from = new MailAddress( $csender, $cname ); $from = new MailAddress( $csender, $cname );
} } else if ( $wgUserEmailUseReplyTo ) {
else if ( $wgUserEmailUseReplyTo ) {
$from = new MailAddress( $csender, $cname ); $from = new MailAddress( $csender, $cname );
$replyto = new MailAddress( $this->fromaddress, $this->fromname ); $replyto = new MailAddress( $this->fromaddress, $this->fromname );
} } else {
else {
$from = new MailAddress( $this->fromaddress, $this->fromname ); $from = new MailAddress( $this->fromaddress, $this->fromname );
} }
$subject = trim( $this->subject ); $subject = trim( $this->subject );
if ( $subject === "" ) { if ( $subject === '' ) {
$subject = wfMsgForContent( "contactpage-defsubject" ); $subject = wfMsgForContent( 'contactpage-defsubject' );
} }
if ( $this->fromname !== "" ) { if ( $this->fromname !== '' ) {
$subject = wfMsgForContent( "contactpage-subject-and-sender", $subject, $this->fromname ); $subject = wfMsgForContent( 'contactpage-subject-and-sender', $subject, $this->fromname );
} } else if ( $this->fromaddress !== '' ) {
else if ( $this->fromaddress !== "" ) { $subject = wfMsgForContent( 'contactpage-subject-and-sender', $subject, $this->fromaddress );
$subject = wfMsgForContent( "contactpage-subject-and-sender", $subject, $this->fromaddress );
} }
if( wfRunHooks( 'ContactForm', array( &$to, &$replyto, &$subject, &$this->text ) ) ) { 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! #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'] ); $ver = preg_replace( '![^\d._+]!', '', $GLOBALS['wgVersion'] );
@ -312,15 +308,14 @@ class EmailContactForm {
$mailResult = userMailer( $to, $from, $subject, $this->text, $replyaddr ); $mailResult = userMailer( $to, $from, $subject, $this->text, $replyaddr );
if( WikiError::isError( $mailResult ) ) { if( WikiError::isError( $mailResult ) ) {
$wgOut->addWikiText( wfMsg( "usermailererror" ) . $mailResult->getMessage()); $wgOut->addWikiMsg( 'usermailererror' ) . $mailResult->getMessage();
} else { } else {
// if the user requested a copy of this mail, do this now, // 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. // 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); $cc_subject = wfMsg('emailccsubject', $this->target->getName(), $subject);
if( wfRunHooks( 'ContactForm', array( &$from, &$replyto, &$cc_subject, &$this->text ) ) ) { 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 ); $ccResult = userMailer( $replyto, $from, $cc_subject, $this->text );
if( WikiError::isError( $ccResult ) ) { if( WikiError::isError( $ccResult ) ) {
// At this stage, the user's CC mail has failed, but their // At this stage, the user's CC mail has failed, but their
@ -328,29 +323,29 @@ class EmailContactForm {
// We can either show them an error, or we can say everything was fine, // 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, // or we can say we sort of failed AND sort of succeeded. Of these options,
// simply saying there was an error is probably best. // simply saying there was an error is probably best.
$wgOut->addWikiText( wfMsg( "usermailererror" ) . $ccResult); $wgOut->addWikiText( wfMsg( 'usermailererror' ) . $ccResult );
return; return;
} }
} }
} }
wfDebug( "$fname: success\n" ); wfDebug( __METHOD__ . ": success\n" );
$titleObj = SpecialPage::getTitleFor( "Contact" ); $titleObj = SpecialPage::getTitleFor( 'Contact' );
$wgOut->redirect( $titleObj->getFullURL( "action=success" ) ); $wgOut->redirect( $titleObj->getFullURL( "action=success" ) );
wfRunHooks( 'ContactFromComplete', array( $to, $replyto, $subject, $this->text ) ); wfRunHooks( 'ContactFromComplete', array( $to, $replyto, $subject, $this->text ) );
} }
} }
wfDebug( "$fname: end\n" ); wfDebug( __METHOD__ . ": end\n" );
} }
function showSuccess( ) { function showSuccess() {
global $wgOut; global $wgOut;
$wgOut->setPagetitle( wfMsg( "emailsent" ) ); $wgOut->setPageTitle( wfMsg( 'emailsent' ) );
$wgOut->addWikiText( wfMsg( "emailsenttext" ) ); $wgOut->addWikiMsg( 'emailsenttext' );
$wgOut->returnToMain( false ); $wgOut->returnToMain( false );
} }
} }