fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2010-07-12 09:33 am

[dw-free] Investigate using cgi-bin/imageconf.pl instead of scattering image URLs all over the place

[commit: http://hg.dwscoalition.org/dw-free/rev/9d9de7627e00]

http://bugs.dwscoalition.org/show_bug.cgi?id=1207

weblib, ssl support for dw-free site scheme.

Patch by [personal profile] kareila.

Files modified:
  • bin/upgrading/en.dat
  • cgi-bin/bml/scheme/celerity.look
  • cgi-bin/imageconf.pl
  • cgi-bin/weblib.pl
--------------------------------------------------------------------------------
diff -r f9070bf7b9e9 -r 9d9de7627e00 bin/upgrading/en.dat
--- a/bin/upgrading/en.dat	Mon Jul 12 16:28:36 2010 +0800
+++ b/bin/upgrading/en.dat	Mon Jul 12 17:39:45 2010 +0800
@@ -2019,6 +2019,8 @@ img.edittags=Edit Tags
 
 img.foaf=FOAF
 
+img.help=Help
+
 img.hourglass=Waiting...
 
 img.id_anonymous=Anonymous
diff -r f9070bf7b9e9 -r 9d9de7627e00 cgi-bin/bml/scheme/celerity.look
--- a/cgi-bin/bml/scheme/celerity.look	Mon Jul 12 16:28:36 2010 +0800
+++ b/cgi-bin/bml/scheme/celerity.look	Mon Jul 12 17:39:45 2010 +0800
@@ -143,7 +143,6 @@ userpic<=
 userpic<=
 <?_code
 {
-    my $imgprefix = $LJ::IS_SSL ? $LJ::SSLIMGPREFIX : $LJ::IMGPREFIX;
     my $remote = LJ::get_remote();
     my $ret;
 
@@ -155,7 +154,7 @@ userpic<=
             my $wh = $userpic->img_fixedsize( width => 80, height => 80 );
             $ret .= "<img src='" . $userpic->url . "' $wh alt=\"$ML{'sitescheme.accountlinks.userpic.alt'}\" />";
         } else {
-            $ret .= "<img src='$imgprefix/nouserpic.png' width='80' height='80' alt=\"$ML{'sitescheme.accountlinks.userpic.alt'}\" />";
+            $ret .= LJ::img( "nouserpic_sitescheme", "", { ssl => 1 } );
         }
     }
 
diff -r f9070bf7b9e9 -r 9d9de7627e00 cgi-bin/imageconf.pl
--- a/cgi-bin/imageconf.pl	Mon Jul 12 16:28:36 2010 +0800
+++ b/cgi-bin/imageconf.pl	Mon Jul 12 17:39:45 2010 +0800
@@ -56,6 +56,13 @@ use vars qw(%img);
     src => '/silk/comments/delete.png',
     width => 16,
     height => 16,
+    alt => 'img.btn_del',
+};
+
+$img{btn_trash} = {
+    src => '/portal/btn_del.gif',
+    width => 15,
+    height => 15,
     alt => 'img.btn_del',
 };
 
@@ -204,6 +211,13 @@ use vars qw(%img);
     width => 16,
     height => 16,
     alt => 'img.key',
+};
+
+$img{help} = {
+    src => '/silk/site/help.png',
+    width => 14,
+    height => 14,
+    alt => 'img.help',
 };
 
 $img{hourglass} = {
diff -r f9070bf7b9e9 -r 9d9de7627e00 cgi-bin/weblib.pl
--- a/cgi-bin/weblib.pl	Mon Jul 12 16:28:36 2010 +0800
+++ b/cgi-bin/weblib.pl	Mon Jul 12 17:39:45 2010 +0800
@@ -53,25 +53,30 @@ sub img
     my $type = shift;  # either "" or "input"
     my $attr = shift;
 
-    my $attrs;
-    my $alt;
-    if ($attr) {
-        if (ref $attr eq "HASH") {
-            $alt = LJ::ehtml($attr->{alt}) if (exists $attr->{alt});
-            foreach (keys %$attr) {
-                $attrs .= " $_=\"" . LJ::ehtml($attr->{$_}) . "\""
-                    unless ((lc $_) eq 'alt');
+    my ( $attrs, $alt, $ssl );
+    if ( $attr ) {
+        if ( ref $attr eq "HASH" ) {
+            if ( exists $attr->{alt} ) {
+                $alt = LJ::ehtml( $attr->{alt} );
+                delete $attr->{alt};
             }
+            if ( exists $attr->{ssl} ) {
+                $ssl = $attr->{ssl} && $LJ::IS_SSL;
+                delete $attr->{ssl};
+            }
+            $attrs .= " $_=\"" . LJ::ehtml( $attr->{$_} ) . "\""
+                foreach keys %$attr;
         } else {
             $attrs = " name=\"$attr\"";
         }
     }
 
     my $i = $LJ::Img::img{$ic};
-    $alt ||= LJ::Lang::string_exists($i->{'alt'}) ? LJ::Lang::ml($i->{'alt'}) : $i->{'alt'};
+    my $imgprefix = $ssl ? $LJ::SSLIMGPREFIX : $LJ::IMGPREFIX;
+    $alt ||= LJ::Lang::string_exists( $i->{alt} ) ? LJ::Lang::ml( $i->{alt} ) : $i->{alt};
     if ($type eq "") {
-        return "<img src=\"$LJ::IMGPREFIX$i->{'src'}\" width=\"$i->{'width'}\" ".
-            "height=\"$i->{'height'}\" alt=\"$alt\" title=\"$alt\" ".
+        return "<img src=\"$imgprefix$i->{src}\" width=\"$i->{width}\" ".
+            "height=\"$i->{height}\" alt=\"$alt\" title=\"$alt\" ".
             "border='0'$attrs />";
     }
     if ($type eq "input") {
@@ -260,8 +265,8 @@ sub help_icon_html {
     my $url = $LJ::HELPURL{$topic} or return "";
     my $pre = shift || "";
     my $post = shift || "";
-    # FIXME: use LJ::img() here, not hard-coding width/height
-    return "$pre<a href=\"$url\" class=\"helplink\" target=\"_blank\"><img src=\"$LJ::IMGPREFIX/silk/site/help.png\" alt=\"Help\" title=\"Help\" width='14' height='14' border='0' /></a>$post";
+    return "$pre<a href=\"$url\" class=\"helplink\" target=\"_blank\">" .
+           LJ::img( 'help', '' ) . "</a>$post";
 }
 
 # <LJFUNC>
@@ -3327,9 +3332,8 @@ sub subscribe_interface {
                     action => 'delsub'
                 );
                 my $deletesub_url = $settings_page ? "$LJ::SITEROOT/manage/settings/?cat=notifications&deletesub_$subid=1" : "?deletesub_$subid=1";
-                $cat_html .= qq {
-                    <a href='$deletesub_url' class='delete-button' subid=$subid auth_token=$auth_token><img src="$LJ::IMGPREFIX/portal/btn_del.gif" alt="Delete"/></a>
-                };
+                $cat_html .= "<a href='$deletesub_url' class='delete-button' subid=$subid auth_token=$auth_token>";
+                $cat_html .= LJ::img( 'btn_trash', '' ) . "</a>\n";
             }
             my $always_checked = eval { "$evt_class"->always_checked; };
             my $disabled = $always_checked ? 1 : !$pending_sub->enabled;
--------------------------------------------------------------------------------