Index: wp-includes/functions.php
===================================================================
--- wp-includes/functions.php	(revision 4776)
+++ wp-includes/functions.php	(working copy)
@@ -920,22 +920,39 @@
 	return wp_specialchars(add_query_arg('_wpnonce', wp_create_nonce($action), $actionurl));
 }
 
-function wp_nonce_field($action = -1) {
-	echo '<input type="hidden" name="_wpnonce" value="' . wp_create_nonce($action) . '" />';
+function wp_nonce_field($action = -1, $return = FALSE) {
+	$nonce = '<input type="hidden" name="_wpnonce" value="' . wp_create_nonce($action) . '" />';
+    
+    if($return) {
+        return $nonce;
+    } else {
+        echo $nonce;
+    }
 	wp_referer_field();
 }
 
-function wp_referer_field() {
+function wp_referer_field($return = FALSE) {
 	$ref = attribute_escape($_SERVER['REQUEST_URI']);
-	echo '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />';
+	$ret_val = '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />';
 	if ( wp_get_original_referer() ) {
 		$original_ref = attribute_escape(stripslashes(wp_get_original_referer()));
-		echo '<input type="hidden" name="_wp_original_http_referer" value="'. $original_ref . '" />';
+		$ret_val .= '<input type="hidden" name="_wp_original_http_referer" value="'. $original_ref . '" />';
 	}
+    if($return) {
+        return $ret_val;
+    } else {
+        echo $ret_val;
+    }
+    
 }
 
-function wp_original_referer_field() {
-	echo '<input type="hidden" name="_wp_original_http_referer" value="' . attribute_escape(stripslashes($_SERVER['REQUEST_URI'])) . '" />';
+function wp_original_referer_field($return = FALSE) {
+    $ret_val = '<input type="hidden" name="_wp_original_http_referer" value="' . attribute_escape(stripslashes($_SERVER['REQUEST_URI'])) . '" />';
+    if($return) {
+        return $ret_val;
+    } else {
+        echo $ret_val;
+    }
 }
 
 function wp_get_referer() {
Index: wp-admin/admin-functions.php
===================================================================
--- wp-admin/admin-functions.php	(revision 4776)
+++ wp-admin/admin-functions.php	(working copy)
@@ -2125,99 +2125,86 @@
 	return apply_filters( 'wp_generate_attachment_metadata', $metadata );
 }
 
-function wp_create_thumbnail( $file, $max_side, $effect = '' ) {
+function wp_create_thumbnail($file, $w = 150, $h = null, $effect = '') {
+    // 1 = GIF, 2 = JPEG, 3 = PNG
+    if (file_exists($file)) {
+        $type = getimagesize($file);
 
-		// 1 = GIF, 2 = JPEG, 3 = PNG
+        // if the associated function doesn't exist - then it's not
+        // handle. duh. i hope.
 
-	if ( file_exists( $file ) ) {
-		$type = getimagesize( $file );
+        if (!function_exists('imagegif') && $type[2] == 1) {
+            return $error = array('error' =>__('Filetype: gif not supported. Thumbnail not created.'));
+        }
+        elseif (!function_exists('imagejpeg') && $type[2] == 2) {
+            return $error = array('error' =>__('Filetype: jpg not supported. Thumbnail not created.'));
+        }
+        elseif (!function_exists('imagepng') && $type[2] == 3) {
+            return $error = array('error' =>__('Filetype: png not supported. Thumbnail not created.'));
+        } else {
+            // create the initial copy from the original file
+            if ($type[2] == 1) {
+                $image = imagecreatefromgif($file);
+            }
+            elseif ($type[2] == 2) {
+                $image = imagecreatefromjpeg($file);
+            }
+            elseif ($type[2] == 3) {
+                $image = imagecreatefrompng($file);
+            }
 
-		// if the associated function doesn't exist - then it's not
-		// handle. duh. i hope.
+            if (function_exists('imageantialias')) { imageantialias($image, TRUE);}
+            $image_attr = getimagesize($file);
+            $image_width  = $image_attr[0];
+            $image_height = $image_attr[1];
+           
+            // either set the max width and/or max height directly, 
+            // proportional or don't do a thing and raise an error
+            if( isset($w) && is_int($w) && isset($h) && is_int($h) ) {
+                $image_new_width  = $w;
+                $image_new_height = $h;
+            } elseif ( isset($w) && is_int($w) ) {
+                $image_new_width  = $w;
+                $image_ratio      = $image_width / $image_new_width;
+                $image_new_height = $image_height / $image_ratio;
+            } elseif ( isset($h) && is_int($h) ) {
+                $image_new_height  = $h;
+                $image_ratio       = $image_height / $image_new_height;
+                $image_new_width   = $image_width / $image_ratio;
+            } else {
+               return $error = array('error' =>__("No thumbnail dimensions specified"));
+            }
+            
+            $thumbnail = imagecreatetruecolor($image_new_width, $image_new_height);
+            @ imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]);
 
-		if (!function_exists( 'imagegif' ) && $type[2] == 1 ) {
-			$error = __( 'Filetype not supported. Thumbnail not created.' );
-		}
-		elseif (!function_exists( 'imagejpeg' ) && $type[2] == 2 ) {
-			$error = __( 'Filetype not supported. Thumbnail not created.' );
-		}
-		elseif (!function_exists( 'imagepng' ) && $type[2] == 3 ) {
-			$error = __( 'Filetype not supported. Thumbnail not created.' );
-		} else {
+            // If no filters change the filename, we'll do a default transformation.
+            $thumb = preg_replace('!(\.[^.]+)?$!', __('.thumbnail').'$1', basename($file), 1);
 
-			// create the initial copy from the original file
-			if ( $type[2] == 1 ) {
-				$image = imagecreatefromgif( $file );
-			}
-			elseif ( $type[2] == 2 ) {
-				$image = imagecreatefromjpeg( $file );
-			}
-			elseif ( $type[2] == 3 ) {
-				$image = imagecreatefrompng( $file );
-			}
-
-			if ( function_exists( 'imageantialias' ))
-				imageantialias( $image, TRUE );
-
-			$image_attr = getimagesize( $file );
-
-			// figure out the longest side
-
-			if ( $image_attr[0] > $image_attr[1] ) {
-				$image_width = $image_attr[0];
-				$image_height = $image_attr[1];
-				$image_new_width = $max_side;
-
-				$image_ratio = $image_width / $image_new_width;
-				$image_new_height = $image_height / $image_ratio;
-				//width is > height
-			} else {
-				$image_width = $image_attr[0];
-				$image_height = $image_attr[1];
-				$image_new_height = $max_side;
-
-				$image_ratio = $image_height / $image_new_height;
-				$image_new_width = $image_width / $image_ratio;
-				//height > width
-			}
-
-			$thumbnail = imagecreatetruecolor( $image_new_width, $image_new_height);
-			@ imagecopyresampled( $thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1] );
-
-			// If no filters change the filename, we'll do a default transformation.
-			if ( basename( $file ) == $thumb = apply_filters( 'thumbnail_filename', basename( $file ) ) )
-				$thumb = preg_replace( '!(\.[^.]+)?$!', __( '.thumbnail' ).'$1', basename( $file ), 1 );
-
-			$thumbpath = str_replace( basename( $file ), $thumb, $file );
-
-			// move the thumbnail to it's final destination
-			if ( $type[2] == 1 ) {
-				if (!imagegif( $thumbnail, $thumbpath ) ) {
-					$error = __( "Thumbnail path invalid" );
-				}
-			}
-			elseif ( $type[2] == 2 ) {
-				if (!imagejpeg( $thumbnail, $thumbpath ) ) {
-					$error = __( "Thumbnail path invalid" );
-				}
-			}
-			elseif ( $type[2] == 3 ) {
-				if (!imagepng( $thumbnail, $thumbpath ) ) {
-					$error = __( "Thumbnail path invalid" );
-				}
-			}
-
-		}
-	} else {
-		$error = __( 'File not found' );
-	}
-
-	if (!empty ( $error ) ) {
-		return $error;
-	} else {
-		apply_filters( 'wp_create_thumbnail', $thumbpath );
-		return $thumbpath;
-	}
+            $thumbpath = str_replace(basename($file), $thumb, $file);
+           
+            // move the thumbnail to it's final destination
+            if ($type[2] == 1) {
+                if (!imagegif($thumbnail, $thumbpath)) {
+                    return $error = array('error'=>__("Thumbnail path invalid"));
+                }
+            }
+            elseif ($type[2] == 2) {
+                if (!imagejpeg($thumbnail, $thumbpath)) {
+                    return $error = array('error'=>__("Thumbnail path invalid"));
+                }
+            }
+            elseif ($type[2] == 3) {
+                if (!imagepng($thumbnail, $thumbpath)) {
+                    return $error = array('error'=>__("Thumbnail path invalid"));
+                }
+            }
+        }
+    } else {
+        return $error = array('error'=>__('File not found'));
+    }
+    apply_filters( 'wp_create_thumbnail', $thumbpath );
+    return $thumbpath;
 }
 
 ?>

