r78101 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78100‎ | r78101 | r78102 >
Date:23:09, 8 December 2010
Author:platonides
Status:resolved (Comments)
Tags:
Comment:
Move wfQuotedPrintable() into UserMailer class
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/UserMailer.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -1298,30 +1298,6 @@
12991299
13001300 /**
13011301 * @todo document
1302 - */
1303 -function wfQuotedPrintable( $string, $charset = '' ) {
1304 - # Probably incomplete; see RFC 2045
1305 - if( empty( $charset ) ) {
1306 - global $wgInputEncoding;
1307 - $charset = $wgInputEncoding;
1308 - }
1309 - $charset = strtoupper( $charset );
1310 - $charset = str_replace( 'ISO-8859', 'ISO8859', $charset ); // ?
1311 -
1312 - $illegal = '\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xff=';
1313 - $replace = $illegal . '\t ?_';
1314 - if( !preg_match( "/[$illegal]/", $string ) ) {
1315 - return $string;
1316 - }
1317 - $out = "=?$charset?Q?";
1318 - $out .= preg_replace( "/([$replace])/e", 'sprintf("=%02X",ord("$1"))', $string );
1319 - $out .= '?=';
1320 - return $out;
1321 -}
1322 -
1323 -
1324 -/**
1325 - * @todo document
13261302 * @return float
13271303 */
13281304 function wfTime() {
Index: trunk/phase3/includes/UserMailer.php
@@ -58,7 +58,7 @@
5959 if ( $this->name != '' && !wfIsWindows() ) {
6060 global $wgEnotifUseRealName;
6161 $name = ( $wgEnotifUseRealName && $this->realName ) ? $this->realName : $this->name;
62 - $quoted = wfQuotedPrintable( $name );
 62+ $quoted = UserMailer::quotedPrintable( $name );
6363 if ( strpos( $quoted, '.' ) !== false || strpos( $quoted, ',' ) !== false ) {
6464 $quoted = '"' . $quoted . '"';
6565 }
@@ -162,7 +162,7 @@
163163 if ( $replyto ) {
164164 $headers['Reply-To'] = $replyto->toString();
165165 }
166 - $headers['Subject'] = wfQuotedPrintable( $subject );
 166+ $headers['Subject'] = self::quotedPrintable( $subject );
167167 $headers['Date'] = date( 'r' );
168168 $headers['MIME-Version'] = '1.0';
169169 $headers['Content-type'] = ( is_null( $contentType ) ?
@@ -225,10 +225,10 @@
226226
227227 if ( is_array( $to ) ) {
228228 foreach ( $to as $recip ) {
229 - $sent = mail( $recip->toString(), wfQuotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams );
 229+ $sent = mail( $recip->toString(), self::quotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams );
230230 }
231231 } else {
232 - $sent = mail( $to->toString(), wfQuotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams );
 232+ $sent = mail( $to->toString(), self::quotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams );
233233 }
234234
235235 restore_error_handler();
@@ -264,6 +264,29 @@
265265 $phrase = strtr( $phrase, array( "\r" => '', "\n" => '', '"' => '' ) );
266266 return '"' . $phrase . '"';
267267 }
 268+
 269+ /**
 270+ * Converts a string into quoted-printable format
 271+ */
 272+ public static function quotedPrintable( $string, $charset = '' ) {
 273+ # Probably incomplete; see RFC 2045
 274+ if( empty( $charset ) ) {
 275+ global $wgInputEncoding;
 276+ $charset = $wgInputEncoding;
 277+ }
 278+ $charset = strtoupper( $charset );
 279+ $charset = str_replace( 'ISO-8859', 'ISO8859', $charset ); // ?
 280+
 281+ $illegal = '\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xff=';
 282+ $replace = $illegal . '\t ?_';
 283+ if( !preg_match( "/[$illegal]/", $string ) ) {
 284+ return $string;
 285+ }
 286+ $out = "=?$charset?Q?";
 287+ $out .= preg_replace( "/([$replace])/e", 'sprintf("=%02X",ord("$1"))', $string );
 288+ $out .= '?=';
 289+ return $out;
 290+ }
268291 }
269292
270293 /**
@@ -642,4 +665,9 @@
643666 wfDeprecated( __FUNCTION__ );
644667 return UserMailer::send( $to, $from, $subject, $body, $replyto );
645668 }
646 -/**@}*/
\ No newline at end of file
 669+
 670+function wfQuotedPrintable( $string, $charset = '' ) {
 671+ wfDeprecated( __FUNCTION__ );
 672+ return UserMailer::quotedPrintable( $string, $charset );
 673+}
 674+/**@}*/

Follow-up revisions

RevisionCommit summaryAuthorDate
r78102Follow up r78101.platonides23:10, 8 December 2010
r78121Follow-up r78101:...siebrand11:27, 9 December 2010
r78195Followup r78101 fixme, remove wfQuotedPrintable per Roans CRreedy15:48, 10 December 2010

Comments

#Comment by Reedy (talk | contribs)   23:57, 8 December 2010

Probably worth adding a comment to say when it was deprecated?

#Comment by Platonides (talk | contribs)   15:52, 9 December 2010

Added by Siebrand in r78121

#Comment by Catrope (talk | contribs)   16:50, 9 December 2010
+function wfQuotedPrintable( $string, $charset = '' ) {
+	wfDeprecated( __FUNCTION__ );
+	return UserMailer::quotedPrintable( $string, $charset );
+}
+/**@}*/

This function has to be put in GlobalFunctions.php , or it won't work when called from random places when UserMailer.php hasn't been loaded yet.

#Comment by Platonides (talk | contribs)   17:07, 9 December 2010

This function wasn't called from anywhere else than UserMailer. Zero usage from svn extensions, too. So I don't think it will be called from any place.

#Comment by Catrope (talk | contribs)   17:09, 9 December 2010

Then kill it. There's no use keepinga back-compat deprecated function around if it'll break in seemingly random situations.

Status & tagging log