Skip to content

Commit

Permalink
Added var comment_nonstartwordchars to allow specifying chars that don't
Browse files Browse the repository at this point in the history
count as word breaks when they start a word.  This is to work around a
display bug in Microsoft Windows/Microsoft Internet Explorer in which a
sequence of words in the format ".foo .bar .baz" does not word-wrap.
  • Loading branch information
jamiemccarthy committed Mar 15, 2002
1 parent 35adc38 commit 03c9379
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 10 deletions.
25 changes: 25 additions & 0 deletions Slash/DB/MySQL/MySQL.pm
Expand Up @@ -4301,6 +4301,31 @@ sub getSlashConf {
};
}
if ($conf{comment_nonstartwordchars}) {
# Expand this into a complete regex. We catch not only
# these chars in their raw form, but also all HTML entities
# (because Windows/MSIE refuses to break before any word
# that starts with either the chars, or their entities).
# Build the regex with qr// and match entities for
# optimal speed.
my $src = $conf{comment_nonstartwordchars};
my @chars = ( );
my @entities = ( );
for my $i (0..length($src)-1) {
my $c = substr($src, $i, 1);
push @chars, "\Q$c";
push @entities, ord($c);
push @entities, sprintf("x%x", ord($c));
}
my $dotchar =
'(?:'
. '[' . join("", @chars) . ']'
. '|&#(?:' . join("|", @entities) . ');'
. ')';
my $regex = '^(\s+' . "$dotchar+" . ')\S';
$conf{comment_nonstartwordchars_regex} = qr{$regex}i;
}

$conf{badreasons} = 4 unless defined $conf{badreasons};

# for fun ... or something
Expand Down
49 changes: 41 additions & 8 deletions Slash/Utility/Data/Data.pm
Expand Up @@ -736,7 +736,8 @@ sub processCustomTags {
=head2 breakHtml(TEXT, MAX_WORD_LENGTH)
Private function. Break up long words in some text. Will ignore the
contents of HTML tags. Called from C<stripByMode> functions.
contents of HTML tags. Called from C<stripByMode> functions. Handles
spaces before dot-words so as to best work around a Microsoft bug.
=over 4
Expand Down Expand Up @@ -776,19 +777,51 @@ sub breakHtml {

$mwl = $mwl || $constants->{'breakhtml_wordlength'} || 50;
$l = length $text;
my $cnswcr = $constants->{comment_nonstartwordchars_regex};

for (my $i = 0; $i < $l; $new .= $c, ++$i) {
for (my $i = 0; $i < $l; ++$i) {
my $append_c = 1;
$c = substr($text, $i, 1);
if ($c eq '<') { $in_tag = 1 }
elsif ($c eq '>') {
if ($c eq '<') { $in_tag = 1 }
elsif ($c eq '>') {
$in_tag = 0;
$this_tag =~ s{^/?(\S+).*}{\U$1};
$cwl = 0 if $is_break_tag{$this_tag};
$this_tag = '';
}
elsif ($in_tag) { $this_tag .= $c }
elsif ($c =~ /\s/) { $cwl = 0 }
elsif (++$cwl > $mwl) { $new .= ' '; $cwl = 1 }
} elsif ($in_tag) { $this_tag .= $c }
elsif ($c =~ /\s/) {
my $nsc;
if (($nsc) = substr($text, $i) =~ $cnswcr) {
# This space doesn't count as a wordbreak because of
# a Windows/MSIE bug. The regex puts everything up to
# and including the non-start-char(s) into $nsc.
my $nsclen = length($nsc);
if ($cwl+$nsclen >= $mwl) {
# If lots of nscs were given, break them up
# before appending. Start with the first,
# then all $mwl-long sequences after that.
$nsc =~ s{(\S)}{$1 };
while ($nsc =~ m{\S{$mwl,}\S}o) {
$nsc =~ s{(\S{$mwl})(\S)}{$1 $2}o;
}
$new .= "$nsc "; # append the nsc(s)
$i += $nsclen # we're skipping ahead
-1; # account for ++$i coming up
$cwl = 0; # starting new word
$append_c = 0;
} else {
$new .= $nsc; # append the nsc(s)
$i += $nsclen # we're skipping ahead
-1; # account for ++$i coming up
$cwl += $nsclen; # still in a word
$append_c = 0;
}
} else {
# This space does count as a wordbreak.
$cwl = 0;
}
} elsif (++$cwl > $mwl) { $new .= ' '; $cwl = 1 }
$new .= $c if $append_c;
}

return $new;
Expand Down
1 change: 1 addition & 0 deletions sql/mysql/defaults.sql
Expand Up @@ -370,6 +370,7 @@ INSERT INTO vars (name, value, description) VALUES ('comment_cache_newstyle','0'
INSERT INTO vars (name, value, description) VALUES ('comment_cache_purge_max_frac','0.75','In purging the _comment_text cache, fraction of max_keys to target');
INSERT INTO vars (name, value, description) VALUES ('comment_cache_purge_min_comm','50','Min number comments in a discussion for it to force a cache purge');
INSERT INTO vars (name, value, description) VALUES ('comment_cache_purge_min_req','5','Min number times a discussion must be requested to force a cache purge');
INSERT INTO vars (name, value, description) VALUES ('comment_nonstartwordchars','.,;:/','Chars which cannot start a word (will be forcibly separated from the rest of the word by a space) - this works around a Windows/MSIE "widening" bug - set blank for no action');
INSERT INTO vars (name, value, description) VALUES ('comment_maxscore','5','Maximum score for a specific comment');
INSERT INTO vars (name, value, description) VALUES ('comment_minscore','-1','Minimum score for a specific comment');
INSERT INTO vars (name, value, description) VALUES ('commentsPerPoint','1000','For every X comments, valid users get a Moderator Point');
Expand Down
15 changes: 13 additions & 2 deletions sql/mysql/upgrades
Expand Up @@ -102,6 +102,17 @@ ALTER TABLE sessions add column last_sid varchar(16);

# Start of T_2_3_0_15

# add ECODE tag ... YMMV if you've edited approvedtags previously
UPDATE vars SET value = "B|I|P|A|LI|OL|UL|EM|BR|TT|STRONG|BLOCKQUOTE|DIV|ECODE" WHERE name = "approvedtags";
# add ECODE tag ...
UPDATE vars SET value=CONCAT(value,'|ECODE') WHERE name='approvedtags';

# Message threshold
INSERT INTO vars (name, value, description) VALUES ('message_threshold','1','Default threshold for a comment to trigger a message');

# End of R_2_3_0_15

# Start of T_2_3_0_16

# Browser bug workaround
INSERT INTO vars (name, value, description) VALUES ('comment_nonstartwordchars','.,;:/','Chars which cannot start a word (will be forcibly separated from the rest of the word by a space) - this works around a Windows/MSIE "widening" bug - set blank for no action')
;

0 comments on commit 03c9379

Please sign in to comment.