r75771 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75770‎ | r75771 | r75772 >
Date:02:01, 1 November 2010
Author:nad
Status:deferred
Tags:
Comment:
dont add recipient to list if already rpesent
Modified paths:
  • /trunk/extensions/EmailPage/EmailPage_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EmailPage/EmailPage_body.php
@@ -6,7 +6,7 @@
77 var $recipients = array();
88 var $title;
99 var $subject;
10 - var $header;
 10+ var $message;
1111 var $group;
1212 var $list;
1313 var $textonly;
@@ -26,7 +26,7 @@
2727 */
2828 function execute( $param ) {
2929 global $wgOut, $wgUser, $wgRequest, $wgParser, $wgEmailPageContactsCat, $wgGroupPermissions, $wgSitename,
30 - $wgRecordAdminCategory, $wgEmailPageCss, $wgEmailPageAllowAllUsers;
 30+ $wgRecordAdminCategory, $wgEmailPageCss, $wgEmailPageAllowAllUsers, $wgEmergencyContact;
3131
3232 $db = wfGetDB( DB_SLAVE );
3333 $param = str_replace( '_', ' ', $param );
@@ -35,10 +35,12 @@
3636
3737 # Get info from request or set to defaults
3838 $this->title = $wgRequest->getText( 'ea-title', $param );
 39+ $this->from = $wgRequest->getText( 'ea-from' );
3940 $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' );
4143 $this->group = $wgRequest->getText( 'ea-group' );
42 - $this->list = $wgRequest->getText( 'ea-list' );
 44+ $this->to = $wgRequest->getText( 'ea-to' ) . ";" . $wgRequest->getText( 'ea-cc' );
4345 $this->textonly = $wgRequest->getText( 'ea-textonly', false );
4446 $this->css = $wgRequest->getText( 'ea-css', $wgEmailPageCss );
4547 $this->record = $wgRequest->getText( 'ea-record', false );
@@ -49,7 +51,7 @@
5052 else return $wgOut->addWikiText( wfMsg( 'ea-nopage' ) );
5153
5254 # 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();
5456
5557 # Render form
5658 $special = SpecialPage::getTitleFor( 'EmailPage' );
@@ -58,10 +60,21 @@
5961 'action' => $special->getLocalURL( 'action=submit' ),
6062 'method' => 'POST'
6163 ), 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;\">" );
6465
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
6679 $groups = "<option />";
6780 foreach( array_keys( $wgGroupPermissions ) as $group ) if( $group != '*' && $group != 'user' ) {
6881 $selected = $group == $this->group ? ' selected' : '';
@@ -71,28 +84,40 @@
7285 $selected = 'user' == $this->group ? ' selected' : '';
7386 $groups .= "<option$selected value=\"user\">" . wfMsg( 'ea-allusers' ) . "</option>";
7487 }
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>" );
7790
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>" );
8292
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>" );
84103
85104 # 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>" );
90114
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>" );
94119
95120 # CSS
96 - $options = "<option value=''>$wgEmailPageCss</option>";
 121+ $options = '';
97122 $res = $db->select(
98123 'page',
99124 'page_id',
@@ -106,28 +131,40 @@
107132 $options .= "<option$selected>$t</option>";
108133 }
109134 $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+ }
111141
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+ }
121158 }
122 - $db->freeResult( $res );
123 - $wgOut->addHTML( wfMsg( 'ea-selectrecord' ) . " <select name=\"ea-record\">$options</select>" );
124 - $wgOut->addHTML( "</fieldset>" );
125159
126160 # 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( "&nbsp;&nbsp;" );
127165 $wgOut->addHTML( Xml::element( 'input', array( 'type' => 'submit', 'name' => 'ea-send', 'value' => wfMsg( 'ea-send' ) ) ) . '&#160;' );
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>" );
130167
131 - $wgOut->addHTML( "</form>" );
 168+ $wgOut->addHTML( "</table></form>" );
132169
133170 # If the show button was clicked, render the list
134171 if( isset( $_REQUEST['ea-show'] ) ) return $this->send( false );
@@ -159,15 +196,15 @@
160197 $db->freeResult( $res );
161198 }
162199
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 );
165202
166203 # Compose the wikitext content of the page to send
167204 $title = Title::newFromText( $this->title );
168205 $opt = new ParserOptions;
169206 $page = new Article( $title );
170207 $message = $page->getContent();
171 - if( $this->header ) $message = "{$this->header}\n\n$message";
 208+ if( $this->message ) $message = "{$this->message}\n\n$message";
172209
173210 # Convert the message text to html unless textonly
174211 if( $this->textonly == '' ) {
@@ -199,7 +236,7 @@
200237 # Set up new mailer instance if sending
201238 if( $send ) {
202239 $mail = new PHPMailer();
203 - $mail->From = $wgUser->isValidEmailAddr( $wgUser->getEmail() ) ? $wgUser->getEmail() : $wgEmergencyContact;
 240+ $mail->From = $this->from;
204241 $mail->FromName = User::whoIsReal( $wgUser->getId() );
205242 $mail->Subject = $this->subject;
206243 $mail->Body = $message;
@@ -227,10 +264,12 @@
228265 }
229266
230267 /**
231 - * Add a recipient the list
 268+ * Add a recipient the list if not already present
232269 */
233270 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+ }
235274 return $valid;
236275 }
237276

Status & tagging log