[dw-free] userpic title should not be keyword
[commit: http://hg.dwscoalition.org/dw-free/rev/3bcc18c882aa]
http://bugs.dwscoalition.org/show_bug.cgi?id=2773
1. Changes alt and title text to:
ALT: username: description (keyword), comment TITLE: username: keyword,
comment (description)
2. Move HTML cleanup into LJ::Userpic's alttext method, instead of the
callers. Call this method where applicable
3. Create a titletext method in LJ::Userpic, and use ths method where
applicable.
Patch by
deborah.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=2773
1. Changes alt and title text to:
ALT: username: description (keyword), comment TITLE: username: keyword,
comment (description)
2. Move HTML cleanup into LJ::Userpic's alttext method, instead of the
callers. Call this method where applicable
3. Create a titletext method in LJ::Userpic, and use ths method where
applicable.
Patch by
Files modified:
- cgi-bin/LJ/S2.pm
- cgi-bin/LJ/Userpic.pm
--------------------------------------------------------------------------------
diff -r 5ba741324569 -r 3bcc18c882aa cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm Sat Feb 18 13:57:48 2012 +0800
+++ b/cgi-bin/LJ/S2.pm Sat Feb 18 14:42:05 2012 +0800
@@ -2371,30 +2371,16 @@
$width ||= $p->width;
$height ||= $p->height;
- # load the alttext. use description by default, keyword as fallback,
- # and all keywords as final fallback (should be for default icon only).
- my $description = $p->description;
- my $alttext;
-
- if ($description) {
- $alttext = $description;
- } elsif ($kw) {
- $alttext = $kw;
- } else {
- my $kwstr = $p->keywords;
- $alttext = $kwstr;
- }
-
- my $title = $u->display_name;
- $title .= $kw ? ": $kw" : ": (default)";
+ my $alttext = $p->alttext( $kw );
+ my $title = $p->titletext( $kw );
return {
'_type' => "Image",
'url' => "$LJ::USERPIC_ROOT/$picid/$u->{'userid'}",
'width' => $width,
'height' => $height,
- 'alttext' => LJ::ehtml( $alttext ),
- 'extra' => { title => LJ::ehtml( $title ) },
+ 'alttext' => $alttext,
+ 'extra' => { title => $title },
};
}
diff -r 5ba741324569 -r 3bcc18c882aa cgi-bin/LJ/Userpic.pm
--- a/cgi-bin/LJ/Userpic.pm Sat Feb 18 13:57:48 2012 +0800
+++ b/cgi-bin/LJ/Userpic.pm Sat Feb 18 14:42:05 2012 +0800
@@ -40,7 +40,7 @@
##
# url : returns a URL directly to the userpic
# fullurl : returns the URL used at upload time, it if exists
-# altext : description with keyword fallback; keyword-recently-used dependent
+# altext : "username: keyword, comment (description)"
# u, owner : return the user object indicated by the userid
# legal image types
@@ -360,24 +360,73 @@
return $self->{url};
}
+
# given a userpic and a keyword, return the alt text
sub alttext {
my ( $self, $kw ) = @_;
- # load the alttext. use description by default, keyword as fallback,
- # and all keywords as final fallback (should be for default icon only).
+ # load the alttext.
+ # "username: description (keyword), comment"
+ # If any of those are not present leave them (and their
+ # affiliated punctuation) out.
+ # Minimum will be "username: (default system keyword)" if user
+ # hasn't set anything manually.
- # NOTE: This returns the alttext raw, and relies on the callers (usually
- # but not always Userpic->imgtag) to strip any special characters.
+ # always include the username
+ my $u = $self->owner;
+ my $alt = $u->username . ":";
if ($self->description) {
- return $self->description;
- } elsif ($kw) {
- return $kw;
+ $alt .= " " . $self->description;
+ }
+
+ # If we don't have the particular keyword, load all of the
+ # keywords for this userpic
+ if ($kw) {
+ $alt .= " (" . $kw . ")";
} else {
- return $self->keywords;
+ $alt .= " (" . $self->keywords . ")";
}
+ if ($self->comment) {
+ $alt .= ", " .$self->comment;
+ }
+
+ return LJ::ehtml( $alt );
+
+}
+
+# given a userpic and a keyword, return the title text
+sub titletext {
+ my ( $self, $kw ) = @_;
+
+ # load the titletext.
+ # "username: keyword, comment (description)"
+ # If any of those are not present leave them (and their
+ # affiliated punctuation) out.
+
+ # always include the username
+ my $u = $self->owner;
+ my $title = $u->username . ":";
+
+ # If we don't have the particular keyword, load all of the
+ # keywords for this userpic
+ if ($kw) {
+ $title .= " " . $kw;
+ } else {
+ $title .= " " . $self->keywords;
+ }
+
+ if ($self->comment) {
+ $title .= ", " .$self->comment;
+ }
+
+ if ($self->description) {
+ $title .= " (" . $self->description . ")";
+ }
+
+ return LJ::ehtml( $title );
+
}
# returns an image tag of this userpic
@@ -393,23 +442,8 @@
my $height = $opts{height} || $self->height;
my $keyword = $opts{keyword} || $self->keywords;
- # if no description is available for alttext, try to fall
- # back to the keyword selected by the user (passed as a
- # parameter to imgtag). Otherwise, use the entire keyword
- # string from the userpic.
-
- my $alttext = LJ::ehtml( $self->alttext( $keyword ) );
-
- # if we passed in a user, format as if for entries or comments
- # otherwise, print out keywords for additional context
- my $title = "";
- if ( $opts{user} ) {
- $title = $opts{user}->display_name;
- $title .= $opts{keyword} ? ": $opts{keyword}" : ": (default)";
- } else {
- $title = $keyword;
- }
- $title = LJ::ehtml( $title );
+ my $alttext = $self->alttext( $keyword );
+ my $title = $self->titletext( $keyword );
return '<img src="' . $self->url . '" width="' . $width .
'" height="' . $height . '" alt="' . $alttext .
--------------------------------------------------------------------------------
