* Add formatting for user messages.
authorMark A. Hershberger <mah@users.mediawiki.org>
Thu, 20 May 2010 18:47:13 +0000 (18:47 +0000)
committerMark A. Hershberger <mah@users.mediawiki.org>
Thu, 20 May 2010 18:47:13 +0000 (18:47 +0000)
** First, try a hook for the user messages
** Next, check for a template
** Otherwise, do something sane.

docs/hooks.txt
includes/User.php
languages/messages/MessagesEn.php
maintenance/language/messages.inc

index 2c63389..13ce078 100644 (file)
@@ -785,6 +785,12 @@ $fileVersions: array of undeleted versions. Empty if all versions were restored
 $user: user who performed the undeletion
 $reason: reason
 
+'FormatUserMessage': Hook to format a message if you want to override
+the internal formatter.
+$subject: Title of the message.
+&$text: Text of the message.
+$signature: Signature that they would like to leave.
+
 'GetAutoPromoteGroups': When determining which autopromote groups a user
 is entitled to be in.
 &$user: user to promote.
index e7910c9..98af4ca 100644 (file)
@@ -3749,9 +3749,37 @@ class User {
                return $ret;
        }
 
+       /**
+        * Format the user message using a hook, a template, or, failing these, a static format.
+        * @param $subject   String the subject of the message
+        * @param $text      String the content of the message
+        * @param $signature String the signature, if provided.
+        */
+       static protected function formatUserMessage( $subject, $text, $signature ) {
+               if ( wfRunHooks( 'FormatUserMessage',
+                               array( $subject, &$text, $signature ) ) ) {
+
+                       $signature = empty($signature) ? "~~~~~" : "{$signature} ~~~~~";
+
+                       $template = Title::newFromText( wfMsg( 'usermessage-template' ) );
+                       if ( !$template
+                                       || $template->getNamespace() !== NS_TEMPLATE
+                                       || !$template->exists() ) {
+                               $text = "== $subject ==\n\n$text\n\n-- $signature"
+                       } else {
+                               $text = '{{'. $template->getText()
+                                       . " | subject=$subject | body=$text | signature=$signature }}";
+                       }
+               }
+
+               return $text;
+       }
+
        /**
         * Leave a user a message
+        * @param $subject String the subject of the message
         * @param $text String the message to leave
+        * @param $signature String Text to leave in the signature
         * @param $summary String the summary for this change, defaults to
         *                        "Leave system message."
         * @param $article Article The article to update, defaults to the
@@ -3779,6 +3807,8 @@ class User {
                wfRunHooks( 'SetupUserMessageArticle',
                        array( $this, &$article, $subject, $text, $signature, $summary, $editor ) );
 
+
+               $text = self::formatUserMessage( $subject, $text, $signature );
                $flags = $article->checkFlags( $flags );
 
                if ( $flags & EDIT_UPDATE ) {
index dc89943..c2b8469 100644 (file)
@@ -2610,6 +2610,7 @@ The e-mail address you entered in [[Special:Preferences|your user preferences]]
 # User Messenger
 'usermessage-summary' => 'Leaving system message.',
 'usermessage-editor'  => 'System messenger',
+'usermessage-template' => 'Template:UserMessage',
 
 # Watchlist
 'watchlist'            => 'My watchlist',
index b9a1d94..c4d27fa 100644 (file)
@@ -1702,6 +1702,7 @@ $wgMessageStructure = array(
        'usermessage' => array(
                'usermessage-summary',
                'usermessage-editor',
+               'usermessage-template',
        ),
        'watchlist' => array(
                'watchlist',