r64759 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64758‎ | r64759 | r64760 >
Date:21:31, 8 April 2010
Author:ialex
Status:ok
Tags:
Comment:
* Fixed some doxygen warnings
* Documented a bit
* Removed trailing spaces
Modified paths:
  • /trunk/phase3/includes/specials/SpecialEmailuser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialEmailuser.php
@@ -5,7 +5,7 @@
66 */
77
88 /**
9 - * Constructor for Special:Emailuser.
 9+ * Constructor for Special:Emailuser.
1010 */
1111 function wfSpecialEmailuser( $par ) {
1212 global $wgRequest, $wgUser, $wgOut;
@@ -18,12 +18,12 @@
1919 $action = $wgRequest->getVal( 'action' );
2020 $target = isset($par) ? $par : $wgRequest->getVal( 'target' );
2121 $targetUser = EmailUserForm::validateEmailTarget( $target );
22 -
 22+
2323 if ( !( $targetUser instanceof User ) ) {
2424 $wgOut->showErrorPage( $targetUser.'title', $targetUser.'text' );
2525 return;
2626 }
27 -
 27+
2828 $form = new EmailUserForm( $targetUser,
2929 $wgRequest->getText( 'wpText' ),
3030 $wgRequest->getText( 'wpSubject' ),
@@ -32,7 +32,7 @@
3333 $form->showSuccess();
3434 return;
3535 }
36 -
 36+
3737 $error = EmailUserForm::getPermissionsError( $wgUser, $wgRequest->getVal( 'wpEditToken' ) );
3838 if ( $error ) {
3939 switch ( $error ) {
@@ -53,13 +53,13 @@
5454 list( $title, $msg, $params ) = $error;
5555 $wgOut->showErrorPage( $title, $msg, $params );
5656 return;
57 -
 57+
5858 }
59 - }
60 -
 59+ }
 60+
