Index: modules/php/php.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/php/php.install,v
retrieving revision 1.2
diff -u -r1.2 php.install
--- modules/php/php.install	14 Apr 2008 17:48:41 -0000	1.2
+++ modules/php/php.install	1 Sep 2008 19:26:35 -0000
@@ -17,6 +17,9 @@
     // Enable the PHP evaluator filter.
     db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, 'php', 0, 0)", $format);
 
+    // Write the filter id to variable table, to facilitate removal later.
+    variable_set('php_code_filter_id', $format);
+
     drupal_set_message(t('A !php-code input format has been created.', array('!php-code' => l('PHP code', 'admin/settings/filters/' . $format))));
   }
 }
@@ -26,4 +29,49 @@
  */
 function php_disable() {
   drupal_set_message(t('The PHP module has been disabled. Please note that any existing content that was using the PHP filter will now be visible in plain text. This might pose a security risk by exposing sensitive information, if any, used in the PHP code.'));
+
+  // Wipe out any pre-existing filters on the /admin/content/node page,
+  // then set "...where Status == Published".
+  $_SESSION['node_overview_filter'] = array(0 => array('status','status-1'));
+  drupal_set_message(t('The PHP module has been disabled. Please note that any existing content that was published using the PHP filter will now be <em>visible in plain text</em>. This might pose a security risk if your PHP code contained sensitive information in it, so you should '. l('check your published content', 'admin/content/node') .' carefully.'));
 }
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function php_uninstall() {
+  // Get default input format.
+  $default = variable_get('filter_default_format', 1);
+
+  // Get list of all formats.
+  $formats = filter_formats();
+
+  $phpfilter = variable_get('php_code_filter_id', 1);
+
+  foreach($formats as $format) {
+    if(($default == $format->format) && ($format->format  == $phpfilter)) // Default input format is the one that we are uninstalling!
+    {
+      $conflict = TRUE;
+    }
+  }
+
+  if($conflict)
+  {
+    variable_set('filter_default_format', 1); // Set default input format to filtered HTML if PHP code is set as the input.
+    drupal_set_message(t('The default input format has been reset to Filtered HTML.'));
+  }
+
+  // Remove PHP filter format.
+  db_query("DELETE FROM {filter_formats} WHERE format = %d", $phpfilter);
+  db_query("DELETE FROM {filters} WHERE format = %d", $phpfilter);
+
+  $default = variable_get('filter_default_format', 1);
+  // Replace existing instances of the deleted format with the default format.
+  db_query("UPDATE {node_revisions} SET format = %d WHERE format = %d", $default, $phpfilter);
+  db_query("UPDATE {comments} SET format = %d WHERE format = %d", $default, $phpfilter);
+  db_query("UPDATE {boxes} SET format = %d WHERE format = %d", $default, $phpfilter);
+
+  cache_clear_all($phpfilter .':', 'cache_filter', TRUE);
+  variable_del('php_code_filter_id');
+  drupal_set_message(t('The PHP module has been uninstalled successfully.'));
+}
\ No newline at end of file