Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.599
diff -u -p -r1.599 theme.inc
--- includes/theme.inc	7 Jun 2010 06:38:09 -0000	1.599
+++ includes/theme.inc	15 Jun 2010 22:07:10 -0000
@@ -866,6 +866,13 @@ function theme($hook, $variables = array
     if (function_exists($info['function'])) {
       $output = $info['function']($variables);
     }
+    else {
+      // If a function implementation is registered but doesn't exist, it's
+      // either due to a bug in a module or theme, or module or theme code has
+      // been updated without the theme registry being rebuilt.
+      watchdog('theme', 'Theme function "@function" not found. It may help to rebuild the theme registry by clicking "Clear all caches" on the admin/config/development/performance page or by directly emptying the {cache} table in the database. If the problem persists after doing so, there is a bug in one of the modules or themes used by this website.', array('@function' => $info['function']), WATCHDOG_WARNING);
+      $output = '';
+    }
   }
   else {
     // Default render function and extension.
@@ -1214,10 +1221,27 @@ function theme_get_setting($setting_name
  *   The output generated by the template.
  */
 function theme_render_template($template_file, $variables) {
-  extract($variables, EXTR_SKIP);               // Extract the variables to a local namespace
-  ob_start();                                   // Start output buffering
-  include DRUPAL_ROOT . '/' . $template_file;   // Include the template file
-  return ob_get_clean();                        // End buffering and return its contents
+  // Extract the variables to a local namespace, setup an output buffer,
+  // include the template file which will output its markup to the buffer, and
+  // then transfer the buffer contents to a variable to be returned.
+  extract($variables, EXTR_SKIP);
+  ob_start();
+  $include_status = include DRUPAL_ROOT . '/' . $template_file;
+  $output = ob_get_clean();
+
+  // If the template file doesn't exist, PHP will have emitted a warning during
+  // the "include" statement above. However, as that warning contains only
+  // information provided by PHP, we also want to log a theme system message. We
+  // could have prevented the PHP warning by first calling file_exists(), but on
+  // high-traffic websites using an opcode cache, that would cause undesired
+  // extraneous disk activity. We also could have suppressed the PHP warning by
+  // calling "@include", but that would also undesirably suppress PHP errors
+  // within the template. We therefore accept that a PHP warning and this
+  // message both get logged when a template file doesn't exist.
+  if ($include_status === FALSE) {
+    watchdog('theme', 'Theme template "@template" not found. It may help to rebuild the theme registry by clicking "Clear all caches" on the admin/config/development/performance page or by directly emptying the {cache} table in the database. If the problem persists after doing so, there is a bug in one of the modules or themes used by this website.', array('@template' => $template_file), WATCHDOG_WARNING);
+  }
+  return $output;
 }
 
 /**
