r35837 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r35836‎ | r35837 | r35838 >
Date:00:45, 4 June 2008
Author:nad
Status:old
Tags:
Comment:
1.1.0 - problem in group query
Modified paths:
  • /trunk/extensions/EmailArticle/EmailArticle.php (modified) (history)
  • /trunk/extensions/EmailArticle/EmailArticle_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EmailArticle/EmailArticle.php
@@ -13,7 +13,7 @@
1414
1515 if (!defined('MEDIAWIKI')) die('Not an entry point.');
1616
17 -define('EMAILARTICLE_VERSION','1.0.10, 2008-05-30');
 17+define('EMAILARTICLE_VERSION', '1.1.0, 2008-06-04');
1818
1919 $wgEmailArticleGroup = 'sysop'; # Users must belong to this group to send emails (empty string means anyone can send)
2020 $wgEmailArticleContactsCat = ''; # This specifies the name of a category containing categories of contact articles
Index: trunk/extensions/EmailArticle/EmailArticle_body.php
@@ -15,14 +15,16 @@
1616
1717 public function __construct() {
1818 global $wgEmailArticleGroup;
19 - SpecialPage::SpecialPage('EmailArticle',$wgEmailArticleGroup);
 19+ SpecialPage::SpecialPage('EmailArticle', $wgEmailArticleGroup);
2020 }
2121
22 - # Override SpecialPage::execute($param = '')
 22+ /**
 23+ * Override SpecialPage::execute($param = '')
 24+ */
