Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Mentions+ to check if Username is available

phreakphreak Vanilla*APP (White Label) & Vanilla*Skins Shop MVP

Hi @R_J,

You know i love your plugin and it makes the Mentions function for the german language and other more usable. I have another idea that could be added to the plugin.

My users tend to @ each other pretty good, they know how it works. The only thing is that they are mistyping others usernames pretty often. That creates hundreds of broken links in my forum. I'm editing those by hand or with SQL, but it would be great if they would be checked against the username table when added.

User then can see that the username is not linked behind the "@amdin" and will change it in their given editing time to "@admin" or leave it as non-linked. Also good as it creates no broken link.

Would this be an idea to add to mentions+, or the original mentions. I also use MentionsLookup, but people tend to ignore it. Especially when on mobile.

Thanx for info,
phreak

  • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
  • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
«1

Comments

  • R_JR_J Ex-Fanboy Munich Admin

    Broken links are bad for SEO so I think it would be a very good addition. I'll take a look at it!

  • Although these are good idea in theory, performing these 'sounds like' or 'similar to' without specialized architecture an ample resources, is a no go for the average joe. Sphinx can improve this, but still were you have opportunity that would be this commonly used you have to justify whether it is worth it.

    What you probably want do is turn auto linking off, even searching for such 'correct' link in discussion is wasting time and resources. You would probably have manually link, on insertion with using a look up. This is of course not as elegant.

    The obvious thing, if when they visit the profile page that is not there to query users, either on soundex, or listing by alphabet and display those options.

    I think that is plugin in its own right.

    grep is your friend.

  • Broken links are bad for SEO so I think it would be a very good addition. I'll take a look at it!

    I doubt the SEO benefit mentions, should really be no follow. Often profile aren't even public.

    grep is your friend.

  • R_JR_J Ex-Fanboy Munich Admin

    Soundex shouldn't be done when it comes to names, but I don't think @phreak was talking about that.

    Speaking of mobile users, using MentionsLookup or any other AJAX solution, needs bandwidth and also a fast connection which you can not set as granted so I think letting them type a wrong user name will happen anyway. You can't avoid that. But I will also doubt that a mobile user will correct a discussion/comment. Most probably they will just fire an additional comment with a single @correctusername. It would be a nice hint if they see that their mention wasn't converted to a link.

    For desktop users, I would always prefer an AJAX just in time solution. Simply because it is way more comfortable to see errors in the moment when they are done.

    I was thinking about performance, too, but broken links are bad. Even if they are nofollow links they are bad. So I think it is worth looking at the plugin.
    I don't like the idea that there is a db query for each and every mentioning, but UserModels GetByUsername uses the cache and so I think it will generally only have negative impact if user name is mistyped and that should be tolerable.

    By now the plugin is calling preg_match_all and preg_replace two times (one for user names with spaces and one for user names without) which is something that I wanted to change someday anyway. So I'll look at the code.

  • x00x00 MVP
    edited February 2014

    I honestly think it is better idea to resolve it when visiting the profile page.

    It I was goign to do what you are doing, I would limit it to on post checks, then find the valid mentions (it can be optimized as one query) store them an as a lookup with the entry. Then when parsing mentions, use this lookup to validate.

    grep is your friend.

  • R_JR_J Ex-Fanboy Munich Admin

    @x00 I see your point on resolving the broken links on wrong profile page and I like that idea for it is much more resource friendly.
    Nevertheless I'm still thinking about using the formatter way because things are not obvious to me and I simply have to munch longer on such a problem before I feel like I really got it ;)

    So basically you'd say, if I stick to the formatter solution, I should do something like that:
    1. on post: check for valid mentions and store them in their own table
    2. on format: check mentions against result of "SELECT UserName FROM MyTable"
    Did I get you right?

    Okay, worst case would be that for every comment with a mention there is one call to db.
    Using GetByName in this case would benefit from cache.
    Worst case for GetByName would be 100 x @Unknown => 100 calls to db

    Well, you've saved me from implementing something that would be funny to abuse :)

    So the obvious question is: is there any better way to store the list of users? Could that list be cached and changed on every post? Does it make sense to do that?

  • No, do not store them in their own table. Store them with the comment or discussion entry in a serialized/normalized column so you don't need extra queries when looking them up.

    Only query when validating collected mentions. Only parse mention which match users in the lookup.

    grep is your friend.

  • Btw I don't know where you get 100 queries from.

    You should be able to query once per post, with a selection of users.

    grep is your friend.

  • None of these technique have 100% integrity, but it is normal to sacrifice that for decent performance.

    grep is your friend.

  • R_JR_J Ex-Fanboy Munich Admin

    Using an additional column was my first guess, but by I'm tweaking public function FormatMentions($Mixed) { from class format so to my understanding all I have is the comment body as string, not a comment object or at least a CommentID. So I wouldn't be able to get any comment related information and that's why I thought about using a custom table

  • hgtonighthgtonight ∞ · New Moderator

    I request if you are going to check the username for correctness, to go ahead and link to the actual profile link rather than the simple version. I.e. /profile/38268/hgtonight instead of /profile/hgtonight. It currently does the latter since they didn't want to hit the db to verify the name in the first place. It, in essence, handles incorrect names on the profile controller.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • phreakphreak Vanilla*APP (White Label) & Vanilla*Skins Shop MVP
    edited February 2014

    Ah yes, Dev-Taaalk full in effect. :) I understood almost 80%. Great you guys pick that up here.

    Regarding "nofollow", i think Google gives this a very minimal weight these days. The whole conception of site structures went so different within the last years, that Google looks for different things in different site approaches. Vanilla creates hundred of thousends of links through the permalink structure of every comment. Also duplicate links for posts and so on.

    It would be a nice hint if they see that their mention wasn't converted to a link.

    That is one very nice way to make the users learn, what works or what works not i think. Errors in writing @username's will reduce as users want to get their text highlighted. @username is not only used to link to people, also to format comments more properly (through the color of the link). My users also startet to relate to different topics (@mumsCake, @work, @myHusband)... naaarfff ;)

    Thanx for making this mind experiment with me.

    • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
    • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
  • x00x00 MVP
    edited February 2014

    @R_J said:
    Using an additional column was my first guess, but by I'm tweaking public function FormatMentions($Mixed) { from class format so to my understanding all I have is the comment body as string, not a comment object or at least a CommentID. So I wouldn't be able to get any comment related information and that's why I thought about using a custom table

    you need to process before saving the post, then check on display, you wouldn't be able to use the core parser.

    grep is your friend.

  • R_JR_J Ex-Fanboy Munich Admin

    I looked at the source and now understand one of the performance problems: by now the function uses one preg_replace to replace every @user to link(@user).
    If I want to check the results against an array of existing users, I would have to loop through the array of existing users and do one preg_replace for each of them. So that's why storing the existing users per comment is crucial. It took me some time longer to understand that.
    Or is there anything like a "conditional preg_replace"? My head is exploding and I doubt that I really understand...

    If I do not use the function GetMentions but use the hooks in discussions and comments, it might lead to inconsistencies. If someone uses the frameworks normal functions (and everybody should!) in any other addon or plugin, the result will look different to how it looks in comments and discussions if I change it there.

    I hate decreasing performance. I hate inconsistencies. I hate broken links. It's all ugly, ugly, ugly.

    The more I think about it, the less I like changing my plugin. :(
    There seems to be no efficient way to solve the problem.

    But if I do nothing, the problem of broken links still prevails. Ugly and I hate it. SOOOO! What about a broken-link-checker-plugin? HA! I think that could be useful! Although checking links takes an awful lot of time, too, but it would without a doubt be useful.
    It might be enough to parse and check a comment on posting, check internal links once a month, and recheck external links once per week or so. It could be combined with a preview of links that is shown when you hover over a link. Would make a great plugin, but I do not want to write it.
    To be honest: I think I wouldn't even use such a plugin because of performance concerns.


    NAAAA! I wouldn't have to do one preg_replace per user! I would have to do a preg_match_all, SELECT Name FROM User WHERE Name in $Result, convert $Result to $ResultRegex and afterwards do a preg_replace based on $ResultRegex!
    Today's not the best day for thinking... I delay the search for a solution...

  • if think maybe you are getting a bit confused about what is really at issue. There are various ways to crack an egg but the parsing isn't the biggest issue you have, if you have a list of names.

    you can array_map('preg_quote', $MentionedUsers) then join them with OR syntax an and use them in a single regular expression. or you can supply an array in the preg_replace, supplying you own callback to the map to produce individual expressions.

    With only a certain number of post per page this isn't really what is at issue. I mean the formatters in general work harder than this.

    grep is your friend.

  • R_JR_J Ex-Fanboy Munich Admin

    @x00 said:
    maybe you are getting a bit confused

    That's definitively my biggest problem right now ;)
    But if I get you right, your point is that only calling the db would be bad, but doing two or three regex operation instead of one wouldn't be a problem? I thought they were to avoid whenever possible.
    I have thought of looking at Gardens cache. Maybe putting a list of users into cache and changing this cached value on every create or delete to the user table could be a way to avoid db access. But as I said before: I have to stop for today (or at least for the next few hours) and you already noticed that I'm losing focus...

  • the formatters call multiple expressions. In fact there is no guarantee that a compound expression performs better or worse the many expressions is sequence. When you supply an array it is the same as running in sequence. You are going to need to parse each comment.

    When you have actual user names technically you don't have to use a regular expression at all, it could be done with str_ireplace although preg offer several conveniences, that make matching a bit easier.

    I basically explained how I would do it.

    grep is your friend.

  • R_JR_J Ex-Fanboy Munich Admin

    Many thanks for all the input!

  • edited February 2014

    @R_J said:
    Many thanks for all the input!

    @R_J
    Will it work for Arabic and Urdu characters.

  • R_JR_J Ex-Fanboy Munich Admin

    The plugin uses the config setting $Configuration['Garden']['User']['ValidationRegex']

    So if you add $Configuration['Garden']['User']['ValidationRegex'] = '\\d\\w_-[\\u0000-\\u0000]' and change the range to what you need, it should work also for any other characters.

Sign In or Register to comment.