Index: modules/php/php.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/php/php.install,v
retrieving revision 1.5
diff -u -p -r1.5 php.install
--- modules/php/php.install	13 Mar 2009 21:35:02 -0000	1.5
+++ modules/php/php.install	26 Apr 2009 07:41:24 -0000
@@ -29,6 +29,9 @@ function php_install() {
       ))
       ->execute();
 
+    // 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 text format has been created.', array('!php-code' => l('PHP code', 'admin/settings/filter/' . $format))));
   }
 }
@@ -38,4 +41,52 @@ function php_install() {
  */
 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);
+
+  $conflict = false;
+  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_format} WHERE format = %d", $phpfilter);
+  db_query("DELETE FROM {filter} WHERE format = %d", $phpfilter);
+
+  $default = variable_get('filter_default_format', 1);
+  // Replace existing instances of the deleted format with the default format and hide the affected node.
+  db_query("UPDATE {node} n JOIN {node_revision} nr ON n.nid = nr.nid SET n.status = 0 WHERE nr.format = %d", $phpfilter);
+  db_query("UPDATE {node_revision} SET format = %d WHERE format = %d", $default, $phpfilter);
+  db_query("UPDATE {comment} SET format = %d WHERE format = %d", $default, $phpfilter);
+  db_query("UPDATE {box} 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.'));
 }
