9

When I link to another's answer (or question, or sometimes comment) in my own answer (or question), I like to name that author, rather than just giving a bare link. As [so-and-so said](link-to-that) seems much friendlier than As [another answer indicated](link-to-that). There are, however, two problems with this.

The big problem: Sometimes, people change their SE user names. When this happens, all those references start looking like nonsense.

The small problem: Sometimes, people's names use characters that are not on my keyboard. This is most problematic when I am posting from a mobile device.

Is there a way to make this work automatically? If not, could we make one?

One approach

If there is a sensible character, like @, that is not allowed to appear in user names, we could use syntax like

As [@author explains](link-to-answer), the simplest way is ...

where @author is essentially a keyword.

4 Answers 4

4

Currently there is no way to do it, but there is a small workaround of your second point: go to the profile, copy the name of this user, place it as the title of your link.

But the first problem is really a problem. I'd like to see it implemented in this way: when you include a bare link to a user page, it should be translated into their name.

This is done, for example, with the links to questions: when you paste a link to the question on (MSE) somewhere in the (MSE) post, it appears as the linked title. E.g.:

Is there a way to automatically mention the author of an answer?

Markdown is just:

https://meta.stackexchange.com/questions/251722/is-there-a-way-to-automatically-mention-the-author-of-an-answer

I'd like to see something similar implemented with the links to profile pages.

3

IMHO it adds very little value to include the name of the author when referencing a post.

I reference answers using the format:

... as mentioned in this answer [and optionally include Question title here] ...

or if it is a question:

... as mentioned in Question title here...

When there is a single author for a post it is redundant to include their name.

When a post has several authors (i.e. multiple substantial edits or it has become community wiki) it is still redundant to mention a single user because the input from a specific user is usually indistinguishable from the input of others (unless you revert to checking the revision history).

When a user has been deleted their name is anonymized, so if the feature was implemented the reference would no longer make sense (who is this random user767834 who has no profile?).

The only time adding a user name to the reference really makes sense is if you are trying to add some authority to your reference and avoid the user having to visit the link. Using Stack Overflow as an example:

...as mentioned by Jon Skeet in this answer...

carries a lot more implicit authority than

...as mentioned by user87649 in this answer...

But even in this case I would argue that the suggested feature is mostly redundant because users like Jon Skeet are long term and stable and highly unlikely to change their moniker.

You also need to consider the cost of the feature. Free text would need to be parsed for username tokens and an additional join to a user table would need to be done to substitute in the current user name for the token every time one occurred. Maybe the devs could come up with something a bit more clever than that, but it would still come at a cost for a feature that has debatable value. As per any development, that cost needs to be balanced against the benefit and likely uptake of the feature, and the existence and convenience of any work-around (the work-around for this is to copy-paste the user name as mentioned in other answers).

2
  • As this here answer said, blah, but as that there answer said, foo. We can deal with both of these using bar, which also addresses point 7 from this here answer, and that also allows us to use quux to address point 3 from that there answer. Wow, my head is spinning.
    – dfeuer
    Commented Mar 23, 2015 at 1:42
  • @dfeuer I guess my answer can be summarized as: it's too expensive for a mostly redundant feature which has an easy workaround for those who want it. I guess that you're not really getting the answers or feedback you were anticipating?
    – slugster
    Commented Mar 23, 2015 at 2:11
3
+100

Whilst a userscript can't solve the problems with mentioning usernames in posts, it can help in mentioning the current username. This userscript adds another link button to the editor toolbar that brings up a popup for a question's link. The script then inserts the link with the author's name.

eg. entering http://meta.stackexchange.com/questions/251722/is-there-a-way-to-automatically-mention-the-author-of-an-answer will produce [@dfeuer says](http://meta.stackexchange.com/questions/251722/is-there-a-way-to-automatically-mention-the-author-of-an-answer).

This makes the process much easier and faster - instead of selecting, copying and pasting the username, and then copying and pasting the link, you can just paste the link to do everything :)

enter image description here

