r89716 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89715‎ | r89716 | r89717 >
Date:03:34, 8 June 2011
Author:nagelp
Status:ok
Tags:
Comment:
Replaced Notificator::checkEmailAddress() with MW's Sanitizer::validateEmail()
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
@@ -21,7 +21,7 @@
2222 }
2323
2424 // Check whether the parameter is a valid e-mail address or not
25 - if($receiver && Notificator::checkEmailAddress($receiver)) {
 25+ if($receiver && Sanitizer::validateEmail($receiver)) {
2626 // Valid e-mail address available, so just show a button
2727 $output = '<form action="' . $wgScript . '/Special:Notificator" method="post" enctype="multipart/form-data">
2828 <input type="hidden" name="pageId" value="' . $wgTitle->getArticleID() . '" />
@@ -58,56 +58,6 @@
5959 return $ret;
6060 }
6161
62 -public static function checkEmailAddress($string) {
63 -// from http://www.linuxjournal.com/article/9585
64 - $isValid = true;
65 - $atIndex = strrpos($string, "@");
66 - if (is_bool($atIndex) && !$atIndex) {
67 - $isValid = false;
68 - } else {
69 - $domain = substr($string, $atIndex+1);
70 - $local = substr($string, 0, $atIndex);
71 - $localLen = strlen($local);
72 - $domainLen = strlen($domain);
73 - if ($localLen < 1 || $localLen > 64) {
74 - // local part length exceeded
75 - $isValid = false;
76 - }
77 - else if ($domainLen < 1 || $domainLen > 255) {
78 - // domain part length exceeded
79 - $isValid = false;
80 - }
81 - else if ($local[0] == '.' || $local[$localLen-1] == '.') {
82 - // local part starts or ends with '.'
83 - $isValid = false;
84 - }
85 - else if (preg_match('/\\.\\./', $local)) {
86 - // local part has two consecutive dots
87 - $isValid = false;
88 - }
89 - else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) {
90 - // character not valid in domain part
91 - $isValid = false;
92 - }
93 - else if (preg_match('/\\.\\./', $domain)) {
94 - // domain part has two consecutive dots
95 - $isValid = false;
96 - }
97 - else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))) {
98 - // character not valid in local part unless
99 - // local part is quoted
100 - if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))) {
101 - $isValid = false;
102 - }
103 - }
104 - if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) {
105 - // domain not found in DNS
106 - $isValid = false;
107 - }
108 - }
109 - return $isValid;
110 -}
111 -
11262 public static function getLastNotifiedRevId($pageId, $revId, $receiver) {
11363 // Returns -1 if any parameter is missing
11464 // Returns -2 if the database revId is the same as the given revId (= notified already)
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(! Sanitizer::validateEmail($receiver)) {
3333 $output = '<span class="error">' . wfMsg('e-mail-address-invalid') . ' ' . wfMsg('notification-not-sent') . '</span>';
3434 $output .= Notificator::getReturnToText($linkToPage, $pageTitle);
3535 $wgOut->addHTML($output);

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r89637Initial commit of new extension Notificatornagelp09:20, 7 June 2011

Status & tagging log