6161 if ( "submit" == $action && $wgRequest->wasPosted() ) {
6262 $result = $form->doSubmit();
63 -
 63+
6464 if ( !is_null( $result ) ) {
6565 $wgOut->addHTML( wfMsg( "usermailererror" ) .
6666 ' ' . htmlspecialchars( $result->getMessage() ) );
@@ -74,26 +74,36 @@
7575 }
7676
7777 /**
78 - * Implements the Special:Emailuser web interface, and invokes userMailer for sending the email message.
 78+ * Implements the Special:Emailuser web interface, and invokes
 79+ * UserMailer::send() for sending the email message.
 80+ *
7981 * @ingroup SpecialPage
8082 */
8183 class EmailUserForm {
8284
8385 var $target;
8486 var $text, $subject;
85 - var $cc_me; // Whether user requested to be sent a separate copy of their email.
 87+ var $cc_me; // Whether user requested to be sent a separate copy of their email.
8688
8789 /**
88 - * @param User $target
 90+ * Constructor
 91+ *
 92+ * @param $target User object
 93+ * @param $text String: message contents
 94+ * @param $subject String: message subject
 95+ * @param $cc_me Boolean: wheter to send a copy of the message to the sender user
8996 */
90 - function EmailUserForm( $target, $text, $subject, $cc_me ) {
 97+ public function EmailUserForm( $target, $text, $subject, $cc_me ) {
9198 $this->target = $target;
9299 $this->text = $text;
93100 $this->subject = $subject;
94101 $this->cc_me = $cc_me;
95102 }
96103
97 - function showForm() {
 104+ /**
 105+ * Display the form to send a email
 106+ */
 107+ public function showForm() {
98108 global $wgOut, $wgUser;
99109 $skin = $wgUser->getSkin();
100110
@@ -108,7 +118,7 @@
109119 $action = $titleObj->getLocalURL( "target=" .
110120 urlencode( $this->target->getName() ) . "&action=submit" );
111121
112 - $wgOut->addHTML(
 122+ $wgOut->addHTML(
113123 Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'emailuser' ) ) .
114124 Xml::openElement( 'fieldset' ) .
115125 Xml::element( 'legend', null, wfMsgExt( 'email-legend', 'parsemag' ) ) .
@@ -164,12 +174,14 @@
165175 );
166176 }
167177
168 - /*
169 - * Really send a mail. Permissions should have been checked using
 178+ /**
 179+ * Really send a mail. Permissions should have been checked using
170180 * EmailUserForm::getPermissionsError. It is probably also a good idea to
171181 * check the edit token and ping limiter in advance.
 182+ *
 183+ * @return Mixed: WikiError on error or null
172184 */
173 - function doSubmit() {
 185+ public function doSubmit() {
174186 global $wgUser, $wgUserEmailUseReplyTo, $wgSiteName;
175187
176188 $to = new MailAddress( $this->target );
@@ -179,7 +191,7 @@
180192 // Add a standard footer and trim up trailing newlines
181193 $this->text = rtrim($this->text) . "\n\n-- \n" . wfMsgExt( 'emailuserfooter',
182194 array( 'content', 'parsemag' ), array( $from->name, $to->name ) );
183 -
 195+
184196 if( wfRunHooks( 'EmailUser', array( &$to, &$from, &$subject, &$this->text ) ) ) {
185197
186198 if( $wgUserEmailUseReplyTo ) {
@@ -209,14 +221,12 @@
210222 $mailFrom = $from;
211223 $replyTo = null;
212224 }
213 -
 225+
214226 $mailResult = UserMailer::send( $to, $mailFrom, $subject, $this->text, $replyTo );
215227
216228 if( WikiError::isError( $mailResult ) ) {
217229 return $mailResult;
218 -
219230 } else {
220 -
221231 // if the user requested a copy of this mail, do this now,
222232 // unless they are emailing themselves, in which case one copy of the message is sufficient.
223233 if ($this->cc_me && $to != $from) {
@@ -240,9 +250,12 @@
241251 }
242252 }
243253
244 - function showSuccess( &$user = null ) {
 254+ /**
 255+ * Show "Your e-mail message has been sent." message
 256+ */
 257+ public function showSuccess( &$user = null ) {
245258 global $wgOut;
246 -
 259+
247260 if ( is_null($user) )
248261 $user = $this->target;
249262
@@ -251,28 +264,44 @@
252265
253266 $wgOut->returnToMain( false, $user->getUserPage() );
254267 }
255 -
256 - function getTarget() {
 268+
 269+ /**
 270+ * Get target user
 271+ *
 272+ * @return User object
 273+ */
 274+ public function getTarget() {
257275 return $this->target;
258276 }
259 -
260 - static function userEmailEnabled() {
 277+
 278+ /**
 279+ * Check whether user-to-user emails are enabled
 280+ *
 281+ * @return Boolean
 282+ */
 283+ public static function userEmailEnabled() {
261284 global $wgEnableEmail, $wgEnableUserEmail;
262285 return $wgEnableEmail && $wgEnableUserEmail;
263 -
264286 }
265 - static function validateEmailTarget ( $target ) {
 287+
 288+ /**
 289+ * Validate target User
 290+ *
 291+ * @param $target String: target user name
 292+ * @return User object on success or a string on error
 293+ */
 294+ public static function validateEmailTarget( $target ) {
266295 if ( $target == "" ) {
267296 wfDebug( "Target is empty.\n" );
268297 return "notarget";
269298 }
270 -
 299+
271300 $nt = Title::newFromURL( $target );
272301 if ( is_null( $nt ) ) {
273302 wfDebug( "Target is invalid title.\n" );
274303 return "notarget";
275304 }
276 -
 305+
277306 $nu = User::newFromName( $nt->getText() );
278307 if( is_null( $nu ) || !$nu->getId() ) {
279308 wfDebug( "Target is invalid user.\n" );
@@ -284,10 +313,18 @@
285314 wfDebug( "User does not allow user emails.\n" );
286315 return "nowikiemail";
287316 }
288 -
 317+
289318 return $nu;
290319 }
291 - static function getPermissionsError ( $user, $editToken ) {
 320+
 321+ /**
 322+ * Check whether user is allowed to send email
 323+ *
 324+ * @param $user User object
 325+ * @param $editToken String: edit token
 326+ * @return null on success or string on error
 327+ */
 328+ public static function getPermissionsError( $user, $editToken ) {
292329 if( !$user->canSendEmail() ) {
293330 wfDebug( "User can't send.\n" );
294331 // FIXME: this is also the error if user is in a group
@@ -296,32 +333,40 @@
297334 // be more fine grained.
298335 return "mailnologin";
299336 }
300 -
 337+
301338 if( $user->isBlockedFromEmailuser() ) {
302339 wfDebug( "User is blocked from sending e-mail.\n" );
303340 return "blockedemailuser";
304341 }
305 -
 342+
306343 if( $user->pingLimiter( 'emailuser' ) ) {
307 - wfDebug( "Ping limiter triggered.\n" );
 344+ wfDebug( "Ping limiter triggered.\n" );
308345 return 'actionthrottledtext';
309346 }
310 -
 347+
311348 $hookErr = null;
312349 wfRunHooks( 'EmailUserPermissionsErrors', array( $user, $editToken, &$hookErr ) );
313 -
 350+
314351 if ($hookErr) {
315352 return $hookErr;
316353 }
317 -
 354+
318355 if( !$user->matchEditToken( $editToken ) ) {
319356 wfDebug( "Matching edit token failed.\n" );
320357 return 'sessionfailure';
321358 }
322359 }
323 -
324 - static function newFromURL( $target, $text, $subject, $cc_me )
325 - {
 360+
 361+ /**
 362+ * Get a EmailUserForm object
 363+ *
 364+ * @param $target String: user name
 365+ * @param $text String: message contents
 366+ * @param $subject String: message subject
 367+ * @param $cc_me Boolean: wheter to send a copy of the message to the sender user
 368+ * @return EmailUserForm object
 369+ */
 370+ public static function newFromURL( $target, $text, $subject, $cc_me ) {
326371 $nt = Title::newFromURL( $target );
327372 $nu = User::newFromName( $nt->getText() );
328373 return new EmailUserForm( $nu, $text, $subject, $cc_me );

Status & tagging log