diff -durN MT-2.661-full-lib/extlib/CGI.pm MT/extlib/CGI.pm
--- MT-2.661-full-lib/extlib/CGI.pm	Mon Dec 22 19:06:32 2003
+++ MT/extlib/new/CGI.pm	Mon Dec 29 19:32:01 2003
@@ -18,22 +18,29 @@
 # The most recent version and complete docs are available at:
 #   http://stein.cshl.org/WWW/software/CGI/
 
-$CGI::revision = '$Id: CGI.pm,v 1.55 2001/09/26 02:15:52 lstein Exp $';
-$CGI::VERSION='2.78';
+$CGI::revision = '$Id: CGI.pm,v 1.88 2003/02/11 14:13:18 lstein Exp $';
+$CGI::VERSION='2.91';
 
 # HARD-CODED LOCATION FOR FILE UPLOAD TEMPORARY FILES.
 # UNCOMMENT THIS ONLY IF YOU KNOW WHAT YOU'RE DOING.
 # $CGITempFile::TMPDIRECTORY = '/usr/tmp';
 use CGI::Util qw(rearrange make_attributes unescape escape expires);
 
-use constant XHTML_DTD => ['-//W3C//DTD XHTML Basic 1.0//EN',
-                           'http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd'];
+#use constant XHTML_DTD => ['-//W3C//DTD XHTML Basic 1.0//EN',
+#                           'http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd'];
+
+use constant XHTML_DTD => ['-//W3C//DTD XHTML 1.0 Transitional//EN',
+                           'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'];
+
+$TAINTED = substr("$0$^X",0,0);
+
+my @SAVED_SYMBOLS;
 
 # >>>>> Here are some globals that you might want to adjust <<<<<<
 sub initialize_globals {
     # Set this to 1 to enable copious autoloader debugging messages
     $AUTOLOAD_DEBUG = 0;
-    
+
     # Set this to 1 to generate XTML-compatible output
     $XHTML = 1;
 
@@ -66,6 +73,16 @@
     #    2) CGI::private_tempfiles(1);
     $PRIVATE_TEMPFILES = 0;
 
+    # Set this to 1 to cause files uploaded in multipart documents
+    # to be closed, instead of caching the file handle
+    # or:
+    #    1) use CGI qw(:close_upload_files)
+    #    2) $CGI::close_upload_files(1);
+    # Uploads with many files run out of file handles.
+    # Also, for performance, since the file is already on disk,
+    # it can just be renamed, instead of read and written.
+    $CLOSE_UPLOAD_FILES = 0;
+
     # Set this to a positive value to limit the size of a POSTing
     # to a certain number of bytes:
     $POST_MAX = -1;
@@ -82,9 +99,9 @@
     # separate the name=value pairs by semicolons rather than ampersands
     $USE_PARAM_SEMICOLONS = 1;
 
-	# Do not include undefined params parsed from query string
-	# use CGI qw(-no_undef_params);
-	$NO_UNDEF_PARAMS = 0;
+    # Do not include undefined params parsed from query string
+    # use CGI qw(-no_undef_params);
+    $NO_UNDEF_PARAMS = 0;
 
     # Other globals that you shouldn't worry about.
     undef $Q;
@@ -124,12 +141,14 @@
     $OS = 'OS2';
 } elsif ($OS =~ /^epoc/i) {
     $OS = 'EPOC';
+} elsif ($OS =~ /^cygwin/i) {
+    $OS = 'CYGWIN';
 } else {
     $OS = 'UNIX';
 }
 
 # Some OS logic.  Binary mode enabled on DOS, NT and VMS
-$needs_binmode = $OS=~/^(WINDOWS|DOS|OS2|MSWin)/;
+$needs_binmode = $OS=~/^(WINDOWS|DOS|OS2|MSWin|CYGWIN)/;
 
 # This is the default class for the CGI object to use when all else fails.
 $DefaultClass = 'CGI' unless defined $CGI::DefaultClass;
@@ -141,7 +160,8 @@
 # on the paltform.
 $SL = {
        UNIX=>'/', OS2=>'\\', EPOC=>'/',
-       WINDOWS=>'\\', DOS=>'\\', MACINTOSH=>':', VMS=>'/'
+       WINDOWS=>'\\', DOS=>'\\', MACINTOSH=>':', VMS=>'/',
+       CYGWIN=>'/',
     }->{$OS};
 
 # This no longer seems to be necessary
@@ -150,13 +170,19 @@
 $IIS++ if defined($ENV{'SERVER_SOFTWARE'}) && $ENV{'SERVER_SOFTWARE'}=~/IIS/;
 
 # Turn on special checking for Doug MacEachern's modperl
