Index: trunk/extensions/EmailPage/EmailPage_body.php |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | <?php |
3 | | -if (!defined('MEDIAWIKI')) die(); |
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) die(); |
4 | 4 | |
5 | 5 | class SpecialEmailPage extends SpecialPage { |
6 | 6 | |
— | — | @@ -19,190 +19,194 @@ |
20 | 20 | |
21 | 21 | public function __construct() { |
22 | 22 | global $wgEmailPageGroup; |
23 | | - SpecialPage::SpecialPage('EmailPage', $wgEmailPageGroup); |
| 23 | + SpecialPage::SpecialPage( 'EmailPage', $wgEmailPageGroup ); |
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Override SpecialPage::execute($param = '') |
28 | 28 | */ |
29 | | - function execute($param) { |
| 29 | + function execute( $param ) { |
30 | 30 | global $wgOut, $wgUser, $wgRequest, $wgParser, $wgEmailPageContactsCat, $wgGroupPermissions, $wgSitename, |
31 | 31 | $wgRecordAdminCategory, $wgEmailPageCss, $wgEmailPageAllowAllUsers; |
32 | 32 | |
33 | | - $db =& wfGetDB(DB_SLAVE); |
34 | | - $param = str_replace('_', ' ', $param); |
| 33 | + $db = wfGetDB(DB_SLAVE); |
| 34 | + $param = str_replace( '_', ' ', $param ); |
35 | 35 | wfLoadExtensionMessages( 'EmailPage' ); |
36 | 36 | $this->setHeaders(); |
37 | 37 | |
38 | 38 | # Get info from request or set to defaults |
39 | | - $this->title = $wgRequest->getText('ea-title', $param); |
40 | | - $this->subject = $wgRequest->getText('ea-subject', wfMsg('ea-pagesend', $this->title, $wgSitename )); |
41 | | - $this->header = $wgRequest->getText('ea-header'); |
42 | | - $this->cat = $wgRequest->getText('ea-cat'); |
43 | | - $this->group = $wgRequest->getText('ea-group'); |
44 | | - $this->list = $wgRequest->getText('ea-list'); |
45 | | - $this->textonly = $wgRequest->getText('ea-textonly', false); |
46 | | - $this->css = $wgRequest->getText('ea-css', $wgEmailPageCss); |
47 | | - $this->record = $wgRequest->getText('ea-record', false); |
| 39 | + $this->title = $wgRequest->getText( 'ea-title', $param ); |
| 40 | + $this->subject = $wgRequest->getText( 'ea-subject', wfMsg( 'ea-pagesend', $this->title, $wgSitename ) ); |
| 41 | + $this->header = $wgRequest->getText( 'ea-header' ); |
| 42 | + $this->cat = $wgRequest->getText( 'ea-cat' ); |
| 43 | + $this->group = $wgRequest->getText( 'ea-group' ); |
| 44 | + $this->list = $wgRequest->getText( 'ea-list' ); |
| 45 | + $this->textonly = $wgRequest->getText( 'ea-textonly', false ); |
| 46 | + $this->css = $wgRequest->getText( 'ea-css', $wgEmailPageCss ); |
| 47 | + $this->record = $wgRequest->getText( 'ea-record', false ); |
48 | 48 | $this->db = $db; |
49 | 49 | $this->parser = $wgParser; |
50 | 50 | |
51 | 51 | # Bail if no page title to send has been specified |
52 | | - if ($this->title) $wgOut->addWikiText(wfMsg('ea-heading', $this->title)); |
53 | | - else return $wgOut->addWikiText(wfMsg('ea-nopage')); |
| 52 | + if ( $this->title ) $wgOut->addWikiText( wfMsg( 'ea-heading', $this->title ) ); |
| 53 | + else return $wgOut->addWikiText( wfMsg( 'ea-nopage' ) ); |
54 | 54 | |
55 | 55 | # If the send button was clicked, attempt to send and exit |
56 | | - if (isset($_REQUEST['ea-send'])) return $this->send(); |
| 56 | + if ( isset( $_REQUEST['ea-send'] ) ) return $this->send(); |
57 | 57 | |
58 | 58 | # Render form |
59 | | - $special = Title::makeTitle(NS_SPECIAL, 'EmailPage'); |
60 | | - $wgOut->addHTML(Xml::element('form',array( |
| 59 | + $special = Title::makeTitle( NS_SPECIAL, 'EmailPage' ); |
| 60 | + $wgOut->addHTML( Xml::element( 'form', array( |
61 | 61 | 'class' => 'EmailPage', |
62 | | - 'action' => $special->getLocalURL('action=submit'), |
| 62 | + 'action' => $special->getLocalURL( 'action=submit' ), |
63 | 63 | 'method' => 'POST' |
64 | | - ),null)); |
65 | | - $wgOut->addHTML('<fieldset><legend>'.wfMsg('ea-selectrecipients').'</legend>'); |
66 | | - $wgOut->addHTML('<table style="padding:0;margin:0;border:none;">'); |
| 64 | + ), null ) ); |
| 65 | + $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'ea-selectrecipients' ) . '</legend>' ); |
| 66 | + $wgOut->addHTML( '<table style="padding:0;margin:0;border:none;">' ); |
67 | 67 | |
68 | 68 | # If $wgEmailPageContactsCat is set, create a select list of all categories |
69 | | - if ($wgEmailPageContactsCat) { |
| 69 | + if ( $wgEmailPageContactsCat ) { |
70 | 70 | $cats = ''; |
71 | 71 | $res = $db->select( |
72 | 72 | 'categorylinks', |
73 | 73 | 'cl_from', |
74 | | - 'cl_to = '.$db->addQuotes($wgEmailPageContactsCat), |
| 74 | + 'cl_to = '.$db->addQuotes( $wgEmailPageContactsCat ), |
75 | 75 | __METHOD__, |
76 | | - array('ORDER BY' => 'cl_sortkey') |
| 76 | + array( 'ORDER BY' => 'cl_sortkey' ) |
77 | 77 | ); |
78 | | - while ($row = $db->fetchRow($res)) { |
79 | | - $t = Title::newFromID($row[0]); |
80 | | - if ($t->getNamespace() == NS_CATEGORY) { |
| 78 | + while ( $row = $db->fetchRow( $res ) ) { |
| 79 | + $t = Title::newFromID( $row[0] ); |
| 80 | + if ( $t->getNamespace() == NS_CATEGORY ) { |
81 | 81 | $cat = $t->getText(); |
82 | 82 | $selected = $cat == $this->cat ? ' selected' : ''; |
83 | 83 | $cats .= "<option$selected>$cat</option>"; |
84 | 84 | } |
85 | 85 | } |
86 | | - $db->freeResult($res); |
87 | | - if ($cats) $wgOut->addHTML("<tr><td>From category:</td><td><select name=\"ea-cat\"><option/>$cats</select></td></tr>\n"); |
| 86 | + $db->freeResult( $res ); |
| 87 | + if ( $cats ) $wgOut->addHTML( "<tr><td>From category:</td><td><select name=\"ea-cat\"><option/>$cats</select></td></tr>\n" ); |
88 | 88 | } |
89 | 89 | |
90 | 90 | # Allow selection of a group |
91 | | - $groups = '<option/>'; |
92 | | - foreach (array_keys($wgGroupPermissions) as $group) if ($group != '*') { |
| 91 | + $groups = "<option />"; |
| 92 | + foreach ( array_keys( $wgGroupPermissions ) as $group ) if ( $group != '*' ) { |
93 | 93 | $selected = $group == $this->group ? ' selected' : ''; |
94 | | - if ($wgEmailPageAllowAllUsers || $group != 'user') $groups .= "<option$selected>$group</option>"; |
| 94 | + if ( $wgEmailPageAllowAllUsers ) $groups .= "<option$selected>$group</option>"; |
95 | 95 | } |
96 | | - $wgOut->addHTML("<tr><td>".wfMsg('ea-fromgroup')."</td><td><select name=\"ea-group\">$groups</select></td></tr>\n"); |
97 | | - $wgOut->addHTML('</table>'); |
| 96 | + $wgOut->addHTML( "<tr><td>" . wfMsg( 'ea-fromgroup' ) . "</td><td><select name=\"ea-group\">$groups</select></td></tr>\n" ); |
| 97 | + $wgOut->addHTML( "</table>" ); |
98 | 98 | |
99 | 99 | # Addition of named list |
100 | | - $wgOut->addWikiText(wfMsg('ea-selectlist')); |
101 | | - $wgOut->addHTML("<textarea name=\"ea-list\" rows=\"5\">{$this->list}</textarea><br />\n"); |
102 | | - $wgOut->addHTML('</fieldset>'); |
| 100 | + $wgOut->addWikiText( wfMsg( 'ea-selectlist' ) ); |
| 101 | + $wgOut->addHTML( "<textarea name=\"ea-list\" rows=\"5\">{$this->list}</textarea><br />\n" ); |
| 102 | + $wgOut->addHTML( "</fieldset>" ); |
103 | 103 | |
104 | | - $wgOut->addHTML('<fieldset><legend>'.wfMsg('ea-compose').'</legend>'); |
| 104 | + $wgOut->addHTML( "<fieldset><legend>" . wfMsg( 'ea-compose' ) . "</legend>" ); |
105 | 105 | |
106 | 106 | # Subject |
107 | | - $wgOut->addWikiText(wfMsg('ea-subject')); |
108 | | - $wgOut->addHTML(Xml::element('input',array('type' => 'text', 'name' => 'ea-subject', 'value' => $this->subject, 'style' => "width:100%"))); |
| 107 | + $wgOut->addWikiText( wfMsg( 'ea-subject' ) ); |
| 108 | + $wgOut->addHTML( |
| 109 | + Xml::element( 'input', array( 'type' => 'text', 'name' => 'ea-subject', 'value' => $this->subject, 'style' => "width:100%" ) ) |
| 110 | + ); |
109 | 111 | |
110 | 112 | # Header |
111 | | - $wgOut->addWikiText(wfMsg('ea-header')); |
112 | | - $wgOut->addHTML("<textarea name=\"ea-header\" rows=\"5\">{$this->header}</textarea><br />\n"); |
| 113 | + $wgOut->addWikiText( wfMsg( 'ea-header' ) ); |
| 114 | + $wgOut->addHTML( "<textarea name=\"ea-header\" rows=\"5\">{$this->header}</textarea><br />\n" ); |
113 | 115 | |
114 | 116 | # CSS |
115 | | - $options = '<option value="">'.$wgEmailPageCss.'</option>'; |
| 117 | + $options = "<option value=''>$wgEmailPageCss</option>"; |
116 | 118 | $res = $db->select( |
117 | 119 | 'page', |
118 | 120 | 'page_id', |
119 | 121 | 'page_title LIKE \'%.css\'', |
120 | 122 | __METHOD__, |
121 | | - array('ORDER BY' => 'page_title') |
| 123 | + array( 'ORDER BY' => 'page_title' ) |
122 | 124 | ); |
123 | | - while ($row = $db->fetchRow($res)) { |
124 | | - $t = Title::newFromID($row[0])->getPrefixedText(); |
| 125 | + while ( $row = $db->fetchRow( $res ) ) { |
| 126 | + $t = Title::newFromID( $row[0] )->getPrefixedText(); |
125 | 127 | $selected = $t == $this->css ? ' selected' : ''; |
126 | 128 | $options .= "<option$selected>$t</option>"; |
127 | 129 | } |
128 | | - $db->freeResult($res); |
129 | | - if ($options) $wgOut->addHTML(wfMsg('ea-selectcss')." <select name=\"ea-css\">$options</select><br>\n"); |
| 130 | + $db->freeResult( $res ); |
| 131 | + if ( $options ) $wgOut->addHTML( wfMsg( 'ea-selectcss' ) . " <select name=\"ea-css\">$options</select><br>\n" ); |
130 | 132 | |
131 | 133 | # Get titles in Category:Records and build option list |
132 | | - $options = '<option/>'; |
133 | | - $cl = $db->tableName('categorylinks'); |
134 | | - $cat = $db->addQuotes($wgRecordAdminCategory ? $wgRecordAdminCategory : 'Records'); |
135 | | - $res = $db->select($cl, 'cl_from', "cl_to = $cat", __METHOD__, array('ORDER BY' => 'cl_sortkey')); |
136 | | - while ($row = $db->fetchRow($res)) { |
137 | | - $t = Title::newFromID($row[0])->getText(); |
| 134 | + $options = "<option />"; |
| 135 | + $cl = $db->tableName( 'categorylinks' ); |
| 136 | + $cat = $db->addQuotes( $wgRecordAdminCategory ? $wgRecordAdminCategory : 'Records' ); |
| 137 | + $res = $db->select( $cl, 'cl_from', "cl_to = $cat", __METHOD__, array( 'ORDER BY' => 'cl_sortkey' ) ); |
| 138 | + while ( $row = $db->fetchRow( $res ) ) { |
| 139 | + $t = Title::newFromID( $row[0] )->getText(); |
138 | 140 | $selected = $t == $this->record ? ' selected' : ''; |
139 | 141 | $options .= "<option$selected>$t</option>"; |
140 | 142 | } |
141 | | - $db->freeResult($res); |
142 | | - $wgOut->addHTML(wfMsg('ea-selectrecord')." <select name=\"ea-record\">$options</select>"); |
| 143 | + $db->freeResult( $res ); |
| 144 | + $wgOut->addHTML( wfMsg( 'ea-selectrecord' ) . " <select name=\"ea-record\">$options</select>" ); |
| 145 | + $wgOut->addHTML( "</fieldset>" ); |
143 | 146 | |
144 | | - $wgOut->addHTML("</fieldset>"); |
145 | | - |
146 | 147 | # Submit buttons & hidden values |
147 | | - $wgOut->addHTML(Xml::element('input', array('type' => 'submit', 'name' => 'ea-send', 'value' => wfMsg('ea-send')))); |
148 | | - $wgOut->addHTML(Xml::element('input', array('type' => 'submit', 'name' => 'ea-show', 'value' => wfMsg('ea-show')))); |
149 | | - $wgOut->addHTML(Xml::element('input', array('type' => 'hidden', 'name' => 'ea-title', 'value' => $this->title))); |
| 148 | + $wgOut->addHTML(Xml::element( 'input', array( 'type' => 'submit', 'name' => 'ea-send', 'value' => wfMsg( 'ea-send' ) ) ) . ' ' ); |
| 149 | + $wgOut->addHTML(Xml::element( 'input', array( 'type' => 'submit', 'name' => 'ea-show', 'value' => wfMsg( 'ea-show' ) ) ) ); |
| 150 | + $wgOut->addHTML(Xml::element( 'input', array( 'type' => 'hidden', 'name' => 'ea-title', 'value' => $this->title ) ) ); |
150 | 151 | |
151 | | - $wgOut->addHTML('</form>'); |
| 152 | + $wgOut->addHTML( "</form>" ); |
152 | 153 | |
153 | 154 | # If the show button was clicked, render the list |
154 | | - if (isset($_REQUEST['ea-show'])) return $this->send(false); |
| 155 | + if ( isset( $_REQUEST['ea-show'] ) ) return $this->send( false ); |
155 | 156 | } |
156 | 157 | |
157 | | - # Send the message to the recipients (or just list them if arg = false) |
158 | | - function send($send = true) { |
| 158 | + /** |
| 159 | + * Send the message to the recipients (or just list them if arg = false) |
| 160 | + */ |
| 161 | + function send( $send = true ) { |
159 | 162 | global $wgOut, $wgUser, $wgParser, $wgServer, $wgScript, $wgArticlePath, $wgScriptPath, |
160 | 163 | $wgEmailPageCss, $wgEmailPageGroup, $wgEmailPageAllowRemoteAddr, $wgEmailPageAllowAllUsers; |
161 | 164 | |
162 | 165 | # Set error and bail if user not in postmaster group, and request not from trusted address |
163 | | - if ($wgEmailPageGroup && !in_array($wgEmailPageGroup, $wgUser->getGroups()) && !in_array($_SERVER['REMOTE_ADDR'], $wgEmailPageAllowRemoteAddr)) { |
164 | | - $denied = wfMsg('ea-denied'); |
165 | | - $wgOut->addWikiText( wfMsg('ea-error', $this->title, $denied )); |
| 166 | + if ( $wgEmailPageGroup && !in_array( $wgEmailPageGroup, $wgUser->getGroups() ) |
| 167 | + && !in_array( $_SERVER['REMOTE_ADDR'], $wgEmailPageAllowRemoteAddr ) ) { |
| 168 | + $denied = wfMsg( 'ea-denied' ); |
| 169 | + $wgOut->addWikiText( wfMsg( 'ea-error', $this->title, $denied ) ); |
166 | 170 | return false; |
167 | 171 | } |
168 | 172 | |
169 | | - $db = wfGetDB(DB_SLAVE); |
170 | | - $title = Title::newFromText($this->title); |
| 173 | + $db = wfGetDB( DB_SLAVE ); |
| 174 | + $title = Title::newFromText( $this->title ); |
171 | 175 | $opt = new ParserOptions; |
172 | 176 | |
173 | 177 | # Get contact page titles from selected cat |
174 | | - if ($this->cat) { |
| 178 | + if ( $this->cat ) { |
175 | 179 | $res = $db->select( |
176 | 180 | 'categorylinks', |
177 | 181 | 'cl_from', |
178 | | - 'cl_to = '.$db->addQuotes($this->cat), |
| 182 | + 'cl_to = '.$db->addQuotes( $this->cat ), |
179 | 183 | __METHOD__, |
180 | | - array('ORDER BY' => 'cl_sortkey') |
| 184 | + array( 'ORDER BY' => 'cl_sortkey' ) |
181 | 185 | ); |
182 | | - if ($res) while ($row = $db->fetchRow($res)) $this->addRecipient(Title::newFromID($row[0])); |
183 | | - $db->freeResult($res); |
| 186 | + if ( $res ) while ( $row = $db->fetchRow( $res ) ) $this->addRecipient( Title::newFromID( $row[0] ) ); |
| 187 | + $db->freeResult( $res ); |
184 | 188 | } |
185 | 189 | |
186 | 190 | # Get email addresses from users in selected group |
187 | | - if ($this->group && ($wgEmailPageAllowAllUsers || $this->group != 'user')) { |
188 | | - $group = $db->addQuotes($this->group); |
| 191 | + if ( $this->group && ( $wgEmailPageAllowAllUsers || $this->group != 'user' ) ) { |
| 192 | + $group = $db->addQuotes( $this->group ); |
189 | 193 | $res = $this->group == 'user' |
190 | | - ? $db->select('user', 'user_email', 'user_email != \'\'', __METHOD__) |
191 | | - : $db->select(array('user', 'user_groups'), 'user_email', "ug_user = user_id AND ug_group = $group", __METHOD__); |
192 | | - while ($row = $db->fetchRow($res)) $this->addRecipient($row[0]); |
193 | | - $db->freeResult($res); |
| 194 | + ? $db->select( 'user', 'user_email', 'user_email != \'\'', __METHOD__ ) |
| 195 | + : $db->select( array( 'user', 'user_groups' ), 'user_email', "ug_user = user_id AND ug_group = $group", __METHOD__ ); |
| 196 | + while ( $row = $db->fetchRow( $res ) ) $this->addRecipient( $row[0] ); |
| 197 | + $db->freeResult( $res ); |
194 | 198 | } |
195 | 199 | |
196 | 200 | # Recipients from list (expand templates in wikitext) |
197 | | - $list = $wgParser->preprocess($this->list, $title, $opt); |
198 | | - foreach (preg_split("/[\\x00-\\x1f,;*]+/", $list) as $item) $this->addRecipient($item); |
| 201 | + $list = $wgParser->preprocess( $this->list, $title, $opt ); |
| 202 | + foreach ( preg_split( "/[\\x00-\\x1f,;*]+/", $list ) as $item ) $this->addRecipient( $item ); |
199 | 203 | |
200 | 204 | # Compose the wikitext content of the page to send |
201 | | - $page = new Article($title); |
| 205 | + $page = new Article( $title ); |
202 | 206 | $message = $page->getContent(); |
203 | | - if ($this->header) $message = "{$this->header}\n\n$message"; |
| 207 | + if ( $this->header ) $message = "{$this->header}\n\n$message"; |
204 | 208 | |
205 | 209 | # Convert the message text to html unless textonly |
206 | | - if ($this->textonly == '') { |
| 210 | + if ( $this->textonly == '' ) { |
207 | 211 | |
208 | 212 | # Parse the wikitext using absolute URL's for local page links |
209 | 213 | $tmp = array($wgArticlePath, $wgScriptPath, $wgScript); |
— | — | @@ -213,47 +217,47 @@ |
214 | 218 | list($wgArticlePath,$wgScriptPath,$wgScript) = $tmp; |
215 | 219 | |
216 | 220 | # Get CSS content if any |
217 | | - if ($this->css) { |
218 | | - $page = new Article(Title::newFromText($this->css)); |
219 | | - $css = '<style type="text/css">'.$page->getContent().'</style>'; |
220 | | - } else $css = ''; |
| 221 | + if ( $this->css ) { |
| 222 | + $page = new Article( Title::newFromText( $this->css ) ); |
| 223 | + $css = "<style type='text/css'>" . $page->getContent() . "</style>"; |
| 224 | + } else $css = ''; |
221 | 225 | |
222 | 226 | # Create a html wrapper for the message |
223 | 227 | $head = "<head>$css</head>"; |
224 | | - $message = "<html>$head<body style=\"margin:10px\"><div id=\"#bodyContent\">$message</div></body></html>"; |
| 228 | + $message = "<html>$head<body style=\"margin:10px\"><div id=\"bodyContent\">$message</div></body></html>"; |
225 | 229 | } |
226 | 230 | |
227 | 231 | # Send message or list recipients |
228 | | - $count = count($this->recipients); |
229 | | - if ($count > 0) { |
| 232 | + $count = count( $this->recipients ); |
| 233 | + if ( $count > 0 ) { |
230 | 234 | |
231 | 235 | # Set up new mailer instance if sending |
232 | | - if ($send) { |
| 236 | + if ( $send ) { |
233 | 237 | $mail = new PHPMailer(); |
234 | | - $mail->From = $wgUser->isValidEmailAddr($wgUser->getEmail()) ? $wgUser->getEmail() : "wiki@$wgServer"; |
235 | | - $mail->FromName = User::whoIsReal($wgUser->getId()); |
| 238 | + $mail->From = $wgUser->isValidEmailAddr( $wgUser->getEmail() ) ? $wgUser->getEmail() : "wiki@$wgServer"; |
| 239 | + $mail->FromName = User::whoIsReal( $wgUser->getId() ); |
236 | 240 | $mail->Subject = $this->subject; |
237 | 241 | $mail->Body = $message; |
238 | | - $mail->IsHTML(!$this->textonly); |
| 242 | + $mail->IsHTML( !$this->textonly ); |
239 | 243 | } |
240 | | - else $msg = wfMsg('ea-listrecipients', $count); |
| 244 | + else $msg = wfMsg( 'ea-listrecipients', $count ); |
241 | 245 | |
242 | 246 | # Loop through recipients sending or adding to list |
243 | | - foreach ($this->recipients as $recipient) { |
| 247 | + foreach ( $this->recipients as $recipient ) { |
244 | 248 | $error = ''; |
245 | | - if ($send) { |
246 | | - if ($this->record) $mail->Body = $this->replaceFields($message, $recipient); |
247 | | - $mail->AddAddress($recipient); |
248 | | - if ($state = $mail->Send()) $msg = wfMsg('ea-sent', $this->title, $count, $wgUser->getName()); |
| 249 | + if ( $send ) { |
| 250 | + if ( $this->record ) $mail->Body = $this->replaceFields( $message, $recipient ); |
| 251 | + $mail->AddAddress( $recipient ); |
| 252 | + if ( $state = $mail->Send() ) $msg = wfMsg( 'ea-sent', $this->title, $count, $wgUser->getName() ); |
249 | 253 | else $error .= "Couldn't send to $recipient: {$mail->ErrorInfo}<br>\n"; |
250 | 254 | $mail->ClearAddresses(); |
251 | 255 | } else $msg .= "\n*[mailto:$recipient $recipient]"; |
252 | | - if ($error) $msg = wfMsg('ea-error', $this->title, $error); |
| 256 | + if ( $error ) $msg = wfMsg( 'ea-error', $this->title, $error ); |
253 | 257 | } |
254 | 258 | } |
255 | | - else $msg = wfMsg('ea-error', $this->title, wfMsg('ea-norecipients')); |
| 259 | + else $msg = wfMsg( 'ea-error', $this->title, wfMsg( 'ea-norecipients' ) ); |
256 | 260 | |
257 | | - $wgOut->addWikiText($msg); |
| 261 | + $wgOut->addWikiText( $msg ); |
258 | 262 | return $send ? $state : $count; |
259 | 263 | } |
260 | 264 | |
— | — | @@ -261,13 +265,13 @@ |
262 | 266 | * Add a recipient the list |
263 | 267 | * - accepts title objects for page containing email address, or string of actual address |
264 | 268 | */ |
265 | | - function addRecipient($recipient) { |
266 | | - if (is_object($recipient) && $recipient->exists()) { |
267 | | - $page = new Article($recipient); |
268 | | - if (preg_match("|[a-z0-9_.-]+@[a-z0-9_.-]+|i", $page->getContent(), $emails)) $recipient = $emails[0]; |
| 269 | + function addRecipient( $recipient ) { |
| 270 | + if ( is_object( $recipient ) && $recipient->exists() ) { |
| 271 | + $page = new Article( $recipient ); |
| 272 | + if ( preg_match( "|[a-z0-9_.-]+@[a-z0-9_.-]+|i", $page->getContent(), $emails ) ) $recipient = $emails[0]; |
269 | 273 | else $recipient = ''; |
270 | 274 | } |
271 | | - if ($valid = User::isValidEmailAddr($recipient)) $this->recipients[] = $recipient; |
| 275 | + if ( $valid = User::isValidEmailAddr( $recipient ) ) $this->recipients[] = $recipient; |
272 | 276 | return $valid; |
273 | 277 | } |
274 | 278 | |
— | — | @@ -275,44 +279,43 @@ |
276 | 280 | * Replace fields in message (enclosed in single braces) |
277 | 281 | * - fields can have a default value, eg {name|default} |
278 | 282 | */ |
279 | | - function replaceFields($text, $email) { |
| 283 | + function replaceFields( $text, $email ) { |
280 | 284 | |
281 | 285 | # Scan all records of this type for the first containing matching email address |
282 | 286 | $dbr = $this->db; |
283 | | - $tbl = $dbr->tableName('templatelinks'); |
284 | | - $type = $dbr->addQuotes($this->record); |
285 | | - $res = $dbr->select($tbl, 'tl_from', "tl_namespace = 10 AND tl_title = $type", __METHOD__); |
286 | | - while ($row = $dbr->fetchRow($res)) { |
287 | | - $a = new Article(Title::newFromID($row[0])); |
| 287 | + $tbl = $dbr->tableName( 'templatelinks' ); |
| 288 | + $type = $dbr->addQuotes( $this->record ); |
| 289 | + $res = $dbr->select( $tbl, 'tl_from', "tl_namespace = 10 AND tl_title = $type", __METHOD__ ); |
| 290 | + while ( $row = $dbr->fetchRow( $res ) ) { |
| 291 | + $a = new Article( Title::newFromID( $row[0] ) ); |
288 | 292 | $c = $a->getContent(); |
289 | 293 | |
290 | 294 | # Check if this records email address matches |
291 | | - if (preg_match("|\s*\|\s*\w+\s*=\s*$email\s*(?=[\|\}])|s", $c)) { |
| 295 | + if ( preg_match( "|\s*\|\s*\w+\s*=\s*$email\s*(?=[\|\}])|s", $c ) ) { |
292 | 296 | |
293 | 297 | # Extract all the fields from the content (should use examineBraces here) |
294 | 298 | $this->args = array(); |
295 | | - preg_match_all("|\|\s*(.+?)\s*=\s*(.*?)\s*(?=[\|\}])|s", $c, $m); |
296 | | - foreach ($m[1] as $i => $k) $this->args[strtolower($k)] = $m[2][$i]; |
| 299 | + preg_match_all( "|\|\s*(.+?)\s*=\s*(.*?)\s*(?=[\|\}])|s", $c, $m ); |
| 300 | + foreach ( $m[1] as $i => $k ) $this->args[strtolower( $k )] = $m[2][$i]; |
297 | 301 | |
298 | 302 | # Replace any fields in the message text with our extracted args (should use wiki parser for this) |
299 | | - $text = preg_replace_callback("|\{(\w+)(\|(.+?))?\}|s", array($this, 'replaceField'), $text); |
| 303 | + $text = preg_replace_callback( "|\{(\w+)(\|(.+?))?\}|s", array( $this, 'replaceField' ), $text ); |
300 | 304 | |
301 | 305 | break; |
302 | 306 | } |
303 | 307 | } |
304 | | - $dbr->freeResult($res); |
| 308 | + $dbr->freeResult( $res ); |
305 | 309 | return $text; |
306 | 310 | } |
307 | 311 | |
308 | 312 | /** |
309 | 313 | * Replace a single field |
310 | 314 | */ |
311 | | - function replaceField($match) { |
312 | | - $key = strtolower($match[1]); |
313 | | - $default = isset($match[3]) ? $match[3] : false; |
314 | | - if (array_key_exists($key, $this->args)) $replace = $this->args[$key]; |
| 315 | + function replaceField( $match ) { |
| 316 | + $key = strtolower( $match[1] ); |
| 317 | + $default = isset( $match[3] ) ? $match[3] : false; |
| 318 | + if ( array_key_exists( $key, $this->args ) ) $replace = $this->args[$key]; |
315 | 319 | else $replace = $default ? $default : $match[0]; |
316 | 320 | return $replace; |
317 | 321 | } |
318 | | - |
319 | 322 | } |
Index: trunk/extensions/EmailPage/EmailPage.php |
— | — | @@ -13,7 +13,7 @@ |
14 | 14 | |
15 | 15 | if (!defined('MEDIAWIKI')) die('Not an entry point.'); |
16 | 16 | |
17 | | -define('EMAILPAGE_VERSION', '1.3.1, 2008-11-05'); |
| 17 | +define('EMAILPAGE_VERSION', '1.3.2, 2008-11-05'); |
18 | 18 | |
19 | 19 | $wgEmailPageGroup = 'sysop'; # Users must belong to this group to send emails (empty string means anyone can send) |
20 | 20 | $wgEmailPageContactsCat = ''; # This specifies the name of a category containing categories of contact pages |