r19933 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r19932‎ | r19933 | r19934 >
Date:23:45, 14 February 2007
Author:daniel
Status:old
Tags:
Comment:
using standard wfMsg() function; plus a compatibility hack for 1.9 vs. 1.10
Modified paths:
  • /trunk/extensions/ContactPage/ContactPage.php (modified) (history)
  • /trunk/extensions/ContactPage/SpecialContact.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ContactPage/SpecialContact.php
@@ -30,7 +30,7 @@
3131 SpecialPage::SpecialPage( 'Contact', '', true );
3232
3333 #inject messages
34 - cpMsg(false);
 34+ loadContactPageI18n();
3535 }
3636
3737 /**
@@ -101,11 +101,11 @@
102102
103103 #TODO: show captcha
104104
105 - $wgOut->setPagetitle( cpMsg( "title" ) );
106 - $wgOut->addWikiText( cpMsg( "pagetext" ) );
 105+ $wgOut->setPagetitle( wfMsg( "contactpage-title" ) );
 106+ $wgOut->addWikiText( wfMsg( "contactpage-pagetext" ) );
107107
108108 if ( $this->subject === "" ) {
109 - $this->subject = cpMsg( "defsubject" );
 109+ $this->subject = wfMsg( "contactpage-defsubject" );
110110 }
111111
112112 #$emf = wfMsg( "emailfrom" );
@@ -116,8 +116,8 @@
117117 $emm = wfMsg( "emailmessage" );
118118 $ems = wfMsg( "emailsend" );
119119 $emc = wfMsg( "emailccme" );
120 - $emfn = cpMsg( "fromname" );
121 - $emfa = cpMsg( "fromaddress" );
 120+ $emfn = wfMsg( "contactpage-fromname" );
 121+ $emfa = wfMsg( "contactpage-fromaddress" );
122122 $encSubject = htmlspecialchars( $this->subject );
123123 $encFromName = htmlspecialchars( $this->fromname );
124124 $encFromAddress = htmlspecialchars( $this->fromaddress );
@@ -148,7 +148,7 @@
149149 <tr>
150150 <td></td>
151151 <td align='left'>
152 -<small>".cpMsg( "formfootnotes" )."</small>
 152+<small>".wfMsg( "contactpage-formfootnotes" )."</small>
153153 </td>
154154 </tr>
155155 </table>
@@ -179,8 +179,15 @@
180180 if( wfRunHooks( 'ContactForm', array( &$to, &$replyto, &$subject, &$this->text ) ) ) {
181181
182182 wfDebug( "$fname: sending mail from ".$from->toString()." to ".$to->toString()." replyto ".($replyto==null?'-/-':$replyto->toString())."\n" );
183 - $mailResult = userMailer( $to, $from, $subject, $this->text, $replyto ? $replyto->toString() : NULL ); #TODO: staring with MW 1.10, $replyto should be passed as an object
184183
 184+ #HACK: in MW 1.9, replyto must be a string, in MW 1.0, it must be an object!
 185+ $ver = preg_replace( '![^\d._+]!', '', $GLOBALS['wgVersion'] );
 186+ $replyaddr = $replyto == null
 187+ ? NULL : version_compare( $ver, '1.10', '<' )
 188+ ? $replyto->toString() : $replyto;
 189+
 190+ $mailResult = userMailer( $to, $from, $subject, $this->text, $replyaddr );
 191+
185192 if( WikiError::isError( $mailResult ) ) {
186193 $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
187194 } else {
Index: trunk/extensions/ContactPage/ContactPage.php
@@ -30,11 +30,15 @@
3131 $wgContactSenderName = 'Contact Form on ' . $wgSitename;
3232
3333 /**
34 -* load the CategoryTree internationalization file
 34+* load the ContactPage internationalization file
3535 */
36 -function cpLoadMessages() {
37 - global $wgLang;
38 -
 36+function loadContactPageI18n() {
 37+ global $wgLang, $wgMessageCache;
 38+
 39+ static $initialized = false;
 40+
 41+ if ( $initialized ) return;
 42+
3943 $messages= array();
4044
4145 $f= dirname( __FILE__ ) . '/ContactPage.i18n.php';
@@ -43,29 +47,8 @@
4448 $f= dirname( __FILE__ ) . '/ContactPage.i18n.' . $wgLang->getCode() . '.php';
4549 if ( file_exists( $f ) ) include( $f );
4650
47 - return $messages;
 51+ $initialized = true;
 52+ $wgMessageCache->addMessages( $messages );
4853 }
4954
50 -/**
51 -* Get a ContactPage message, "contactpage-" prefix added automatically
52 -*/
53 -function cpMsg( $msg /*, ...*/ ) {
54 - static $initialized = false;
55 - global $wgMessageCache;
56 - if ( !$initialized ) {
57 - $wgMessageCache->addMessages( cpLoadMessages() );
58 - $initialized = true;
59 - }
60 - if ( $msg === false ) {
61 - return null;
62 - }
63 - $args = func_get_args();
64 - $msg = array_shift( $args );
65 - if ( $msg == '' ) {
66 - return wfMsgReal( $msg, $args );
67 - } else {
68 - return wfMsgReal( "contactpage-$msg", $args );
69 - }
70 -}
71 -
7255 ?>
\ No newline at end of file