r81966 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81965‎ | r81966 | r81967 >
Date:14:46, 11 February 2011
Author:btongminh
Status:ok (Comments)
Tags:
Comment:
Fixes for NewUserMessage:
* If subject/text is empty, don't wrap it in {{braces}}
* For backwards compatibility, fallback to newusermessage-template
* If subject is empty, don't add == heading ==
Modified paths:
  • /trunk/extensions/NewUserMessage/NewUserMessage.class.php (modified) (history)
  • /trunk/extensions/NewUserMessage/NewUserMessage.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/NewUserMessage/NewUserMessage.i18n.php
@@ -15,6 +15,7 @@
1616 $messages['en'] = array(
1717 'newusermessage-desc' => "Adds a message to newly created user's talk pages",
1818 'newuseredit-summary' => 'Adding [[{{int:newusermessage-template}}|welcome message]] to new user\'s talk page',
 19+ 'newusermessage-template' => 'Template:Welcome', # The title of the message template
1920 'newusermessage-template-subject' => 'Template:Welcome-subject', # Always substituted. Used if LiquidThreads is enabled in the User_talk namespace. Do not translate or duplicate this message to other languages
2021 'newusermessage-template-body' => 'Template:Welcome-body', # Used if LiquidThreads is enabled in the User_talk namespace. Do not translate or duplicate this message to other languages
2122 'newusermessage-editor' => 'New user message', # The username used for the edit
Index: trunk/extensions/NewUserMessage/NewUserMessage.class.php
@@ -84,7 +84,12 @@
8585 * @returns String
8686 */
8787 static function fetchText() {
88 - return self::fetchTemplateIfExists( wfMsg( 'newusermessage-template-body' ) );
 88+ $text = self::fetchTemplateIfExists( wfMsg( 'newusermessage-template-body' ) );
 89+ // Fall back if necessary to the old template
 90+ if ( !$text ) {
 91+ $text = self::fetchTemplateIfExists( wfMsg( 'newusermessage-template' ) );
 92+ }
 93+ return $text;
8994 }
9095
9196 /**
@@ -149,8 +154,12 @@
150155 $editor = self::fetchEditor();
151156 $flags = self::fetchFlags();
152157
153 - $subject = self::substString( $subject, $user, $editor, $talk, "preparse" );
154 - $text = self::substString( $text, $user, $editor, $talk );
 158+ if ( $subject ) {
 159+ $subject = self::substString( $subject, $user, $editor, $talk, "preparse" );
 160+ }
 161+ if ( $text ) {
 162+ $text = self::substString( $text, $user, $editor, $talk );
 163+ }
155164
156165 return self::leaveUserMessage( $user, $article, $subject, $text,
157166 $signature, $editSummary, $editor, $flags );
@@ -233,9 +242,14 @@
234243 * @param $signature String the signature, if provided.
235244 */
236245 static protected function formatUserMessage( $subject, $text, $signature ) {
237 - $signature = empty($signature) ? "~~~~~" : "{$signature} ~~~~~";
238 - $text = "\n== $subject ==\n\n$text\n\n-- $signature";
 246+ $contents = "\n";
 247+ $signature = empty( $signature ) ? "~~~~~" : "{$signature} ~~~~~";
 248+
 249+ if ( $subject ) {
 250+ $contents .= "== $subject ==\n";
 251+ }
 252+ $contents .= "\n$text\n\n-- $signature\n";
239253
240 - return $text;
 254+ return $contents;
241255 }
242256 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r81967Follow-up r81966: qqqbtongminh14:52, 11 February 2011
r81975FoFollow-up r81966 for Translatewikiraymond17:18, 11 February 2011
r82032MFT r81966, r81969 NewUserMessage fixesdemon21:02, 12 February 2011
r85027MFT various extension fixes: r81713, r81742, r81743, r81908, r81966, r81969, ...demon18:23, 30 March 2011

Comments

#Comment by 😂 (talk | contribs)   20:59, 12 February 2011

Should use wfMsgForContent like in the original, but otherwise ok.

Status & tagging log