Index: trunk/extensions/EmailPage/EmailPage_body.php |
— | — | @@ -6,7 +6,7 @@ |
7 | 7 | var $recipients = array(); |
8 | 8 | var $title; |
9 | 9 | var $subject; |
10 | | - var $header; |
| 10 | + var $message; |
11 | 11 | var $group; |
12 | 12 | var $list; |
13 | 13 | var $textonly; |
— | — | @@ -26,7 +26,7 @@ |
27 | 27 | */ |
28 | 28 | function execute( $param ) { |
29 | 29 | global $wgOut, $wgUser, $wgRequest, $wgParser, $wgEmailPageContactsCat, $wgGroupPermissions, $wgSitename, |
30 | | - $wgRecordAdminCategory, $wgEmailPageCss, $wgEmailPageAllowAllUsers; |
| 30 | + $wgRecordAdminCategory, $wgEmailPageCss, $wgEmailPageAllowAllUsers, $wgEmergencyContact; |
31 | 31 | |
32 | 32 | $db = wfGetDB( DB_SLAVE ); |
33 | 33 | $param = str_replace( '_', ' ', $param ); |
— | — | @@ -35,10 +35,12 @@ |
36 | 36 | |
37 | 37 | # Get info from request or set to defaults |
38 | 38 | $this->title = $wgRequest->getText( 'ea-title', $param ); |
| 39 | + $this->from = $wgRequest->getText( 'ea-from' ); |
39 | 40 | $this->subject = $wgRequest->getText( 'ea-subject', wfMsg( 'ea-pagesend', $this->title, $wgSitename ) ); |
40 | | - $this->header = $wgRequest->getText( 'ea-header' ); |
| 41 | + $this->message = $wgRequest->getText( 'ea-message' ); |
| 42 | + $this->message = $wgRequest->getText( 'ea-message' ); |
41 | 43 | $this->group = $wgRequest->getText( 'ea-group' ); |
42 | | - $this->list = $wgRequest->getText( 'ea-list' ); |
| 44 | + $this->to = $wgRequest->getText( 'ea-to' ) . ";" . $wgRequest->getText( 'ea-cc' ); |
43 | 45 | $this->textonly = $wgRequest->getText( 'ea-textonly', false ); |
44 | 46 | $this->css = $wgRequest->getText( 'ea-css', $wgEmailPageCss ); |
45 | 47 | $this->record = $wgRequest->getText( 'ea-record', false ); |
— | — | @@ -49,7 +51,7 @@ |
50 | 52 | else return $wgOut->addWikiText( wfMsg( 'ea-nopage' ) ); |
51 | 53 | |
52 | 54 | # If the send button was clicked, attempt to send and exit |
53 | | - if( isset( $_REQUEST['ea-send'] ) ) return $this->send(); |
| 55 | + if( $wgRequest->getText( 'ea-send', false ) ) return $this->send(); |
54 | 56 | |
55 | 57 | # Render form |
56 | 58 | $special = SpecialPage::getTitleFor( 'EmailPage' ); |
— | — | @@ -58,10 +60,21 @@ |
59 | 61 | 'action' => $special->getLocalURL( 'action=submit' ), |
60 | 62 | 'method' => 'POST' |
61 | 63 | ), null ) ); |
62 | | - $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'ea-selectrecipients' ) . '</legend>' ); |
63 | | - $wgOut->addHTML( '<table style="padding:0;margin:0;border:none;">' ); |
| 64 | + $wgOut->addHTML( "<table style=\"padding:0;margin:0;border:none;\">" ); |
64 | 65 | |
65 | | - # Allow selection of a group |
| 66 | + # From (dropdown list of self and wiki addresses) |
| 67 | + $from = "<option>$wgEmergencyContact</option>"; |
| 68 | + $ue = $wgUser->getEmail(); |
| 69 | + if( $wgUser->isValidEmailAddr( $ue ) ) $from = "<option>$ue</option>$from"; else $ue = ""; |
| 70 | + $wgOut->addHTML( "<tr id=\"ea-from\"><th align=\"right\">" . wfMsg( 'ea-from' ) . ":</th>" ); |
| 71 | + $wgOut->addHTML( "<td><select name=\"ea-from\">$from</select></td></tr>\n" ); |
| 72 | + |
| 73 | + # To |
| 74 | + $wgOut->addHTML( "<tr id=\"ea-to\"><th align=\"right\" valign=\"top\">" . wfMsg( 'ea-to' ) . ":</th>" ); |
| 75 | + $wgOut->addHTML( "<td><textarea name=\"ea-to\" rows=\"2\" style=\"width:100%\"></textarea>" ); |
| 76 | + $wgOut->addHTML( "<br /><small><i>(" . wfMsg( 'ea-to-info' ) . ")</i></small>" ); |
| 77 | + |
| 78 | + # To group |
66 | 79 | $groups = "<option />"; |
67 | 80 | foreach( array_keys( $wgGroupPermissions ) as $group ) if( $group != '*' && $group != 'user' ) { |
68 | 81 | $selected = $group == $this->group ? ' selected' : ''; |
— | — | @@ -71,28 +84,40 @@ |
72 | 85 | $selected = 'user' == $this->group ? ' selected' : ''; |
73 | 86 | $groups .= "<option$selected value=\"user\">" . wfMsg( 'ea-allusers' ) . "</option>"; |
74 | 87 | } |
75 | | - $wgOut->addHTML( "<tr><td>" . wfMsg( 'ea-fromgroup' ) . "</td><td><select name=\"ea-group\">$groups</select></td></tr>\n" ); |
76 | | - $wgOut->addHTML( "</table>" ); |
| 88 | + $wgOut->addHTML( "<div id=\"ea-group\"><select name=\"ea-group\">$groups</select>" ); |
| 89 | + $wgOut->addHTML( " <i><small>(" . wfMsg( 'ea-group-info' ) . "</small></i></div>" ); |
77 | 90 | |
78 | | - # Addition of named list |
79 | | - $wgOut->addWikiText( wfMsg( 'ea-selectlist' ) ); |
80 | | - $wgOut->addHTML( "<textarea name=\"ea-list\" rows=\"5\">{$this->list}</textarea><br />\n" ); |
81 | | - $wgOut->addHTML( "</fieldset>" ); |
| 91 | + $wgOut->addHTML( "</td></tr>" ); |
82 | 92 | |
83 | | - $wgOut->addHTML( "<fieldset><legend>" . wfMsg( 'ea-compose' ) . "</legend>" ); |
| 93 | + # Cc |
| 94 | + $wgOut->addHTML( "<tr id=\"ea-cc\"><th align=\"right\">" . wfMsg( 'ea-cc' ) . ":</th>" ); |
| 95 | + $wgOut->addHTML( "<td>" . |
| 96 | + Xml::element( 'input', array( |
| 97 | + 'type' => 'text', |
| 98 | + 'name' => 'ea-cc', |
| 99 | + 'value' => $ue, |
| 100 | + 'style' => "width:100%" |
| 101 | + ) ) |
| 102 | + . "</td></tr>" ); |
84 | 103 | |
85 | 104 | # Subject |
86 | | - $wgOut->addWikiText( wfMsg( 'ea-subject' ) ); |
87 | | - $wgOut->addHTML( |
88 | | - Xml::element( 'input', array( 'type' => 'text', 'name' => 'ea-subject', 'value' => $this->subject, 'style' => "width:100%" ) ) |
89 | | - ); |
| 105 | + $wgOut->addHTML( "<tr id=\"ea-subject\"><th align=\"right\">" . wfMsg( 'ea-subject' ) . ":</th>" ); |
| 106 | + $wgOut->addHTML( "<td>" . |
| 107 | + Xml::element( 'input', array( |
| 108 | + 'type' => 'text', |
| 109 | + 'name' => 'ea-subject', |
| 110 | + 'value' => $this->subject, |
| 111 | + 'style' => "width:100%" |
| 112 | + ) ) |
| 113 | + . "</td></tr>" ); |
90 | 114 | |
91 | | - # Header |
92 | | - $wgOut->addWikiText( wfMsg( 'ea-header' ) ); |
93 | | - $wgOut->addHTML( "<textarea name=\"ea-header\" rows=\"5\">{$this->header}</textarea><br />\n" ); |
| 115 | + # Message |
| 116 | + $wgOut->addHTML( "<tr id=\"ea-message\"><th align=\"right\" valign=\"top\">" . wfMsg( 'ea-message' ) . ":</th>" ); |
| 117 | + $wgOut->addHTML( "<td><textarea name=\"ea-header\" rows=\"3\" style=\"width:100%\">{$this->message}</textarea>" ); |
| 118 | + $wgOut->addHTML( "<br /><i><small>(" . wfMsg( 'ea-message-info' ) . ")</small></i></td></tr>" ); |
94 | 119 | |
95 | 120 | # CSS |
96 | | - $options = "<option value=''>$wgEmailPageCss</option>"; |
| 121 | + $options = ''; |
97 | 122 | $res = $db->select( |
98 | 123 | 'page', |
99 | 124 | 'page_id', |
— | — | @@ -106,28 +131,40 @@ |
107 | 132 | $options .= "<option$selected>$t</option>"; |
108 | 133 | } |
109 | 134 | $db->freeResult( $res ); |
110 | | - if( $options ) $wgOut->addHTML( wfMsg( 'ea-selectcss' ) . " <select name=\"ea-css\">$options</select><br />\n" ); |
| 135 | + if( $options ) { |
| 136 | + if( $wgEmailPageCss ) $options = "<option value=''>$wgEmailPageCss</option>$options"; |
| 137 | + $wgOut->addHTML( "<tr id=\"ea-css\"><th align=\"right\">" . wfMsg( 'ea-style' ) . ":</th><td>" ); |
| 138 | + $wgOut->addHTML( "<select name=\"ea-css\"><option />$options</select>" ); |
| 139 | + $wgOut->addHTML( " <small><i>(" . wfMsg( 'ea-selectcss' ) . ")</i></small></td></tr>" ); |
| 140 | + } |
111 | 141 | |
112 | | - # Get titles in Category:Records and build option list |
113 | | - $options = "<option />"; |
114 | | - $cl = $db->tableName( 'categorylinks' ); |
115 | | - $cat = $db->addQuotes( $wgRecordAdminCategory ? $wgRecordAdminCategory : 'Records' ); |
116 | | - $res = $db->select( $cl, 'cl_from', "cl_to = $cat", __METHOD__, array( 'ORDER BY' => 'cl_sortkey' ) ); |
117 | | - while( $row = $db->fetchRow( $res ) ) { |
118 | | - $t = Title::newFromID( $row[0] )->getText(); |
119 | | - $selected = $t == $this->record ? ' selected' : ''; |
120 | | - $options .= "<option$selected>$t</option>"; |
| 142 | + # Data |
| 143 | + if( defined( 'NS_FORM' ) ) { |
| 144 | + $options = ""; |
| 145 | + $tbl = $db->tableName( 'page' ); |
| 146 | + $res = $db->select( $tbl, 'page_id', "page_namespace = " . NS_FORM ); |
| 147 | + while( $row = $db->fetchRow( $res ) ) { |
| 148 | + $t = Title::newFromID( $row[0] )->getText(); |
| 149 | + $selected = $t == $this->record ? ' selected' : ''; |
| 150 | + $options .= "<option$selected>$t</option>"; |
| 151 | + } |
| 152 | + $db->freeResult( $res ); |
| 153 | + if( $options ) { |
| 154 | + $wgOut->addHTML( "<tr id=\"ea-data\"><th align=\"right\">" . wfMsg( 'ea-data' ) . ":</th><td>" ); |
| 155 | + $wgOut->addHTML( "<select name=\"ea-record\"><option />$options</select>" ); |
| 156 | + $wgOut->addHTML( " <small><i>(" . wfMsg( 'ea-selectrecord' ) . ")</i></small></td></tr>" ); |
| 157 | + } |
121 | 158 | } |
122 | | - $db->freeResult( $res ); |
123 | | - $wgOut->addHTML( wfMsg( 'ea-selectrecord' ) . " <select name=\"ea-record\">$options</select>" ); |
124 | | - $wgOut->addHTML( "</fieldset>" ); |
125 | 159 | |
126 | 160 | # Submit buttons & hidden values |
| 161 | + $wgOut->addHTML( "<tr><td colspan=\"2\" align=\"right\">" ); |
| 162 | + $wgOut->addHTML( Xml::element( 'input', array( 'type' => 'hidden', 'name' => 'ea-title', 'value' => $this->title ) ) ); |
| 163 | + $wgOut->addHTML( Xml::element( 'input', array( 'id' => 'ea-show', 'type' => 'submit', 'name' => 'ea-show', 'value' => wfMsg( 'ea-show' ) ) ) ); |
| 164 | + $wgOut->addHTML( " " ); |
127 | 165 | $wgOut->addHTML( Xml::element( 'input', array( 'type' => 'submit', 'name' => 'ea-send', 'value' => wfMsg( 'ea-send' ) ) ) . ' ' ); |
128 | | - $wgOut->addHTML( Xml::element( 'input', array( 'type' => 'submit', 'name' => 'ea-show', 'value' => wfMsg( 'ea-show' ) ) ) ); |
129 | | - $wgOut->addHTML( Xml::element( 'input', array( 'type' => 'hidden', 'name' => 'ea-title', 'value' => $this->title ) ) ); |
| 166 | + $wgOut->addHTML( "</td></tr>" ); |
130 | 167 | |
131 | | - $wgOut->addHTML( "</form>" ); |
| 168 | + $wgOut->addHTML( "</table></form>" ); |
132 | 169 | |
133 | 170 | # If the show button was clicked, render the list |
134 | 171 | if( isset( $_REQUEST['ea-show'] ) ) return $this->send( false ); |
— | — | @@ -159,15 +196,15 @@ |
160 | 197 | $db->freeResult( $res ); |
161 | 198 | } |
162 | 199 | |
163 | | - # Recipients from list (expand templates in wikitext) |
164 | | - foreach( preg_split( "/[\\x00-\\x1f,;*]+/", $this->list ) as $item ) $this->addRecipient( $item ); |
| 200 | + # Recipients from the "to" field |
| 201 | + foreach( preg_split( "|[\\x00-\\x1f,;*]+|", $this->to ) as $item ) $this->addRecipient( $item ); |
165 | 202 | |
166 | 203 | # Compose the wikitext content of the page to send |
167 | 204 | $title = Title::newFromText( $this->title ); |
168 | 205 | $opt = new ParserOptions; |
169 | 206 | $page = new Article( $title ); |
170 | 207 | $message = $page->getContent(); |
171 | | - if( $this->header ) $message = "{$this->header}\n\n$message"; |
| 208 | + if( $this->message ) $message = "{$this->message}\n\n$message"; |
172 | 209 | |
173 | 210 | # Convert the message text to html unless textonly |
174 | 211 | if( $this->textonly == '' ) { |
— | — | @@ -199,7 +236,7 @@ |
200 | 237 | # Set up new mailer instance if sending |
201 | 238 | if( $send ) { |
202 | 239 | $mail = new PHPMailer(); |
203 | | - $mail->From = $wgUser->isValidEmailAddr( $wgUser->getEmail() ) ? $wgUser->getEmail() : $wgEmergencyContact; |
| 240 | + $mail->From = $this->from; |
204 | 241 | $mail->FromName = User::whoIsReal( $wgUser->getId() ); |
205 | 242 | $mail->Subject = $this->subject; |
206 | 243 | $mail->Body = $message; |
— | — | @@ -227,10 +264,12 @@ |
228 | 265 | } |
229 | 266 | |
230 | 267 | /** |
231 | | - * Add a recipient the list |
| 268 | + * Add a recipient the list if not already present |
232 | 269 | */ |
233 | 270 | function addRecipient( $recipient ) { |
234 | | - if( $valid = User::isValidEmailAddr( $recipient ) ) $this->recipients[] = $recipient; |
| 271 | + if( $valid = User::isValidEmailAddr( $recipient ) && !in_array( $recipient, $this->recipients ) ) { |
| 272 | + $this->recipients[] = $recipient; |
| 273 | + } |
235 | 274 | return $valid; |
236 | 275 | } |
237 | 276 | |