r45666 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45665‎ | r45666 | r45667 >
Date:12:16, 11 January 2009
Author:ashley
Status:ok
Tags:
Comment:
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
Modified paths:
  • /trunk/extensions/ContactPage/ContactPage.alias.php (modified) (history)
  • /trunk/extensions/ContactPage/ContactPage.i18n.php (modified) (history)
  • /trunk/extensions/ContactPage/ContactPage.php (modified) (history)
  • /trunk/extensions/ContactPage/SpecialContact.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ContactPage/SpecialContact.php
@@ -3,7 +3,8 @@
44 * Speclial:Contact, a contact form for visitors.
55 * Based on SpecialEmailUser.php
66 *
7 - * @addtogroup SpecialPage
 7+ * @file
 8+ * @ingroup SpecialPage
89 * @author Daniel Kinzler, brightbyte.de
910 * @copyright © 2007 Daniel Kinzler
1011 * @license GNU General Public Licence 2.0 or later
@@ -18,30 +19,30 @@
1920 require_once("$IP/includes/UserMailer.php");
2021
2122 /**
22 - *
 23+ * Provides the contact form
 24+ * @ingroup SpecialPage
2325 */
2426 class SpecialContact extends SpecialPage {
2527
2628 /**
2729 * Constructor
2830 */
29 - function __construct() {
30 - global $wgOut;
31 - SpecialPage::SpecialPage( 'Contact', '', true );
 31+ public function __construct() {
 32+ parent::__construct( 'Contact' );
3233 }
3334
3435 /**
3536 * Main execution function
36 - * @param $par Parameters passed to the page
 37+ *
 38+ * @param $par Mixed: Parameters passed to the page
3739 */
38 - function execute( $par ) {
 40+ public function execute( $par ) {
3941 global $wgUser, $wgOut, $wgRequest, $wgEnableEmail, $wgContactUser;
4042
4143 wfLoadExtensionMessages( 'ContactPage' );
42 - $fname = "SpecialContact::execute";
4344
4445 if( !$wgEnableEmail || !$wgContactUser ) {
45 - $wgOut->showErrorPage( "nosuchspecialpage", "nospecialpagetext" );
 46+ $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
4647 return;
4748 }
4849
@@ -50,16 +51,16 @@
5152 $nu = User::newFromName( $wgContactUser );
5253 if( is_null( $nu ) || !$nu->canReceiveEmail() ) {
5354 wfDebug( "Target is invalid user or can't receive.\n" );
54 - $wgOut->showErrorPage( "noemailtitle", "noemailtext" );
 55+ $wgOut->showErrorPage( 'noemailtitle', 'noemailtext' );
5556 return;
5657 }
5758
5859 $f = new EmailContactForm( $nu );
5960
60 - if ( "success" == $action ) {
61 - wfDebug( "$fname: success.\n" );
62 - $f->showSuccess( );
63 - } else if ( "submit" == $action && $wgRequest->wasPosted() && $f->hasAllInfo() ) {
 61+ if ( 'success' == $action ) {
 62+ wfDebug( __METHOD__ . ": success.\n" );
 63+ $f->showSuccess();
 64+ } else if ( 'submit' == $action && $wgRequest->wasPosted() && $f->hasAllInfo() ) {
6465 $token = $wgRequest->getVal( 'wpEditToken' );
6566
6667 if( $wgUser->isAnon() ) {
@@ -71,19 +72,19 @@
7273 }
7374
7475 if ( !$tokenOk ) {
75 - wfDebug( "$fname: bad token (".($wgUser->isAnon()?'anon':'user')."): $token\n" );
76 - $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
 76+ wfDebug( __METHOD__ . ": bad token (".( $wgUser->isAnon() ? 'anon' : 'user' )."): $token\n" );
 77+ $wgOut->addWikiMsg( 'sessionfailure' );
7778 $f->showForm();
7879 } else if ( !$f->passCaptcha() ) {
79 - wfDebug( "$fname: captcha failed" );
80 - $wgOut->addWikiText( wfMsg( 'contactpage-captcha-failed' ) ); //TODO: provide a message for this!
 80+ wfDebug( __METHOD__ . ": captcha failed" );
 81+ $wgOut->addWikiMsg( 'contactpage-captcha-failed' );
8182 $f->showForm();
8283 } else {
83 - wfDebug( "$fname: submit\n" );
 84+ wfDebug( __METHOD__ . ": submit\n" );
8485 $f->doSubmit();
8586 }
8687 } else {
87 - wfDebug( "$fname: form\n" );
 88+ wfDebug( __METHOD__ . ": form\n" );
8889 $f->showForm();
8990 }
9091 }
@@ -91,13 +92,13 @@
9293
9394 /**
9495 * @todo document
95 - * @addtogroup SpecialPage
 96+ * @ingroup SpecialPage
9697 */
9798 class EmailContactForm {
9899
99100 var $target;
100101 var $text, $subject;
101 - var $cc_me; // Whether user requested to be sent a separate copy of their email.
 102+ var $cc_me; // Whether user requested to be sent a separate copy of their email.
102103
103104 /**
104105 * @param User $target
@@ -114,12 +115,12 @@
115116 $this->fromname = $wgRequest->getText( 'wpFromName' );
116117 $this->fromaddress = $wgRequest->getText( 'wpFromAddress' );
117118
118 - if ($wgUser->isLoggedIn()) {
119 - if (!$this->fromname) $this->fromname = $wgUser->getName();
120 - if (!$this->fromaddress) $this->fromaddress = $wgUser->getEmail();
 119+ if( $wgUser->isLoggedIn() ) {
 120+ if( !$this->fromname ) $this->fromname = $wgUser->getName();
 121+ if( !$this->fromaddress ) $this->fromaddress = $wgUser->getEmail();
121122 }
122123
123 - //prepare captcha if applicable
 124+ // prepare captcha if applicable
124125 if ( $this->useCaptcha() ) {
125126 $captcha = ConfirmEditHooks::getInstance();
126127 $captcha->trigger = 'contactpage';
@@ -152,11 +153,11 @@
153154
154155 #TODO: show captcha
155156
156 - $wgOut->setPagetitle( wfMsg( "contactpage-title" ) );
157 - $wgOut->addWikiText( wfMsg( "contactpage-pagetext" ) );
 157+ $wgOut->setPageTitle( wfMsg( 'contactpage-title' ) );
 158+ $wgOut->addWikiMsg( 'contactpage-pagetext' );
158159
159 - if ( $this->subject === "" ) {
160 - $this->subject = wfMsgForContent( "contactpage-defsubject" );
 160+ if ( $this->subject === '' ) {
 161+ $this->subject = wfMsgForContent( 'contactpage-defsubject' );
161162 }
162163
163164 $msgSuffix = $wgContactRequireAll ? '-required' : '';
@@ -230,8 +231,8 @@
231232
232233 function useCaptcha() {
233234 global $wgCaptchaClass, $wgCaptchaTriggers, $wgUser;
234 - if ( !$wgCaptchaClass ) return false; //no captcha installed
235 - if ( !@$wgCaptchaTriggers['contactpage'] ) return false; //don't trigger on contact form
 235+ if ( !$wgCaptchaClass ) return false; // no captcha installed
 236+ if ( !@$wgCaptchaTriggers['contactpage'] ) return false; // don't trigger on contact form
236237
237238 if( $wgUser->isAllowed( 'skipcaptcha' ) ) {
238239 wfDebug( "EmailContactForm::useCaptcha: user group allows skipping captcha\n" );
@@ -243,7 +244,7 @@
244245
245246 function getCaptcha() {
246247 global $wgCaptcha;
247 - if ( !$this->useCaptcha() ) return "";
 248+ if ( !$this->useCaptcha() ) return '';
248249
249250 wfSetupSession(); #NOTE: make sure we have a session. May be required for captchas to work.
250251
@@ -260,7 +261,7 @@
261262 return $wgCaptcha->passCaptcha();
262263 }
263264
264 - function doSubmit( ) {
 265+ function doSubmit() {
265266 global $wgOut;
266267 global $wgEnableEmail, $wgUserEmailUseReplyTo, $wgEmergencyContact;
267268 global $wgContactUser, $wgContactSender, $wgContactSenderName;
@@ -268,40 +269,35 @@
269270 $csender = $wgContactSender ? $wgContactSender : $wgEmergencyContact;
270271 $cname = $wgContactSenderName;
271272
272 - $fname = 'EmailContactForm::doSubmit';
 273+ wfDebug( __METHOD__ . ": start\n" );
273274
274 - wfDebug( "$fname: start\n" );
275 -
276275 $to = new MailAddress( $this->target );
277276 $replyto = NULL;
278277
279278 if ( !$this->fromaddress ) {
280279 $from = new MailAddress( $csender, $cname );
281 - }
282 - else if ( $wgUserEmailUseReplyTo ) {
 280+ } else if ( $wgUserEmailUseReplyTo ) {
283281 $from = new MailAddress( $csender, $cname );
284282 $replyto = new MailAddress( $this->fromaddress, $this->fromname );
285 - }
286 - else {
 283+ } else {
287284 $from = new MailAddress( $this->fromaddress, $this->fromname );
288285 }
289286
290287 $subject = trim( $this->subject );
291288
292 - if ( $subject === "" ) {
293 - $subject = wfMsgForContent( "contactpage-defsubject" );
 289+ if ( $subject === '' ) {
 290+ $subject = wfMsgForContent( 'contactpage-defsubject' );
294291 }
295292
296 - if ( $this->fromname !== "" ) {
297 - $subject = wfMsgForContent( "contactpage-subject-and-sender", $subject, $this->fromname );
 293+ if ( $this->fromname !== '' ) {
 294+ $subject = wfMsgForContent( 'contactpage-subject-and-sender', $subject, $this->fromname );
 295+ } else if ( $this->fromaddress !== '' ) {
 296+ $subject = wfMsgForContent( 'contactpage-subject-and-sender', $subject, $this->fromaddress );
298297 }
299 - else if ( $this->fromaddress !== "" ) {
300 - $subject = wfMsgForContent( "contactpage-subject-and-sender", $subject, $this->fromaddress );
301 - }
302298
303299 if( wfRunHooks( 'ContactForm', array( &$to, &$replyto, &$subject, &$this->text ) ) ) {
304300
305 - wfDebug( "$fname: sending mail from ".$from->toString()." to ".$to->toString()." replyto ".($replyto==null?'-/-':$replyto->toString())."\n" );
 301+ wfDebug( __METHOD__ . ": sending mail from ".$from->toString()." to ".$to->toString()." replyto ".( $replyto == null ? '-/-' : $replyto->toString() )."\n" );
306302
307303 #HACK: in MW 1.9, replyto must be a string, in MW 1.10 it must be an object!
308304 $ver = preg_replace( '![^\d._+]!', '', $GLOBALS['wgVersion'] );
@@ -312,15 +308,14 @@
313309 $mailResult = userMailer( $to, $from, $subject, $this->text, $replyaddr );
314310
315311 if( WikiError::isError( $mailResult ) ) {
316 - $wgOut->addWikiText( wfMsg( "usermailererror" ) . $mailResult->getMessage());
 312+ $wgOut->addWikiMsg( 'usermailererror' ) . $mailResult->getMessage();
317313 } else {
318 -
319314 // if the user requested a copy of this mail, do this now,
320315 // unless they are emailing themselves, in which case one copy of the message is sufficient.
321 - if ($this->cc_me && $replyto) {
 316+ if( $this->cc_me && $replyto ) {
322317 $cc_subject = wfMsg('emailccsubject', $this->target->getName(), $subject);
323318 if( wfRunHooks( 'ContactForm', array( &$from, &$replyto, &$cc_subject, &$this->text ) ) ) {
324 - wfDebug( "$fname: sending cc mail from ".$from->toString()." to ".$replyto->toString()."\n" );
 319+ wfDebug( __METHOD__ . ": sending cc mail from ".$from->toString()." to ".$replyto->toString()."\n" );
325320 $ccResult = userMailer( $replyto, $from, $cc_subject, $this->text );
326321 if( WikiError::isError( $ccResult ) ) {
327322 // At this stage, the user's CC mail has failed, but their
@@ -328,29 +323,29 @@
329324 // We can either show them an error, or we can say everything was fine,
330325 // or we can say we sort of failed AND sort of succeeded. Of these options,
331326 // simply saying there was an error is probably best.
332 - $wgOut->addWikiText( wfMsg( "usermailererror" ) . $ccResult);
 327+ $wgOut->addWikiText( wfMsg( 'usermailererror' ) . $ccResult );
333328 return;
334329 }
335330 }
336331 }
337332
338 - wfDebug( "$fname: success\n" );
 333+ wfDebug( __METHOD__ . ": success\n" );
339334
340 - $titleObj = SpecialPage::getTitleFor( "Contact" );
 335+ $titleObj = SpecialPage::getTitleFor( 'Contact' );
341336 $wgOut->redirect( $titleObj->getFullURL( "action=success" ) );
342337 wfRunHooks( 'ContactFromComplete', array( $to, $replyto, $subject, $this->text ) );
343338 }
344339 }
345340
346 - wfDebug( "$fname: end\n" );
 341+ wfDebug( __METHOD__ . ": end\n" );
347342 }
348343
349 - function showSuccess( ) {
 344+ function showSuccess() {
350345 global $wgOut;
351346
352 - $wgOut->setPagetitle( wfMsg( "emailsent" ) );
353 - $wgOut->addWikiText( wfMsg( "emailsenttext" ) );
 347+ $wgOut->setPageTitle( wfMsg( 'emailsent' ) );
 348+ $wgOut->addWikiMsg( 'emailsenttext' );
354349
355350 $wgOut->returnToMain( false );
356351 }
357 -}
 352+}
\ No newline at end of file
Index: trunk/extensions/ContactPage/ContactPage.alias.php
@@ -2,7 +2,8 @@
33 /**
44 * Aliases for Special:Contact
55 *
6 - * @addtogroup Extensions
 6+ * @file
 7+ * @ingroup Extensions
78 */
89
910 $aliases = array();
@@ -55,7 +56,7 @@
5657
5758 /** Finnish (Suomi) */
5859 $aliases['fi'] = array(
59 - 'Contact' => array( 'Yhteystiedot' ),
 60+ 'Contact' => array( 'Ota yhteyttä' ),
6061 );
6162
6263 /** Galician (Galego) */
Index: trunk/extensions/ContactPage/ContactPage.i18n.php
@@ -1,8 +1,9 @@
22 <?php
33 /**
4 - * Internationalisation file for extension ContactPage.
 4+ * Internationalisation file for ContactPage extension.
55 *
6 - * @addtogroup Extensions
 6+ * @file
 7+ * @ingroup Extensions
78 * @author Daniel Kinzler, brightbyte.de
89 * @copyright © 2007 Daniel Kinzler
910 * @license GNU General Public Licence 2.0 or later
@@ -10,6 +11,9 @@
1112
1213 $messages = array();
1314
 15+/** English
 16+ * @author Daniel Kinzler
 17+ */
1418 $messages['en'] = array(
1519 'contact' => 'Contact page',
1620 'contactpage' => 'Contact page',
Index: trunk/extensions/ContactPage/ContactPage.php
@@ -3,8 +3,8 @@
44 * Setup for ContactPage extension, a special page that implements a contact form
55 * for use by anonymous visitors.
66 *
7 - * @package MediaWiki
8 - * @subpackage Extensions
 7+ * @file
 8+ * @ingroup Extensions
99 * @author Daniel Kinzler, brightbyte.de
1010 * @copyright © 2007 Daniel Kinzler
1111 * @licence GNU General Public Licence 2.0 or later

Status & tagging log