-if (exists $ENV{'GATEWAY_INTERFACE'} 
-    && 
+if (exists $ENV{'GATEWAY_INTERFACE'}
+    &&
     ($MOD_PERL = $ENV{'GATEWAY_INTERFACE'} =~ /^CGI-Perl\//))
-{
+  {
     $| = 1;
-    require Apache;
-}
+    require mod_perl;
+    if ($mod_perl::VERSION >= 1.99) {
+      eval "require Apache::compat";
+    } else {
+      eval "require Apache";
+    }
+  }
+
 # Turn on special checking for ActiveState's PerlEx
 $PERLEX++ if defined($ENV{'GATEWAY_INTERFACE'}) && $ENV{'GATEWAY_INTERFACE'} =~ /^CGI-PerlEx/;
 
@@ -188,6 +214,9 @@
 			   input Select option comment charset escapeHTML/],
 		':html3'=>[qw/div table caption th td TR Tr sup Sub strike applet Param 
 			   embed basefont style span layer ilayer font frameset frame script small big/],
+                ':html4'=>[qw/abbr acronym bdo col colgroup del fieldset iframe
+                            ins label legend noframes noscript object optgroup Q 
+                            thead tbody tfoot/], 
 		':netscape'=>[qw/blink fontsize center/],
 		':form'=>[qw/textfield textarea filefield password_field hidden checkbox checkbox_group 
 			  submit reset defaults radio_group popup_menu button autoEscape
@@ -203,19 +232,19 @@
 		':ssl' => [qw/https/],
 		':imagemap' => [qw/Area Map/],
 		':cgi-lib' => [qw/ReadParse PrintHeader HtmlTop HtmlBot SplitParam Vars/],
-		':html' => [qw/:html2 :html3 :netscape/],
-		':standard' => [qw/:html2 :html3 :form :cgi/],
+		':html' => [qw/:html2 :html3 :html4 :netscape/],
+		':standard' => [qw/:html2 :html3 :html4 :form :cgi/],
 		':push' => [qw/multipart_init multipart_start multipart_end multipart_final/],
-		':all' => [qw/:html2 :html3 :netscape :form :cgi :internal/]
+		':all' => [qw/:html2 :html3 :netscape :form :cgi :internal :html4/]
 		);
 
 # to import symbols into caller
 sub import {
     my $self = shift;
 
-# This causes modules to clash.  
-#    undef %EXPORT_OK;
-#    undef %EXPORT;
+    # This causes modules to clash.
+    undef %EXPORT_OK;
+    undef %EXPORT;
 
     $self->_setup_symbols(@_);
     my ($callpack, $callfile, $callline) = caller;
@@ -372,8 +401,11 @@
 
     $fh = to_filehandle($initializer) if $initializer;
 
-    # set charset to the safe ISO-8859-1
-    $self->charset('ISO-8859-1');
+    # set charset to UTF-8
+    $self->charset('UTF-8');
+
+    # set autoescaping to on
+    $self->{'escape'} = 1;
 
   METHOD: {
 
@@ -546,6 +578,7 @@
     my($param,$value);
     foreach (@pairs) {
 	($param,$value) = split('=',$_,2);
+	next unless defined $param;
 	next if $NO_UNDEF_PARAMS and not defined $value;
 	$value = '' unless defined $value;
 	$param = unescape($param);
@@ -578,15 +611,14 @@
     my ($self,$tagname) = @_;
     my $func = qq(
 	sub $tagname {
-            shift if \$_[0] && 
-                    (ref(\$_[0]) &&
-                     (substr(ref(\$_[0]),0,3) eq 'CGI' ||
-                    UNIVERSAL::isa(\$_[0],'CGI')));
-	    my(\$attr) = '';
-	    if (ref(\$_[0]) && ref(\$_[0]) eq 'HASH') {
-		my(\@attr) = make_attributes(shift()||undef,1);
-		\$attr = " \@attr" if \@attr;
-	    }
+         my (\$q,\$a,\@rest) = self_or_default(\@_);
+         my(\$attr) = '';
+	 if (ref(\$a) && ref(\$a) eq 'HASH') {
+	    my(\@attr) = make_attributes(\$a,\$q->{'escape'});
+	    \$attr = " \@attr" if \@attr;
+	  } else {
+	    unshift \@rest,\$a;
+	  }
 	);
     if ($tagname=~/start_(\w+)/i) {
 	$func .= qq! return "<\L$1\E\$attr>";} !;
@@ -597,7 +629,7 @@
 	    return \$XHTML ? "\L<$tagname\E\$attr />" : "\L<$tagname\E\$attr>" unless \@_;
 	    my(\$tag,\$untag) = ("\L<$tagname\E\$attr>","\L</$tagname>\E");
 	    my \@result = map { "\$tag\$_\$untag" } 
-                              (ref(\$_[0]) eq 'ARRAY') ? \@{\$_[0]} : "\@_";
+                              (ref(\$rest[0]) eq 'ARRAY') ? \@{\$rest[0]} : "\@rest";
 	    return "\@result";
             }#;
     }
@@ -652,11 +684,29 @@
     return "$pack\:\:$func_name";
 }
 
+sub _selected {
+  my $self = shift;
+  my $value = shift;
+  return '' unless $value;
+  return $XHTML ? qq( selected="selected") : qq( selected);
+}
+
+sub _checked {
+  my $self = shift;
+  my $value = shift;
+  return '' unless $value;
+  return $XHTML ? qq( checked="checked") : qq( checked);
+}
+
 sub _reset_globals { initialize_globals(); }
 
 sub _setup_symbols {
     my $self = shift;
     my $compile = 0;
+
+    # to avoid reexporting unwanted variables
+    undef %EXPORT;
+
     foreach (@_) {
 	$HEADERS_ONCE++,         next if /^[:-]unique_headers$/;
 	$NPH++,                  next if /^[:-]nph$/;
@@ -668,6 +718,7 @@
 	$XHTML=0,                next if /^[:-]no_?xhtml$/;
 	$USE_PARAM_SEMICOLONS=0, next if /^[:-]oldstyle_urls$/;
 	$PRIVATE_TEMPFILES++,    next if /^[:-]private_tempfiles$/;
+    $CLOSE_UPLOAD_FILES++,   next if /^[:-]close_upload_files$/;
 	$EXPORT{$_}++,           next if /^[:-]any$/;
 	$compile++,              next if /^[:-]compile$/;
 	$NO_UNDEF_PARAMS++,      next if /^[:-]no_undef_params$/;
@@ -689,6 +740,7 @@
 	}
     }
     _compile_all(keys %EXPORT) if $compile;
+    @SAVED_SYMBOLS = @_;
 }
 
 sub charset {
@@ -742,9 +794,15 @@
 sub delete {
     my($self,@p) = self_or_default(@_);
     my($name) = rearrange([NAME],@p);
-    CORE::delete $self->{$name};
-    CORE::delete $self->{'.fieldnames'}->{$name};
-    @{$self->{'.parameters'}}=grep($_ ne $name,$self->param());
+    my @to_delete = ref($name) eq 'ARRAY' ? @$name : ($name);
+    my %to_delete;
+    foreach my $name (@to_delete)
+    {
+        CORE::delete $self->{$name};
+        CORE::delete $self->{'.fieldnames'}->{$name};
+        $to_delete{$name}++;
+    }
+    @{$self->{'.parameters'}}=grep { !exists($to_delete{$_}) } $self->param();
     return wantarray ? () : undef;
 }
 END_OF_FUNC
@@ -967,7 +1025,9 @@
 'autoEscape' => <<'END_OF_FUNC',
 sub autoEscape {
     my($self,$escape) = self_or_default(@_);
-    $self->{'dontescape'}=!$escape;
+    my $d = $self->{'escape'};
+    $self->{'escape'} = $escape;
+    $d;
 }
 END_OF_FUNC
 
@@ -1021,20 +1081,20 @@
 sub Dump {
     my($self) = self_or_default(@_);
     my($param,$value,@result);
-    return '<UL></UL>' unless $self->param;
-    push(@result,"<UL>");
+    return '<ul></ul>' unless $self->param;
+    push(@result,"<ul>");
     foreach $param ($self->param) {
 	my($name)=$self->escapeHTML($param);
-	push(@result,"<LI><STRONG>$param</STRONG>");
-	push(@result,"<UL>");
+	push(@result,"<li><strong>$param</strong>");
+	push(@result,"<ul>");
 	foreach $value ($self->param($param)) {
 	    $value = $self->escapeHTML($value);
-            $value =~ s/\n/<BR>\n/g;
-	    push(@result,"<LI>$value");
+            $value =~ s/\n/<br>\n/g;
+	    push(@result,"<li>$value");
 	}
-	push(@result,"</UL>");
+	push(@result,"</ul>");
     }
-    push(@result,"</UL>");
+    push(@result,"</ul>");
     return join("\n",@result);
 }
 END_OF_FUNC
@@ -1185,11 +1245,11 @@
 
     return undef if $self->{'.header_printed'}++ and $HEADERS_ONCE;
 
-    my($type,$status,$cookie,$target,$expires,$nph,$charset,$attachment,@other) = 
+    my($type,$status,$cookie,$target,$expires,$nph,$charset,$attachment,$p3p,@other) = 
 	rearrange([['TYPE','CONTENT_TYPE','CONTENT-TYPE'],
 			    'STATUS',['COOKIE','COOKIES'],'TARGET',
                             'EXPIRES','NPH','CHARSET',
-                            'ATTACHMENT'],@p);
+                            'ATTACHMENT','P3P'],@p);
 
     $nph     ||= $NPH;
     if (defined $charset) {
@@ -1202,12 +1262,11 @@
     # need to fix it up a little.
     foreach (@other) {
         next unless my($header,$value) = /([^\s=]+)=\"?(.+?)\"?$/;
-	($_ = $header) =~ s/^(\w)(.*)/$1 . lc ($2) . ': '.$self->unescapeHTML($value)/e;
-        $header = ucfirst($header);
+        ($_ = $header) =~ s/^(\w)(.*)/"\u$1\L$2" . ': '.$self->unescapeHTML($value)/e;
     }
 
     $type ||= 'text/html' unless defined($type);
-    $type .= "; charset=$charset" if $type ne '' and $type =~ m!^text/! and $type !~ /\bcharset\b/;
+    $type .= "; charset=$charset" if $type ne '' and $type =~ m!^text/! and $type !~ /\bcharset\b/ and $charset ne '';
 
     # Maybe future compatibility.  Maybe not.
     my $protocol = $ENV{SERVER_PROTOCOL} || 'HTTP/1.0';
@@ -1216,6 +1275,10 @@
 
     push(@header,"Status: $status") if $status;
     push(@header,"Window-Target: $target") if $target;
+    if ($p3p) {
+       $p3p = join ' ',@$p3p if ref($p3p) eq 'ARRAY';
+       push(@header,qq(P3P: policyref="/w3c/p3p.xml" CP="$p3p"));
+    }
     # push all the cookies -- there may be several
     if ($cookie) {
 	my(@cookie) = ref($cookie) && ref($cookie) eq 'ARRAY' ? @{$cookie} : $cookie;
@@ -1280,7 +1343,7 @@
     unshift(@o,'-Target'=>$target) if $target;
     unshift(@o,'-Cookie'=>$cookie) if $cookie;
     unshift(@o,'-Type'=>'');
-    return $self->header(@o);
+    return $self->header(map {$self->unescapeHTML($_)} @o);
 }
 END_OF_FUNC
 
@@ -1298,11 +1361,11 @@
 # $script -> (option) Javascript code (-script)
 # $no_script -> (option) Javascript <noscript> tag (-noscript)
 # $meta -> (optional) Meta information tags
-# $head -> (optional) any other elements you'd like to incorporate into the <HEAD> tag
+# $head -> (optional) any other elements you'd like to incorporate into the <head> tag
 #           (a scalar or array ref)
 # $style -> (optional) reference to an external style sheet
 # @other -> (optional) any other named parameters you'd like to incorporate into
-#           the <BODY> tag.
+#           the <body> tag.
 ####
 'start_html' => <<'END_OF_FUNC',
 sub start_html {
@@ -1317,7 +1380,7 @@
     # while the author needs to be escaped as a URL
     $title = $self->escapeHTML($title || 'Untitled Document');
     $author = $self->escape($author);
-    $lang ||= 'en-US';
+    $lang = 'en-US' unless defined $lang;
     my(@result,$xml_dtd);
     if ($dtd) {
         if (defined(ref($dtd)) and (ref($dtd) eq 'ARRAY')) {
@@ -1334,12 +1397,13 @@
     push @result,qq(<?xml version="1.0" encoding="$encoding"?>) if $xml_dtd; 
 
     if (ref($dtd) && ref($dtd) eq 'ARRAY') {
-        push(@result,qq(<!DOCTYPE html\n\tPUBLIC "$dtd->[0]"\n\t"$dtd->[1]">));
+        push(@result,qq(<!DOCTYPE html\n\tPUBLIC "$dtd->[0]"\n\t "$dtd->[1]">));
     } else {
         push(@result,qq(<!DOCTYPE html\n\tPUBLIC "$dtd">));
     }
-    push(@result,$XHTML ? qq(<html xmlns="http://www.w3.org/1999/xhtml" lang="$lang"><head><title>$title</title>)
-                        : qq(<html lang="$lang"><head><title>$title</title>));
+    push(@result,$XHTML ? qq(<html xmlns="http://www.w3.org/1999/xhtml" lang="$lang" xml:lang="$lang"><head><title>$title</title>)
+                        : ($lang ? qq(<html lang="$lang">) : "<html>") 
+	                  . "<head><title>$title</title>");
 	if (defined $author) {
     push(@result,$XHTML ? "<link rev=\"made\" href=\"mailto:$author\" />"
 								: "<link rev=\"made\" href=\"mailto:$author\">");
@@ -1388,17 +1452,18 @@
     my $cdata_end   = $XHTML ? "\n/* ]]> */-->\n" : " -->\n";
 
     if (ref($style)) {
-     my($src,$code,$stype,@other) =
-         rearrange([SRC,CODE,TYPE],
+     my($src,$code,$verbatim,$stype,@other) =
+         rearrange([SRC,CODE,VERBATIM,TYPE],
                     '-foo'=>'bar', # a trick to allow the '-' to be omitted
                     ref($style) eq 'ARRAY' ? @$style : %$style);
      $type = $stype if $stype;
+     
      if (ref($src) eq "ARRAY") # Check to see if the $src variable is an array reference
-     { # If it is, push a LINK tag for each one.
-       foreach $src (@$src)
+     { # If it is, push a LINK tag for each one
+         foreach $src (@$src)
        {
          push(@result,$XHTML ? qq(<link rel="stylesheet" type="$type" href="$src" />)
-                             : qq(<link rel="stylesheet" type="$type" href="$src">/)) if $src;
+                             : qq(<link rel="stylesheet" type="$type" href="$src">)) if $src;
        }
      }
      else
@@ -1407,7 +1472,10 @@
                            : qq(<link rel="stylesheet" type="$type" href="$src">)
             ) if $src;
       }
-     push(@result,style({'type'=>$type},"$cdata_start\n$code\n$cdata_end")) if $code;
+      if ($verbatim) {
+         push(@result, "<style type=\"text/css\">\n$verbatim\n</style>");
+    }      
+      push(@result,style({'type'=>$type},"$cdata_start\n$code\n$cdata_end")) if $code;
     } else {
      push(@result,style({'type'=>$type},"$cdata_start\n$style\n$cdata_end"));
     }
@@ -1461,7 +1529,7 @@
 
 #### Method: end_html
 # End an HTML document.
-# Trivial method for completeness.  Just returns "</BODY>"
+# Trivial method for completeness.  Just returns "</body>"
 ####
 'end_html' => <<'END_OF_FUNC',
 sub end_html {
@@ -1479,14 +1547,14 @@
 # Parameters:
 #  $action -> optional URL of script to run
 # Returns:
-#   A string containing a <ISINDEX> tag
+#   A string containing a <isindex> tag
 'isindex' => <<'END_OF_FUNC',
 sub isindex {
     my($self,@p) = self_or_default(@_);
     my($action,@other) = rearrange([ACTION],@p);
-    $action = qq/action="$action"/ if $action;
+    $action = qq/ action="$action"/ if $action;
     my($other) = @other ? " @other" : '';
-    return $XHTML ? "<isindex $action$other />" : "<isindex $action$other>";
+    return $XHTML ? "<isindex$action$other />" : "<isindex$action$other>";
 }
 END_OF_FUNC
 
@@ -1508,7 +1576,9 @@
     $enctype = $enctype || &URL_ENCODED;
     unless (defined $action) {
        $action = $self->url(-absolute=>1,-path=>1);
-       $action .= "?$ENV{QUERY_STRING}" if $ENV{QUERY_STRING};
+       if (length($ENV{QUERY_STRING})>0) {
+           $action .= "?$ENV{QUERY_STRING}";
+       }
     }
     $action = qq(action="$action");
     my($other) = @other ? " @other" : '';
@@ -1558,8 +1628,8 @@
     if ( $NOSTICKY ) {
     return wantarray ? ("</form>") : "\n</form>";
     } else {
-    return wantarray ? ($self->get_fields,"</form>") : 
-                        $self->get_fields ."\n</form>";
+    return wantarray ? ("<div>",$self->get_fields,"</div>","</form>") : 
+                        "<div>".$self->get_fields ."</div>\n</form>";
     }
 }
 END_OF_FUNC
@@ -1592,7 +1662,7 @@
     # and WebTV -- not sure it won't break stuff
     my($value) = $current ne '' ? qq(value="$current") : '';
     return $XHTML ? qq(<input type="$tag" name="$name" $value$s$m$other />) 
-                  : qq/<input type="$tag" name="$name" $value$s$m$other>/;
+                  : qq(<input type="$tag" name="$name" $value$s$m$other>);
 }
 END_OF_FUNC
 
@@ -1604,7 +1674,7 @@
 #   $size ->  Optional width of field in characaters.
 #   $maxlength -> Optional maximum number of characters.
 # Returns:
-#   A string containing a <INPUT TYPE="text"> field
+#   A string containing a <input type="text"> field
 #
 'textfield' => <<'END_OF_FUNC',
 sub textfield {
@@ -1620,7 +1690,7 @@
 #   $size ->  Optional width of field in characaters.
 #   $maxlength -> Optional maximum number of characters.
 # Returns:
-#   A string containing a <INPUT TYPE="text"> field
+#   A string containing a <input type="file"> field
 #
 'filefield' => <<'END_OF_FUNC',
 sub filefield {
@@ -1639,7 +1709,7 @@
 #   $size ->  Optional width of field in characters.
 #   $maxlength -> Optional maximum characters that can be entered.
 # Returns:
-#   A string containing a <INPUT TYPE="password"> field
+#   A string containing a <input type="password"> field
 #
 'password_field' => <<'END_OF_FUNC',
 sub password_field {
@@ -1656,7 +1726,7 @@
 #   $rows ->  Optional number of rows in text area
 #   $columns -> Optional number of columns in text area
 # Returns:
-#   A string containing a <TEXTAREA></TEXTAREA> tag
+#   A string containing a <textarea></textarea> tag
 #
 'textarea' => <<'END_OF_FUNC',
 sub textarea {
@@ -1670,8 +1740,8 @@
 
     $name = defined($name) ? $self->escapeHTML($name) : '';
     $current = defined($current) ? $self->escapeHTML($current) : '';
-    my($r) = $rows ? " rows=$rows" : '';
-    my($c) = $cols ? " cols=$cols" : '';
+    my($r) = $rows ? qq/ rows="$rows"/ : '';
+    my($c) = $cols ? qq/ cols="$cols"/ : '';
     my($other) = @other ? " @other" : '';
     return qq{<textarea name="$name"$r$c$other>$current</textarea>};
 }
@@ -1686,7 +1756,7 @@
 #   $onclick -> (optional) Text of the JavaScript to run when the button is
 #                clicked.
 # Returns:
-#   A string containing a <INPUT TYPE="button"> tag
+#   A string containing a <input type="button"> tag
 ####
 'button' => <<'END_OF_FUNC',
 sub button {
@@ -1707,7 +1777,7 @@
     $script = qq/ onclick="$script"/ if $script;
     my($other) = @other ? " @other" : '';
     return $XHTML ? qq(<input type="button"$name$val$script$other />)
-                  : qq/<input type="button"$name$val$script$other>/;
+                  : qq(<input type="button"$name$val$script$other>);
 }
 END_OF_FUNC
 
@@ -1719,7 +1789,7 @@
 #   $value -> (optional) Value of the button when selected (also doubles as label).
 #   $label -> (optional) Label printed on the button(also doubles as the value).
 # Returns:
-#   A string containing a <INPUT TYPE="submit"> tag
+#   A string containing a <input type="submit"> tag
 ####
 'submit' => <<'END_OF_FUNC',
 sub submit {
@@ -1737,7 +1807,7 @@
     $val = qq/ value="$value"/ if defined($value);
     my($other) = @other ? " @other" : '';
     return $XHTML ? qq(<input type="submit"$name$val$other />)
-                  : qq/<input type="submit"$name$val$other>/;
+                  : qq(<input type="submit"$name$val$other>);
 }
 END_OF_FUNC
 
@@ -1747,7 +1817,7 @@
 # Parameters:
 #   $name -> (optional) Name for the button.
 # Returns:
-#   A string containing a <INPUT TYPE="reset"> tag
+#   A string containing a <input type="reset"> tag
 ####
 'reset' => <<'END_OF_FUNC',
 sub reset {
@@ -1757,7 +1827,7 @@
     my($value) = defined($label) ? qq/ value="$label"/ : '';
     my($other) = @other ? " @other" : '';
     return $XHTML ? qq(<input type="reset"$value$other />)
-                  : qq/<input type="reset"$value$other>/;
+                  : qq(<input type="reset"$value$other>);
 }
 END_OF_FUNC
 
@@ -1767,7 +1837,7 @@
 # Parameters:
 #   $name -> (optional) Name for the button.
 # Returns:
-#   A string containing a <INPUT TYPE="submit" NAME=".defaults"> tag
+#   A string containing a <input type="submit" name=".defaults"> tag
 #
 # Note: this button has a special meaning to the initialization script,
 # and tells it to ERASE the current query string so that your defaults
@@ -1809,7 +1879,7 @@
 #   $label -> (optional) a user-readable label printed next to the box.
 #             Otherwise the checkbox name is used.
 # Returns:
-#   A string containing a <INPUT TYPE="checkbox"> field
+#   A string containing a <input type="checkbox"> field
 ####
 'checkbox' => <<'END_OF_FUNC',
 sub checkbox {
@@ -1822,9 +1892,9 @@
 
     if (!$override && ($self->{'.fieldnames'}->{$name} || 
 		       defined $self->param($name))) {
-	$checked = grep($_ eq $value,$self->param($name)) ? ' checked="1"' : '';
+	$checked = grep($_ eq $value,$self->param($name)) ? $self->_checked(1) : '';
     } else {
-	$checked = $checked ? qq/ checked="1"/ : '';
+	$checked = $self->_checked($checked);
     }
     my($the_label) = defined $label ? $label : $name;
     $name = $self->escapeHTML($name);
@@ -1857,16 +1927,16 @@
 #             in the form $label{'value'}="Long explanatory label".
 #             Otherwise the provided values are used as the labels.
 # Returns:
-#   An ARRAY containing a series of <INPUT TYPE="checkbox"> fields
+#   An ARRAY containing a series of <input type="checkbox"> fields
 ####
 'checkbox_group' => <<'END_OF_FUNC',
 sub checkbox_group {
     my($self,@p) = self_or_default(@_);
 
-    my($name,$values,$defaults,$linebreak,$labels,$rows,$columns,
+    my($name,$values,$defaults,$linebreak,$labels,$attributes,$rows,$columns,
        $rowheaders,$colheaders,$override,$nolabels,@other) =
 	rearrange([NAME,[VALUES,VALUE],[DEFAULTS,DEFAULT],
-			  LINEBREAK,LABELS,ROWS,[COLUMNS,COLS],
+            LINEBREAK,LABELS,ATTRIBUTES,ROWS,[COLUMNS,COLS],
 			  ROWHEADERS,COLHEADERS,
 			  [OVERRIDE,FORCE],NOLABELS],@p);
 
@@ -1889,20 +1959,23 @@
 
     my($other) = @other ? " @other" : '';
     foreach (@values) {
-	$checked = $checked{$_} ? qq/ checked="1"/ : '';
+	$checked = $self->_checked($checked{$_});
 	$label = '';
 	unless (defined($nolabels) && $nolabels) {
 	    $label = $_;
 	    $label = $labels->{$_} if defined($labels) && defined($labels->{$_});
 	    $label = $self->escapeHTML($label);
 	}
+        my $attribs = $self->_set_attributes($_, $attributes);
 	$_ = $self->escapeHTML($_,1);
-	push(@elements,$XHTML ? qq(<input type="checkbox" name="$name" value="$_"$checked$other />${label}${break})
-                              : qq/<input type="checkbox" name="$name" value="$_"$checked$other>${label}${break}/);
+        push(@elements,$XHTML ? qq(<input type="checkbox" name="$name" value="$_"$checked$other$attribs />${label}${break})
+                              : qq/<input type="checkbox" name="$name" value="$_"$checked$other$attribs>${label}${break}/);
     }
     $self->register_parameter($name);
     return wantarray ? @elements : join(' ',@elements)            
         unless defined($columns) || defined($rows);
+    $rows = 1 if $rows && $rows < 1;
+    $cols = 1 if $cols && $cols < 1;
     return _tableize($rows,$columns,$rowheaders,$colheaders,@elements);
 }
 END_OF_FUNC
@@ -1914,7 +1987,7 @@
          push @_,$_[0] if @_==1 && $_[0] eq 'CGI';
          my ($self,$toencode,$newlinestoo) = CGI::self_or_default(@_);
          return undef unless defined($toencode);
-         return $toencode if ref($self) && $self->{'dontescape'};
+         return $toencode if ref($self) && !$self->{'escape'};
          $toencode =~ s{&}{&amp;}gso;
          $toencode =~ s{<}{&lt;}gso;
          $toencode =~ s{>}{&gt;}gso;
@@ -1923,8 +1996,8 @@
                      uc $self->{'.charset'} eq 'WINDOWS-1252';
          if ($latin) {  # bug in some browsers
                 $toencode =~ s{'}{&#39;}gso;
-                $toencode =~ s{\x8b}{&#139;}gso;
-                $toencode =~ s{\x9b}{&#155;}gso;
+                $toencode =~ s{\x8b}{&#8249;}gso;
+                $toencode =~ s{\x9b}{&#8250;}gso;
                 if (defined $newlinestoo && $newlinestoo) {
                      $toencode =~ s{\012}{&#10;}gso;
                      $toencode =~ s{\015}{&#13;}gso;
@@ -2009,15 +2082,15 @@
 #             in the form $label{'value'}="Long explanatory label".
 #             Otherwise the provided values are used as the labels.
 # Returns:
-#   An ARRAY containing a series of <INPUT TYPE="radio"> fields
+#   An ARRAY containing a series of <input type="radio"> fields
 ####
 'radio_group' => <<'END_OF_FUNC',
 sub radio_group {
     my($self,@p) = self_or_default(@_);
 
-    my($name,$values,$default,$linebreak,$labels,
+    my($name,$values,$default,$linebreak,$labels,$attributes,
        $rows,$columns,$rowheaders,$colheaders,$override,$nolabels,@other) =
-	rearrange([NAME,[VALUES,VALUE],DEFAULT,LINEBREAK,LABELS,
+  rearrange([NAME,[VALUES,VALUE],DEFAULT,LINEBREAK,LABELS,ATTRIBUTES,
 			  ROWS,[COLUMNS,COLS],
 			  ROWHEADERS,COLHEADERS,
 			  [OVERRIDE,FORCE],NOLABELS],@p);
@@ -2037,7 +2110,7 @@
 
     my($other) = @other ? " @other" : '';
     foreach (@values) {
-	my($checkit) = $checked eq $_ ? qq/ checked="1"/ : '';
+	my($checkit) = $checked eq $_ ? qq/ checked="checked"/ : '';
 	my($break);
 	if ($linebreak) {
           $break = $XHTML ? "<br />" : "<br>";
@@ -2051,9 +2124,10 @@
 	    $label = $labels->{$_} if defined($labels) && defined($labels->{$_});
 	    $label = $self->escapeHTML($label,1);
 	}
+  my $attribs = $self->_set_attributes($_, $attributes);
 	$_=$self->escapeHTML($_);
-	push(@elements,$XHTML ? qq(<input type="radio" name="$name" value="$_"$checkit$other />${label}${break})
-                              : qq/<input type="radio" name="$name" value="$_"$checkit$other>${label}${break}/);
+  push(@elements,$XHTML ? qq(<input type="radio" name="$name" value="$_"$checkit$other$attribs />${label}${break})
+                              : qq/<input type="radio" name="$name" value="$_"$checkit$other$attribs>${label}${break}/);
     }
     $self->register_parameter($name);
     return wantarray ? @elements : join(' ',@elements) 
@@ -2081,8 +2155,9 @@
 sub popup_menu {
     my($self,@p) = self_or_default(@_);
 
-    my($name,$values,$default,$labels,$override,@other) =
-	rearrange([NAME,[VALUES,VALUE],[DEFAULT,DEFAULTS],LABELS,[OVERRIDE,FORCE]],@p);
+    my($name,$values,$default,$labels,$attributes,$override,@other) =
+       rearrange([NAME,[VALUES,VALUE],[DEFAULT,DEFAULTS],LABELS,
+       ATTRIBUTES,[OVERRIDE,FORCE]],@p);
     my($result,$selected);
 
     if (!$override && defined($self->param($name))) {
@@ -2098,12 +2173,22 @@
 
     $result = qq/<select name="$name"$other>\n/;
     foreach (@values) {
-	my($selectit) = defined($selected) ? ($selected eq $_ ? qq/selected="1"/ : '' ) : '';
+        if (/<optgroup/) {
+            foreach (split(/\n/)) {
+                my $selectit = $XHTML ? 'selected="selected"' : 'selected';
+                s/(value="$selected")/$selectit $1/ if defined $selected;
+                $result .= "$_\n";
+            }
+        }
+        else {
+            my $attribs = $self->_set_attributes($_, $attributes);
+	my($selectit) = defined($selected) ? $self->_selected($selected eq $_) : '';
 	my($label) = $_;
 	$label = $labels->{$_} if defined($labels) && defined($labels->{$_});
 	my($value) = $self->escapeHTML($_);
 	$label=$self->escapeHTML($label,1);
-	$result .= "<option $selectit value=\"$value\">$label</option>\n";
+            $result .= "<option$selectit$attribs value=\"$value\">$label</option>\n";
+        }
     }
 
     $result .= "</select>";
@@ -2112,6 +2197,66 @@
 END_OF_FUNC
 
 
+#### Method: optgroup
+# Create a optgroup.
+# Parameters:
+#   $name -> Label for the group
+#   $values -> A pointer to a regular array containing the
+#              values for each option line in the group.
+#   $labels -> (optional)
+#              A pointer to an associative array of labels to print next to each item
+#              in the form $label{'value'}="Long explanatory label".
+#              Otherwise the provided values are used as the labels.
+#   $labeled -> (optional)
+#               A true value indicates the value should be used as the label attribute
+#               in the option elements.
+#               The label attribute specifies the option label presented to the user.
+#               This defaults to the content of the <option> element, but the label
+#               attribute allows authors to more easily use optgroup without sacrificing
+#               compatibility with browsers that do not support option groups.
+#   $novals -> (optional)
+#              A true value indicates to suppress the val attribute in the option elements
+# Returns:
+#   A string containing the definition of an option group.
+####
+'optgroup' => <<'END_OF_FUNC',
+sub optgroup {
+    my($self,@p) = self_or_default(@_);
+    my($name,$values,$attributes,$labeled,$noval,$labels,@other)
+        = rearrange([NAME,[VALUES,VALUE],ATTRIBUTES,LABELED,NOVALS,LABELS],@p);
+
+    my($result,@values);
+    @values = $self->_set_values_and_labels($values,\$labels,$name,$labeled,$novals);
+    my($other) = @other ? " @other" : '';
+
+    $name=$self->escapeHTML($name);
+    $result = qq/<optgroup label="$name"$other>\n/;
+    foreach (@values) {
+        if (/<optgroup/) {
+            foreach (split(/\n/)) {
+                my $selectit = $XHTML ? 'selected="selected"' : 'selected';
+                s/(value="$selected")/$selectit $1/ if defined $selected;
+                $result .= "$_\n";
+            }
+        }
+        else {
+            my $attribs = $self->_set_attributes($_, $attributes);
+            my($label) = $_;
+            $label = $labels->{$_} if defined($labels) && defined($labels->{$_});
+            $label=$self->escapeHTML($label);
+            my($value)=$self->escapeHTML($_,1);
+            $result .= $labeled ? $novals ? "<option$attribs label=\"$value\">$label</option>\n"
+                                          : "<option$attribs label=\"$value\" value=\"$value\">$label</option>\n"
+                                : $novals ? "<option$attribs>$label</option>\n"
+                                          : "<option$attribs value=\"$value\">$label</option>\n";
+        }
+    }
+    $result .= "</optgroup>";
+    return $result;
+}
+END_OF_FUNC
+
+
 #### Method: scrolling_list
 # Create a scrolling list.
 # Parameters:
@@ -2135,9 +2280,9 @@
 'scrolling_list' => <<'END_OF_FUNC',
 sub scrolling_list {
     my($self,@p) = self_or_default(@_);
-    my($name,$values,$defaults,$size,$multiple,$labels,$override,@other)
+    my($name,$values,$defaults,$size,$multiple,$labels,$attributes,$override,@other)
 	= rearrange([NAME,[VALUES,VALUE],[DEFAULTS,DEFAULT],
-			    SIZE,MULTIPLE,LABELS,[OVERRIDE,FORCE]],@p);
+          SIZE,MULTIPLE,LABELS,ATTRIBUTES,[OVERRIDE,FORCE]],@p);
 
     my($result,@values);
     @values = $self->_set_values_and_labels($values,\$labels,$name);
@@ -2152,12 +2297,13 @@
     $name=$self->escapeHTML($name);
     $result = qq/<select name="$name"$has_size$is_multiple$other>\n/;
     foreach (@values) {
-	my($selectit) = $selected{$_} ? qq/selected="1"/ : '';
+	my($selectit) = $self->_selected($selected{$_});
 	my($label) = $_;
 	$label = $labels->{$_} if defined($labels) && defined($labels->{$_});
 	$label=$self->escapeHTML($label);
 	my($value)=$self->escapeHTML($_,1);
-	$result .= "<option $selectit value=\"$value\">$label</option>\n";
+        my $attribs = $self->_set_attributes($_, $attributes);
+        $result .= "<option$selectit$attribs value=\"$value\">$label</option>\n";
     }
     $result .= "</select>";
     $self->register_parameter($name);
@@ -2173,7 +2319,7 @@
 #      or
 #   $default->[initial values of field]
 # Returns:
-#   A string containing a <INPUT TYPE="hidden" NAME="name" VALUE="value">
+#   A string containing a <input type="hidden" name="name" value="value">
 ####
 'hidden' => <<'END_OF_FUNC',
 sub hidden {
@@ -2216,7 +2362,7 @@
 #   $src ->  URL of the image source
 #   $align -> Alignment style (TOP, BOTTOM or MIDDLE)
 # Returns:
-#   A string containing a <INPUT TYPE="image" NAME="name" SRC="url" ALIGN="alignment">
+#   A string containing a <input type="image" name="name" src="url" align="alignment">
 ####
 'image_button' => <<'END_OF_FUNC',
 sub image_button {
@@ -2267,25 +2413,22 @@
     my ($relative,$absolute,$full,$path_info,$query,$base) = 
 	rearrange(['RELATIVE','ABSOLUTE','FULL',['PATH','PATH_INFO'],['QUERY','QUERY_STRING'],'BASE'],@p);
     my $url;
-    $full++ if $base || !($relative || $absolute);
+    $full++      if $base || !($relative || $absolute);
 
     my $path = $self->path_info;
     my $script_name = $self->script_name;
 
-# If anybody knows why I ever wrote this please tell me!
-#    if (exists($ENV{REQUEST_URI})) {
-#        my $index;
-#	$script_name = $ENV{REQUEST_URI};
-#        # strip query string
-#        substr($script_name,$index) = '' if ($index = index($script_name,'?')) >= 0;
-#        # and path
-#        if (exists($ENV{PATH_INFO})) {
-#           (my $encoded_path = $ENV{PATH_INFO}) =~ s!([^a-zA-Z0-9_./-])!uc sprintf("%%%02x",ord($1))!eg;;
-#           substr($script_name,$index) = '' if ($index = rindex($script_name,$encoded_path)) >= 0;
-#         }
-#    } else {
-#	$script_name = $self->script_name;
-#    }
+    # for compatibility with Apache's MultiViews
+    if (exists($ENV{REQUEST_URI})) {
+        my $index;
+	$script_name = $ENV{REQUEST_URI};
+        $script_name =~ s/\?.+$//;   # strip query string
+        # and path
+        if (exists($ENV{PATH_INFO})) {
+           (my $encoded_path = $ENV{PATH_INFO}) =~ s/([^a-zA-Z0-9_.%;&?\/\\:+=~-])/sprintf("%%%02X",ord($1))/eg;
+           $script_name      =~ s/$encoded_path$//i;
+         }
+    }
 
     if ($full) {
 	my $protocol = $self->protocol();
@@ -2311,7 +2454,7 @@
     $url .= $path if $path_info and defined $path;
     $url .= "?" . $self->query_string if $query and $self->query_string;
     $url = '' unless defined $url;
-    $url =~ s/([^a-zA-Z0-9_.%;&?\/\\:+=~-])/uc sprintf("%%%02x",ord($1))/eg;
+    $url =~ s/([^a-zA-Z0-9_.%;&?\/\\:+=~-])/sprintf("%%%02X",ord($1))/eg;
     return $url;
 }
 
@@ -2783,6 +2926,17 @@
     return $CGI::PRIVATE_TEMPFILES;
 }
 END_OF_FUNC
+#### Method: close_upload_files
+# Set or return the close_upload_files global flag
+####
+'close_upload_files' => <<'END_OF_FUNC',
+sub close_upload_files {
+    my ($self,$param) = self_or_CGI(@_);
+    $CGI::CLOSE_UPLOAD_FILES = $param if defined($param);
+    return $CGI::CLOSE_UPLOAD_FILES;
+}
+END_OF_FUNC
+
 
 #### Method: default_dtd
 # Set or return the default_dtd global
@@ -2886,17 +3040,23 @@
 	}
 
 	my($param)= $header{'Content-Disposition'}=~/ name="?([^\";]*)"?/;
+        $param .= $TAINTED;
 
 	# Bug:  Netscape doesn't escape quotation marks in file names!!!
 	my($filename) = $header{'Content-Disposition'}=~/ filename="?([^\"]*)"?/;
+	# Test for Opera's multiple upload feature
+	my($multipart) = ( defined( $header{'Content-Type'} ) &&
+		$header{'Content-Type'} =~ /multipart\/mixed/ ) ?
+		1 : 0;
 
 	# add this parameter to our list
 	$self->add_parameter($param);
 
 	# If no filename specified, then just read the data and assign it
 	# to our parameter list.
-	if ( !defined($filename) || $filename eq '' ) {
+	if ( ( !defined($filename) || $filename eq '' ) && !$multipart ) {
 	    my($value) = $buffer->readBody;
+            $value .= $TAINTED;
 	    push(@{$self->{$param}},$value);
 	    next;
 	}
@@ -2913,6 +3073,11 @@
 	      last UPLOADS;
 	  }
 
+	  # set the filename to some recognizable value
+          if ( ( !defined($filename) || $filename eq '' ) && $multipart ) {
+              $filename = "multipart/mixed";
+          }
+
 	  # choose a relatively unpredictable tmpfile sequence number
           my $seqno = unpack("%16C*",join('',localtime,values %ENV));
           for (my $cnt=10;$cnt>0;$cnt--) {
@@ -2924,6 +3089,16 @@
           die "CGI open of tmpfile: $!\n" unless defined $filehandle;
 	  $CGI::DefaultClass->binmode($filehandle) if $CGI::needs_binmode;
 
+	  # if this is an multipart/mixed attachment, save the header
+	  # together with the body for lateron parsing with an external
+	  # MIME parser module
+	  if ( $multipart ) {
+	      foreach ( keys %header ) {
+		  print $filehandle "$_: $header{$_}${CRLF}";
+	      }
+	      print $filehandle "${CRLF}";
+	  }
+
 	  my ($data);
 	  local($\) = '';
 	  while (defined($data = $buffer->read)) {
@@ -2932,6 +3107,12 @@
 
 	  # back up to beginning of file
 	  seek($filehandle,0,0);
+
+      ## Close the filehandle if requested this allows a multipart MIME
+      ## upload to contain many files, and we won't die due to too many
+      ## open file handles. The user can access the files using the hash
+      ## below.
+      close $filehandle if $CLOSE_UPLOAD_FILES;
 	  $CGI::DefaultClass->binmode($filehandle) if $CGI::needs_binmode;
 
 	  # Save some information about the uploaded file where we can get
@@ -2983,6 +3164,22 @@
 }
 END_OF_FUNC
 
+# internal routine, don't use
+'_set_attributes' => <<'END_OF_FUNC',
+sub _set_attributes {
+    my $self = shift;
+    my($element, $attributes) = @_;
+    return '' unless defined($attributes->{$element});
+    $attribs = ' ';
+    foreach my $attrib (keys %{$attributes->{$element}}) {
+        $attrib =~ s/^-//;
+        $attribs .= "@{[lc($attrib)]}=\"$attributes->{$element}{$attrib}\" ";
+    }
+    $attribs =~ s/ $//;
+    return $attribs;
+}
+END_OF_FUNC
+
 '_compile_all' => <<'END_OF_FUNC',
 sub _compile_all {
     foreach (@_) {
@@ -3021,7 +3218,7 @@
     # get rid of package name
     (my $i = $$self) =~ s/^\*(\w+::fh\d{5})+//; 
     $i =~ s/%(..)/ chr(hex($1)) /eg;
-    return $i;
+    return $i.$CGI::TAINTED;
 # BEGIN DEAD CODE
 # This was an extremely clever patch that allowed "use strict refs".
 # Unfortunately it relied on another bug that caused leaky file descriptors.
@@ -3044,12 +3241,15 @@
 'new'  => <<'END_OF_FUNC',
 sub new {
     my($pack,$name,$file,$delete) = @_;
+    _setup_symbols(@SAVED_SYMBOLS) if @SAVED_SYMBOLS;
     require Fcntl unless defined &Fcntl::O_RDWR;
     (my $safename = $name) =~ s/([':%])/ sprintf '%%%02X', ord $1 /eg;
     my $fv = ++$FH . $safename;
     my $ref = \*{"Fh::$fv"};
-    sysopen($ref,$file,Fcntl::O_RDWR()|Fcntl::O_CREAT()|Fcntl::O_EXCL(),0600) || return;
-    unlink($file) if $delete;
+    $file =~ m!^([a-zA-Z0-9_ \'\":/.\$\\-]+)$! || return;
+    my $safe = $1;
+    sysopen($ref,$safe,Fcntl::O_RDWR()|Fcntl::O_CREAT()|Fcntl::O_EXCL(),0600) || return;
+    unlink($safe) if $delete;
     CORE::delete $Fh::{$fv};
     return bless $ref,$pack;
 }
@@ -3175,15 +3375,15 @@
     substr($self->{BUFFER},0,$end+4) = '';
     my %return;
 
-    
     # See RFC 2045 Appendix A and RFC 822 sections 3.4.8
     #   (Folding Long Header Fields), 3.4.3 (Comments)
     #   and 3.4.5 (Quoted-Strings).
 
     my $token = '[-\w!\#$%&\'*+.^_\`|{}~]';
     $header=~s/$CRLF\s+/ /og;		# merge continuation lines
+
     while ($header=~/($token+):\s+([^$CRLF]*)/mgox) {
-	my ($field_name,$field_value) = ($1,$2); # avoid taintedness
+        my ($field_name,$field_value) = ($1,$2);
 	$field_name =~ s/\b(\w)/uc($1)/eg; #canonicalize
 	$return{$field_name}=$field_value;
     }
@@ -3240,9 +3440,9 @@
 	return undef;
     }
 
-    my $bytesToReturn;    
+    my $bytesToReturn;
     if ($start > 0) {           # read up to the boundary
-	$bytesToReturn = $start > $bytes ? $bytes : $start;
+        $bytesToReturn = $start-2 > $bytes ? $bytes : $start;
     } else {    # read the requested number of bytes
 	# leave enough bytes in the buffer to allow us to read
 	# the boundary.  Thanks to Kevin Hendrick for finding
@@ -3254,7 +3454,7 @@
     substr($self->{BUFFER},0,$bytesToReturn)='';
     
     # If we hit the boundary, remove the CRLF from the end.
-    return (($start > 0) && ($start <= $bytes)) 
+    return ($bytesToReturn==$start)
            ? substr($returnval,0,-2) : $returnval;
 }
 END_OF_FUNC
@@ -3323,7 +3523,7 @@
 	   "${vol}${SL}Temporary Items",
            "${SL}WWW_ROOT", "${SL}SYS\$SCRATCH",
 	   "C:${SL}system${SL}temp");
-    unshift(@TEMP,$ENV{'TMPDIR'}) if exists $ENV{'TMPDIR'};
+    unshift(@TEMP,$ENV{'TMPDIR'}) if defined $ENV{'TMPDIR'};
 
     # this feature was supposed to provide per-user tmpfiles, but
     # it is problematic.
@@ -3346,6 +3546,13 @@
 # %OVERLOAD = ('""'=>'as_string');
 *CGITempFile::AUTOLOAD = \&CGI::AUTOLOAD;
 
+sub DESTROY {
+    my($self) = @_;
+    $$self =~ m!^([a-zA-Z0-9_ \'\":/.\$\\-]+)$! || return;
+    my $safe = $1;             # untaint operation
+    unlink $safe;              # get rid of the file
+}
+
 ###############################################################################
 ################# THESE FUNCTIONS ARE AUTOLOADED ON DEMAND ####################
 ###############################################################################
@@ -3360,20 +3567,14 @@
     for (my $i = 0; $i < $MAXTRIES; $i++) {
 	last if ! -f ($filename = sprintf("${TMPDIRECTORY}${SL}CGItemp%d",$sequence++));
     }
-    # untaint the darn thing
-    return unless $filename =~ m!^([a-zA-Z0-9_ '":/.\$\\-]+)$!;
-    $filename = $1;
+    # check that it is a more-or-less valid filename
+    return unless $filename =~ m!^([a-zA-Z0-9_ \'\":/.\$\\-]+)$!;
+    # this used to untaint, now it doesn't
+    # $filename = $1;
     return bless \$filename;
 }
 END_OF_FUNC
 
-'DESTROY' => <<'END_OF_FUNC',
-sub DESTROY {
-    my($self) = @_;
-    unlink $$self;              # get rid of the file
-}
-END_OF_FUNC
-
 'as_string' => <<'END_OF_FUNC'
 sub as_string {
     my($self) = @_;
@@ -3552,12 +3753,12 @@
 
    Code                           Generated HTML
    ----                           --------------
-   h1()                           <H1>
-   h1('some','contents');         <H1>some contents</H1>
-   h1({-align=>left});            <H1 ALIGN="LEFT">
-   h1({-align=>left},'contents'); <H1 ALIGN="LEFT">contents</H1>
+   h1()                           <h1>
+   h1('some','contents');         <h1>some contents</h1>
+   h1({-align=>left});            <h1 align="LEFT">
+   h1({-align=>left},'contents'); <h1 align="LEFT">contents</h1>
 
-HTML tags are described in more detail later.  
+HTML tags are described in more detail later.
 
 Many newcomers to CGI.pm are puzzled by the difference between the
 calling conventions for the HTML shortcuts, which require curly braces
@@ -3721,6 +3922,11 @@
 "name1=&name2=" or "name1&name2", it will be returned as an empty
 string.  This feature is new in 2.63.
 
+
+If the parameter does not exist at all, then param() will return undef
+in a scalar context, and the empty list in a list context.
+
+
 =head2 SETTING THE VALUE(S) OF A NAMED PARAMETER:
 
     $query->param('foo','an','array','of','values');
@@ -3759,17 +3965,22 @@
 WARNING:  don't import anything into 'main'; this is a major security
 risk!!!!
 
-In older versions, this method was called B<import()>.  As of version 2.20, 
+NOTE 1: Variable names are transformed as necessary into legal Perl
+variable names.  All non-legal characters are transformed into
+underscores.  If you need to keep the original names, you should use
+the param() method instead to access CGI variables by name.
+
+NOTE 2: In older versions, this method was called B<import()>.  As of version 2.20, 
 this name has been removed completely to avoid conflict with the built-in
 Perl module B<import> operator.
 
 =head2 DELETING A PARAMETER COMPLETELY:
 
-    $query->delete('foo');
+    $query->delete('foo','bar','baz');
 
-This completely clears a parameter.  It sometimes useful for
-resetting parameters that you don't want passed down between
-script invocations.
+This completely clears a list of parameters.  It sometimes useful for
+resetting parameters that you don't want passed down between script
+invocations.
 
 If you are using the function call interface, use "Delete()" instead
 to avoid conflicts with Perl's built-in delete operator.
@@ -3944,9 +4155,14 @@
 
 =item B<:html3>
 
-Import all methods that generate HTML 3.0 proposed elements (such as
+Import all methods that generate HTML 3.0 elements (such as
 <table>, <super> and <sub>).
 
+=item B<:html4>
+
+Import all methods that generate HTML 4 elements (such as
+<abbrev>, <acronym> and <thead>).
+
 =item B<:netscape>
 
 Import all methods that generate Netscape-specific HTML extensions.
@@ -3958,7 +4174,7 @@
 
 =item B<:standard>
 
-Import "standard" features, 'html2', 'html3', 'form' and 'cgi'.
+Import "standard" features, 'html2', 'html3', 'html4', 'form' and 'cgi'.
 
 =item B<:all>
 
@@ -3971,7 +4187,7 @@
 will treat it as a new HTML tag and generate the appropriate
 subroutine.  You can then use it like any other HTML tag.  This is to
 provide for the rapidly-evolving HTML "standard."  For example, say
-Microsoft comes out with a new tag called <GRADIENT> (which causes the
+Microsoft comes out with a new tag called <gradient> (which causes the
 user's desktop to be flooded with a rotating gradient fill until his
 machine reboots).  You don't need to wait for a new version of CGI.pm
 to start using it immediately:
@@ -4065,7 +4281,14 @@
 Note that using the -compile pragma in this way will always have
 the effect of importing the compiled functions into the current
 namespace.  If you want to compile without importing use the
-compile() method instead (see below).
+compile() method instead:
+
+   use CGI();
+   CGI->compile();
+
+This is particularly useful in a mod_perl environment, in which you
+might want to precompile all CGI routines in a startup script, and
+then import the functions individually in each mod_perl script.
 
 =item -nosticky
 
@@ -4185,7 +4408,7 @@
 
 produces
 
-  <H1>Level 1 Header</H1>
+  <h1>Level 1 Header</h1>
 
 There will be some times when you want to produce the start and end
 tags yourself.  In this case, you can use the form start_I<tag_name>
@@ -4209,13 +4432,13 @@
 
 =over 4
 
-=item 1. start_table() (generates a <TABLE> tag)
+=item 1. start_table() (generates a <table> tag)
 
-=item 2. end_table() (generates a </TABLE> tag)
+=item 2. end_table() (generates a </table> tag)
 
-=item 3. start_ul() (generates a <UL> tag)
+=item 3. start_ul() (generates a <ul> tag)
 
-=item 4. end_ul() (generates a </UL> tag)
+=item 4. end_ul() (generates a </ul> tag)
 
 =back
 
@@ -4313,6 +4536,17 @@
 suggested name for the saved file.  In order for this to work, you may
 have to set the B<-type> to "application/octet-stream".
 
+The B<-p3p> parameter will add a P3P tag to the outgoing header.  The
+parameter can be an arrayref or a space-delimited string of P3P tags.
+For example:
+
+   print header(-p3p=>[qw(CAO DSP LAW CURa)]);
+   print header(-p3p=>'CAO DSP LAW CURa');
+
+In either case, the outgoing header will be formatted as:
+
+  P3P: policyref="/w3c/p3p.xml" cp="CAO DSP LAW CURa"
+
 =head2 GENERATING A REDIRECTION HEADER
 
    print $query->redirect('http://somewhere.else/in/movie/land');
@@ -4357,15 +4591,15 @@
 page, along with a lot of optional information that controls the
 page's appearance and behavior.
 
-This method returns a canned HTML header and the opening <BODY> tag.
+This method returns a canned HTML header and the opening <body> tag.
 All parameters are optional.  In the named parameter form, recognized
 parameters are -title, -author, -base, -xbase, -dtd, -lang and -target
 (see below for the explanation).  Any additional parameters you
 provide, such as the Netscape unofficial BGCOLOR attribute, are added
-to the <BODY> tag.  Additional parameters must be proceeded by a
+to the <body> tag.  Additional parameters must be proceeded by a
 hyphen.
 
-The argument B<-xbase> allows you to provide an HREF for the <BASE> tag
+The argument B<-xbase> allows you to provide an HREF for the <base> tag
 different from the current location, as in
 
     -xbase=>"http://home.mcom.com/"
@@ -4384,12 +4618,12 @@
 You add arbitrary meta information to the header with the B<-meta>
 argument.  This argument expects a reference to an associative array
 containing name/value pairs of meta information.  These will be turned
-into a series of header <META> tags that look something like this:
+into a series of header <meta> tags that look something like this:
 
-    <META NAME="keywords" CONTENT="pharaoh secret mummy">
-    <META NAME="description" CONTENT="copyright 1996 King Tut">
+    <meta name="keywords" content="pharaoh secret mummy">
+    <meta name="description" content="copyright 1996 King Tut">
 
-To create an HTTP-EQUIV type of <META> tag, use B<-head>, described
+To create an HTTP-EQUIV type of <meta> tag, use B<-head>, described
 below.
 
 The B<-style> argument is used to incorporate cascading stylesheets
@@ -4397,22 +4631,25 @@
 information.
 
 The B<-lang> argument is used to incorporate a language attribute into
-the <HTML> tag.  The default if not specified is "en-US" for US
+the <html> tag.  The default if not specified is "en-US" for US
 English.  For example:
 
     print $q->start_html(-lang=>'fr-CA');
 
+To leave off the lang attribute, as you must do if you want to generate
+legal HTML 3.2 or earlier, pass the empty string (-lang=>'').
+
 The B<-encoding> argument can be used to specify the character set for
-XHTML.  It defaults to UTF-8 if not specified.
+XHTML.  It defaults to iso-8859-1 if not specified.
 
-You can place other arbitrary HTML elements to the <HEAD> section with the
-B<-head> tag.  For example, to place the rarely-used <LINK> element in the
+You can place other arbitrary HTML elements to the <head> section with the
+B<-head> tag.  For example, to place the rarely-used <link> element in the
 head section, use this:
 
     print start_html(-head=>Link({-rel=>'next',
 		                  -href=>'http://www.capricorn.com/s2.html'}));
 
-To incorporate multiple HTML elements into the <HEAD> section, just pass an
+To incorporate multiple HTML elements into the <head> section, just pass an
 array reference:
 
     print start_html(-head=>[ 
@@ -4423,7 +4660,7 @@
 			     ]
 		     );
 
-And here's how to create an HTTP-EQUIV <META> tag:
+And here's how to create an HTTP-EQUIV <meta> tag:
 
       print start_html(-head=>meta({-http_equiv => 'Content-Type',
                                     -content    => 'text/html'}))
@@ -4433,7 +4670,7 @@
 B<-onMouseOver>, B<-onMouseOut> and B<-onUnload> parameters are used
 to add Netscape JavaScript calls to your pages.  B<-script> should
 point to a block of text containing JavaScript function definitions.
-This block will be placed within a <SCRIPT> block inside the HTML (not
+This block will be placed within a <script> block inside the HTML (not
 HTTP) header.  The block is placed in the header in order to give your
 page a fighting chance of having all its JavaScript functions in place
 even if the user presses the stop button before the page has loaded
@@ -4472,7 +4709,7 @@
 browsers that do not have JavaScript (or browsers where JavaScript is turned
 off).
 
-Netscape 3.0 recognizes several attributes of the <SCRIPT> tag,
+Netscape 3.0 recognizes several attributes of the <script> tag,
 including LANGUAGE and SRC.  The latter is particularly interesting,
 as it allows you to keep the JavaScript code in a file or CGI script
 rather than cluttering up each page with the source.  To use these
@@ -4490,7 +4727,7 @@
 	       );
 
 
-A final feature allows you to incorporate multiple <SCRIPT> sections into the
+A final feature allows you to incorporate multiple <script> sections into the
 header.  Just pass the list of script sections as an array reference.
 this allows you to specify different source files for different dialects
 of JavaScript.  Example:     
@@ -4511,7 +4748,6 @@
                                     }
                                  ]
                              );
-     </pre>
 
 If this looks a bit extreme, take my advice and stick with straight CGI scripting.  
 
@@ -4533,17 +4769,17 @@
 
 =item 2.
 
-The author's e-mail address (will create a <LINK REV="MADE"> tag if present
+The author's e-mail address (will create a <link rev="MADE"> tag if present
 
 =item 3.
 
-A 'true' flag if you want to include a <BASE> tag in the header.  This
+A 'true' flag if you want to include a <base> tag in the header.  This
 helps resolve relative addresses to absolute ones when the document is moved, 
 but makes the document hierarchy non-portable.  Use with care!
 
 =item 4, 5, 6...
 
-Any other parameters you want to include in the <BODY> tag.  This is a good
+Any other parameters you want to include in the <body> tag.  This is a good
 place to put Netscape extensions, such as colors and wallpaper patterns.
 
 =back
@@ -4552,12 +4788,12 @@
 
 	print $query->end_html
 
-This ends an HTML document by printing the </BODY></HTML> tags.
+This ends an HTML document by printing the </body></html> tags.
 
 =head2 CREATING A SELF-REFERENCING URL THAT PRESERVES STATE INFORMATION:
 
     $myself = $query->self_url;
-    print q(<A HREF="$myself">I'm talking to myself.</A>);
+    print q(<a href="$myself">I'm talking to myself.</a>);
 
 self_url() will return a URL, that, when selected, will reinvoke
 this script with all its state information intact.  This is most
@@ -4566,9 +4802,9 @@
 of the form(s).  Something like this will do the trick.
 
      $myself = $query->self_url;
-     print "<A HREF=$myself#table1>See table 1</A>";
-     print "<A HREF=$myself#table2>See table 2</A>";
-     print "<A HREF=$myself#yourself>See for yourself</A>";
+     print "<a href=\"$myself#table1\">See table 1</a>";
+     print "<a href=\"$myself#table2\">See table 2</a>";
+     print "<a href=\"$myself#yourself\">See for yourself</a>";
 
 If you want more control over what's returned, using the B<url()>
 method instead.
@@ -4677,7 +4913,7 @@
 
    <blockquote>
    Many years ago on the island of
-   <a HREF="http://crete.org/">Crete</a> there lived
+   <a href="http://crete.org/">Crete</a> there lived
    a minotaur named <strong>Fred.</strong> 
    </blockquote>
    <hr>
@@ -4700,12 +4936,12 @@
 The HTML methods will accept zero, one or multiple arguments.  If you
 provide no arguments, you get a single tag:
 
-   print hr;  	#  <HR>
+   print hr;  	#  <hr>
 
 If you provide one or more string arguments, they are concatenated
 together with spaces and placed between opening and closing tags:
 
-   print h1("Chapter","1"); # <H1>Chapter 1</H1>"
+   print h1("Chapter","1"); # <h1>Chapter 1</h1>"
 
 If the first argument is an associative array reference, then the keys
 and values of the associative array become the HTML tag's attributes:
@@ -4713,14 +4949,14 @@
    print a({-href=>'fred.html',-target=>'_new'},
       "Open a new frame");
 
-	    <A HREF="fred.html",TARGET="_new">Open a new frame</A>
+	    <a href="fred.html",target="_new">Open a new frame</a>
 
 You may dispense with the dashes in front of the attribute names if
 you prefer:
 
    print img {src=>'fred.gif',align=>'LEFT'};
 
-	   <IMG ALIGN="LEFT" SRC="fred.gif">
+	   <img align="LEFT" src="fred.gif">
 
 Sometimes an HTML tag attribute has no argument.  For example, ordered
 lists can be marked as COMPACT.  The syntax for this is an argument that
@@ -4731,11 +4967,11 @@
 Prior to CGI.pm version 2.41, providing an empty ('') string as an
 attribute argument was the same as providing undef.  However, this has
 changed in order to accommodate those who want to create tags of the form 
-<IMG ALT="">.  The difference is shown in these two pieces of code:
+<img alt="">.  The difference is shown in these two pieces of code:
 
    CODE                   RESULT
-   img({alt=>undef})      <IMG ALT>
-   img({alt=>''})         <IMT ALT="">
+   img({alt=>undef})      <img alt>
+   img({alt=>''})         <img alt="">
 
 =head2 THE DISTRIBUTIVE PROPERTY OF HTML SHORTCUTS
 
@@ -4751,12 +4987,12 @@
 
 This example will result in HTML output that looks like this:
 
-   <UL>
-     <LI TYPE="disc">Sneezy</LI>
-     <LI TYPE="disc">Doc</LI>
-     <LI TYPE="disc">Sleepy</LI>
-     <LI TYPE="disc">Happy</LI>
-   </UL>
+   <ul>
+     <li type="disc">Sneezy</li>
+     <li type="disc">Doc</li>
+     <li type="disc">Sleepy</li>
+     <li type="disc">Happy</li>
+   </ul>
 
 This is extremely useful for creating tables.  For example:
 
@@ -4780,7 +5016,7 @@
 
 It will ordinarily return the string that you probably expect, namely:
 
-   <BLOCKQUOTE><EM>Hi</EM> mom!</BLOCKQUOTE>
+   <blockquote><em>Hi</em> mom!</blockquote>
 
 Note the space between the element "Hi" and the element "mom!".
 CGI.pm puts the extra space there using array interpolation, which is
@@ -4839,9 +5075,9 @@
 default), the standard HTML escaping rules will be used.  The "<"
 character becomes "&lt;", ">" becomes "&gt;", "&" becomes "&amp;", and
 the quote character becomes "&quot;".  In addition, the hexadecimal
-0x8b and 0x9b characters, which many windows-based browsers interpret
+0x8b and 0x9b characters, which some browsers incorrectly interpret
 as the left and right angle-bracket characters, are replaced by their
-numeric HTML entities ("&#139" and "&#155;").  If you manually change
+numeric character entities ("&#8249" and "&#8250;").  If you manually change
 the charset, either by calling the charset() method explicitly or by
 passing a -charset argument to header(), then B<all> characters will
 be replaced by their numeric entities, since CGI.pm has no lookup
@@ -4851,7 +5087,7 @@
 h1().  You should call escapeHTML() yourself on untrusted data in
 order to protect your pages against nasty tricks that people may enter
 into guestbooks, etc..  To change the character set, use charset().
-To turn autoescaping off completely, use autoescape():
+To turn autoescaping off completely, use autoEscape(0):
 
 =over 4
 
@@ -4918,7 +5154,7 @@
 
    print $query->isindex($action);
 
-Prints out an <ISINDEX> tag.  Not very exciting.  The parameter
+Prints out an <isindex> tag.  Not very exciting.  The parameter
 -action specifies the URL of the script to process the query.  The
 default is to process the query with the current script.
 
@@ -4936,14 +5172,14 @@
       <... various form stuff ...>
     print $query->endform;
 
-start_form() will return a <FORM> tag with the optional method,
+start_form() will return a <form> tag with the optional method,
 action and form encoding that you specify.  The defaults are:
 
     method: POST
     action: this script
     enctype: application/x-www-form-urlencoded
 
-endform() returns the closing </FORM> tag.  
+endform() returns the closing </form> tag.  
 
 Start_form()'s enctype argument tells the browser how to package the various
 fields of the form before sending the form to the server.  Two
@@ -4992,7 +5228,7 @@
 can put up an alert box or maybe fix things up yourself.  You can 
 abort the submission by returning false from this function.  
 
-Usually the bulk of JavaScript functions are defined in a <SCRIPT>
+Usually the bulk of JavaScript functions are defined in a <script>
 block in the HTML header and -onSubmit points to one of these function
 call.  See start_html() for details.
 
@@ -5254,16 +5490,18 @@
    %labels = ('eenie'=>'your first choice',
 	      'meenie'=>'your second choice',
 	      'minie'=>'your third choice');
+   %attributes = ('eenie'=>{'class'=>'class of first choice'});
    print $query->popup_menu('menu_name',
 			    ['eenie','meenie','minie'],
-			    'meenie',\%labels);
+          'meenie',\%labels,\%attributes);
 
 	-or (named parameter style)-
 
    print $query->popup_menu(-name=>'menu_name',
 			    -values=>['eenie','meenie','minie'],
 			    -default=>'meenie',
-			    -labels=>\%labels);
+          -labels=>\%labels,
+          -attributes=>\%attributes);
 
 popup_menu() creates a menu.
 
@@ -5290,11 +5528,19 @@
 
 The optional fourth parameter (-labels) is provided for people who
 want to use different values for the user-visible label inside the
-popup menu nd the value returned to your script.  It's a pointer to an
+popup menu and the value returned to your script.  It's a pointer to an
 associative array relating menu values to user-visible labels.  If you
 leave this parameter blank, the menu values will be displayed by
 default.  (You can also leave a label undefined if you want to).
 
+=item 5.
+
+The optional fifth parameter (-attributes) is provided to assign
+any of the common HTML attributes to an individual menu item. It's
+a pointer to an associative array relating menu values to another
+associative array with the attribute's name as the key and the
+attribute's value as the value.
+
 =back
 
 When the form is processed, the selected value of the popup menu can
@@ -5307,17 +5553,90 @@
 B<-onBlur>.  See the textfield() section for details on when these
 handlers are called.
 
+=head2 CREATING AN OPTION GROUP
+
+Named parameter style
+
+  print $query->popup_menu(-name=>'menu_name',
+                  -values=>[qw/eenie meenie minie/,
+                            $q->optgroup(-name=>'optgroup_name',
+                                         -values ['moe','catch'],
+                                         -attributes=>{'catch'=>{'class'=>'red'}}),
+                  -labels=>{'eenie'=>'one',
+                            'meenie'=>'two',
+                            'minie'=>'three'},
+                  -default=>'meenie');
+
+  Old style
+  print $query->popup_menu('menu_name',
+                  ['eenie','meenie','minie',
+                   $q->optgroup('optgroup_name', ['moe', 'catch'],
+                         {'catch'=>{'class'=>'red'}})],'meenie',
+                  {'eenie'=>'one','meenie'=>'two','minie'=>'three'});
+
+optgroup creates an option group within a popup menu.
+
+=over 4
+
+=item 1.
+
+The required first argument (B<-name>) is the label attribute of the
+optgroup and is B<not> inserted in the parameter list of the query.
+
+=item 2.
+
+The required second argument (B<-values>)  is an array reference
+containing the list of menu items in the menu.  You can pass the
+method an anonymous array, as shown in the example, or a reference
+to a named array, such as \@foo.  If you pass a HASH reference,
+the keys will be used for the menu values, and the values will be
+used for the menu labels (see -labels below).
+
+=item 3.
+
+The optional third parameter (B<-labels>) allows you to pass a reference
+to an associative array containing user-visible labels for one or more
+of the menu items.  You can use this when you want the user to see one
+menu string, but have the browser return your program a different one.
+If you don't specify this, the value string will be used instead
+("eenie", "meenie" and "minie" in this example).  This is equivalent
+to using a hash reference for the -values parameter.
+
+=item 4.
+
+An optional fourth parameter (B<-labeled>) can be set to a true value
+and indicates that the values should be used as the label attribute
+for each option element within the optgroup.
+
+=item 5.
+
+An optional fifth parameter (-novals) can be set to a true value and
+indicates to suppress the val attribut in each option element within
+the optgroup.
+
+See the discussion on optgroup at W3C
+(http://www.w3.org/TR/REC-html40/interact/forms.html#edef-OPTGROUP)
+for details.
+
+=item 6.
+
+An optional sixth parameter (-attributes) is provided to assign
+any of the common HTML attributes to an individual menu item. It's
+a pointer to an associative array relating menu values to another
+associative array with the attribute's name as the key and the
+attribute's value as the value.
+
 =head2 CREATING A SCROLLING LIST
 
    print $query->scrolling_list('list_name',
 				['eenie','meenie','minie','moe'],
-				['eenie','moe'],5,'true');
+        ['eenie','moe'],5,'true',{'moe'=>{'class'=>'red'}});
       -or-
 
    print $query->scrolling_list('list_name',
 				['eenie','meenie','minie','moe'],
 				['eenie','moe'],5,'true',
-				\%labels);
+        \%labels,%attributes);
 
 	-or-
 
@@ -5326,7 +5645,8 @@
 				-default=>['eenie','moe'],
 				-size=>5,
 				-multiple=>'true',
-				-labels=>\%labels);
+        -labels=>\%labels,
+        -attributes=>\%attributes);
 
 scrolling_list() creates a scrolling list.  
 
@@ -5365,6 +5685,14 @@
 containing long user-visible labels for the list items (-labels).
 If not provided, the values will be displayed.
 
+=item 6.
+
+The optional sixth parameter (-attributes) is provided to assign
+any of the common HTML attributes to an individual menu item. It's
+a pointer to an associative array relating menu values to another
+associative array with the attribute's name as the key and the
+attribute's value as the value.
+
 When this form is processed, all selected list items will be returned as
 a list under the parameter name 'list_name'.  The values of the
 selected items can be retrieved with:
@@ -5384,11 +5712,13 @@
 				-values=>['eenie','meenie','minie','moe'],
 				-default=>['eenie','moe'],
 				-linebreak=>'true',
-				-labels=>\%labels);
+        -labels=>\%labels,
+        -attributes=>\%attributes);
 
    print $query->checkbox_group('group_name',
 				['eenie','meenie','minie','moe'],
-				['eenie','moe'],'true',\%labels);
+        ['eenie','moe'],'true',\%labels,
+        {'moe'=>{'class'=>'red'}});
 
    HTML3-COMPATIBLE BROWSERS ONLY:
 
@@ -5441,6 +5771,14 @@
 columns.  You can provide just the -columns parameter if you wish;
 checkbox_group will calculate the correct number of rows for you.
 
+=item 6.
+
+The optional sixth parameter (-attributes) is provided to assign
+any of the common HTML attributes to an individual menu item. It's
+a pointer to an associative array relating menu values to another
+associative array with the attribute's name as the key and the
+attribute's value as the value.
+
 To include row and column headings in the returned table, you
 can use the B<-rowheaders> and B<-colheaders> parameters.  Both
 of these accept a pointer to an array of headings to use.
@@ -5525,12 +5863,13 @@
 			     -values=>['eenie','meenie','minie'],
 			     -default=>'meenie',
 			     -linebreak=>'true',
-			     -labels=>\%labels);
+           -labels=>\%labels,
+           -attributes=>\%attributes);
 
 	-or-
 
    print $query->radio_group('group_name',['eenie','meenie','minie'],
-					  'meenie','true',\%labels);
+            'meenie','true',\%labels,\%attributes);
 
 
    HTML3-COMPATIBLE BROWSERS ONLY:
@@ -5588,6 +5927,14 @@
 wish; radio_group will calculate the correct number of rows
 for you.
 
+=item 6.
+
+The optional sixth parameter (-attributes) is provided to assign
+any of the common HTML attributes to an individual menu item. It's
+a pointer to an associative array relating menu values to another
+associative array with the attribute's name as the key and the
+attribute's value as the value.
+
 To include row and column headings in the returned table, you
 can use the B<-rowheader> and B<-colheader> parameters.  Both
 of these accept a pointer to an array of headings to use.
@@ -5924,11 +6271,11 @@
 =item 1. Create a <Frameset> document
 
 After writing out the HTTP header, instead of creating a standard
-HTML document using the start_html() call, create a <FRAMESET> 
+HTML document using the start_html() call, create a <frameset> 
 document that defines the frames on the page.  Specify your script(s)
 (with appropriate parameters) as the SRC for each of the frames.
 
-There is no specific support for creating <FRAMESET> sections 
+There is no specific support for creating <frameset> sections 
 in CGI.pm, but the HTML is very simple to write.  See the frame
 documentation in Netscape's home pages for details 
 
@@ -5947,7 +6294,7 @@
 use for targets.  See the frame documents on Netscape's home pages for
 details.
 
-=item 3. Specify the destination for the document in the <FORM> tag
+=item 3. Specify the destination for the document in the <form> tag
 
 You can specify the frame to load in the FORM tag itself.  With
 CGI.pm it looks like this:
@@ -5970,11 +6317,11 @@
 To incorporate a stylesheet into your document, pass the
 start_html() method a B<-style> parameter.  The value of this
 parameter may be a scalar, in which case it is incorporated directly
-into a <STYLE> section, or it may be a hash reference.  In the latter
+into a <style> section, or it may be a hash reference.  In the latter
 case you should provide the hash with one or more of B<-src> or
 B<-code>.  B<-src> points to a URL where an externally-defined
 stylesheet can be found.  B<-code> points to a scalar value to be
-incorporated into a <STYLE> section.  Style definitions in B<-code>
+incorporated into a <style> section.  Style definitions in B<-code>
 override similarly-named ones in B<-src>, hence the name "cascading."
 
 You may also specify the type of the stylesheet by adding the optional
@@ -6038,6 +6385,23 @@
 Pass an array reference to B<-style> in order to incorporate multiple
 stylesheets into your document.
 
+Should you wish to incorporate a verbatim stylesheet that includes
+arbitrary formatting in the header, you may pass a -verbatim tag to
+the -style hash, as follows:
+
+print $q->start_html (-STYLE  =>  {-verbatim => '@import
+url("/server-common/css/'.$cssFile.'");',
+                      -src      =>  '/server-common/css/core.css'});
+</blockquote></pre>
+
+
+This will generate an HTML header that contains this:
+
+ <link rel="stylesheet" type="text/css"  href="/server-common/css/core.css">
+   <style type="text/css">
+   @import url("/server-common/css/main.css");
+   </style>
+
 =head1 DEBUGGING
 
 If you are running the script from the command line or in the perl
@@ -6084,23 +6448,23 @@
 
 Produces something that looks like:
 
-    <UL>
-    <LI>name1
-	<UL>
-	<LI>value1
-	<LI>value2
-	</UL>
-    <LI>name2
-	<UL>
-	<LI>value1
-	</UL>
-    </UL>
+    <ul>
+    <li>name1
+	<ul>
+	<li>value1
+	<li>value2
+	</ul>
+    <li>name2
+	<ul>
+	<li>value1
+	</ul>
+    </ul>
 
 As a shortcut, you can interpolate the entire CGI object into a string
 and it will be replaced with the a nice HTML dump shown above:
 
     $query=new CGI;
-    print "<H2>Current Values</H2> $query\n";
+    print "<h2>Current Values</h2> $query\n";
 
 =head1 FETCHING ENVIRONMENT VARIABLES
 
@@ -6576,7 +6940,7 @@
 
 	print $query->header;
 	print $query->start_html("Example CGI.pm Form");
-	print "<H1> Example CGI.pm Form</H1>\n";
+	print "<h1> Example CGI.pm Form</h1>\n";
 	&print_prompt($query);
 	&do_work($query);
 	&print_tail;
@@ -6586,31 +6950,31 @@
 	   my($query) = @_;
 
 	   print $query->start_form;
-	   print "<EM>What's your name?</EM><BR>";
+	   print "<em>What's your name?</em><br>";
 	   print $query->textfield('name');
 	   print $query->checkbox('Not my real name');
 
-	   print "<P><EM>Where can you find English Sparrows?</EM><BR>";
+	   print "<p><em>Where can you find English Sparrows?</em><br>";
 	   print $query->checkbox_group(
 				 -name=>'Sparrow locations',
 				 -values=>[England,France,Spain,Asia,Hoboken],
 				 -linebreak=>'yes',
 				 -defaults=>[England,Asia]);
 
-	   print "<P><EM>How far can they fly?</EM><BR>",
+	   print "<p><em>How far can they fly?</em><br>",
 		$query->radio_group(
 			-name=>'how far',
 			-values=>['10 ft','1 mile','10 miles','real far'],
 			-default=>'1 mile');
 
-	   print "<P><EM>What's your favorite color?</EM>  ";
+	   print "<p><em>What's your favorite color?</em>  ";
 	   print $query->popup_menu(-name=>'Color',
 				    -values=>['black','brown','red','yellow'],
 				    -default=>'red');
 
 	   print $query->hidden('Reference','Monty Python and the Holy Grail');
 
-	   print "<P><EM>What have you got there?</EM><BR>";
+	   print "<p><em>What have you got there?</em><br>";
 	   print $query->scrolling_list(
 			 -name=>'possessions',
 			 -values=>['A Coconut','A Grail','An Icon',
@@ -6618,54 +6982,46 @@
 			 -size=>5,
 			 -multiple=>'true');
 
-	   print "<P><EM>Any parting comments?</EM><BR>";
+	   print "<p><em>Any parting comments?</em><br>";
 	   print $query->textarea(-name=>'Comments',
 				  -rows=>10,
 				  -columns=>50);
 
-	   print "<P>",$query->reset;
+	   print "<p>",$query->reset;
 	   print $query->submit('Action','Shout');
 	   print $query->submit('Action','Scream');
 	   print $query->endform;
-	   print "<HR>\n";
+	   print "<hr>\n";
 	}
 
 	sub do_work {
 	   my($query) = @_;
 	   my(@values,$key);
 
-	   print "<H2>Here are the current settings in this form</H2>";
+	   print "<h2>Here are the current settings in this form</h2>";
 
 	   foreach $key ($query->param) {
-	      print "<STRONG>$key</STRONG> -> ";
+	      print "<strong>$key</strong> -> ";
 	      @values = $query->param($key);
-	      print join(", ",@values),"<BR>\n";
+	      print join(", ",@values),"<br>\n";
 	  }
 	}
 
 	sub print_tail {
 	   print <<END;
-	<HR>
-	<ADDRESS>Lincoln D. Stein</ADDRESS><BR>
-	<A HREF="/">Home Page</A>
+	<hr>
+	<address>Lincoln D. Stein</address><br>
+	<a href="/">Home Page</a>
 	END
 	}
 
 =head1 BUGS
 
-This module has grown large and monolithic.  Furthermore it's doing many
-things, such as handling URLs, parsing CGI input, writing HTML, etc., that
-are also done in the LWP modules. It should be discarded in favor of
-the CGI::* modules, but somehow I continue to work on it.
-
-Note that the code is truly contorted in order to avoid spurious
-warnings when programs are run with the B<-w> switch.
+Please report them.
 
 =head1 SEE ALSO
 
-L<CGI::Carp>, L<URI::URL>, L<CGI::Request>, L<CGI::MiniSvr>,
-L<CGI::Base>, L<CGI::Form>, L<CGI::Push>, L<CGI::Fast>,
-L<CGI::Pretty>
+L<CGI::Carp>, L<CGI::Fast>, L<CGI::Pretty>
 
 =cut
 
diff -durN MT-2.661-full-lib/extlib/Apache/SOAP.pm MT/extlib/Apache/SOAP.pm
--- MT-2.661-full-lib/extlib/Apache/SOAP.pm	Mon Dec 22 19:06:32 2003
+++ MT/extlib/Apache/SOAP.pm	Tue Dec 23 13:39:36 2003
@@ -15,7 +15,7 @@
 use SOAP::Transport::HTTP;
 
 @ISA = qw(SOAP::Transport::HTTP::Apache);
-$VERSION = eval sprintf("%d.%s", q$Name: release-0_52-public $ =~ /-(\d+)_([\d_]+)/);
+$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: release-0_55-public $ =~ /-(\d+)_([\d_]+)/);
 
 my $server = __PACKAGE__->new;
 
diff -durN MT-2.661-full-lib/extlib/Apache/XMLRPC/Lite.pm MT/extlib/Apache/XMLRPC/Lite.pm
--- MT-2.661-full-lib/extlib/Apache/XMLRPC/Lite.pm	Mon Dec 22 19:06:32 2003
+++ MT/extlib/Apache/XMLRPC/Lite.pm	Tue Dec 23 13:40:07 2003
@@ -15,7 +15,7 @@
 use XMLRPC::Transport::HTTP;
 
 @ISA = qw(XMLRPC::Transport::HTTP::Apache);
-$VERSION = eval sprintf("%d.%s", q$Name: release-0_52-public $ =~ /-(\d+)_([\d_]+)/);
+$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: release-0_55-public $ =~ /-(\d+)_([\d_]+)/);
 
 my $server = __PACKAGE__->new;
 
diff -durN MT-2.661-full-lib/extlib/IO/SessionData.pm MT/extlib/IO/SessionData.pm
--- MT-2.661-full-lib/extlib/IO/SessionData.pm	Mon Dec 22 19:06:32 2003
+++ MT/extlib/IO/SessionData.pm	Tue Dec 23 13:43:20 2003
@@ -11,7 +11,7 @@
 use Carp;
 use IO::SessionSet;
 use vars '$VERSION';
-$VERSION = 1.01;
+$VERSION = 1.02;
 
 use constant BUFSIZE => 3000;
 
@@ -30,8 +30,9 @@
 sub new {
   my $pack = shift;
   my ($sset,$handle,$writeonly) = @_;
-  # make the handle nonblocking
-  $handle->blocking(0);
+  # make the handle nonblocking (but check for 'blocking' method first)
+  # thanks to Jos Clijmans <jos.clijmans@recyfin.be>
+  $handle->blocking(0) if $handle->can('blocking');
   my $self = bless {
                 outbuffer   => '',
                 sset        => $sset,
@@ -88,7 +89,8 @@
   my $rc;
   if ($self->pending) { # data in the out buffer to write
     local $SIG{PIPE}='IGNORE';
-    $rc = syswrite($handle,$self->{outbuffer});
+    # added length() to make it work on Mac. Thanks to Robin Fuller <rfuller@broadjump.com>
+    $rc = syswrite($handle,$self->{outbuffer},length($self->{outbuffer}));
 
     # able to write, so truncate out buffer apropriately
     if ($rc) {
@@ -103,7 +105,7 @@
   }
   
   $self->adjust_state;
-
+  
   # Result code is the number of bytes successfully transmitted
   return $rc;
 }
@@ -126,7 +128,7 @@
   my $self = shift;
   unless ($self->pending) {
     $self->sessions->delete($self);
-    close($self->handle);
+    CORE::close($self->handle);
   } else {
     $self->readable(0);
     $self->{closing}++;  # delayed close
diff -durN MT-2.661-full-lib/extlib/SOAP/Lite.pm MT/extlib/SOAP/Lite.pm
--- MT-2.661-full-lib/extlib/SOAP/Lite.pm	Mon Dec 22 19:06:32 2003
+++ MT/extlib/SOAP/Lite.pm	Tue Dec 23 13:43:09 2003
@@ -4,7 +4,7 @@
 # SOAP::Lite is free software; you can redistribute it
 # and/or modify it under the same terms as Perl itself.
 #                      
-# $Id: Lite.pm,v 1.44 2001/10/18 16:18:56 paulk Exp $
+# $Id: Lite.pm,v 1.47 2002/04/15 16:17:38 paulk Exp $
 #
 # ======================================================================
 
@@ -13,7 +13,7 @@
 use 5.004;
 use strict;
 use vars qw($VERSION);
-$VERSION = eval sprintf("%d.%s", q$Name: release-0_52-public $ =~ /-(\d+)_([\d_]+)/)
+$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: release-0_55-public $ =~ /-(\d+)_([\d_]+)/)
   or warn "warning: unspecified/non-released version of ", __PACKAGE__, "\n";
 
 # ======================================================================
@@ -270,6 +270,7 @@
               $DO_NOT_USE_XML_PARSER $DO_NOT_CHECK_MUSTUNDERSTAND 
               $DO_NOT_USE_CHARSET $DO_NOT_PROCESS_XML_IN_MIME
               $DO_NOT_USE_LWP_LENGTH_HACK $DO_NOT_CHECK_CONTENT_TYPE
+              $MAX_CONTENT_SIZE
   );  
 
   $FAULT_CLIENT = 'Client';
@@ -671,7 +672,7 @@
       _seen => {},
       _typelookup => {
         base64 => [10, sub {$_[0] =~ /[^\x09\x0a\x0d\x20-\x7f]/}, 'as_base64'],
-        int    => [20, sub {$_[0] =~ /^[+-]?\d+$/}, 'as_int'],
+        'int'  => [20, sub {$_[0] =~ /^[+-]?\d+$/}, 'as_int'],
         float  => [30, sub {$_[0] =~ /^(-?(?:\d+(?:\.\d*)?|\.\d+|NaN|INF)|([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?)$/}, 'as_float'],
         string => [40, sub {1}, 'as_string'],
       },
@@ -897,7 +898,7 @@
     # try to call method specified for this type
     my @values = map { 
       # store null/nil attribute if value is undef
-      $attr->{qualify(xsi => $self->xmlschemaclass->nilValue)} = $self->xmlschemaclass->as_undef(1)
+      local $attr->{qualify(xsi => $self->xmlschemaclass->nilValue)} = $self->xmlschemaclass->as_undef(1)
         unless defined;
          $self->can($method) && $self->$method($_, $name || gen_name, $object->SOAP::Data::type, $attr)
       || $self->typecast($_, $name || gen_name, $object->SOAP::Data::type, $attr)
@@ -987,7 +988,7 @@
     return $self->as_map($hash, $name || gen_name, $type, $attr);
   }
 
-  $type = 'SOAPStruct' if $self->autotype && !defined $type && exists $self->maptype->{SOAPStruct};
+  $type = 'SOAPStruct' if $self->autotype && !defined($type) && exists $self->maptype->{SOAPStruct};
   return [$name || gen_name, 
           {'xsi:type' => $self->maptypetouri($type), %$attr},
           [map {$self->encode_object($hash->{$_}, $_)} keys %$hash], 
@@ -1011,7 +1012,7 @@
   my $self = shift;
   my($value, $name, $type, $attr) = @_;
   die "Not a HASH reference for 'map' type" unless UNIVERSAL::isa($value => 'HASH');
-  my $prefix = ($self->namespaces->{$SOAP::Constants::NS_APS} ||= 'xmlsoap');
+  my $prefix = ($self->namespaces->{$SOAP::Constants::NS_APS} ||= 'apachens');
   my @items = map {$self->encode_object(SOAP::Data->type(ordered_hash => [key => $_, value => $value->{$_}]), 'item', '')} keys %$value;
   return [$name, {'xsi:type' => "$prefix:Map", %$attr}, [@items], $self->gen_id($value)];
 }
@@ -1275,12 +1276,15 @@
 
 sub start { push @{shift->{_values}}, [shift, {@_}] }
 
-sub char { shift->{_values}->[-1]->[3] .= shift }
+# string concatenation changed to arrays which should improve performance
+# for strings with many entity-encoded elements.
+# Thanks to Mathieu Longtin <mrdamnfrenchy@yahoo.com>
+sub char { push @{shift->{_values}->[-1]->[3]}, shift }
 
 sub end { 
   my $self = shift; 
   my $done = pop @{$self->{_values}};
-  $done->[2] = defined $done->[3] ? $done->[3] : '' unless ref $done->[2];
+  $done->[2] = defined $done->[3] ? join('',@{$done->[3]}) : '' unless ref $done->[2];
   undef $done->[3]; 
   @{$self->{_values}} ? (push @{$self->{_values}->[-1]->[2]}, $done)
                       : ($self->{_done} = $done);
@@ -1491,6 +1495,8 @@
   my $self = shift;
   my($pointer, $itself, $path, @path) = @_;
 
+  die "Incorrect parameter" unless $itself =~ /^\d*$/;
+
   if ($path && substr($path, 0, 1) eq '{') {
     $path = join '/', $path, shift @path while @path && $path !~ /}/;
   }
@@ -1583,7 +1589,9 @@
 }
 
 sub is_xml {
-  $_[1] =~ /^\s*</ || $_[1] !~ /^[\w-]+:/;
+  # Added check for envelope delivery. Fairly standard with MMDF and sendmail
+  # Thanks to Chris Davies <Chris.Davies@ManheimEurope.com> 
+  $_[1] =~ /^\s*</ || $_[1] !~ /^(?:[\w-]+:|From )/;
 }
 
 sub baselocation { 
@@ -1672,7 +1680,7 @@
       $uris{$1} && 
         do { 
           $attrs->{SOAP::Utils::longname($uris{$1}, $2)} = do { 
-            my $value = delete $attrs->{$_};
+            my $value = $attrs->{$_};
             $2 ne 'type' && $2 ne 'arrayType'
               ? $value 
               : SOAP::Utils::longname($value =~ m/^($SOAP::Constants::NSMASK?):(${SOAP::Constants::NSMASK}(?:\[[\d,]*\])*)/ 
@@ -1976,8 +1984,8 @@
     my(@params, @methods);
 
     while (@_) { my($method, $params) = splice(@_,0,2);
-      $class->can($_[0]) ? push(@methods, $method, $params) 
-                         : $^W && Carp::carp "Unrecognized parameter '$method' in new()";
+      $class->can($method) ? push(@methods, $method, $params) 
+                           : $^W && Carp::carp "Unrecognized parameter '$method' in new()";
     }
     $self = bless {
       _dispatch_to => [], 
@@ -2027,7 +2035,10 @@
       my $self = shift->new;
       return $self->{$field} unless @_;
       local $@;
-      $self->{$field} = ref $_[0] eq 'CODE' ? shift : eval shift;
+      # commented out because that 'eval' was unsecure
+      # > ref $_[0] eq 'CODE' ? shift : eval shift;
+      # Am I paranoid enough?
+      $self->{$field} = shift; 
       Carp::croak $@ if $@;
       Carp::croak "$method() expects subroutine (CODE) or string that evaluates into subroutine (CODE)"
         unless ref $self->{$field} eq 'CODE';
@@ -2070,6 +2081,10 @@
 
   $self->on_action->(my $action = $self->action, $method_uri, $method_name);
 
+  # check to avoid security vulnerability: Protected->Unprotected::method(@parameters)
+  # see for more details: http://www.phrack.org/phrack/58/p58-0x09
+  die "Denied access to method ($method_name)\n" unless $method_name =~ /^\w+$/;
+
   my($class, $static);
   # try to bind directly
   if (defined($class = $self->dispatch_with->{$method_uri} 
@@ -2625,7 +2640,7 @@
   die qq!$SOAP::Constants::WRONG_VERSION Supported versions:\n@{[
         join "\n", map {"  $_ ($SOAP::Constants::SOAP_VERSIONS{$_}->{NS_ENV})"} keys %SOAP::Constants::SOAP_VERSIONS
         ]}\n!
-    unless defined(my $def = $SOAP::Constants::SOAP_VERSIONS{$version});
+    unless defined($version) && defined(my $def = $SOAP::Constants::SOAP_VERSIONS{$version});
 
   foreach (keys %$def) {
     eval "\$SOAP::Constants::$_ = '$SOAP::Constants::SOAP_VERSIONS{$version}->{$_}'";
@@ -2725,7 +2740,10 @@
       my $self = shift->new;
       return $self->{$field} unless @_;
       local $@;
-      $self->{$field} = ref $_[0] eq 'CODE' ? shift : eval shift;
+      # commented out because that 'eval' was unsecure
+      # > ref $_[0] eq 'CODE' ? shift : eval shift;
+      # Am I paranoid enough?
+      $self->{$field} = shift;
       Carp::croak $@ if $@;
       Carp::croak "$method() expects subroutine (CODE) or string that evaluates into subroutine (CODE)"
         unless ref $self->{$field} eq 'CODE';
@@ -2878,7 +2896,12 @@
 
 sub hash   { +{@_} }
 
-sub instanceof { my $class = shift; eval "require $class"; $class->new(@_) }
+sub instanceof { 
+  my $class = shift; 
+  die "Incorrect class name" unless $class =~ /^(\w[\w:]*)$/; 
+  eval "require $class"; 
+  $class->new(@_); 
+}
 
 # ======================================================================
 
diff -durN MT-2.661-full-lib/extlib/SOAP/Test.pm MT/extlib/SOAP/Test.pm
--- MT-2.661-full-lib/extlib/SOAP/Test.pm	Mon Dec 22 19:06:32 2003
+++ MT/extlib/SOAP/Test.pm	Tue Dec 23 13:42:59 2003
@@ -4,7 +4,7 @@
 # SOAP::Lite is free software; you can redistribute it
 # and/or modify it under the same terms as Perl itself.
 #
-# $Id: Test.pm,v 1.8 2001/09/19 22:02:01 paulk Exp $
+# $Id: Test.pm,v 1.9 2002/04/15 22:02:01 paulk Exp $
 #
 # ======================================================================
 
@@ -12,7 +12,7 @@
 
 use 5.004;
 use vars qw($VERSION $TIMEOUT);
-$VERSION = eval sprintf("%d.%s", q$Name: release-0_52-public $ =~ /-(\d+)_([\d_]+)/);
+$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: release-0_55-public $ =~ /-(\d+)_([\d_]+)/);
 
 $TIMEOUT = 5;
 
@@ -256,8 +256,9 @@
 
      my $latin1 = 'ਢ';
      my $utf8 = pack('U*', unpack('C*', $latin1));
+     my $result = $s->echo(SOAP::Data->type(string => $utf8))->result;
 
-     ok(pack('U0A*', $s->echo(SOAP::Data->type(string => $utf8))->result) eq $utf8);
+     ok(pack('U*', unpack('C*', $result)) eq $utf8);
   }
 
   {
diff -durN MT-2.661-full-lib/extlib/SOAP/Transport/FTP.pm MT/extlib/SOAP/Transport/FTP.pm
--- MT-2.661-full-lib/extlib/SOAP/Transport/FTP.pm	Mon Dec 22 19:06:32 2003
+++ MT/extlib/SOAP/Transport/FTP.pm	Tue Dec 23 13:42:55 2003
@@ -12,7 +12,7 @@
 
 use strict;
 use vars qw($VERSION);
-$VERSION = eval sprintf("%d.%s", q$Name: release-0_52-public $ =~ /-(\d+)_([\d_]+)/);
+$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: release-0_55-public $ =~ /-(\d+)_([\d_]+)/);
 
 use Net::FTP;
 use IO::File;
diff -durN MT-2.661-full-lib/extlib/SOAP/Transport/HTTP.pm MT/extlib/SOAP/Transport/HTTP.pm
--- MT-2.661-full-lib/extlib/SOAP/Transport/HTTP.pm	Mon Dec 22 19:06:32 2003
+++ MT/extlib/SOAP/Transport/HTTP.pm	Tue Dec 23 13:42:51 2003
@@ -4,7 +4,7 @@
 # SOAP::Lite is free software; you can redistribute it
 # and/or modify it under the same terms as Perl itself.
 #
-# $Id: HTTP.pm,v 1.9 2001/10/18 15:23:55 paulk Exp $
+# $Id: HTTP.pm,v 1.11 2002/04/15 17:35:11 paulk Exp $
 #
 # ======================================================================
 
@@ -12,7 +12,7 @@
 
 use strict;
 use vars qw($VERSION);
-$VERSION = eval sprintf("%d.%s", q$Name: release-0_52-public $ =~ /-(\d+)_([\d_]+)/);
+$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: release-0_55-public $ =~ /-(\d+)_([\d_]+)/);
 
 use SOAP::Lite;
 
@@ -226,12 +226,12 @@
   my $self = shift->new;
 
   if ($self->request->method eq 'POST') {
-    $self->action($self->request->header('SOAPAction'));
+    $self->action($self->request->header('SOAPAction') || undef);
   } elsif ($self->request->method eq 'M-POST') {
     return $self->response(HTTP::Response->new(510, # NOT EXTENDED
            "Expected Mandatory header with $SOAP::Constants::NS_ENV as unique URI")) 
       if $self->request->header('Man') !~ /^"$SOAP::Constants::NS_ENV";\s*ns\s*=\s*(\d+)/;
-    $self->action($self->request->header("$1-SOAPAction"));
+    $self->action($self->request->header("$1-SOAPAction") || undef);
   } else {
     return $self->response(HTTP::Response->new(405)) # METHOD NOT ALLOWED
   }
@@ -321,13 +321,21 @@
 sub handle {
   my $self = shift->new;
 
-  my $content; binmode(STDIN); read(STDIN,$content,$ENV{'CONTENT_LENGTH'} || 0);
-  $self->request(HTTP::Request->new( 
-    $ENV{'REQUEST_METHOD'} || '' => $ENV{'SCRIPT_NAME'},
-    HTTP::Headers->new(map {(/^HTTP_(.+)/i ? $1 : $_) => $ENV{$_}} keys %ENV),
-    $content,
-  ));
-  $self->SUPER::handle;
+  my $length = $ENV{'CONTENT_LENGTH'} || 0;
+
+  if (!$length) {     
+    $self->response(HTTP::Response->new(411)) # LENGTH REQUIRED
+  } elsif (defined $SOAP::Constants::MAX_CONTENT_SIZE && $length > $SOAP::Constants::MAX_CONTENT_SIZE) {
+    $self->response(HTTP::Response->new(413)) # REQUEST ENTITY TOO LARGE
+  } else {
+    my $content; binmode(STDIN); read(STDIN,$content,$length);
+    $self->request(HTTP::Request->new( 
+      $ENV{'REQUEST_METHOD'} || '' => $ENV{'SCRIPT_NAME'},
+      HTTP::Headers->new(map {(/^HTTP_(.+)/i ? $1 : $_) => $ENV{$_}} keys %ENV),
+      $content,
+    ));
+    $self->SUPER::handle;
+  }
 
   # imitate nph- cgi for IIS (pointed by Murray Nesbitt)
   my $status = defined($ENV{'SERVER_SOFTWARE'}) && $ENV{'SERVER_SOFTWARE'}=~/IIS/
@@ -385,7 +393,9 @@
       $self->SUPER::handle;
       $c->send_response($self->response)
     }
-    $c->shutdown(2); # replaced ->close, thanks to Sean Meisner <Sean.Meisner@VerizonWireless.com>
+    # replaced ->close, thanks to Sean Meisner <Sean.Meisner@VerizonWireless.com>
+    # shutdown() doesn't work on AIX. close() is used in this case. Thanks to Jos Clijmans <jos.clijmans@recyfin.be>
+    UNIVERSAL::isa($c, 'shutdown') ? $c->shutdown(2) : $c->close(); 
     undef $c;
   }
 }
@@ -453,8 +463,6 @@
 #
 # Copyright (C) 2001 Single Source oy (marko.asplund@kronodoc.fi)
 # a FastCGI transport class for SOAP::Lite.
-#
-# $Id: HTTP.pm,v 1.9 2001/10/18 15:23:55 paulk Exp $
 #
 # ======================================================================
 
diff -durN MT-2.661-full-lib/extlib/SOAP/Transport/IO.pm MT/extlib/SOAP/Transport/IO.pm
--- MT-2.661-full-lib/extlib/SOAP/Transport/IO.pm	Mon Dec 22 19:06:32 2003
+++ MT/extlib/SOAP/Transport/IO.pm	Tue Dec 23 13:42:46 2003
@@ -12,7 +12,7 @@
 
 use strict;
 use vars qw($VERSION);
-$VERSION = eval sprintf("%d.%s", q$Name: release-0_52-public $ =~ /-(\d+)_([\d_]+)/);
+$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: release-0_55-public $ =~ /-(\d+)_([\d_]+)/);
 
 use IO::File;
 use SOAP::Lite;
diff -durN MT-2.661-full-lib/extlib/SOAP/Transport/JABBER.pm MT/extlib/SOAP/Transport/JABBER.pm
--- MT-2.661-full-lib/extlib/SOAP/Transport/JABBER.pm	Mon Dec 22 19:06:32 2003
+++ MT/extlib/SOAP/Transport/JABBER.pm	Tue Dec 23 13:42:40 2003
@@ -12,7 +12,7 @@
 
 use strict;
 use vars qw($VERSION);
-$VERSION = eval sprintf("%d.%s", q$Name: release-0_52-public $ =~ /-(\d+)_([\d_]+)/);
+$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: release-0_55-public $ =~ /-(\d+)_([\d_]+)/);
 
 use Net::Jabber 1.0021 qw(Client); 
 use URI::Escape; 
diff -durN MT-2.661-full-lib/extlib/SOAP/Transport/LOCAL.pm MT/extlib/SOAP/Transport/LOCAL.pm
--- MT-2.661-full-lib/extlib/SOAP/Transport/LOCAL.pm	Mon Dec 22 19:06:32 2003
+++ MT/extlib/SOAP/Transport/LOCAL.pm	Tue Dec 23 13:42:36 2003
@@ -12,7 +12,7 @@
 
 use strict;
 use vars qw($VERSION);
-$VERSION = eval sprintf("%d.%s", q$Name: release-0_52-public $ =~ /-(\d+)_([\d_]+)/);
+$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: release-0_55-public $ =~ /-(\d+)_([\d_]+)/);
 
 # ======================================================================
 
diff -durN MT-2.661-full-lib/extlib/SOAP/Transport/MAILTO.pm MT/extlib/SOAP/Transport/MAILTO.pm
--- MT-2.661-full-lib/extlib/SOAP/Transport/MAILTO.pm	Mon Dec 22 19:06:32 2003
+++ MT/extlib/SOAP/Transport/MAILTO.pm	Tue Dec 23 13:42:31 2003
@@ -12,7 +12,7 @@
 
 use strict;
 use vars qw($VERSION);
-$VERSION = eval sprintf("%d.%s", q$Name: release-0_52-public $ =~ /-(\d+)_([\d_]+)/);
+$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: release-0_55-public $ =~ /-(\d+)_([\d_]+)/);
 
 use MIME::Lite; 
 use URI;
diff -durN MT-2.661-full-lib/extlib/SOAP/Transport/MQ.pm MT/extlib/SOAP/Transport/MQ.pm
--- MT-2.661-full-lib/extlib/SOAP/Transport/MQ.pm	Mon Dec 22 19:06:32 2003
+++ MT/extlib/SOAP/Transport/MQ.pm	Tue Dec 23 13:42:26 2003
@@ -12,7 +12,7 @@
 
 use strict;
 use vars qw($VERSION);
-$VERSION = eval sprintf("%d.%s", q$Name: release-0_52-public $ =~ /-(\d+)_([\d_]+)/);
+$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: release-0_55-public $ =~ /-(\d+)_([\d_]+)/);
 
 use MQClient::MQSeries; 
 use MQSeries::QueueManager;
diff -durN MT-2.661-full-lib/extlib/SOAP/Transport/POP3.pm MT/extlib/SOAP/Transport/POP3.pm
--- MT-2.661-full-lib/extlib/SOAP/Transport/POP3.pm	Mon Dec 22 19:06:32 2003
+++ MT/extlib/SOAP/Transport/POP3.pm	Tue Dec 23 13:42:18 2003
@@ -12,7 +12,7 @@
 
 use strict;
 use vars qw($VERSION);
-$VERSION = eval sprintf("%d.%s", q$Name: release-0_52-public $ =~ /-(\d+)_([\d_]+)/);
+$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: release-0_55-public $ =~ /-(\d+)_([\d_]+)/);
 
 use Net::POP3; 
 use URI; 
diff -durN MT-2.661-full-lib/extlib/SOAP/Transport/TCP.pm MT/extlib/SOAP/Transport/TCP.pm
--- MT-2.661-full-lib/extlib/SOAP/Transport/TCP.pm	Mon Dec 22 19:06:32 2003
+++ MT/extlib/SOAP/Transport/TCP.pm	Tue Dec 23 13:42:11 2003
@@ -4,7 +4,7 @@
 # SOAP::Lite is free software; you can redistribute it
 # and/or modify it under the same terms as Perl itself.
 #
-# $Id: TCP.pm,v 1.3 2001/08/11 19:09:57 paulk Exp $
+# $Id: TCP.pm,v 1.4 2002/04/15 19:09:57 paulk Exp $
 #
 # ======================================================================
 
@@ -12,7 +12,7 @@
 
 use strict;
 use vars qw($VERSION);
-$VERSION = eval sprintf("%d.%s", q$Name: release-0_52-public $ =~ /-(\d+)_([\d_]+)/);
+$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: release-0_55-public $ =~ /-(\d+)_([\d_]+)/);
 
 use URI;
 use IO::Socket;
@@ -22,7 +22,7 @@
 
 # ======================================================================
 
-package URI::tcp; # ok, lets do 'tcp://' scheme
+package URI::tcp; # ok, let's do 'tcp://' scheme
 require URI::_server; 
 @URI::tcp::ISA=qw(URI::_server);
 
@@ -71,7 +71,8 @@
   while (length $data > 0) {
     return unless $select->can_write($timeout);
     local $SIG{PIPE} = 'IGNORE';
-    my $wc = syswrite($sock, $data);
+    # added length() to make it work on Mac. Thanks to Robin Fuller <rfuller@broadjump.com>
+    my $wc = syswrite($sock, $data, length($data));
     if (defined $wc) {
       substr($data, 0, $wc) = '';
     } elsif (!IO::SessionData::WOULDBLOCK($!)) {
@@ -113,11 +114,18 @@
   my $uri = URI->new($endpoint);
 
   local($^W, $@, $!);
-  my $sock = $self->io_socket_class->new (
+  my $socket = $self->io_socket_class; 
+  eval "require $socket" or Carp::croak $@ unless UNIVERSAL::can($socket => 'new');
+  my $sock = $socket->new (
     PeerAddr => $uri->host, PeerPort => $uri->port, Proto => $uri->scheme, %$self
   );
 
   SOAP::Trace::debug($envelope);
+
+  # bytelength hack. See SOAP::Transport::HTTP.pm for details.
+  my $bytelength = SOAP::Utils::bytelength($envelope);
+  $envelope = pack('C0A*', $envelope) 
+    if !$SOAP::Constants::DO_NOT_USE_LWP_LENGTH_HACK && length($envelope) != $bytelength;
 
   my $result;
   if ($sock) {
diff -durN MT-2.661-full-lib/extlib/UDDI/Lite.pm MT/extlib/UDDI/Lite.pm
--- MT-2.661-full-lib/extlib/UDDI/Lite.pm	Mon Dec 22 19:06:32 2003
+++ MT/extlib/UDDI/Lite.pm	Tue Dec 23 13:44:57 2003
@@ -13,7 +13,7 @@
 use 5.004;
 use strict;
 use vars qw($VERSION);
-$VERSION = eval sprintf("%d.%s", q$Name: release-0_52-public $ =~ /-(\d+)_([\d_]+)/);
+$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: release-0_55-public $ =~ /-(\d+)_([\d_]+)/);
 
 use SOAP::Lite;
 
diff -durN MT-2.661-full-lib/extlib/XML/Parser/Lite.pm MT/extlib/XML/Parser/Lite.pm
--- MT-2.661-full-lib/extlib/XML/Parser/Lite.pm	Mon Dec 22 19:06:32 2003
+++ MT/extlib/XML/Parser/Lite.pm	Tue Dec 23 13:49:06 2003
@@ -12,7 +12,7 @@
 
 use strict;
 use vars qw($VERSION);
-$VERSION = eval sprintf("%d.%s", q$Name: release-0_52-public $ =~ /-(\d+)_([\d_]+)/);
+$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: release-0_55-public $ =~ /-(\d+)_([\d_]+)/);
 
 sub new { 
   my $self = shift;
diff -durN MT-2.661-full-lib/extlib/XMLRPC/Lite.pm MT/extlib/XMLRPC/Lite.pm
--- MT-2.661-full-lib/extlib/XMLRPC/Lite.pm	Mon Dec 22 19:06:32 2003
+++ MT/extlib/XMLRPC/Lite.pm	Tue Dec 23 13:52:30 2003
@@ -13,7 +13,7 @@
 use SOAP::Lite;
 use strict;
 use vars qw($VERSION);
-$VERSION = eval sprintf("%d.%s", q$Name: release-0_52-public $ =~ /-(\d+)_([\d_]+)/);
+$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: release-0_55-public $ =~ /-(\d+)_([\d_]+)/);
 
 # ======================================================================
 
diff -durN MT-2.661-full-lib/extlib/XMLRPC/Test.pm MT/extlib/XMLRPC/Test.pm
--- MT-2.661-full-lib/extlib/XMLRPC/Test.pm	Mon Dec 22 19:06:32 2003
+++ MT/extlib/XMLRPC/Test.pm	Tue Dec 23 13:52:27 2003
@@ -12,7 +12,7 @@
 
 use 5.004;
 use vars qw($VERSION $TIMEOUT);
-$VERSION = eval sprintf("%d.%s", q$Name: release-0_52-public $ =~ /-(\d+)_([\d_]+)/);
+$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: release-0_55-public $ =~ /-(\d+)_([\d_]+)/);
 
 $TIMEOUT = 5;
 
diff -durN MT-2.661-full-lib/extlib/XMLRPC/Transport/HTTP.pm MT/extlib/XMLRPC/Transport/HTTP.pm
--- MT-2.661-full-lib/extlib/XMLRPC/Transport/HTTP.pm	Mon Dec 22 19:06:32 2003
+++ MT/extlib/XMLRPC/Transport/HTTP.pm	Tue Dec 23 13:52:22 2003
@@ -12,7 +12,7 @@
 
 use strict;
 use vars qw($VERSION);
-$VERSION = eval sprintf("%d.%s", q$Name: release-0_52-public $ =~ /-(\d+)_([\d_]+)/);
+$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: release-0_55-public $ =~ /-(\d+)_([\d_]+)/);
 
 use XMLRPC::Lite;
 use SOAP::Transport::HTTP;
diff -durN MT-2.661-full-lib/extlib/XMLRPC/Transport/POP3.pm MT/extlib/XMLRPC/Transport/POP3.pm
--- MT-2.661-full-lib/extlib/XMLRPC/Transport/POP3.pm	Mon Dec 22 19:06:32 2003
+++ MT/extlib/XMLRPC/Transport/POP3.pm	Tue Dec 23 13:52:18 2003
@@ -12,7 +12,7 @@
 
 use strict;
 use vars qw($VERSION);
-$VERSION = eval sprintf("%d.%s", q$Name: release-0_52-public $ =~ /-(\d+)_([\d_]+)/);
+$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: release-0_55-public $ =~ /-(\d+)_([\d_]+)/);
 
 use XMLRPC::Lite;
 use SOAP::Transport::POP3;
diff -durN MT-2.661-full-lib/extlib/XMLRPC/Transport/TCP.pm MT/extlib/XMLRPC/Transport/TCP.pm
--- MT-2.661-full-lib/extlib/XMLRPC/Transport/TCP.pm	Mon Dec 22 19:06:32 2003
+++ MT/extlib/XMLRPC/Transport/TCP.pm	Tue Dec 23 13:52:14 2003
@@ -12,7 +12,7 @@
 
 use strict;
 use vars qw($VERSION);
-$VERSION = eval sprintf("%d.%s", q$Name: release-0_52-public $ =~ /-(\d+)_([\d_]+)/);
+$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: release-0_55-public $ =~ /-(\d+)_([\d_]+)/);
 
 use XMLRPC::Lite;
 use SOAP::Transport::TCP;
diff -durN MT-2.661-full-lib/lib/MT/App/CMS.pm MT/lib/MT/App/CMS.pm
--- MT-2.661-full-lib/lib/MT/App/CMS.pm	Thu Mar 27 07:24:20 2003
+++ MT/lib/MT/App/CMS.pm	Wed Nov 12 19:48:34 2003
@@ -790,7 +790,7 @@
                 $param{site_path} = $cwd;
             }
             if (!$param{archive_path}) {
-                $param{archive_path} = File::Spec->catdir($cwd, 'archives');
+                $param{archive_path} = $cwd . '/archives';
             }
             if (!$param{site_url}) {
                 $param{site_url} = $app->base . '/';
@@ -1523,7 +1523,7 @@
         $row->{title_short} = encode_html($row->{title_short}, 1);
         $row->{status_text} =
             $app->translate(MT::Entry::status_text($obj->status));
-        $row->{"status_$row->{status_text}"} = 1;
+        $row->{"status_".MT::Entry::status_text($obj->status)} = 1;
         $row->{entry_odd} = $i++ % 2 ? 1 : 0;
         $row->{has_edit_access} = $perms->can_edit_all_posts ||
             $obj->author_id == $app->{author}->id;
@@ -2586,8 +2586,10 @@
     }
     my $subj = $app->translate("[_1] Update: [_2]", $blog->name, $entry->title);
     $subj =~ s![\x80-\xFF]!!g;
+    # subj need QP! XXX - autrijus
+    require MIME::QuotedPrint;
     my %head = ( To => $author->email, From => $author->email,
-                 Subject => $subj,
+                 Subject => MIME::QuotedPrint::encode($subj),
                  'Content-Transfer-Encoding' => '8bit' );
     my $charset = $app->{cfg}->PublishCharset || 'iso-8859-1';
     $head{'Content-Type'} = qq(text/plain; charset="$charset");
@@ -2740,6 +2742,8 @@
                     "File::Temp if you'd like to be able to overwrite " .
                     "existing uploaded files.)", $fname));
             }
+            $fmgr->mkpath( $app->{cfg}->TempDir )
+		unless -d $app->{cfg}->TempDir;
             my($tmp_fh, $tmp_file) =
                 File::Temp::tempfile(DIR => $app->{cfg}->TempDir);
             defined(_write_upload($fh, $tmp_fh))
diff -durN MT-2.661-full-lib/lib/MT/FileMgr/Local.pm MT/lib/MT/FileMgr/Local.pm
--- MT-2.661-full-lib/lib/MT/FileMgr/Local.pm	Mon Feb 17 06:15:28 2003
+++ MT/lib/MT/FileMgr/Local.pm	Wed Nov 12 19:48:35 2003
@@ -10,6 +10,7 @@
 @MT::FileMgr::Local::ISA = qw( MT::FileMgr );
 
 use Symbol;
+use File::Basename;
 use Fcntl qw( :DEFAULT :flock );
 
 sub get_data {
@@ -67,6 +68,7 @@
         $perms = $cfg->HTMLPerms;
     }
     my $old = umask(oct $umask);
+    $fmgr->mkpath(dirname($to)) unless -d dirname($to);
     sysopen FH, $to, O_RDWR|O_CREAT|O_TRUNC, oct $perms
         or return $fmgr->error(MT->translate(
             "Opening local file '[_1]' failed: [_2]", $to, "$!"));
diff -durN MT-2.661-full-lib/lib/MT/L10N.pm MT/lib/MT/L10N.pm
--- MT-2.661-full-lib/lib/MT/L10N.pm	Wed Feb 12 08:15:04 2003
+++ MT/lib/MT/L10N.pm	Wed Nov 12 19:48:35 2003
@@ -17,6 +17,6 @@
     I18N::LangTags::List::name($tag);
 }
 
-sub encoding { 'iso-8859-1' }   ## Latin-1
+sub encoding { 'utf-8' }   ## Latin-1
 
 1;
diff -durN MT-2.661-full-lib/lib/MT/Util.pm MT/lib/MT/Util.pm
--- MT-2.661-full-lib/lib/MT/Util.pm	Wed May 28 15:48:42 2003
+++ MT/lib/MT/Util.pm	Tue Dec 23 13:59:13 2003
@@ -44,6 +44,58 @@
         my $leap = $y % 4 == 0 && ($y % 100 != 0 || $y % 400 == 0) ? 1 : 0;
         $In_Year[$leap][$m-1] + $d;
     }
+    
+    # Chinese date format by MH (mhsin)
+    my @cnums_index = qw( 0 1 2 3 4 5 6 7 8 9 B C D A);
+    my %all_cnums = (
+      'normal' => [ '&#38646;', '&#19968;', '&#20108;', '&#19977;', '&#22235;',
+                    '&#20116;', '&#20845;', '&#19971;', '&#20843;', '&#20061;',
+                    '&#21313;', '&#30334;', '&#21315;', '' ],
+      'capital' => [ '&#38646;', '&#22777;', '&#36019;', '&#21443;', '&#32902;',
+                     '&#20237;', '&#38520;', '&#26578;', '&#25420;', '&#29590;',
+                     '&#25342;', '&#20336;', '&#20191;', '' ],
+      );
+
+    sub get_cnums
+    {
+      my ($type, $short) = @_;
+      my %cnums;
+      
+      @cnums{@cnums_index} = @{$all_cnums{$type}};
+      $short and @cnums{qw( B C D )} = ('', '', '');
+      
+      return {%cnums};
+    }
+
+    sub num_to_cnstring
+    {
+      my ($num_as_string, $limit_num_of_digits, $retain_initialzero, $retain_zeroes, $retain_ten) = @_;
+      my $base = 0;
+      
+      $_ = reverse(($limit_num_of_digits ? substr($num_as_string, -$limit_num_of_digits) : $num_as_string));
+      $limit_num_of_digits and s/(\d)/chr(ord('A') + $base ++) . $1/ge;
+      $_ = reverse;
+
+      $retain_initialzero	or s/^(0[A-Z])*//;
+      $retain_zeroes	or s/0[0A-Z]*/0/g, s/0+$//;
+      $retain_ten		or s/^1B/B/;
+      s/^$/0/;
+      
+      return $_;
+    }
+
+    sub num_to_chinese
+    {
+      my ($num_as_string, $type, $short) = @_;
+      my $cnums;
+      
+      $_ = num_to_cnstring($num_as_string, 4, $short, $short, $short);
+      $cnums = get_cnums($type, $short);
+      s/(\w)/$$cnums{$1}/g;
+      
+      return $_;
+    }
+    # End of Chinese date format
 }
 
 use vars qw( %Languages );
@@ -91,6 +143,65 @@
         ($f{l} = $f{I}) =~ s!^0! !;
         $f{j} = sprintf "%03d", $f{j};
         $f{Z} = '';
+        # Chisese date format by MH (mhsin)
+        
+        #abdehijklmpswxyz
+        #         
+        #year: VvUuTtCc
+        #month: Qq
+        #day: Rr
+        #hour: FfGg
+        #min: Nn
+        #sec: Oo
+        
+        # 年, 小寫, 簡讀, 四位
+        $f{V} = num_to_chinese(sprintf("%d", $f{Y}), 'normal', 1);
+        # 年, 小寫, 簡讀, 二位
+        $f{v} = num_to_chinese(sprintf("%02d", $f{y}), 'normal', 1);
+        # 年, 大寫, 簡讀, 四位
+        $f{U} = num_to_chinese(sprintf("%d", $f{Y}), 'capital', 1);
+        # 年, 大寫, 簡讀, 二位
+        $f{u} = num_to_chinese(sprintf("%02d", $f{y}), 'capital', 1);
+        # 民國年, 小寫, 全讀
+        $f{C} = num_to_chinese(sprintf("%d", $f{Y} - 1911), 'normal', 0);
+        # 民國年, 大寫, 全讀
+        $f{c} = num_to_chinese(sprintf("%d", $f{Y} - 1911), 'capital', 0);
+        
+        # 年, 小寫, 全讀
+        $f{T} = num_to_chinese(sprintf("%d", $f{Y}), 'normal', 0);
+        # 年, 大寫, 全讀
+        $f{t} = num_to_chinese(sprintf("%d", $f{Y}), 'capital', 0);
+        
+        # 月, 小寫, 全讀
+        $f{Q} = num_to_chinese(sprintf("%d", $f{m}), 'normal', 0);
+        # 月, 大寫, 全讀
+        $f{q} = num_to_chinese(sprintf("%d", $f{m}), 'capital', 0);
+        
+        # 日, 小寫, 全讀
+        $f{R} = num_to_chinese(sprintf("%d", $f{d}), 'normal', 0);
+        # 日, 大寫, 全讀
+        $f{r} = num_to_chinese(sprintf("%d", $f{d}), 'capital', 0);
+        
+        # 時, 小寫, 全讀, 24時制
+        $f{F} = num_to_chinese(sprintf("%d", $f{H}), 'normal', 0);
+        # 時, 小寫, 全讀, 12時制
+        $f{f} = num_to_chinese(sprintf("%d", $f{I}), 'normal', 0);
+        # 時, 小寫, 簡讀, 24時制
+        $f{G} = num_to_chinese(sprintf("%02d", $f{H}), 'normal', 1);
+        # 時, 小寫, 簡讀, 12時制
+        $f{g} = num_to_chinese(sprintf("%02d", $f{I}), 'normal', 1);
+        
+        # 分, 小寫, 全讀
+        $f{N} = num_to_chinese(sprintf("%d", $f{M}), 'normal', 0);
+        # 分, 小寫, 簡讀
+        $f{n} = num_to_chinese(sprintf("%02d", $f{M}), 'normal', 1);
+        
+        # 秒, 小寫, 全讀
+        $f{O} = num_to_chinese(sprintf("%d", $f{S}), 'normal', 0);
+        # 秒, 小寫, 簡讀
+        $f{o} = num_to_chinese(sprintf("%02d", $f{S}), 'normal', 1);
+        
+        # End of Chisese date format
         $cache->{$ts . $lang} = \%f;
     }
     my $date_format = $Languages{$lang}->[4] || "%B %d, %Y";
@@ -103,6 +214,22 @@
     if ($lang eq 'jp') {
         $format =~ s!%B %Y!$Languages{$lang}->[6]!g;
     }
+
+    ## Codes below are provided by contagious, for Chinese Date Format.
+    ## Please see http://www.csie.nctu.edu.tw/~tnlin/blog/archives/000008.html
+    if($lang eq 'tw'){
+        $format =~ s!%B %Y!$Languages{$lang}->[6]!g;
+
+        my %ff = %f;
+        $ff{Y}=to_hz($ff{Y}-1911);
+        $ff{m}=to_hz($ff{m});
+        $ff{d}=to_hz($ff{d});
+        $ff{H}=to_hz($ff{H});
+        $ff{M}=to_hz($ff{M});
+        $ff{S}=to_hz($ff{S});
+        $format =~ s!%(\w)!$ff{$1}!g if defined $format;
+    }
+
     $format =~ s!%(\w)!$f{$1}!g if defined $format;
     $format;
 }
@@ -145,6 +272,25 @@
     ($start, $end);
 }
 
+## Codes below are provided by contagious, for Chinese Date Format.
+## Please see http://www.csie.nctu.edu.tw/~tnlin/blog/archives/000008.html
+sub to_hz{
+    my @num=('零','一','二','三','四','五','六','七','八','九');
+    my $tmp = $_[0];
+    my $n1 = $tmp % 10;
+    my $n2 = ($tmp /= 10) %10;
+    my $n3 = ($tmp /= 10) %10;
+    my $r='';
+    $r  = "$num[$n3]百" unless $n3 == 0;
+    if($n3 ==0 && $n2 ==1){ $r.= "十";}
+    else{
+        $r .="$num[$n2]十" unless $n2 == 0;
+        if($n2==0 && $n3!=0 && $n1!=0){ $r .= "零"; }
+    }
+    $r .="$num[$n1]" unless ($n1 ==0  && ($n2 !=0 || $n3 !=0)) ;
+    $r;
+}
+
 sub start_end_month {
     my($ts) = @_;
     my($y, $mo) = unpack 'A4A2', $ts;
@@ -863,6 +1009,43 @@
             "%Y&#24180;%m&#26376;",
           ],
 
+    'zh' => [
+            [ '&#26143;&#26399;&#26085;', '&#26143;&#26399;&#19968;',
+              '&#26143;&#26399;&#20108;', '&#26143;&#26399;&#19977;',
+              '&#26143;&#26399;&#22235;', '&#26143;&#26399;&#20116;',
+              '&#26143;&#26399;&#20845;'],
+            [ '&#19968;&#26376;', '&#20108;&#26376;', '&#19977;&#26376;', '&#22235;&#26376;', '&#20116;&#26376;', '&#20845;&#26376;', '&#19971;&#26376;', '&#20843;&#26376;', '&#20061;&#26376;', '&#21313;&#26376;', '&#21313;&#19968;&#26376;', '&#21313;&#20108;&#26376;' ],
+            [ '&#19978;&#21320;', '&#19979;&#21320;' ],
+            "%Y&#24180;%m&#26376;%d&#26085; %p%I&#26178;%M&#20998;",
+            "%Y&#24180;%m&#26376;%d&#26085; %A",
+            "%p%I&#26178;%M&#20998;",
+            "%Y&#24180;%m&#26376;",
+          ],
+
+    'zhall' => [
+            [ '&#26143;&#26399;&#26085;', '&#26143;&#26399;&#19968;',
+              '&#26143;&#26399;&#20108;', '&#26143;&#26399;&#19977;',
+              '&#26143;&#26399;&#22235;', '&#26143;&#26399;&#20116;',
+              '&#26143;&#26399;&#20845;'],
+            [ '&#19968;&#26376;', '&#20108;&#26376;', '&#19977;&#26376;', '&#22235;&#26376;', '&#20116;&#26376;', '&#20845;&#26376;', '&#19971;&#26376;', '&#20843;&#26376;', '&#20061;&#26376;', '&#21313;&#26376;', '&#21313;&#19968;&#26376;', '&#21313;&#20108;&#26376;' ],
+            [ '&#19978;&#21320;', '&#19979;&#21320;' ],
+            "&#27665;&#22283%C&#24180;%Q&#26376;%R&#26085; %p%F&#26178;%N&#20998;",
+            "&#27665;&#22283%C&#24180;%Q&#26376;%R&#26085; %A",
+            "%p%F&#26178;%N&#20998;",
+            "&#27665;&#22283%C&#24180;%Q&#26376;",
+          ],
+
+    'tw' => [
+            [ '星期日', '星期一', '星期二',
+              '星期三', '星期四', '星期五', '星期六', ],
+            [ qw( 1 2 3 4 5 6 7 8 9 10 11 12 ) ],
+            [ ('上午','下午') ],
+            "民國%Y年%m月%日 %p%H點%M分",
+            "民國%Y年%m月%d日",
+            "%p%H點%M分",
+            "民國%Y年%m月",
+          ], 
+
     'et' => [
             [ qw( p&uuml;hap&auml;ev esmasp&auml;ev teisip&auml;ev
                   kolmap&auml;ev neljap&auml;ev reede laup&auml;ev ) ],
diff -durN MT-2.661-full-lib/lib/MT/default-templates.pl MT/lib/MT/default-templates.pl
--- MT-2.661-full-lib/lib/MT/default-templates.pl	Sun Dec 21 05:50:42 2003
+++ MT/lib/MT/default-templates.pl	Sun Dec 26 19:28:27 2003
@@ -149,7 +149,7 @@
 </div>
 
 <div class="side">
-<a href="">Add Your Links Here</a><br />
+<a href="">請在此加入鏈結</a><br />
 </div>
 
 <div class="syndicate">
@@ -165,6 +165,7 @@
 
 <div class="powered">
 <MT_TRANS phrase="Powered by"><br /><a href="http://www.movabletype.org">Movable Type <$MTVersion$></a><br />    
+<a href="<$MTCGIPath$>mt.cgi">管理介面</a>
 </div>
 
 </div>
@@ -177,7 +178,7 @@
           'outfile' => 'index.html',
           'rebuild_me' => '1',
           'type' => 'index',
-          'name' => 'Main Index'
+          'name' => '主索引'
         },
 
 {
@@ -201,30 +202,30 @@
 
 {
           'text' => '<?xml version="1.0" encoding="<$MTPublishCharset$>"?>
-<feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en">
+<feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="zh-tw">
   <title><$MTBlogName remove_html="1" encode_xml="1"$></title>
   <link rel="alternate" type="text/html" href="<$MTBlogURL encode_xml="1"$>" />
-  <modified><MTEntries lastn="1"><$MTEntryModifiedDate utc="1" format="%Y-%m-%dT%H:%M:%SZ"$></MTEntries></modified>
+  <modified><MTEntries lastn="1"><$MTEntryModifiedDate language="en" utc="1" format="%Y-%m-%dT%H:%M:%SZ"$></MTEntries></modified>
   <tagline><$MTBlogDescription remove_html="1" encode_xml="1"$></tagline>
-  <id>tag:<$MTBlogHost exclude_port="1" encode_xml="1"$>,<$MTDate format="%Y"$>:<$MTBlogRelativeURL encode_xml="1"$>/<$MTBlogID$></id>
+  <id>tag:<$MTBlogHost exclude_port="1" encode_xml="1"$>,<$MTDate language="en" format="%Y"$>:<$MTBlogRelativeURL encode_xml="1"$>/<$MTBlogID$></id>
   <generator url="http://www.movabletype.org/" version="<$MTVersion$>">Movable Type</generator>
-  <copyright><MTEntries lastn="1">Copyright (c) <$MTEntryDate format="%Y"$>, <$MTEntryAuthor encode_xml="1"$></MTEntries></copyright>
+  <copyright><MTEntries lastn="1">Copyright (c) <$MTEntryDate language="en" format="%Y"$>, <$MTEntryAuthor encode_xml="1"$></MTEntries></copyright>
 <MTEntries lastn="15">
   <entry>
     <title><$MTEntryTitle remove_html="1" encode_xml="1"$></title>
     <link rel="alternate" type="text/html" href="<$MTEntryPermalink encode_xml="1"$>" />
-    <modified><$MTEntryModifiedDate utc="1" format="%Y-%m-%dT%H:%M:%SZ"$></modified>
-    <issued><$MTEntryDate format="%Y-%m-%dT%H:%M:%S"$><$MTBlogTimezone$></issued>
-    <id>tag:<$MTBlogHost exclude_port="1" encode_xml="1"$>,<$MTEntryDate format="%Y">:<$MTBlogRelativeURL encode_xml="1"$>/<$MTBlogID$>.<$MTEntryID$></id>
-    <created><$MTEntryDate utc="1" format="%Y-%m-%dT%H:%M:%SZ"$></created>
+    <modified><$MTEntryModifiedDate language="en" utc="1" format="%Y-%m-%dT%H:%M:%SZ"$></modified>
+    <issued><$MTEntryDate language="en" format="%Y-%m-%dT%H:%M:%S"$><$MTBlogTimezone$></issued>
+    <id>tag:<$MTBlogHost exclude_port="1" encode_xml="1"$>,<$MTEntryDate language="en" format="%Y">:<$MTBlogRelativeURL encode_xml="1"$>/<$MTBlogID$>.<$MTEntryID$></id>
+    <created><$MTEntryDate language="en" utc="1" format="%Y-%m-%dT%H:%M:%SZ"$></created>
     <summary type="text/plain"><$MTEntryExcerpt remove_html="1" encode_xml="1"$></summary>
     <author>
       <name><$MTEntryAuthor encode_xml="1"$></name>
       <MTIfNonEmpty tag="MTEntryAuthorURL"><url><$MTEntryAuthorURL encode_xml="1"$></url></MTIfNonEmpty>
       <MTIfNonEmpty tag="MTEntryAuthorEmail"><email><$MTEntryAuthorEmail encode_xml="1"$></email></MTIfNonEmpty>
     </author>
-    <MTIfNonEmpty tag="MTEntryCategory"><dc:subject><$MTEntryCategory encode_xml="1"$></dc:subject></MTIfNonEmpty>
-    <content type="text/html" mode="escaped" xml:lang="en" xml:base="<$MTBlogURL encode_xml="1"$>">
+    <MTIfNonEmpty tag="MTEntryCategory"><dc:subject><MTEntryCategories glue=", "><MTIfNonEmpty tag="MTCategoryDescription"><$MTCategoryDescription encode_xml="1"$><MTElse><$MTCategoryLabel encode_xml="1"$></MTElse></MTIfNonEmpty></MTEntryCategories></dc:subject></MTIfNonEmpty>
+    <content type="text/html" mode="escaped" xml:lang="zh-tw" xml:base="<$MTBlogURL encode_xml="1"$>">
       <$MTEntryBody encode_xml="1"$>
       <$MTEntryMore encode_xml="1"$>
     </content>
@@ -234,7 +235,7 @@
           'outfile' => 'atom.xml',
           'rebuild_me' => '1',
           'type' => 'index',
-          'name' => 'Atom Index'
+          'name' => 'Atom 索引'
         },
 
 {
@@ -249,9 +250,9 @@
 <title><$MTBlogName remove_html="1" encode_xml="1"$></title>
 <link><$MTBlogURL$></link>
 <description><$MTBlogDescription remove_html="1" encode_xml="1"$></description>
-<dc:language>en-us</dc:language>
+<dc:language>zh-tw</dc:language>
 <dc:creator><MTEntries lastn="1"><$MTEntryAuthorEmail$></MTEntries></dc:creator>
-<dc:date><MTEntries lastn="1"><$MTEntryDate format="%Y-%m-%dT%H:%M:%S"$><$MTBlogTimezone$></MTEntries></dc:date>
+<dc:date><MTEntries lastn="1"><$MTEntryDate language="en" format="%Y-%m-%d %H:%M:%S"$> <$MTBlogTimezone no_colon="1"$></MTEntries></dc:date>
 <admin:generatorAgent rdf:resource="http://www.movabletype.org/?v=<$MTVersion$>" />
 <sy:updatePeriod>hourly</sy:updatePeriod>
 <sy:updateFrequency>1</sy:updateFrequency>
@@ -264,7 +265,7 @@
 <description><$MTEntryExcerpt remove_html="1" encode_xml="1"$></description>
 <guid isPermaLink="false"><$MTEntryID$>@<$MTBlogURL$></guid>
 <dc:subject><$MTEntryCategory remove_html="1" encode_xml="1"$></dc:subject>
-<dc:date><$MTEntryDate format="%Y-%m-%dT%H:%M:%S"$><$MTBlogTimezone$></dc:date>
+<dc:date><$MTEntryDate language="en" format="%Y-%m-%dT%H:%M:%S"$><$MTBlogTimezone$></dc:date>
 </item>
 </MTEntries>
 
@@ -273,7 +274,7 @@
           'outfile' => 'index.xml',
           'rebuild_me' => '1',
           'type' => 'index',
-          'name' => 'RSS 2.0 Index'
+          'name' => 'RSS 2.0 索引'
         },
 
 {
@@ -311,7 +312,7 @@
           'outfile' => 'archives.html',
           'rebuild_me' => '1',
           'type' => 'index',
-          'name' => 'Master Archive Index'
+          'name' => '總彙整索引'
         },
 
 {
@@ -337,7 +338,7 @@
 
 <div class="comments-body">
 <$MTCommentPreviewBody$>
-<span class="comments-post"><MT_TRANS phrase="Posted by"> <$MTCommentPreviewAuthorLink spam_protect="1"$> <MT_TRANS phrase="at"> <$MTCommentPreviewDate$></span>
+<span class="comments-post"><MTIfNonEmpty tag="MTCommentPreviewAuthorLink"><MT_TRANS phrase="Posted by"> <$MTCommentPreviewAuthorLink spam_protect="1"$> <MT_TRANS phrase="at"><MTElse><MT_TRANS phrase="Posted at"></MTElse></MTIfNonEmpty> <$MTCommentPreviewDate$></span>
 </div>
 
 <div class="comments-body">
@@ -354,7 +355,7 @@
 <label for="url"><MT_TRANS phrase="URL:"></label><br />
 <input id="url" name="url" value="<$MTCommentPreviewURL encode_html="1"$>" /><br /><br />
 
-<label for="text"><MT_TRANS phrase="Comments:"></label><br />
+<label for="text"><MT_TRANS phrase="Comments: "></label><br />
 <textarea id="text" name="text" rows="10" cols="50"><$MTCommentPreviewBody convert_breaks="0" encode_html="1"$></textarea><br /><br />
 
 <input type="submit" name="preview" value="&nbsp;<MT_TRANS phrase="Preview">&nbsp;" />
@@ -368,7 +369,7 @@
 <MTComments>
 <div class="comments-body">
 <$MTCommentBody$>
-<span class="comments-post"><MT_TRANS phrase="Posted by"> <$MTCommentAuthorLink spam_protect="1"$> <MT_TRANS phrase="at"> <$MTCommentDate$></span>
+<span class="comments-post"><MTIfNonEmpty tag="MTCommentAuthorLink"><MT_TRANS phrase="Posted by"> <$MTCommentAuthorLink spam_protect="1"$> <MT_TRANS phrase="at"><MTElse><MT_TRANS phrase="Posted at"></MTElse></MTIfNonEmpty> <$MTCommentDate$></span>
 </div>
 </MTComments>
 
@@ -376,7 +377,7 @@
 </body>
 </html>',
           'type' => 'comment_preview',
-          'name' => 'Comment Preview Template'
+          'name' => '預覽迴響模版'
         },
 
 {
@@ -425,7 +426,7 @@
 <label for="url"><MT_TRANS phrase="URL:"></label><br />
 <input id="url" name="url" value="<$MTCommentPreviewURL encode_html="1"$>" /><br /><br />
 
-<label for="text"><MT_TRANS phrase="Comments:"></label><br />
+<label for="text"><MT_TRANS phrase="Comments: "></label><br />
 <textarea id="text" name="text" rows="10" cols="50"><$MTCommentPreviewBody convert_breaks="0" encode_html="1"$></textarea><br /><br />
 
 <input type="submit" name="preview" value="&nbsp;<MT_TRANS phrase="Preview">&nbsp;" />
@@ -437,7 +438,7 @@
 </body>
 </html>',
           'type' => 'comment_error',
-          'name' => 'Comment Error Template'
+          'name' => '迴響出錯模版'
         },
 
 {
@@ -449,7 +450,7 @@
 </body>
 </html>',
           'type' => 'popup_image',
-          'name' => 'Uploaded Image Popup Template'
+          'name' => '彈出式圖片上傳模版'
         },
 
 {
@@ -533,13 +534,13 @@
 
 <div class="blog">
 
-<div class="comments-head"><MT_TRANS phrase="Comments:"> <$MTEntryTitle$></div>
+<div class="comments-head"><MT_TRANS phrase="Comments: "> <$MTEntryTitle$></div>
 
 
 <MTComments>
 <div class="comments-body">
 <$MTCommentBody$>
-<span class="comments-post"><MT_TRANS phrase="Posted by"> <$MTCommentAuthorLink spam_protect="1"$> <MT_TRANS phrase="at"> <$MTCommentDate$></span>
+<span class="comments-post"><MTIfNonEmpty tag="MTCommentAuthorLink"><MT_TRANS phrase="Posted by"> <$MTCommentAuthorLink spam_protect="1"$> <MT_TRANS phrase="at"><MTElse><MT_TRANS phrase="Posted at"></MTElse></MTIfNonEmpty> <$MTCommentDate$></span>
 </div>
 </MTComments>
 
@@ -565,7 +566,7 @@
 <MT_TRANS phrase="Remember personal info?"><br />
 <input type="radio" id="bakecookie" name="bakecookie" /><label for="bakecookie"><MT_TRANS phrase="Yes"></label><input type="radio" id="forget" name="bakecookie" onclick="forgetMe(this.form)" value="Forget Info" style="margin-left: 15px;" /><label for="forget"><MT_TRANS phrase="No"></label><br style="clear: both;" />
 
-<label for="text"><MT_TRANS phrase="Comments:"></label><br />
+<label for="text"><MT_TRANS phrase="Comments: "></label><br />
 <textarea tabindex="4" id="text" name="text" rows="10" cols="50"></textarea><br /><br />
 
 <input type="button" onclick="window.close()" value="&nbsp;<MT_TRANS phrase="Cancel">&nbsp;" />
@@ -595,7 +596,7 @@
 </body>
 </html>',
           'type' => 'comments',
-          'name' => 'Comment Listing Template'
+          'name' => '迴響清單模版'
         },
 
 {
@@ -613,9 +614,9 @@
 <title><$MTBlogName encode_xml="1"$></title>
 <link><$MTBlogURL$></link>
 <description><$MTBlogDescription encode_xml="1"$></description>
-<dc:language>en-us</dc:language>
+<dc:language>zh-tw</dc:language>
 <dc:creator></dc:creator>
-<dc:date><MTEntries lastn="1"><$MTEntryDate format="%Y-%m-%dT%H:%M:%S" language="en"$><$MTBlogTimezone$></MTEntries></dc:date>
+<dc:date><MTEntries lastn="1"><$MTEntryDate language="en" format="%Y-%m-%dT%H:%M:%S"$><$MTBlogTimezone$></MTEntries></dc:date>
 <admin:generatorAgent rdf:resource="http://www.movabletype.org/?v=<$MTVersion$>" />
 <MTBlogIfCCLicense>
 <cc:license rdf:resource="<$MTBlogCCLicenseURL$>" />
@@ -636,7 +637,7 @@
 <description><$MTEntryExcerpt encode_xml="1"$></description>
 <dc:subject><$MTEntryCategory encode_xml="1"$></dc:subject>
 <dc:creator><$MTEntryAuthor encode_xml="1"$></dc:creator>
-<dc:date><$MTEntryDate format="%Y-%m-%dT%H:%M:%S" language="en"$><$MTBlogTimezone$></dc:date>
+<dc:date><$MTEntryDate language="en" format="%Y-%m-%dT%H:%M:%S"$><$MTBlogTimezone$></dc:date>
 </item>
 </MTEntries>
 
@@ -644,7 +645,7 @@
           'outfile' => 'index.rdf',
           'rebuild_me' => '1',
           'type' => 'index',
-          'name' => 'RSS 1.0 Index'
+          'name' => 'RSS 1.0 索引'
         },
 
 {
@@ -687,15 +688,15 @@
 	.description {
 		font-family:palatino,  georgia, times new roman, serif;
 		color:#333;
-		font-size:small;
+		font-size:medium;
   		text-transform:none;	
 		}
 				
 	#content {
 		position:absolute;
 		background:#FFF;
+		left:225px;
 		margin-right:20px;
-		margin-left:225px;
 		margin-bottom:20px;
 		border:1px solid #FFF;
 		width: 70%;
@@ -720,7 +721,7 @@
 	.blogbody {
 		font-family:palatino, georgia, verdana, arial, sans-serif;
 		color:#333;
-		font-size:small;
+		font-size:medium;
 		font-weight:normal;
   		background:#FFF;
   		line-height:200%;
@@ -737,7 +738,7 @@
 
 	.title	{
 		font-family: palatino, georgia, times new roman, serif;
-		font-size: medium;
+		font-size: large;
 		color: #666;
 		}			
 
@@ -758,7 +759,7 @@
 		
 	.posted	{ 
 		font-family:verdana, arial, sans-serif; 
-		font-size: x-small; 
+		font-size: small; 
 		color: #000000; 
 		margin-bottom:25px;
 		}
@@ -767,7 +768,7 @@
 	.calendar {
 		font-family:verdana, arial, sans-serif;
 		color:#666;
-		font-size:x-small;
+		font-size:small;
 		font-weight:normal;
   		background:#FFF;
   		line-height:140%;
@@ -778,7 +779,7 @@
 	.calendarhead {	
 		font-family:palatino, georgia, times new roman, serif;
 		color:#666600;
-		font-size:small;
+		font-size:medium;
 		font-weight:normal;
   		padding:2px;
 		letter-spacing: .3em;
@@ -790,7 +791,7 @@
 	.side {
 		font-family:verdana, arial, sans-serif;
 		color:#333;
-		font-size:x-small;
+		font-size:small;
 		font-weight:normal;
   		background:#FFF;
   		line-height:140%;
@@ -800,7 +801,7 @@
 	.sidetitle {
 		font-family:palatino, georgia, times new roman, serif;
 		color:#666600;
-		font-size:small;
+		font-size:medium;
 		font-weight:normal;
   		padding:2px;
   		margin-top:30px;
@@ -811,7 +812,7 @@
 	
 	.syndicate {
 		font-family:verdana, arial, sans-serif;
-		font-size:xx-small;		
+		font-size:xsmall;		
   		line-height:140%;
   		padding:2px;
   		margin-top:15px;
@@ -821,7 +822,7 @@
 	.powered {
 		font-family:palatino, georgia, times new roman, serif;
 		color:#666;
-		font-size:x-small;		
+		font-size:small;		
 		line-height:140%;
 		text-transform:uppercase; 
 		padding:2px;
@@ -834,7 +835,7 @@
 	.comments-body {
 		font-family:palatino, georgia, verdana, arial, sans-serif;
 		color:#666;
-		font-size:small;
+		font-size:medium;
 		font-weight:normal;
   		background:#FFF;
   		line-height:140%;
@@ -846,7 +847,7 @@
 	.comments-post {
 		font-family:verdana, arial, sans-serif;
 		color:#666;
-		font-size:x-small;
+		font-size:small;
 		font-weight:normal;
   		background:#FFF;		
 		}	
@@ -855,7 +856,7 @@
 	.trackback-url {
 		font-family:palatino, georgia, verdana, arial, sans-serif;
 		color:#666;
-		font-size:small;
+		font-size:medium;
 		font-weight:normal;
   		background:#FFF;
   		line-height:140%;
@@ -867,7 +868,7 @@
 	.trackback-body {
 		font-family:palatino, georgia, verdana, arial, sans-serif;
 		color:#666;
-		font-size:small;
+		font-size:medium;
 		font-weight:normal;
   		background:#FFF;
   		line-height:140%;
@@ -879,7 +880,7 @@
 	.trackback-post {
 		font-family:verdana, arial, sans-serif;
 		color:#666;
-		font-size:x-small;
+		font-size:small;
 		font-weight:normal;
   		background:#FFF;		
 		}	
@@ -887,7 +888,7 @@
 		
 	.comments-head	{ 
 		font-family:palatino, georgia, verdana, arial, sans-serif; 
-		font-size:small; 
+		font-size:medium; 
 		color: #666; 
 		border-bottom:1px solid #999;
 		margin-top:20px;
@@ -913,7 +914,7 @@
           'outfile' => 'styles-site.css',
           'rebuild_me' => '1',
           'type' => 'index',
-          'name' => 'Stylesheet'
+          'name' => '樣式表'
         },
 
 {
@@ -1012,7 +1013,7 @@
 </html>
 ',
           'type' => 'archive',
-          'name' => 'Date-Based Archive'
+          'name' => '按時彙整'
         },
 
 {
@@ -1092,7 +1093,7 @@
 </html>
 ',
           'type' => 'category',
-          'name' => 'Category Archive'
+          'name' => '分類彙整'
         },
 
 {
@@ -1242,7 +1243,7 @@
 <MTComments>
 <div class="comments-body">
 <$MTCommentBody$>
-<span class="comments-post"><MT_TRANS phrase="Posted by:"> <$MTCommentAuthorLink spam_protect="1"$> <MT_TRANS phrase="at"> <$MTCommentDate$></span>
+<span class="comments-post"><MTIfNonEmpty tag="MTCommentAuthorLink"><MT_TRANS phrase="Posted by"> <$MTCommentAuthorLink spam_protect="1"$> <MT_TRANS phrase="at"><MTElse><MT_TRANS phrase="Posted at"></MTElse></MTIfNonEmpty> <$MTCommentDate$></span>
 </div>
 </MTComments>
 
@@ -1269,7 +1270,7 @@
 <MT_TRANS phrase="Remember personal info?"><br />
 <input type="radio" id="bakecookie" name="bakecookie" /><label for="bakecookie"><MT_TRANS phrase="Yes"></label><input type="radio" id="forget" name="bakecookie" onclick="forgetMe(this.form)" value="Forget Info" style="margin-left: 15px;" /><label for="forget"><MT_TRANS phrase="No"></label><br style="clear: both;" />
 
-<label for="text"><MT_TRANS phrase="Comments:"></label><br />
+<label for="text"><MT_TRANS phrase="Comments: "></label><br />
 <textarea tabindex="4" id="text" name="text" rows="10" cols="50"></textarea><br /><br />
 
 <input type="submit" name="preview" value="&nbsp;<MT_TRANS phrase="Preview">&nbsp;" />
@@ -1298,7 +1299,7 @@
 </html>
 ',
           'type' => 'individual',
-          'name' => 'Individual Entry Archive'
+          'name' => '單篇彙整'
         },
 
 {
@@ -1339,6 +1340,6 @@
 </html>',
           'rebuild_me' => '0',
           'type' => 'pings',
-          'name' => 'TrackBack Listing Template'
+          'name' => '引用清單模版'
         },
 ]
diff -durN MT-2.661-full-lib/lib/MT.pm MT/lib/MT.pm
--- MT-2.661-full-lib/lib/MT.pm	Fri Jan 16 04:36:14 2004
+++ MT/lib/MT.pm	Sun Jan 25 16:39:13 2004
@@ -744,7 +744,8 @@
     my $mt = shift;
     my($str, $filters, @extra) = @_;
     for my $filter (@$filters) {
-        next unless $Text_filters{$filter};
+        next unless exists $Text_filters{$filter}
+                and $Text_filters{$filter}{on_format};
         $str = $Text_filters{$filter}{on_format}->($str, @extra);
     }
     $str;
diff -durN MT-2.661-full-lib/mt-load.cgi MT/mt-load.cgi
--- MT-2.661-full-lib/mt-load.cgi	Fri Feb 14 08:17:28 2003
+++ MT/mt-load.cgi	Wed Nov 12 19:48:36 2003
@@ -19,8 +19,8 @@
 
 local $| = 1;
 
-print "Content-Type: text/html\n\n";
-print "<pre>\n\n";
+print "Content-Type: text/html; charset=utf-8\n\n";
+print "<html><body><pre>\n\n";
 
 use File::Spec;
 
@@ -28,11 +28,11 @@
 
 my $tmpl_list;
 eval { $tmpl_list = require 'MT/default-templates.pl' };
-die "Can't find default template list; where is 'default-templates.pl'?\n" .
-    "Error: $@\n"
+die "找不到預設模版清單; 'default-templates.pl' 在哪裡?\n" .
+    "錯誤訊息 $@\n"
     if $@ || !$tmpl_list || ref($tmpl_list) ne 'ARRAY' || !@$tmpl_list;
 
-print "Loading initial data into system...\n";
+print "載入初始系統資料中...\n";
 
 require MT;
 my $mt = MT->new( Config => $MT_DIR . 'mt.cfg', Directory => $MT_DIR )
@@ -42,12 +42,12 @@
     my $type = $1;
     my $dbh = MT::Object->driver->{dbh};
     my $schema = File::Spec->catfile($MT_DIR, 'schemas', $type . '.dump');
-    open FH, $schema or die "Can't open schema file '$schema': $!";
+    open FH, $schema or die "無法開啟規格檔 '$schema': $!";
     my $ddl;
     { local $/; $ddl = <FH> }
     close FH;
     my @stmts = split /;/, $ddl;
-    print "Loading database schema...\n\n";
+    print "載入資料庫規格...\n\n";
     for my $stmt (@stmts) {
         $stmt =~ s!^\s*!!;
         $stmt =~ s!\s*$!!;
@@ -65,19 +65,19 @@
 if (MT::Author->count || MT::Blog->count) {
     print <<MSG, security_notice();
 
-SYSTEM ALREADY INITIALIZED
+系統已設