r66698 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66697‎ | r66698 | r66699 >
Date:18:47, 20 May 2010
Author:mah
Status:resolved (Comments)
Tags:
Comment:
* Add formatting for user messages.
** First, try a hook for the user messages
** Next, check for a template
** Otherwise, do something sane.
Modified paths:
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -1702,6 +1702,7 @@
17031703 'usermessage' => array(
17041704 'usermessage-summary',
17051705 'usermessage-editor',
 1706+ 'usermessage-template',
17061707 ),
17071708 'watchlist' => array(
17081709 'watchlist',
Index: trunk/phase3/docs/hooks.txt
@@ -785,6 +785,12 @@
786786 $user: user who performed the undeletion
787787 $reason: reason
788788
 789+'FormatUserMessage': Hook to format a message if you want to override
 790+the internal formatter.
 791+$subject: Title of the message.
 792+&$text: Text of the message.
 793+$signature: Signature that they would like to leave.
 794+
789795 'GetAutoPromoteGroups': When determining which autopromote groups a user
790796 is entitled to be in.
791797 &$user: user to promote.
Index: trunk/phase3/includes/User.php
@@ -3750,8 +3750,36 @@
37513751 }
37523752
37533753 /**
 3754+ * Format the user message using a hook, a template, or, failing these, a static format.
 3755+ * @param $subject String the subject of the message
 3756+ * @param $text String the content of the message
 3757+ * @param $signature String the signature, if provided.
 3758+ */
 3759+ static protected function formatUserMessage( $subject, $text, $signature ) {
 3760+ if ( wfRunHooks( 'FormatUserMessage',
 3761+ array( $subject, &$text, $signature ) ) ) {
 3762+
 3763+ $signature = empty($signature) ? "~~~~~" : "{$signature} ~~~~~";
 3764+
 3765+ $template = Title::newFromText( wfMsg( 'usermessage-template' ) );
 3766+ if ( !$template
 3767+ || $template->getNamespace() !== NS_TEMPLATE
 3768+ || !$template->exists() ) {
 3769+ $text = "== $subject ==\n\n$text\n\n-- $signature"
 3770+ } else {
 3771+ $text = '{{'. $template->getText()
 3772+ . " | subject=$subject | body=$text | signature=$signature }}";
 3773+ }
 3774+ }
 3775+
 3776+ return $text;
 3777+ }
 3778+
 3779+ /**
37543780 * Leave a user a message
 3781+ * @param $subject String the subject of the message
37553782 * @param $text String the message to leave
 3783+ * @param $signature String Text to leave in the signature
37563784 * @param $summary String the summary for this change, defaults to
37573785 * "Leave system message."
37583786 * @param $article Article The article to update, defaults to the
@@ -3779,6 +3807,8 @@
37803808 wfRunHooks( 'SetupUserMessageArticle',
37813809 array( $this, &$article, $subject, $text, $signature, $summary, $editor ) );
37823810
 3811+
 3812+ $text = self::formatUserMessage( $subject, $text, $signature );
37833813 $flags = $article->checkFlags( $flags );
37843814
37853815 if ( $flags & EDIT_UPDATE ) {
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2610,6 +2610,7 @@
26112611 # User Messenger
26122612 'usermessage-summary' => 'Leaving system message.',
26132613 'usermessage-editor' => 'System messenger',
 2614+'usermessage-template' => 'Template:UserMessage',
26142615
26152616 # Watchlist
26162617 'watchlist' => 'My watchlist',

Follow-up revisions

RevisionCommit summaryAuthorDate
r66702Follow-up r66698: Fix syntax error (missing ;)raymond19:02, 20 May 2010
r67774follow-up r66698 - change Template:UserMessage to MediaWiki:UserMessage as su...mah04:46, 10 June 2010

Comments

#Comment by Raymond (talk | contribs)   19:21, 20 May 2010
+			$template = Title::newFromText( wfMsg( 'usermessage-template' ) );

Shouldn't it be wfMsgForContent() ?

#Comment by MarkAHershberger (talk | contribs)   00:53, 21 May 2010

Changed after I read the code docs, see r66716

#Comment by 😂 (talk | contribs)   22:05, 20 May 2010

This feels kind of scary to me...UI stuff controlled via something in the Template namespace?

#Comment by MarkAHershberger (talk | contribs)   00:47, 21 May 2010

I'm completely open to other ways of handling this. The only other place I could find in core that uses a template is disambiguation pages.

What would you suggest?

#Comment by Platonides (talk | contribs)   21:40, 27 May 2010

Just place the message content inside the MediaWiki: namespace.

If they want to move it into Template: they can redirect it or make the message include the template.

#Comment by MarkAHershberger (talk | contribs)   04:54, 10 June 2010

See r67774

#Comment by MZMcBride (talk | contribs)   01:18, 21 May 2010
+'usermessage-template' => 'Template:UserMessage',

Needs to not specify a namespace name, surely. There's a constant for this, I think. NS_TEMPLATE or something? PHP sucks.

#Comment by MarkAHershberger (talk | contribs)   01:20, 21 May 2010

In that particular place, its a string and needs it. See 'disambiguationspage' for another instance.

#Comment by 😂 (talk | contribs)   21:44, 6 February 2011

No it doesn't, you could force NS_TEMPLATE, disambiguationspage could do the same if it wanted.

This is fine with the followups. See r66438 for the full review.

Status & tagging log