Add constant Linker::TOOL_LINKS_EMAIL to allow adding a "send e-mail" link from Linker::
authorSiebrand Mazeland <siebrand@users.mediawiki.org>
Wed, 7 Sep 2011 12:12:24 +0000 (12:12 +0000)
committerSiebrand Mazeland <siebrand@users.mediawiki.org>
Wed, 7 Sep 2011 12:12:24 +0000 (12:12 +0000)
Add "send e-mail" link in user tools for developer details (Special:Code/Project/author/authorname) in CodeReview.

includes/Linker.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc

index e37bbb3..ffe5a89 100644 (file)
@@ -12,6 +12,7 @@ class Linker {
         * Flags for userToolLinks()
         */
        const TOOL_LINKS_NOBLOCK = 1;
+       const TOOL_LINKS_EMAIL   = 2;
 
        /**
         * Get the appropriate HTML attributes to add to the "a" element of an ex-
@@ -932,7 +933,7 @@ class Linker {
         * @param $userText String: user name or IP address
         * @param $redContribsWhenNoEdits Boolean: should the contributions link be
         *        red if the user has no edits?
-        * @param $flags Integer: customisation flags (e.g. Linker::TOOL_LINKS_NOBLOCK)
+        * @param $flags Integer: customisation flags (e.g. Linker::TOOL_LINKS_NOBLOCK and Linker::TOOL_LINKS_EMAIL)
         * @param $edits Integer: user edit count (optional, for performance)
         * @return String: HTML fragment
         */
@@ -942,6 +943,7 @@ class Linker {
                global $wgUser, $wgDisableAnonTalk, $wgLang;
                $talkable = !( $wgDisableAnonTalk && 0 == $userId );
                $blockable = !$flags & self::TOOL_LINKS_NOBLOCK;
+               $addEmailLink = $flags & self::TOOL_LINKS_EMAIL;
 
                $items = array();
                if ( $talkable ) {
@@ -964,6 +966,10 @@ class Linker {
                        $items[] = self::blockLink( $userId, $userText );
                }
 
+               if ( $addEmailLink && $wgUser->canSendEmail() ) {
+                       $items[] = self::emailLink( $userId, $userText );
+               }
+
                if ( $items ) {
                        return ' <span class="mw-usertoollinks">(' . $wgLang->pipeList( $items ) . ')</span>';
                } else {
@@ -1006,6 +1012,18 @@ class Linker {
                return $blockLink;
        }
 
+       /**
+        * @param $userId Integer: userid
+        * @param $userText String: user name in database.
+        * @return String: HTML fragment with e-mail user link
+        * @private
+        */
+       static function emailLink( $userId, $userText ) {
+               $emailPage = SpecialPage::getTitleFor( 'EmailUser', $userText );
+               $emailLink = self::link( $emailPage, wfMsgHtml( 'emaillink' ) );
+               return $emailLink;
+       }
+
        /**
         * Generate a user link if the current user is allowed to view it
         * @param $rev Revision object.
index 576f6ac..346ef61 100644 (file)
@@ -3111,6 +3111,7 @@ See [[Special:BlockList|IP block list]] to review blocks.',
 'unblocklink'                     => 'unblock',
 'change-blocklink'                => 'change block',
 'contribslink'                    => 'contribs',
+'emaillink'                       => 'send e-mail',
 'autoblocker'                     => 'Autoblocked because your IP address has been recently used by "[[User:$1|$1]]".
 The reason given for $1\'s block is: "$2"',
 'blocklogpage'                    => 'Block log',
index 6e348c4..b166e36 100644 (file)
@@ -2794,6 +2794,7 @@ Usage:
 'blocklink'                   => "Display name for a link that, when selected, leads to a form where a user can be blocked. Used in page history and recent changes pages. Example: \"''UserName (Talk | contribs | '''block''')''\".",
 'change-blocklink'            => 'Used to name the link on Special:Log',
 'contribslink'                => 'Short for "contributions". Used as display name for a link to user contributions on history pages, [[Special:RecentChanges]], [[Special:Watchlist]], etc.',
+'emaillink'                   => 'Used as display name for a link to send an e-mail to a user in the user tool links. Example: "(Talk | contribs | block | send e-mail)".',
 'blocklogpage'                => "The page name of [[Special:Log/block]]. Also appears in the drop down menu of [[Special:Log]] pages and in the action links of Special:Contributions/''Username'' pages (e.g. \"For Somebody (talk | block log | logs)\").
 
 {{Identical|Block log}}",
index 19733a7..66514e3 100644 (file)
@@ -2128,6 +2128,7 @@ $wgMessageStructure = array(
                'unblocklink',
                'change-blocklink',
                'contribslink',
+               'emaillink',
                'autoblocker',
                'blocklogpage',
                'blocklog-showlog',