Highlight nonexistent freelinks
tonderai - January 29, 2007 - 16:04
| Project: | freelinking |
| Version: | HEAD |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
I wanted to highlight those freelinks which don't link to existing content, Wikipedia style. This patch, against 4.7 (v1.28), tests every link on the page, and attaches different CSS classes for existant and nonexistant links.
It seems to work, but hasn't been thoroughly tested. I'd imagine there aren't too many complications, since it relies exclusively on pre-existing functions. Hopefully I've done the patch correctly, as it's my first one!
I guess this could add some significant server load, but I think it is an important feature for the usability of a wiki.
| Attachment | Size |
|---|---|
| freelinking_highlight_nonexistants.patch | 1.23 KB |

#1
IMHO it should only be necessary to add the class for the "redlink" to the nonexistent content. A link to content that exists is, well, an ordinary link.
#2
Here's my patch (against freelinking.module 5.x-1.2) for the same ends.
-N
276a277,279
> else if (!_freelinking_exists($phrase)) {
> $replacement = l($phrase, 'freelinking/' . rawurlencode($freelink), array('class' => 'freelinking_nonexistent'));
> }
#3
Two things I'll point out about this as well is that 1) CamelCase links don't currently get any class at all which isn't good and also in the same vein 2) this patch should apply the nonexistent class to both freelinking and CamelCase links. The only question about implementation is what is the desired set of classes?
E.g. we can have:
- all links get something like class="wikilink"
- in addition each gets a class for the type (freelinking or camelcase)
- then we add nonexistent where needed
This could give you then something like this, for example: class="wikilink freelinking nonexistent"
That gives the most flexibility when theming and I'm inclined to give people enough to do what they want but what do you all think? There is no problem with backwards compatibility since we are adding and not taking away. I'll work up a patch for this tomorrow.
#4
OK, well I started the patch tonight and while the logic for adding classes is very straightforward the problem we encounter is that filters are cached. What this means is that once I create a freelink, then I go create that page, freelinking doesn't realize the page has been created now and still adds the no-page class because it is just getting its stuff from the cache and running the logic fresh again.
I've attached a patch with what I did but I didn't get so far as to get the 'no cache' to work properly so the link classes are updated real time.
#5
Thank you Addison Berry,
I think following code maybe usefull for some people:
after excute the freelinking_nonexistent-pages-class-113869-4.patch
add too style.css file (for example:drupal\themes\bluemarine) this code
.wikilink.freelinking {
color: #39c;
}
.wikilink.freelinking.no-page {
color: #FF0000;
}
#6
FYI susurrus has submitted a patch that classes external and nonexistent freelinks for D6 at http://drupal.org/node/204282 , though of course it will be some time before our site will be making that upgrade.
#7
A method to replicate the behavior through theming is available at http://groups.drupal.org/node/9561#comments .
#8
Could we somehow get this integrated correctly into freelinking? I've tried adding that code as suggested, and it does not work for me.
<?php// put it in the theme/node page, right before you print $content
// assumes $content, and gives back colorized $content
$theHTML = $content;
$result = "";
$strLength = strlen($theHTML);
while (true) {
$spot = strpos($theHTML, "<a ");
if (!$spot) {
break;
} else {
$result = $result . substr($theHTML,0,$spot);
$theHTML = substr($theHTML, $spot, strlen($theHTML) - $spot);
$spot2 = strpos($theHTML, ">");
if ( !spot2 ) {
break;
} else {
$theLink = substr($theHTML, 0, $spot2+4);
if (strpos($theLink, "href=\"/wiki/")) {
$start = strpos($theLink, "href=\"/wiki/");
$end = strpos($theLink, "\">");
$start = $start +12;
$xtitle = substr($theLink, $start, $end-$start);
$start = strpos($theLink, "href=\"\">");
$start2 = strpos($theLink, "\">", $start);
$start3 = strpos($theLink, "\">", $start2);
$end = strpos($theLink, "</a>");
$start3 = $start3 +3;
$titletext = substr($theLink, $start3-1, $end-$start3+1);
$xtitle = str_replace("%2C", ",", $xtitle);
$xtitle = str_replace("_", " ", $xtitle);
$MrNode = node_load(array('title' => $xtitle));
$theTitle = $MrNode->xtitle;
$theNode = $MrNode->nid;
if ( !$theNode > 0 ) {
$theLink = str_replace("class=\"\"", "class=\"broken\"", $theLink);
$theLink = str_replace("style=\"\"", "style=\"color: grey; font-weight: 100\"", $theLink);
}
}
$result = $result . $theLink;
$theHTML = substr($theHTML, $spot2 +4, strlen($theHTML) - $spot2);
}
}
$strLength = strlen($theHTML);
}
$result = $result . $theHTML;
$content = $result;
?>
#9
Will it be implemented in future releases of Freelinking?
It is very usefull feature for making wiki-like site.
The code above didn't helped - it always recognizes links as broken.
#10
I use the D6 version of freelinking and non existant freelinks have a class called 'noexist'. Using this class in the theme css file, I can mimic the behavior of Wikipedia. Don't know whether the noexist class is available for D5.
#11
Do you use code above?
I tried it but it always adds class "broken" (noexist) even if article is available
#12
ah.. #4 works very well. Just tweaked it a little.
Thank you!
#13
+subscribing
Please could this be ported to version 6?
#14
Development effort right now is focused on the 6.x-3.x. Reviewed & tested patches will be considered for earlier versions of Freelinking.
#15
#16
"Non-existing freelinks" are taken care of in FL3.
#17
Automatically closed -- issue fixed for 2 weeks with no activity.