merge with Mentions module
soxofaan - July 20, 2009 - 17:55
| Project: | User name highlighter |
| Version: | 6.x-1.0 |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
the Mentions module (http://drupal.org/project/mentions) is a more powerful module than user name highlighter.
wouldn't it be a good idea to merge both and put User Name Highlighter asleep?

#1
Hi soxofaan,
I really appreciate the compliment, and I have to apologize for stepping on your toes, I thought I searched thoroughly for modules that did something similar to what I was looking at for the Mentions module and really I should have released the Mentions functionality as a patch to User name highlighter.
However, as I didn't, and you seem to be open to possibilities, I'd be more than happy to discuss options.
It would be simple enough to highlight the mentions as each mention gets two classes - 'mentions' and 'mentions-[uid]' (mentions-1, mentions-2, etc) - so that wouldn't even really need anything rolled into the Mentions module, you could simply simplify the User name highlighter module and set it to require the Mentions module.
I do have an unreleased version of Mentions for Drupal 5 which does everything except for offer the Views integration. I wasn't specifically going to release unless I got enough requests for it, and even then I wouldn't want to release it without Views integration, and I'm sure backporting Views 2 integration to Views 1 wouldn't be a walk in the park.
Let me know what you think.
Cheers,
Deciphered.
#2
Hi Deciphered,
No problem, I don't feel toe stepped :) I know how hard it can be to find modules on drupal.org.
I wonder though how you then found this issue thread less than six hours after I posted it.
After I discovered the Mentions module (from the new module rss feed), I considered to post an issue on the Mentions issue queue, but I first wanted to sort out how I would handle the User Name Highlighter module.
Anyway, functionality-wise Mentions outpowers User Name Highlighter. User Name Highlighter started very simple (as a proof of concept for a small project that is more or less dead now) and it never got more advanced due to lack of user interest and lack of time to spend on it.
I agree that putting User Name Highighter functionality in Mentions will be the easiest. I see two things:
$hue = ($uid * 67) % 360, there is an admin interface to set the saturation and value level. I decided to add the background color with inline CSS to avoid managing an extra CSS file (you never know in advance how many users there will be on a site). Is this feasible to add this to Mentions? Maybe it could be an optional submodule?I'm open to discussion.
I also have no real interest in Drupal 5 anymore, so no problem there.
cheers
#3
Hi soxofaan,
I was googling 'Mentions Module' and just happened across this issue :)
The first issue would technically be possible, but I wouldn't do it.
Without a prefix you have a very inefficient system, having to treat every single word in a node as a potential username when in all likelihood only a small percentage are, which means heavy load on the server and unnecessary database calls. With a prefix, you only inspect the words that match the exact pattern which are very likely to actually be usernames.
You can however set the output to not have a prefix or suffix.
As for the unique background, that is all possible, the second class of attached to the mention contains the user id, so all you need is either a straight css file or a simple module that outputs a css file with the colors for the users.
Cheers,
Deciphered.
#4
I think the two modules serves different purposes, completely different purposes.
One should not break the other. In other words they should be mutually compatible.
So far as the server load is concerned it depends on the user and their servers but please leave the options open.
And if plain user name has server load problems user highlight can have two administrative options, one the way it is now, the other - prefix or suffix the username with any character to highlight it.
#5
Hi guys,
I had a look into the latest version and it appears that the User name highlighter module is causing the issue kaakuu initially posted on the Mentions module (#531234: Incompatibility with username_highlighter).
The issue is that User name highlighter is replacing any reference of the the username, even if it's in an HTML element. The Mentions module will replace [@username] with
<a href="/user/uid" class="mentions mentions-uid" title="username">@username</a>, and then User name highlighter will replace that with<a href="/user/uid" class="mentions mentions-uid" title="<span style="background-color:#color;">username</span>">@<span style="background-color:#color;">username</span></a>.So at this stage the two modules can not work together.
If it was entirely up to me, I would strip User name highlighter completely back so that it just provides the background color for Mentions using the 'mentions-[uid]' class instead of providing a filter.
I still disagree with non-prefixed usernames and here are a few more reasons why:
- Users with a HTML element as their username ('href', 'a', 'div', etc) break things in a big way.
- Users with comment english words as their username ('the', 'a', 'in', etc) return excessive false positives.
- References of the users name in HTML elements ('title="username"', 'alt="username"', etc) break things.
However, I am willing to look into making it possible for Mentions input patterns to use no prefix but it wouldn't be without a warning.
#6
It can be entirely upto you if you can create a highlight module 2 :)
That can solve this problem too and help us!
#7
kaakuu,
There's two reasons that I wouldn't do it myself:
1. It would be directly stepping soxofaan's toes, I would prefer to work with him to come out with an option.
2. I don't personally have the need for this module and I'm all about scratching my own itches, generally I only work on modules that I would personally use myself. Although, Mentions kind of breaks that, as I don't currently have any plans to launch any sites that use the module, but I would love to use the functionality on D.o.
I have implemented the ability to use a non-prefix pattern in an internal build which I will likely commit shortly.
I did come across another reason why I don't like the idea, users with spaces in their name will just not be picked up, even if you have a suffix in the pattern. It probably could be achieved, but that would require increasing the server load to a ridiculously high level, e.g., while currently without a prefix, 3 words means 3 checks, checking for users with a space would mean 3 words would be 6 checks, 4 calls would be 10 checks, and 1000 words would probably crash your server. While I can think of other ways to do this, they would require too many changes to the way things are currently done and it's still not going to be as efficient as using a prefix.
Cheers,
Deciphered.
#8
Hi guys,
some random thoughts:
I disagree here, I think both modules do comparable things: catching usernames in text and doing something with it (adding color, or linking it to user profile). In my view it only makes sense to unify the source code to minimize duplication
<?php$username_map = _username_highlighter_username_map();
return preg_replace(array_keys($username_map), array_values($username_map), $text);
?>
Doing plain user names in the workflow of Mentions (checking each word being a user name, as suggested in #7 I think) would be of course be server load suicide. But I think the search+replace way of User Name Highlighter does not cause real troubles unless you have a site with thousands of users and megabytes of text to filter. In any case: if plain user name filtering become an option in Mentions, it should be advertised that it can become heavy on the server if there are a lot of users.
cheers
#9
@soxofaan,
I agree in part; I definitely think one unified solution to prevent duplication is the right way to go, but I can't see why anyone would want to highlight a user in the way that your module does, design wise it just doesn't look good to me. This is a bit of an issue, because that is really the core behavior of your module.
I disagree with this, when you are saying someones name in a piece of text, you are mentioning that user, therefore Mentions are everything. I also think that a one word name is far better than an overly descriptive name, just look at 'Views'.
This goes against your other argument, as user name filtering is only a small part of the functionality.
It will be an option, but it will be heavily warned against.
Ultimately I would have prefered to lock the pattern to a single character prefix only (@username), no suffix, to take advantage of the learned behavior from twitter, but as Drupal allows usernames with spaces I had to offer a suffix. Plain names require a very controlled environment.
While it may not be a huge issue for you or me, it could be for someone with a certain setup, or it could be a breaking point for someone. Best not to add server load when it's not necessary.
Anyway, I leave it up to you on how to proceed. I still think that the best path would be to have UNH require Mentions and leverage the classes to do the highlighting as it seems to be the only thing that Mentions does not already do (other than a non-prefixed pattern, but I will commit that shortly).
Cheers,
Deciphered.
#10
There can be actually plenty of usages and FUN things opening up for community/social sites
provided these two modules (Mentions and User name highlighter) do not break each other OR are merged usefully keeping all the options of both open to a site administrator.
If the issue of server load can be minimized or are predictable/throttlable this can prove useful to shared webhosting users too!
Highlighting an user name is FUN particularly in community or social sites and it can be turned on special days like valentines. If it is themable, more than the background color, with small pixes or icons it can add lot of jingle :). In fact it can be sounds also ( small 1kb flash files with fun sounds on click ) which you get on-name-click.
The Mentions is of another dimension where there can twitter / jaiko / pownce like springboard for those who all want it. It can be not just an important community-add-on but also an useful tool for business or exchanges/classified sites.
I cannot believe with such brilliant coders around in the community that
# The two modules cannot be kept as it is OR merged keeping whatever functions both of them do now
# resource load issue cannot be sorted favorably
These two modules needs MORE attention, perhaps BOOK PAGES ( will try to write one when have time) MORE forum posts and multiple focuses in the various groups of drupal org.
Pledging it for Drupal7x and 8x is surely going to attract a lot more feedback and users.
#11
Attached is a quick patch I knocked up. I know this may be stepping over the line, but I thought I would show you how I think this should be done.
Patch strips out the filter functions from UNH and adds dependency on Mentions.
For the highlighting I used hook_theme_registry_alter() to override theme_mentions() with theme_username_highlighter_mentions(), which adds the background-color style to the output.
Let me know what you think.
Cheers,
Deciphered.