Regarding Bug #2779591, a more sophisticated algorithm for truncating a string would be as follows:
// Truncate a string S at the first space following N characters.
Function shorten($s,$n) {
$i = strpos($s," ",$n);
if ($i > 0) {
return substr($s,0,$i);
}
else return substr($s,0,$n);
}
One step further in sophistication, which preserves elements in [] bracket pairs (as I suggest in Feature Request #2777810):
// Truncate a string S at the first space following N characters.
Function shorten($s,$n) {
for ($i=0; $i<strlen($s); $i++) {
if ($s[$i] == '[') $wiki = 1; // Preserve [] pairs.
if ($s[$i] == ']') $wiki = 0;
if ($s[$i] == ' ' && $i>$n && !$wiki) {
return (substr($s,0,$i));
}
}
return $s;
}