From: Mark A. Hershberger Date: Thu, 20 May 2010 18:47:13 +0000 (+0000) Subject: * Add formatting for user messages. X-Git-Tag: 1.31.0-rc.0~36782 X-Git-Url: http://git.cyclocoop.org/ecrire?a=commitdiff_plain;h=4f01b9f10b914dd8e4451f15b054bd984fd13629;p=lhc%2Fweb%2Fwiklou.git * Add formatting for user messages. ** First, try a hook for the user messages ** Next, check for a template ** Otherwise, do something sane. --- diff --git a/docs/hooks.txt b/docs/hooks.txt index 2c633893bd..13ce078b10 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -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. diff --git a/includes/User.php b/includes/User.php index e7910c91fe..98af4ca2cf 100644 --- a/includes/User.php +++ b/includes/User.php @@ -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 ) { diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index dc89943fbd..c2b846914c 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index b9a1d94982..c4d27fa94d 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -1702,6 +1702,7 @@ $wgMessageStructure = array( 'usermessage' => array( 'usermessage-summary', 'usermessage-editor', + 'usermessage-template', ), 'watchlist' => array( 'watchlist',