r96420 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96419‎ | r96420 | r96421 >
Date:12:12, 7 September 2011
Author:siebrand
Status:resolved (Comments)
Tags:
Comment:
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.
Modified paths:
  • /trunk/extensions/CodeReview/ui/CodeRevisionAuthorView.php (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesQqq.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -2128,6 +2128,7 @@
21292129 'unblocklink',
21302130 'change-blocklink',
21312131 'contribslink',
 2132+ 'emaillink',
21322133 'autoblocker',
21332134 'blocklogpage',
21342135 'blocklog-showlog',
Index: trunk/phase3/includes/Linker.php
@@ -12,6 +12,7 @@
1313 * Flags for userToolLinks()
1414 */
1515 const TOOL_LINKS_NOBLOCK = 1;
 16+ const TOOL_LINKS_EMAIL = 2;
1617
1718 /**
1819 * Get the appropriate HTML attributes to add to the "a" element of an ex-
@@ -932,7 +933,7 @@
933934 * @param $userText String: user name or IP address
934935 * @param $redContribsWhenNoEdits Boolean: should the contributions link be
935936 * red if the user has no edits?
936 - * @param $flags Integer: customisation flags (e.g. Linker::TOOL_LINKS_NOBLOCK)
 937+ * @param $flags Integer: customisation flags (e.g. Linker::TOOL_LINKS_NOBLOCK and Linker::TOOL_LINKS_EMAIL)
937938 * @param $edits Integer: user edit count (optional, for performance)
938939 * @return String: HTML fragment
939940 */
@@ -942,6 +943,7 @@
943944 global $wgUser, $wgDisableAnonTalk, $wgLang;
944945 $talkable = !( $wgDisableAnonTalk && 0 == $userId );
945946 $blockable = !$flags & self::TOOL_LINKS_NOBLOCK;
 947+ $addEmailLink = $flags & self::TOOL_LINKS_EMAIL;
946948
947949 $items = array();
948950 if ( $talkable ) {
@@ -964,6 +966,10 @@
965967 $items[] = self::blockLink( $userId, $userText );
966968 }
967969
 970+ if ( $addEmailLink && $wgUser->canSendEmail() ) {
 971+ $items[] = self::emailLink( $userId, $userText );
 972+ }
 973+
968974 if ( $items ) {
969975 return ' <span class="mw-usertoollinks">(' . $wgLang->pipeList( $items ) . ')</span>';
970976 } else {
@@ -1007,6 +1013,18 @@
10081014 }
10091015
10101016 /**
 1017+ * @param $userId Integer: userid
 1018+ * @param $userText String: user name in database.
 1019+ * @return String: HTML fragment with e-mail user link
 1020+ * @private
 1021+ */
 1022+ static function emailLink( $userId, $userText ) {
 1023+ $emailPage = SpecialPage::getTitleFor( 'EmailUser', $userText );
 1024+ $emailLink = self::link( $emailPage, wfMsgHtml( 'emaillink' ) );
 1025+ return $emailLink;
 1026+ }
 1027+
 1028+ /**
10111029 * Generate a user link if the current user is allowed to view it
10121030 * @param $rev Revision object.
10131031 * @param $isPublic Boolean: show only if all users can see it
Index: trunk/phase3/languages/messages/MessagesQqq.php
@@ -2794,6 +2794,7 @@
27952795 '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''')''\".",
27962796 'change-blocklink' => 'Used to name the link on Special:Log',
27972797 'contribslink' => 'Short for "contributions". Used as display name for a link to user contributions on history pages, [[Special:RecentChanges]], [[Special:Watchlist]], etc.',
 2798+'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)".',
27982799 '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)\").
27992800
28002801 {{Identical|Block log}}",
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -3111,6 +3111,7 @@
31123112 'unblocklink' => 'unblock',
31133113 'change-blocklink' => 'change block',
31143114 'contribslink' => 'contribs',
 3115+'emaillink' => 'send e-mail',
31153116 'autoblocker' => 'Autoblocked because your IP address has been recently used by "[[User:$1|$1]]".
31163117 The reason given for $1\'s block is: "$2"',
31173118 'blocklogpage' => 'Block log',
Index: trunk/extensions/CodeReview/ui/CodeRevisionAuthorView.php
@@ -19,7 +19,12 @@
2020
2121 return wfMsgHtml( 'code-author-haslink',
2222 $this->skin->userLink( $this->mUser->getId(), $this->mUser->getName() ) .
23 - $this->skin->userToolLinks( $this->mUser->getId(), $this->mUser->getName() ) );
 23+ $this->skin->userToolLinks(
 24+ $this->mUser->getId(),
 25+ $this->mUser->getName(),
 26+ false, /* default for redContribsWhenNoEdits */
 27+ Linker::TOOL_LINKS_EMAIL /* Add "send e-mail" link */
 28+ ) );
2429 }
2530
2631 function execute() {

Follow-up revisions

RevisionCommit summaryAuthorDate
r96430Follow-up r96420: correct casing for special page to prevent "PHP Notice: Fo...siebrand13:35, 7 September 2011
r96449Mark userLink, userTalkLink, blockLink() and emailLink() as public static per...siebrand17:00, 7 September 2011
r96773* Follow-up r96420: don't show e-mail links to anon users...ialex08:14, 11 September 2011
r968561.17wmf1: MFT r94212, r96373, r96386, r96389, r96420, r96645...reedy15:35, 12 September 2011
r968601.17wmf1: MFT r96420, r96627reedy16:30, 12 September 2011

Comments

#Comment by Hashar (talk | contribs)   12:26, 7 September 2011

"Linker::TOOL_LINKS_EMAIL" really sounds lame. What about Linker::EMAIL_LINK ? :)

#Comment by Siebrand (talk | contribs)   12:36, 7 September 2011

I have no preference if the feature itself is agreed upon. I tried to follow the "naming convention" of Linker::TOOL_LINKS_NOBLOCK which was used in the same method for the same purpose.

#Comment by Hashar (talk | contribs)   19:57, 7 September 2011

At least we are using the same convention :-) Fine for me.

#Comment by Siebrand (talk | contribs)   20:30, 7 September 2011

Well, now that there are still only two constants, we could of course rename them all, or rename the one I added, add a second with value 1 and deprecate the existing 1. I'm very unfamiliar with using constants, do please don't mInd me...

#Comment by Nikerabbit (talk | contribs)   14:35, 7 September 2011
+	 * @private

If the function is really private (or rather protected) mark it has such with "protected static function .."

Status & tagging log