// ==UserScript==
// @name         Link to questions with author's name
// @namespace    http://stackexchange.com/users/4337810/%E1%94%95%E1%96%BA%E1%98%8E%E1%95%8A
// @version      1.0
// @description  Adds a button to the SE editor toolbar to add a link and automatically insert the author of the question
// @author       ᔕᖺᘎᕊ (http://stackexchange.com/users/4337810/%E1%94%95%E1%96%BA%E1%98%8E%E1%95%8A)
// @match        *://*.stackexchange.com/*
// @match        *://*.stackoverflow.com/*
// @match        *://*.superuser.com/*
// @match        *://*.serverfault.com/*
// @match        *://*.askubuntu.com/*
// @match        *://*.stackapps.com/*
// @match        *://*.mathoverflow.net/*
// @grant        none
// ==/UserScript==
var div = "<div id='addLinkAuthorName' class='wmd-prompt-dialog'> \
            <h5>Insert hyperlink with author's name</h5> \
            <br /> \
            <input id='link' placeholder='http://example.com/ \"optional title\"' size='50'> \
            <input id='addLinkOk' value='OK' type='button' style='margin: 10px; display: inline; width: 7em;'><input id='addLinkCancel' value='Cancel' type='button' style='margin: 10px; display: inline; width: 7em;'> \
           </div>",
    css = {
        "position": "fixed",
        "width": "400px",
        "z-index": "1001",
        "top": "50%",
        "left": "50%",
        "display": "none",
        "margin-top": "-95.5px",
        "margin-left": "-216px"
    };
$('body').append(div);
$('#addLinkAuthorName').css(css);

$('#addLinkAuthorName #addLinkCancel').on('click', function() {
    $(this).parent().hide();
});

$('#addLinkAuthorName #addLinkOk').on('click', function() {
    var textarea = $('#post-editor #wmd-input'),
        link = $('#addLinkAuthorName #link').val(),
        id = link.split('/')[4],
        sitename = link.split('/')[2].split('.')[0],
        title = link.split('"')[1];

    if(link.split('/')[3].substr(0, 1) == 'a') { //for answers
        alert('here');
        $.getJSON("https://api.stackexchange.com/2.2/answers/" + id + "?order=desc&sort=activity&site=" + sitename, function(json) {
            //Insert at caret thanks to http://stackoverflow.com/a/15977052/3541881
            var caretPos = document.getElementById('wmd-input').selectionStart,
                textAreaTxt = textarea.val(),
                txtToAdd;

            if (title) {
                txtToAdd = '[@' + json.items[0].owner.display_name + ' says](' + link + ' "' + title + '")';
            } else {
                txtToAdd = '[@' + json.items[0].owner.display_name + ' says](' + link + ')';
            }

            textarea.val(textAreaTxt.substring(0, caretPos) + txtToAdd + textAreaTxt.substring(caretPos));
            $('#addLinkAuthorName').hide();
        });      
    } else { //for questions
        $.getJSON("https://api.stackexchange.com/2.2/questions/" + id + "?order=desc&sort=activity&site=" + sitename, function(json) {
            //Insert at caret thanks to http://stackoverflow.com/a/15977052/3541881
            var caretPos = document.getElementById('wmd-input').selectionStart,
                textAreaTxt = textarea.val(),
                txtToAdd;

            if (title) {
                txtToAdd = '[@' + json.items[0].owner.display_name + ' says](' + json.items[0].link + ' "' + title + '")';
            } else {
                txtToAdd = '[@' + json.items[0].owner.display_name + ' says](' + json.items[0].link + ')';
            }

            textarea.val(textAreaTxt.substring(0, caretPos) + txtToAdd + textAreaTxt.substring(caretPos));
            $('#addLinkAuthorName').hide();
        });
    }
});

var liSpan = "<li class='wmd-button' title='Hyperlink (with author name)' style='left: 450px;'><span id='wmd-author-link-button' style='background-position: -40px 0px;'></span></li>";

setTimeout(function() {
    $('[id^="wmd-redo-button"]').after(liSpan);
    $('#wmd-author-link-button').on('click', function() {
        $('#addLinkAuthorName').show();    
    });
}, 1000);

I've also added this to my SE Optional Features userscript.

0

Well, you could just copy and paste to do figure out your second problem about not having those characters on your keyboard, nothing to worry about here. Like if someone's username was 我真棒, I would just use copy-paste (name taken from Google translator).

Well, I hope in the big problem, the username would somehow auto-update as you said, but I guess this could be a way:

  • Copy-paste link to profile of the person who answered

  • Say something like this: [current user's name][link to profile] answered this [question][link to question]... You could take really far and add a note like this: NOTE: User's name subject to change.

I mean if the user's name does get change, you just need to hope someone is kind enough to edit your post and edit the user's name for you. I hope this helps you!

NOTE: I ain't a programmer for SE so I'll just let the pros take care of the coding stuff.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .