[33mdiff --git includes/bootstrap.inc includes/bootstrap.inc[m
[33mindex d58b4ea..368b48e 100644[m
[33m--- includes/bootstrap.inc[m
[33m+++ includes/bootstrap.inc[m
[36m@@ -1308,9 +1308,12 @@[m [mfunction watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NO[m
 [m
   static $in_error_state = FALSE;[m
 [m
[31m-  // It is possible that the error handling will itself trigger an error. In that case, we could[m
[31m-  // end up in an infinite loop. To avoid that, we implement a simple static semaphore.[m
[31m-  if (!$in_error_state) {[m
[1;32m+[m[1;32m  // It is possible that the error handling will itself trigger an error. In[m
[1;32m+[m[1;32m  // that case, we could end up in an infinite loop. To avoid that, we[m
[1;32m+[m[1;32m  // implement a simple static semaphore.  In addition, watchdog may be called[m
[1;32m+[m[1;32m  // by the error or exception handles very early in bootstrap before module.inc[m
[1;32m+[m[1;32m  // has been included, so we must check for it.[m
[1;32m+[m[1;32m  if (!$in_error_state && function_exists('module_implements')) {[m
     $in_error_state = TRUE;[m
 [m
     // Prepare the fields to be logged[m
[33mdiff --git includes/errors.inc includes/errors.inc[m
[33mindex 42bd3a1..f1a9891 100644[m
[33m--- includes/errors.inc[m
[33m+++ includes/errors.inc[m
[36m@@ -125,6 +125,30 @@[m [mfunction _drupal_decode_exception($exception) {[m
   );[m
 }[m
 [m
[1;32m+[m
[1;32m+[m[1;32m/**[m
[1;32m+[m[1;32m * Minimal substitute for t() when it is not available..[m
[1;32m+[m[1;32m */[m
[1;32m+[m[1;32mfunction _drupal_error_t($string, $args = array()) {[m
[1;32m+[m[1;32m  // Transform arguments before inserting them[m
[1;32m+[m[1;32m  foreach ($args as $key => $value) {[m
[1;32m+[m[1;32m    switch ($key[0]) {[m
[1;32m+[m[1;32m      // Escaped only[m
[1;32m+[m[1;32m      case '@':[m
[1;32m+[m[1;32m        $args[$key] = check_plain($value);[m
[1;32m+[m[1;32m        break;[m
[1;32m+[m[1;32m      // Escaped and placeholder[m
[1;32m+[m[1;32m      case '%':[m
[1;32m+[m[1;32m      default:[m
[1;32m+[m[1;32m        $args[$key] = '<em>' . check_plain($value) . '</em>';[m
[1;32m+[m[1;32m        break;[m
[1;32m+[m[1;32m      // Pass-through[m
[1;32m+[m[1;32m      case '!':[m
[1;32m+[m[1;32m    }[m
[1;32m+[m[1;32m  }[m
[1;32m+[m[1;32m  return strtr((!empty($locale_strings[$string]) ? $locale_strings[$string] : $string), $args);[m
[1;32m+[m[1;32m}[m
[1;32m+[m
 /**[m
  * Log a PHP error or exception, display an error page in fatal cases.[m
  *[m
[36m@@ -143,6 +167,12 @@[m [mfunction _drupal_log_error($error, $fatal = FALSE) {[m
     }[m
     drupal_maintenance_theme();[m
   }[m
[1;32m+[m[1;32m  if (function_exists('t')) {[m
[1;32m+[m[1;32m    $t = 't';[m
[1;32m+[m[1;32m  }[m
[1;32m+[m[1;32m  else {[m
[1;32m+[m[1;32m    $t = '_drupal_error_t';[m
[1;32m+[m[1;32m  }[m
 [m
   // When running inside the testing framework, we relay the errors[m
   // to the tested site by the way of HTTP headers.[m
[36m@@ -178,7 +208,7 @@[m [mfunction _drupal_log_error($error, $fatal = FALSE) {[m
   if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {[m
     if ($fatal) {[m
       // When called from JavaScript, simply output the error message.[m
[31m-      print t('%type: %message in %function (line %line of %file).', $error);[m
[1;32m+[m[1;32m      print $t('%type: %message in %function (line %line of %file).', $error);[m
       exit;[m
     }[m
   }[m
[36m@@ -197,14 +227,14 @@[m [mfunction _drupal_log_error($error, $fatal = FALSE) {[m
         $class = 'status';[m
       }[m
 [m
[31m-      drupal_set_message(t('%type: %message in %function (line %line of %file).', $error), $class);[m
[1;32m+[m[1;32m      drupal_set_message($t('%type: %message in %function (line %line of %file).', $error), $class);[m
     }[m
 [m
     if ($fatal) {[m
       drupal_set_title(t('Error'));[m
       // We fallback to a maintenance page at this point, because the page generation[m
       // itself can generate errors.[m
[31m-      print theme('maintenance_page', array('content' => t('The website encountered an unexpected error. Please try again later.')));[m
[1;32m+[m[1;32m      print theme('maintenance_page', array('content' => $t('The website encountered an unexpected error. Please try again later.')));[m
       exit;[m
     }[m
   }[m
[33mdiff --git modules/system/image.gd.inc modules/system/image.gd.inc[m
[33mindex ebfdcf2..75c53ab 100644[m
[33m--- modules/system/image.gd.inc[m
[33m+++ modules/system/image.gd.inc[m
[36m@@ -244,7 +244,7 @@[m [mfunction image_gd_load(stdClass $image) {[m
  * @param $image[m
  *   An image object.[m
  * @param $destination[m
[31m- *   A string file path where the image should be saved.[m
[1;32m+[m[1;32m *   A string file URI where the image should be saved.[m
  * @param $extension[m
  *   A string containing one of the following extensions: gif, jpg, jpeg, png.[m
  * @return[m
[36m@@ -253,9 +253,18 @@[m [mfunction image_gd_load(stdClass $image) {[m
  * @see image_save()[m
  */[m
 function image_gd_save(stdClass $image, $destination) {[m
[31m-  // Convert URI to a normal path because PHP apparently has some gaps in stream wrapper support.[m
[1;32m+[m[1;32m  $tempnam = '';[m
   if ($wrapper = file_stream_wrapper_get_instance_by_uri($destination)) {[m
[31m-    $destination = $wrapper->realpath();[m
[1;32m+[m[1;32m    $parents = class_parents($wrapper);[m
[1;32m+[m[1;32m    if (empty($parents['DrupalLocalStreamWrapper'])) {[m
[1;32m+[m[1;32m      // Use a temp file as an intermediate step for a remote URI.[m
[1;32m+[m[1;32m      $tempwrapper = file_stream_wrapper_get_instance_by_scheme('temporary');[m
[1;32m+[m[1;32m      $tempnam = tempnam($tempwrapper->getDirectoryPath(), 'gd_');[m
[1;32m+[m[1;32m    }[m
[1;32m+[m[1;32m    else {[m
[1;32m+[m[1;32m      // Convert URI to a normal path because PHP apparently has some gaps in stream wrapper support.[m
[1;32m+[m[1;32m      $destination = $wrapper->realpath();[m
[1;32m+[m[1;32m    }[m
   }[m
 [m
   $extension = str_replace('jpg', 'jpeg', $image->info['extension']);[m
[36m@@ -272,6 +281,13 @@[m [mfunction image_gd_save(stdClass $image, $destination) {[m
       imagealphablending($image->resource, FALSE);[m
       imagesavealpha($image->resource, TRUE);[m
     }[m
[1;32m+[m[1;32m    if ($tempnam) {[m
[1;32m+[m[1;32m      // Use a temp file as an intermediate step.[m
[1;32m+[m[1;32m      if ($function($image->resource, $tempnam)) {[m
[1;32m+[m[1;32m        return (bool) file_unmanaged_move($tempnam, $destination, FILE_EXISTS_REPLACE);[m
[1;32m+[m[1;32m      }[m
[1;32m+[m[1;32m      return FALSE;[m
[1;32m+[m[1;32m    }[m
     return $function($image->resource, $destination);[m
   }[m
 }[m