2325 function execute($param) {
24 - global $wgOut,$wgUser,$wgEmailArticleContactsCat,$wgGroupPermissions,$wgSitename,$wgEmailArticleCss,$wgEmailArticleAllowAllUsers;
 26+ global $wgOut, $wgUser, $wgEmailArticleContactsCat, $wgGroupPermissions, $wgSitename, $wgEmailArticleCss, $wgEmailArticleAllowAllUsers;
2527 $db =& wfGetDB(DB_SLAVE);
26 - $param = str_replace('_',' ',$param);
 28+ $param = str_replace('_', ' ', $param);
2729
2830 wfLoadExtensionMessages( 'EmailArticle' );
2931
@@ -39,14 +41,14 @@
4042 $this->css = isset($_REQUEST['ea-css']) ? $_REQUEST['ea-css'] : $wgEmailArticleCss;
4143
4244 # Bail if no article title to send has been specified
43 - if ($this->title) $wgOut->addWikiText(wfMsg('ea-heading',$this->title));
 45+ if ($this->title) $wgOut->addWikiText(wfMsg('ea-heading', $this->title));
4446 else return $wgOut->addWikiText(wfMsg('ea-noarticle'));
4547
4648 # If the send button was clicked, attempt to send and exit
4749 if (isset($_REQUEST['ea-send'])) return $this->send();
4850
4951 # Render form
50 - $special = Title::makeTitle(NS_SPECIAL,'EmailArticle');
 52+ $special = Title::makeTitle(NS_SPECIAL, 'EmailArticle');
5153 $wgOut->addHTML(wfElement('form',array(
5254 'class' => 'EmailArticle',
5355 'action' => $special->getLocalURL('action=submit'),
@@ -124,9 +126,9 @@
125127 $wgOut->addHTML("</fieldset>");
126128
127129 # Submit buttons & hidden values
128 - $wgOut->addHTML(wfElement('input',array('type' => 'submit','name' => 'ea-send', 'value' => wfMsg('ea-send'))));
129 - $wgOut->addHTML(wfElement('input',array('type' => 'submit','name' => 'ea-show', 'value' => wfMsg('ea-show'))));
130 - $wgOut->addHTML(wfElement('input',array('type' => 'hidden','name' => 'ea-title','value' => $this->title)));
 130+ $wgOut->addHTML(wfElement('input', array('type' => 'submit', 'name' => 'ea-send', 'value' => wfMsg('ea-send'))));
 131+ $wgOut->addHTML(wfElement('input', array('type' => 'submit', 'name' => 'ea-show', 'value' => wfMsg('ea-show'))));
 132+ $wgOut->addHTML(wfElement('input', array('type' => 'hidden', 'name' => 'ea-title', 'value' => $this->title)));
131133
132134 $wgOut->addHTML('</form>');
133135
@@ -136,13 +138,13 @@
137139
138140 # Send the message to the recipients (or just list them if arg = false)
139141 function send($send = true) {
140 - global $wgOut,$wgUser,$wgParser,$wgServer,$wgScript,$wgArticlePath,$wgScriptPath,
141 - $wgEmailArticleCss,$wgEmailArticleGroup,$wgEmailArticleAllowRemoteAddr,$wgEmailArticleAllowAllUsers;
 142+ global $wgOut, $wgUser, $wgParser, $wgServer, $wgScript, $wgArticlePath, $wgScriptPath,
 143+ $wgEmailArticleCss, $wgEmailArticleGroup, $wgEmailArticleAllowRemoteAddr, $wgEmailArticleAllowAllUsers;
142144
143145 # Set error and bail if user not in postmaster group, and request not from trusted address
144 - if ($wgEmailArticleGroup && !in_array($wgEmailArticleGroup,$wgUser->getGroups()) && !in_array($_SERVER['REMOTE_ADDR'],$wgEmailArticleAllowRemoteAddr)) {
 146+ if ($wgEmailArticleGroup && !in_array($wgEmailArticleGroup, $wgUser->getGroups()) && !in_array($_SERVER['REMOTE_ADDR'], $wgEmailArticleAllowRemoteAddr)) {
145147 $denied = wfMsg('ea-denied');
146 - $wgOut->addWikiText(wfMsg('ea-error',$this->title, $denied ));
 148+ $wgOut->addWikiText(wfMsg('ea-error', $this->title, $denied ));
147149 return false;
148150 }
149151
@@ -168,14 +170,14 @@
169171 $group = $db->addQuotes($this->group);
170172 $result = $this->group == 'user'
171173 ? $db->select('user', 'user_email', 'user_email != \'\'', __METHOD__)
172 - : $db->select(array('user', 'user_groups'), 'user_email', 'ug_user = user_id AND ug_group = $group', __METHOD__);
 174+ : $db->select(array('user', 'user_groups'), 'user_email', "ug_user = user_id AND ug_group = $group", __METHOD__);
173175 if ($result instanceof ResultWrapper) $result = $result->result;
174176 if ($result) while ($row = $db->fetchRow($result)) $this->addRecipient($row[0]);
175177 }
176178
177179 # Recipients from list (expand templates in wikitext)
178 - $list = $wgParser->preprocess($this->list,$title,$opt);
179 - foreach (preg_split("/[\\x00-\\x1f,;*]+/",$list) as $item) $this->addRecipient($item);
 180+ $list = $wgParser->preprocess($this->list, $title, $opt);
 181+ foreach (preg_split("/[\\x00-\\x1f,;*]+/", $list) as $item) $this->addRecipient($item);
180182
181183 # Compose the wikitext content of the article to send
182184 $article = new Article($title);
@@ -186,11 +188,11 @@
187189 if ($this->textonly == '') {
188190
189191 # Parse the wikitext using absolute URL's for local article links
190 - $tmp = array($wgArticlePath,$wgScriptPath,$wgScript);
 192+ $tmp = array($wgArticlePath, $wgScriptPath, $wgScript);
191193 $wgArticlePath = $wgServer.$wgArticlePath;
192194 $wgScriptPath = $wgServer.$wgScriptPath;
193195 $wgScript = $wgServer.$wgScript;
194 - $message = $wgParser->parse($message,$title,$opt,true,true)->getText();
 196+ $message = $wgParser->parse($message, $title, $opt, true, true)->getText();
195197 list($wgArticlePath,$wgScriptPath,$wgScript) = $tmp;
196198
197199 # Get CSS content if any
@@ -218,29 +220,31 @@
219221 $mail->Body = $message;
220222 $mail->IsHTML(!$this->textonly);
221223 }
222 - else $msg = wfMsg('ea-listrecipients',$count);
 224+ else $msg = wfMsg('ea-listrecipients', $count);
223225
224226 # Loop through recipients sending or adding to list
225227 foreach ($this->recipients as $recipient) $send ? $mail->AddAddress($recipient) : $msg .= "\n*[mailto:$recipient $recipient]";
226228
227229 if ($send) {
228 - if ($state = $mail->Send()) $msg = wfMsg('ea-sent',$this->title,$count,$wgUser->getName());
229 - else $msg = wfMsg('ea-error',$this->title,$mail->ErrorInfo);
 230+ if ($state = $mail->Send()) $msg = wfMsg('ea-sent', $this->title, $count, $wgUser->getName());
 231+ else $msg = wfMsg('ea-error', $this->title, $mail->ErrorInfo);
230232 }
231233 else $state = $count;
232234 }
233 - else $msg = wfMsg('ea-error',$this->title,wfMsg('ea-norecipients'));
 235+ else $msg = wfMsg('ea-error', $this->title, wfMsg('ea-norecipients'));
234236
235237 $wgOut->addWikiText($msg);
236238 return $state;
237239 }
238240
239 - # Add a recipient the list
240 - # - accepts title objects for article containing email address, or string of actual address
 241+ /**
 242+ * Add a recipient the list
 243+ * - accepts title objects for article containing email address, or string of actual address
 244+ */
241245 function addRecipient($recipient) {
242246 if (is_object($recipient) && $recipient->exists()) {
243247 $article = new Article($recipient);
244 - if (preg_match('/[a-z0-9_.-]+@[a-z0-9_.-]+/i',$article->getContent(),$emails)) $recipient = $emails[0];
 248+ if (preg_match('/[a-z0-9_.-]+@[a-z0-9_.-]+/i', $article->getContent(), $emails)) $recipient = $emails[0];
245249 else $recipient = '';
246250 }
247251 if ($valid = User::isValidEmailAddr($recipient)) $this->recipients[] = $recipient;

Status & tagging log