r90507 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90506‎ | r90507 | r90508 >
Date:02:47, 21 June 2011
Author:nagelp
Status:ok
Tags:
Comment:
Dumped own checkEmailAddress() function again, now using User::isValidEmailAddr or Sanitizer::validateEmail, whichever is available
Modified paths:
  • /trunk/extensions/Notificator/Notificator.body.php (modified) (history)
  • /trunk/extensions/Notificator/SpecialNotificator.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Notificator/Notificator.body.php
@@ -22,8 +22,7 @@
2323 return array( $output, 'noparse' => true, 'isHTML' => true );
2424 }
2525
26 - // Check whether the parameter is a valid e-mail address or not
27 - if ( $receiver && Notificator::checkEmailAddress( $receiver ) ) {
 26+ if ( Notificator::receiverIsValid( $receiver ) ) {
2827 // Valid e-mail address available, so just show a button
2928 $output = '<form action="' . $wgScript .
3029 '/Special:Notificator" method="post" enctype="multipart/form-data">
@@ -65,55 +64,22 @@
6665 return $ret;
6766 }
6867
69 -public static function checkEmailAddress( $string ) {
70 -// from http://www.linuxjournal.com/article/9585
71 - $isValid = true;
72 - $atIndex = strrpos( $string, "@" );
73 - if ( is_bool( $atIndex ) && !$atIndex ) {
74 - $isValid = false;
 68+public static function receiverIsValid( $receiver ) {
 69+ // Returns true if the parameter is a valid e-mail address, false if not
 70+ $receiverIsValid = false;
 71+
 72+ // User::isValidEmailAddr() has been moved to Sanitizer::validateEmail as of
 73+ // MediaWiki version 1.18 (I think).
 74+ if ( method_exists( Sanitizer, validateEmail ) ) {
 75+ if ( Sanitizer::validateEmail( $receiver ) ) {
 76+ $receiverIsValid = true;
 77+ }
7578 } else {
76 - $domain = substr( $string, $atIndex + 1 );
77 - $local = substr( $string, 0, $atIndex );
78 - $localLen = strlen( $local );
79 - $domainLen = strlen( $domain );
80 - if ( $localLen < 1 || $localLen > 64 ) {
81 - // local part length exceeded
82 - $isValid = false;
 79+ if ( User::isValidEmailAddr( $receiver ) ) {
 80+ $receiverIsValid = true;
8381 }
84 - elseif ( $domainLen < 1 || $domainLen > 255 ) {
85 - // domain part length exceeded
86 - $isValid = false;
87 - }
88 - elseif ( $local[0] == '.' || $local[$localLen -1] == '.' ) {
89 - // local part starts or ends with '.'
90 - $isValid = false;
91 - }
92 - elseif ( preg_match( '/\\.\\./', $local ) ) {
93 - // local part has two consecutive dots
94 - $isValid = false;
95 - }
96 - elseif ( !preg_match( '/^[A-Za-z0-9\\-\\.]+$/', $domain ) ) {
97 - // character not valid in domain part
98 - $isValid = false;
99 - }
100 - elseif ( preg_match( '/\\.\\./', $domain ) ) {
101 - // domain part has two consecutive dots
102 - $isValid = false;
103 - }
104 - elseif ( !preg_match( '/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
105 - str_replace( "\\\\", "", $local ) ) ) {
106 - // character not valid in local part unless
107 - // local part is quoted
108 - if ( !preg_match( '/^"(\\\\"|[^"])+"$/', str_replace( "\\\\", "", $local ) ) ) {
109 - $isValid = false;
110 - }
111 - }
112 - if ( $isValid && !( checkdnsrr( $domain, "MX" ) || checkdnsrr( $domain, "A" ) ) ) {
113 - // domain not found in DNS
114 - $isValid = false;
115 - }
11682 }
117 - return $isValid;
 83+ return $receiverIsValid;
11884 }
11985
12086 public static function getLastNotifiedRevId( $pageId, $revId, $receiver ) {
Index: trunk/extensions/Notificator/SpecialNotificator.php
@@ -28,7 +28,7 @@
2929 $pageTitle = $titleObj->getFullText();
3030 $linkToPage = $titleObj->getFullURL();
3131
32 - if ( ! Notificator::checkEmailAddress( $receiver ) ) {
 32+ if ( ! Notificator::receiverIsValid( $receiver ) ) {
3333 $output = '<span class="error">' . wfMsg( 'notificator-e-mail-address-invalid' ) . ' ' .
3434 wfMsg( 'notificator-notification-not-sent' ) . '</span>';
3535 $output .= Notificator::getReturnToText( $linkToPage, $pageTitle );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r89719Switched to Notificator::checkEmailAddress() again, after discovering that Sa...nagelp04:50, 8 June 2011

Status & tagging log