From 0c127900896ad1cc892c090a41364b2d1bca1594 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Wed, 7 Sep 2011 12:12:24 +0000 Subject: [PATCH] Add constant Linker::TOOL_LINKS_EMAIL to allow adding a "send e-mail" link from Linker:: Add "send e-mail" link in user tools for developer details (Special:Code/Project/author/authorname) in CodeReview. --- includes/Linker.php | 20 +++++++++++++++++++- languages/messages/MessagesEn.php | 1 + languages/messages/MessagesQqq.php | 1 + maintenance/language/messages.inc | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/includes/Linker.php b/includes/Linker.php index e37bbb3d04..ffe5a895c2 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -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 ' (' . $wgLang->pipeList( $items ) . ')'; } 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. diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 576f6ac3a7..346ef61bb0 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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', diff --git a/languages/messages/MessagesQqq.php b/languages/messages/MessagesQqq.php index 6e348c41e6..b166e3611b 100644 --- a/languages/messages/MessagesQqq.php +++ b/languages/messages/MessagesQqq.php @@ -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}}", diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 19733a7b46..66514e3877 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -2128,6 +2128,7 @@ $wgMessageStructure = array( 'unblocklink', 'change-blocklink', 'contribslink', + 'emaillink', 'autoblocker', 'blocklogpage', 'blocklog-showlog', -- 2.20.1