Index: wysiwyg.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/wysiwyg.admin.inc,v
retrieving revision 1.2
diff -u -p -r1.2 wysiwyg.admin.inc
--- wysiwyg.admin.inc	15 Oct 2008 14:24:36 -0000	1.2
+++ wysiwyg.admin.inc	28 Oct 2008 19:42:02 -0000
@@ -11,7 +11,7 @@
  *
  * @todo Move into hook_menu(), resp. FAPI functions.
  */
-function wysiwyg_admin($arg = '', $name = '') {
+function wysiwyg_admin($arg = '', $format = '') {
   switch ($arg) {
     case 'add':
       $breadcrumb[] = l(t('Home'), NULL);
@@ -24,14 +24,13 @@ function wysiwyg_admin($arg = '', $name 
       return drupal_get_form('wysiwyg_profile_form', $profile);
 
     case 'edit':
-      drupal_set_title(t('Edit Wysiwyg Editor profile'));
-      return drupal_get_form('wysiwyg_profile_form', wysiwyg_load_profile($name));
+      return drupal_get_form('wysiwyg_profile_form', wysiwyg_load_profile($format));
 
     case 'delete':
-      return drupal_get_form('wysiwyg_profile_delete_confirm', $name);
+      return drupal_get_form('wysiwyg_profile_delete_confirm', $format);
 
     default:
-      return wysiwyg_profile_overview();
+      return drupal_get_form('wysiwyg_profile_overview');
   }
 }
 
@@ -42,12 +41,13 @@ function wysiwyg_profile_form($form_stat
   // Merge in defaults.
   settype($profile, 'array');
   $profile += array(
-    'name' => NULL,
-    'rids' => array(),
-    'settings' => array(),
+    'format' => 0,
+    'editor' => '',
   );
+  if (empty($profile['settings'])) {
+    $profile['settings'] = array();
+  }
   $profile['settings'] += array(
-    'editor' => NULL,
     'default' => TRUE,
     'user_choose' => FALSE,
     'show_toggle' => TRUE,
@@ -74,15 +74,13 @@ function wysiwyg_profile_form($form_stat
   );
   settype($profile, 'object');
 
-  $form = array();
+  $formats = filter_formats();
+  drupal_set_title(t('%format Wysiwyg profile', array('%format' => $formats[$profile->format]->name)));
 
-  if (arg(4) == 'add') {
-    $submit_label = t('Create profile');
-  }
-  else {
-    $form['old_name'] = array('#type' => 'hidden', '#value' => $profile->name);
-    $submit_label = t('Update profile');
-  }
+  $form = array();
+  $form['format'] = array('#type' => 'value', '#value' => $profile->format);
+  $form['input_format'] = array('#type' => 'value', '#value' => $formats[$profile->format]->name);
+  $form['editor'] = array('#type' => 'value', '#value' => $profile->editor);
 
   $form['basic'] = array(
     '#type' => 'fieldset',
@@ -91,40 +89,6 @@ function wysiwyg_profile_form($form_stat
     '#collapsed' => TRUE,
   );
 
-  $form['basic']['name'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Profile name'),
-    '#default_value' => $profile->name,
-    '#size' => 40,
-    '#maxlength' => 128,
-    '#description' => t('Enter a name for this profile. This name is only visible within the Wysiwyg Editor administration page.'),
-    '#required' => TRUE,
-  );
-
-  $form['basic']['rids'] = array(
-    '#type' => 'checkboxes',
-    '#title' => t('Roles allowed to use this profile'),
-    '#default_value' => array_keys($profile->rids),
-    '#options' => user_roles(FALSE, 'access wysiwyg editor'),
-    '#description' => t('Only roles with the %access permission will be shown here.', array('%access' => 'access wysiwyg editor')),
-    '#required' => TRUE,
-  );
-
-  $editors = wysiwyg_get_all_editors();
-  $options = array();
-  foreach ($editors as $name => $properties) {
-    if ($properties['installed']) {
-      $options[$name] = $properties['title'];
-    }
-  }
-  $form['basic']['editor'] = array(
-    '#type' => 'select',
-    '#title' => t('Editor'),
-    '#default_value' => $profile->settings['editor'],
-    '#options' => $options,
-    '#description' => t('Choose an editor to use for this profile.'),
-  );
-
   $form['basic']['default'] = array(
     '#type' => 'checkbox',
     '#title' => t('Enabled by default'),
@@ -138,15 +102,15 @@ function wysiwyg_profile_form($form_stat
     '#title' => t('Allow users to choose default'),
     '#default_value' => $profile->settings['user_choose'],
     '#return_value' => 1,
-    '#description' => t('If allowed, users will be able to choose their own Wysiwyg Editor default state in their user account settings.'),
+    '#description' => t('If allowed, users will be able to choose their own editor default state in their user account settings.'),
   );
 
   $form['basic']['show_toggle'] = array(
     '#type' => 'checkbox',
-    '#title' => t('Show %editor toggle link', array('%editor' => t('enable/disable rich text'))),
+    '#title' => t('Show <em>enable/disable rich text</em> toggle link'),
     '#default_value' => $profile->settings['show_toggle'],
     '#return_value' => 1,
-    '#description' => t('Whether or not to show the %editor toggle link below a textarea. If disabled, the user setting or global default is used (see above).', array('%editor' => t('enable/disable rich text'))),
+    '#description' => t('Whether or not to show the <em>enable/disable rich text</em> toggle link below a textarea. If disabled, the user setting or global default is used (see above).'),
   );
 
   $form['basic']['theme'] = array(
@@ -159,7 +123,7 @@ function wysiwyg_profile_form($form_stat
     '#title' => t('Language'),
     '#default_value' => $profile->settings['language'],
     '#options' => drupal_map_assoc(array('ar', 'ca', 'cs', 'cy', 'da', 'de', 'el', 'en', 'es', 'fa', 'fi', 'fr', 'fr_ca', 'he', 'hu', 'is', 'it', 'ja', 'ko', 'nb', 'nl', 'nn', 'pl', 'pt', 'pt_br', 'ru', 'ru_KOI8-R', 'ru_UTF-8', 'si', 'sk', 'sv', 'th', 'zh_cn', 'zh_tw', 'zh_tw_utf8')),
-    '#description' => t('The language for the Wysiwyg Editor interface. Language codes are based on the <a href="http://www.loc.gov/standards/iso639-2/englangn.html">ISO-639-2</a> format.'),
+    '#description' => t('The language to use for the editor interface. Language codes are based on the <a href="http://www.loc.gov/standards/iso639-2/englangn.html">ISO-639-2</a> format.'),
   );
 
   $form['buttons'] = array(
@@ -171,7 +135,7 @@ function wysiwyg_profile_form($form_stat
     '#theme' => 'wysiwyg_admin_button_table',
   );
 
-  $plugins = wysiwyg_get_plugins($profile->settings['editor']);
+  $plugins = wysiwyg_get_plugins($profile->editor);
   // Generate the button list.
   foreach ($plugins as $name => $meta) {
     if (isset($meta['buttons']) && is_array($meta['buttons'])) {
@@ -343,7 +307,7 @@ function wysiwyg_profile_form($form_stat
 
   $form['submit'] = array(
     '#type' => 'submit',
-    '#value' => $submit_label,
+    '#value' => t('Save'),
   );
 
   return $form;
@@ -355,40 +319,29 @@ function wysiwyg_profile_form($form_stat
  * @see wysiwyg_profile_form()
  */
 function wysiwyg_profile_form_submit($form, &$form_state) {
-  // Count enabled plugins for this profile.
-  $plugin_count = 0;
-  foreach ($form_state['values']['buttons'] as $plugin => $buttons) {
-    $form_state['values']['buttons'][$plugin] = array_filter($form_state['values']['buttons'][$plugin]);
-    $plugin_count += count($form_state['values']['buttons'][$plugin]);
-  }
-  // Store only enabled buttons.
-  $form_state['values']['buttons'] = array_filter($form_state['values']['buttons']);
-
-  // Filter enabled roles for this profile.
-  $form_state['values']['rids'] = array_filter($form_state['values']['rids']);
-
-  // Delete existing profile(s) with the current profile name.
-  if (!empty($form_state['values']['old_name'])) {
-    db_query("DELETE FROM {wysiwyg_profile} WHERE name = '%s' OR name = '%s'", $form_state['values']['name'], $form_state['values']['old_name']);
-    db_query("DELETE FROM {wysiwyg_role} WHERE name = '%s' OR name = '%s'", $form_state['values']['name'], $form_state['values']['old_name']);
+  if (isset($form_state['values']['buttons'])) {
+    // Store only enabled buttons for each plugin.
+    foreach ($form_state['values']['buttons'] as $plugin => $buttons) {
+      $form_state['values']['buttons'][$plugin] = array_filter($form_state['values']['buttons'][$plugin]);
+    }
+    // Store only enabled plugins.
+    $form_state['values']['buttons'] = array_filter($form_state['values']['buttons']);
   }
+  // Remove input format name.
+  $format = $form_state['values']['format'];
+  $input_format = $form_state['values']['input_format'];
+  $editor = $form_state['values']['editor'];
+  unset($form_state['values']['format'], $form_state['values']['input_format'], $form_state['values']['editor']);
 
   // Remove FAPI values.
   // @see system_settings_form_submit()
   unset($form_state['values']['submit'], $form_state['values']['form_id'], $form_state['values']['op'], $form_state['values']['form_token']);
 
   // Insert new profile data.
-  db_query("INSERT INTO {wysiwyg_profile} (name, settings, plugin_count) VALUES ('%s', '%s', %d)", $form_state['values']['name'], serialize($form_state['values']), $plugin_count);
-  foreach ($form_state['values']['rids'] as $rid => $value) {
-    db_query("INSERT INTO {wysiwyg_role} (name, rid) VALUES ('%s', %d)", $form_state['values']['name'], $rid);
-  }
+  db_query("REPLACE INTO {wysiwyg} (format, editor, settings) VALUES (%d, '%s', '%s')", $format, $editor, serialize($form_state['values']));
+
+  drupal_set_message(t('Wysiwyg profile for %format has been saved.', array('%format' => $input_format)));
 
-  if (isset($form_state['values']['old_name'])) {
-    drupal_set_message(t('Wysiwyg profile %name has been updated.', array('%name' => $form_state['values']['name'])));
-  }
-  else {
-    drupal_set_message(t('Wysiwyg profile %name has been created.', array('%name' => $form_state['values']['name'])));
-  }
   drupal_goto('admin/settings/wysiwyg/profile');
 }
 
@@ -429,7 +382,7 @@ function theme_wysiwyg_admin_button_tabl
  * Display overview of setup Wysiwyg Editor profiles; menu callback.
  */
 function wysiwyg_profile_overview() {
-  $output = '';
+  $form = array();
   $usable = TRUE;
 
   // Check which wysiwyg editors are installed.
@@ -456,37 +409,82 @@ function wysiwyg_profile_overview() {
     $usable = FALSE;
   }
 
-  // Check if at least one role is granted access to Wysiwyg Editor.
-  $access_check = user_roles(FALSE, 'access wysiwyg editor');
-  if (!$access_check) {
-    drupal_set_message(t('You must <a href="!access-control-url">assign</a> at least one role with the \'access wysiwyg editor\' permission before creating a profile.', array('!access-control-url' => url('admin/user/permissions'))), 'error');
-    $usable = FALSE;
-  }
   if (!$usable) {
-    return $output;
+    return $form;
   }
 
+  $formats = filter_formats();
+
   $profiles = wysiwyg_load_profile();
-  if ($profiles) {
-    $roles = user_roles(FALSE, 'access wysiwyg editor');
-    $header = array(t('Profile'), t('Editor'), t('Roles'), array('data' => t('Operations'), 'colspan' => 2));
-    foreach ($profiles as $p) {
-      $rows[] = array(
-        array('data' => $p->name, 'valign' => 'top'),
-        array('data' => $editors[$p->settings['editor']]['title'], 'valign' => 'top'),
-        array('data' => implode("<br />\n", $p->rids)),
-        array('data' => l(t('Edit'), 'admin/settings/wysiwyg/profile/edit/'. urlencode($p->name)), 'valign' => 'top'),
-        array('data' => l(t('Delete'), 'admin/settings/wysiwyg/profile/delete/'. urlencode($p->name)), 'valign' => 'top'),
+  $options = array('' => t('No editor'));
+  foreach ($editors as $name => $properties) {
+    if ($properties['installed']) {
+      $options[$name] = $properties['title'];
+    }
+  }
+
+  $form['formats']['#tree'] = TRUE;
+  foreach ($formats as $id => $format) {
+    $form['formats'][$id]['name'] = array(
+      '#value' => check_plain($format->name),
+    );
+    $form['formats'][$id]['editor'] = array(
+      '#type' => 'select',
+      '#default_value' => isset($profiles[$id]) ? $profiles[$id]->editor : '',
+      '#options' => $options,
+      '#id' => "edit-editor-$id",
+    );
+    if (isset($profiles[$id]) && !empty($profiles[$id]->editor)) {
+      $form['formats'][$id]['edit'] = array(
+        '#value' => l(t('Edit'), 'admin/settings/wysiwyg/profile/edit/'. $profiles[$id]->format),
+      );
+      $form['formats'][$id]['remove'] = array(
+        '#value' => l(t('Remove'), 'admin/settings/wysiwyg/profile/delete/'. $profiles[$id]->format),
       );
     }
-    $output .= theme('table', $header, $rows);
   }
-  $output .= '<p>'. t('<a href="!create-profile-url">Create new profile</a>', array('!create-profile-url' => url('admin/settings/wysiwyg/profile/add'))) .'</p>';
 
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save'),
+  );
+  return $form;
+}
+
+/**
+ * Return HTML for the Wysiwyg profile overview form.
+ */
+function theme_wysiwyg_profile_overview(&$form) {
+  $output = '';
+  $header = array(t('Input format'), t('Editor'), array('data' => t('Operations'), 'colspan' => 2));
+  $rows = array();
+  foreach (element_children($form['formats']) as $item) {
+    $format = &$form['formats'][$item];
+    $rows[] = array(
+      drupal_render($format['name']),
+      drupal_render($format['editor']),
+      isset($format['edit']) ? drupal_render($format['edit']) : '',
+      isset($format['remove']) ? drupal_render($format['remove']) : '',
+    );
+  }
+  $output .= theme('table', $header, $rows);
+  $output .= drupal_render($form);
   return $output;
 }
 
 /**
+ * Submit callback for Wysiwyg profile overview form.
+ */
+function wysiwyg_profile_overview_submit($form, &$form_state) {
+  foreach ($form_state['values']['formats'] as $format => $values) {
+    db_query("UPDATE {wysiwyg} SET editor = '%s' WHERE format = %d", $values['editor'], $format);
+    if (!db_affected_rows()) {
+      db_query("INSERT INTO {wysiwyg} (format, editor) VALUES (%d, '%s')", $format, $values['editor']);
+    }
+  }
+}
+
+/**
  * Delete editor profile confirmation form.
  */
 function wysiwyg_profile_delete_confirm(&$form_state, $name) {
@@ -518,7 +516,6 @@ function wysiwyg_profile_delete_confirm_
  * Remove a profile from the database.
  */
 function wysiwyg_profile_delete($name) {
-  db_query("DELETE FROM {wysiwyg_profile} WHERE name = '%s'", $name);
-  db_query("DELETE FROM {wysiwyg_role} WHERE name = '%s'", $name);
+  db_query("DELETE FROM {wysiwyg} WHERE name = '%s'", $name);
 }
 
Index: wysiwyg.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/wysiwyg.install,v
retrieving revision 1.1
diff -u -p -r1.1 wysiwyg.install
--- wysiwyg.install	14 Oct 2008 21:45:07 -0000	1.1
+++ wysiwyg.install	28 Oct 2008 20:13:34 -0000
@@ -6,22 +6,14 @@
  */
 function wysiwyg_schema() {
   $schema = array();
-  $schema['wysiwyg_profile'] = array(
-    'description' => t('Stores Wysiwyg Editor profiles.'),
+  $schema['wysiwyg'] = array(
+    'description' => t('Stores Wysiwyg profiles.'),
     'fields' => array(
-      'name' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
+      'format' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+      'editor' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
       'settings' => array('type' => 'text', 'size' => 'normal'),
-      'plugin_count' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
     ),
-    'primary key' => array('name'),
-  );
-  $schema['wysiwyg_role'] = array(
-    'description' => t('Stores user role access permissions for Wysiwyg Editor profiles.'),
-    'fields' => array(
-      'name' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
-      'rid' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
-    ),
-    'primary key' => array('name', 'rid'),
+    'primary key' => array('format'),
   );
   return $schema;
 }
@@ -31,8 +23,7 @@ function wysiwyg_schema() {
  */
 function wysiwyg_install() {
   drupal_install_schema('wysiwyg');
-  // Import data from old editor modules.
-  wysiwyg_migrate_wysiwyg_editor();
+  // Import settings from old editor modules.
   wysiwyg_migrate_tinymce();
 }
 
@@ -44,53 +35,33 @@ function wysiwyg_uninstall() {
 }
 
 /**
- * Migrate from Wysiwyg Editor.
- */
-function wysiwyg_migrate_wysiwyg_editor() {
-  if (db_table_exists('wysiwyg_editor_profile')) {
-    // Import Wysiwyg Editor profiles.
-    db_query('INSERT INTO {wysiwyg_profile} (name, settings, plugin_count) SELECT name, settings, plugin_count FROM {wysiwyg_editor_profile}');
-    // Import Wysiwyg Editor profile role associations.
-    db_query('INSERT INTO {wysiwyg_role} (name, rid) SELECT name, rid FROM {wysiwyg_editor_role}');
-
-    // Disable Wysiwyg Editor module.
-    module_disable(array('wysiwyg_editor'));
-    drupal_set_message(t('Wysiwyg Editor module can be safely uninstalled now.'));
-  }
-}
-
-/**
  * Migrate from TinyMCE.
  */
 function wysiwyg_migrate_tinymce() {
   if (db_table_exists('tinymce_settings')) {
     $schema = db_result(db_query("SELECT schema_version FROM {system} WHERE name = 'tinymce'"));
     if ($schema >= 1) {
-      // Import TinyMCE settings.
-      db_query('INSERT INTO {wysiwyg_profile} (name, settings) SELECT name, settings FROM {tinymce_settings}');
-      // Import TinyMCE profile role associations.
-      db_query('INSERT INTO {wysiwyg_role} (name, rid) SELECT name, rid FROM {tinymce_role}');
-
       // Migrate profile configurations.
-      // Convert buttons/plugins into an associative array and fix plugin count.
-      $profiles = db_query("SELECT name, settings, plugin_count FROM {wysiwyg_profile}");
+      // Convert buttons/plugins into an associative array.
+      $profiles = db_query("SELECT settings FROM {tinymce_settings}");
       while ($profile = db_fetch_array($profiles)) {
         $settings = unserialize($profile['settings']);
         if (isset($settings['form_id'])) {
           $old_buttons = (isset($settings['buttons']) ? $settings['buttons'] : array());
           $settings['buttons'] = array();
-          $plugin_count = 0;
           foreach ($old_buttons as $old_button => $enabled) {
             list($plugin, $button) = explode('-', $old_button, 2);
             $settings['buttons'][$plugin][$button] = 1;
-            $plugin_count++;
           }
-          // We can't use update_sql() here because of curly braces in serialized
-          // array.
-          db_query("UPDATE {wysiwyg_profile} SET settings = '%s', plugin_count = %d WHERE name = '%s'", serialize($settings), $plugin_count, $profile['name']);
+          foreach (_wysiwyg_install_get_formats() as $format => $name) {
+            // We can't use update_sql() here because of curly braces in serialized
+            // array.
+            db_query("INSERT INTO {wysiwyg} (format, editor, settings) VALUES (%d, 'tinymce', '%s')", $format, serialize($settings));
+          }
         }
+        // We can only migrate one profile.
+        break;
       }
-
       // Disable TinyMCE module.
       module_disable(array('tinymce'));
       drupal_set_message(t('TinyMCE module can be safely uninstalled now.'));
@@ -101,3 +72,93 @@ function wysiwyg_migrate_tinymce() {
   }
 }
 
+/**
+ * Retrieve a list of input formats to associate profiles to.
+ */
+function _wysiwyg_install_get_formats() {
+  $formats = array();
+  $result = db_query("SELECT format, name FROM {filter_formats}");
+  while ($format = db_fetch_object($result)) {
+    // Build a list of all formats.
+    $formats[$format->format] = $format->name;
+    // Fetch filters.
+    $result2 = db_query("SELECT module, delta FROM {filters} WHERE format = %d", $format->format);
+    while ($filter = db_fetch_object($result2)) {
+      // If PHP filter is enabled, remove this format.
+      if ($filter->module == 'php') {
+        unset($formats[$format->format]);
+        break;
+      }
+    }
+  }
+  return $formats;
+}
+
+/**
+ * Associate Wysiwyg profiles with input formats.
+ *
+ * Since there was no association yet, we can only assume that there is one
+ * profile only, and that profile must be duplicated and assigned to all input
+ * formats (other than PHP).
+ *
+ * Input formats already have titles/names, so Wysiwyg profiles do not need an
+ * own.
+ *
+ * Because input formats are already granted to certain user roles only, we can
+ * remove our custom Wysiwyg profile permissions. A 1:1 relationship between
+ * input formats and permissions makes plugin_count obsolete, too.
+ *
+ * Since the resulting table is completely different, a new schema is installed.
+ */
+function wysiwyg_update_5001() {
+  $ret = array();
+  // Install new schema.
+  db_create_table($ret, 'wysiwyg', array(
+    'description' => t('Stores Wysiwyg profiles.'),
+    'fields' => array(
+      'format' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+      'editor' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
+      'settings' => array('type' => 'text', 'size' => 'normal'),
+    ),
+    'primary key' => array('format'),
+  ));
+
+  // Fetch all input formats.
+  $formats = _wysiwyg_install_get_formats();
+
+  // Fetch all profiles.
+  $result = db_query("SELECT name, settings FROM {wysiwyg_profile}");
+  while ($profile = db_fetch_object($result)) {
+    $profile->settings = unserialize($profile->settings);
+    // Extract editor name from profile settings.
+    $profile->editor = $profile->settings['editor'];
+    // Clean-up.
+    unset($profile->settings['editor']);
+    unset($profile->settings['old_name']);
+    unset($profile->settings['name']);
+    unset($profile->settings['rids']);
+    // Sorry.  There Can Be Only One. ;)
+    break;
+  }
+
+  if ($profile) {
+    // Rebuild profiles and associate with input formats.
+    foreach ($formats as $format => $name) {
+      // Insert profiles.
+      // We can't use update_sql() here because of curly braces in serialized
+      // array.
+      db_query("INSERT INTO {wysiwyg} (format, editor, settings) VALUES (%d, '%s', '%s')", $format, $profile->editor, serialize($profile->settings));
+      $ret[] = array(
+        'success' => TRUE,
+        'query' => t('Wysiwyg profile %profile converted and associated with input format %format.', array('%profile' => $profile->name, '%format' => $name)),
+      );
+    }
+  }
+
+  // Drop obsolete tables {wysiwyg_profile} and {wysiwyg_role}.
+  db_drop_table($ret, 'wysiwyg_profile');
+  db_drop_table($ret, 'wysiwyg_role');
+
+  return $ret;
+}
+
Index: wysiwyg.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/wysiwyg.module,v
retrieving revision 1.4
diff -u -p -r1.4 wysiwyg.module
--- wysiwyg.module	19 Oct 2008 21:29:21 -0000	1.4
+++ wysiwyg.module	28 Oct 2008 20:05:23 -0000
@@ -27,6 +27,7 @@ function wysiwyg_menu() {
 function wysiwyg_theme() {
   return array(
     'wysiwyg_admin_button_table' => array('arguments' => array('form')),
+    'wysiwyg_profile_overview' => array('arguments' => array('form')),
   );
 }
 
@@ -36,9 +37,8 @@ function wysiwyg_theme() {
 function wysiwyg_help($path, $arg) {
   switch ($path) {
     case 'admin/settings/wysiwyg/profile':
-    case 'admin/help#wysiwyg':
       if (empty($arg[4])) {
-        $output = '<p>'. t('Profiles can be defined based on user roles. A Wysiwyg Editor profile can define which pages receive this Wysiwyg Editor capability, what buttons or themes are enabled for the editor, how the editor is displayed, and a few other editor functions. Lastly, only users with the %permission <a href="!url">user permission</a> are able to use Wysiwyg Editor.', array('%permission' => 'access wysiwyg editor', '!url' => url('admin/user/permissions'))) .'</p>';
+        $output = '<p>'. t('A Wysiwyg profile can be associated to an input format. A Wysiwyg profile defines, which client-side editor is loaded, can define what buttons or themes are enabled for the editor, how the editor is displayed, and a few other editor-specific functions.') .'</p>';
         return $output;
       }
       break;
@@ -46,13 +46,6 @@ function wysiwyg_help($path, $arg) {
 }
 
 /**
- * Implementation of hook_perm().
- */
-function wysiwyg_perm() {
-  return array('access wysiwyg editor');
-}
-
-/**
  * Implementation of hook_elements().
  *
  * Before Drupal 7, there is no way to easily identify form fields that are
@@ -72,11 +65,9 @@ function wysiwyg_perm() {
  */
 function wysiwyg_elements() {
   $type = array();
-  if (user_access('access wysiwyg editor')) {
-    // @todo Derive editor theme from input format.
-    $type['textarea'] = array('#wysiwyg_style' => 'advanced');
-    $type['form'] = array('#after_build' => array('wysiwyg_process_form'));
-  }
+  // @todo Derive editor theme from input format.
+  $type['textarea'] = array('#wysiwyg_style' => 'advanced');
+  $type['form'] = array('#after_build' => array('wysiwyg_process_form'));
   return $type;
 }
 
@@ -143,7 +134,7 @@ function wysiwyg_process_form(&$form) {
             // Fetch the profile associated to this input format.
             $profile = wysiwyg_get_profile($format);
             if ($profile) {
-              $editor = $profile->settings['editor'];
+              $editor = $profile->editor;
               // Check editor theme (and reset it if not/no longer available).
               $theme = wysiwyg_get_editor_themes($profile, $field['#wysiwyg_style']);
 
@@ -195,20 +186,9 @@ function wysiwyg_process_form(&$form) {
  *   A wysiwyg profile.
  *
  * @see wysiwyg_load_editor(), wysiwyg_get_editor()
- *
- * @todo Replace wysiwyg_current_profile() with a input format to profile
- *   association.
  */
 function wysiwyg_get_profile($format) {
-  // Determine whether this input format has PHP filter enabled.
-  // Temporary, until input format to profile associations are in place.
-  $filters = filter_list_format($format);
-  foreach ($filters as $filter) {
-    if ($filter->module == 'php') {
-      return FALSE;
-    }
-  }
-  if ($profile = wysiwyg_load_profile(wysiwyg_current_profile())) {
+  if ($profile = wysiwyg_load_profile($format)) {
     if (wysiwyg_load_editor($profile)) {
       return $profile;
     }
@@ -231,7 +211,7 @@ function wysiwyg_load_editor($profile) {
   static $settings_added;
   static $loaded = array();
 
-  $name = $profile->settings['editor'];
+  $name = $profile->editor;
   // Library files must be loaded only once.
   if (!isset($loaded[$name])) {
     // Load editor.
@@ -258,7 +238,7 @@ function wysiwyg_load_editor($profile) {
         $files = $editor['js files'];
       }
       foreach ($files as $file) {
-        drupal_add_js($editor['js path'] . '/' . $file, 'module', 'footer');
+        drupal_add_js($editor['js path'] . '/' . $file);
       }
       // Load CSS stylesheets for this editor.
       $files = array();
@@ -297,11 +277,11 @@ function wysiwyg_load_editor($profile) {
 
     // Initialize our namespaces in the *header* to do not force editor
     // integration scripts to check and define Drupal.wysiwyg on its own.
-    drupal_add_js(wysiwyg_get_path('wysiwyg.init.js'));
+    drupal_add_js(wysiwyg_get_path('wysiwyg.init.js'), 'core');
 
     // The 'none' editor is a special editor implementation, allowing us to
     // attach and detach regular Drupal behaviors just like any other editor.
-    drupal_add_js(wysiwyg_get_path('editors/js/none.js'), 'module', 'footer');
+    drupal_add_js(wysiwyg_get_path('editors/js/none.js'));
 
     // Add wysiwyg.js to the footer to ensure it's executed after the
     // Drupal.settings array has been rendered and populated. Also, since editor
@@ -321,9 +301,9 @@ function wysiwyg_load_editor($profile) {
  * Register a theme.
  */
 function wysiwyg_add_editor_settings($profile, $theme) {
-  static $themes = array();
+  static $editors = array();
 
-  if (!isset($themes[$theme])) {
+  if (!isset($editors[$profile->editor][$theme])) {
     $config = wysiwyg_get_editor_config($profile, $theme);
     // Convert the config values into the form expected by Wysiwyg Editor.
     // @todo Is this conversion TinyMCE specific?
@@ -335,8 +315,8 @@ function wysiwyg_add_editor_settings($pr
         $config[$key] = implode(',', $config[$key]);
       }
     }
-    drupal_add_js(array('wysiwyg' => array('configs' => array($profile->settings['editor'] => array($theme => $config)))), 'setting');
-    $themes[$theme] = TRUE;
+    drupal_add_js(array('wysiwyg' => array('configs' => array($profile->editor => array($theme => $config)))), 'setting');
+    $editors[$profile->editor][$theme] = TRUE;
   }
 }
 
@@ -349,9 +329,9 @@ function wysiwyg_add_editor_settings($pr
 function wysiwyg_add_plugin_settings($profile) {
   static $plugins_added = array();
   
-  if (!isset($plugins_added[$profile->settings['editor']])) {
+  if (!isset($plugins_added[$profile->editor])) {
     $plugins = array();
-    $editor = wysiwyg_get_editor($profile->settings['editor']);
+    $editor = wysiwyg_get_editor($profile->editor);
     // Collect editor plugins provided via hook_wysiwyg_plugin().
     $info = module_invoke_all('wysiwyg_plugin', $editor['name'], $editor['installed version']);
     // Only keep enabled plugins in this profile.
@@ -365,9 +345,9 @@ function wysiwyg_add_plugin_settings($pr
       $plugins = $editor['plugin settings callback']($editor, $profile, $info);
     }
 
-    drupal_add_js(array('wysiwyg' => array('plugins' => array($profile->settings['editor'] => $plugins))), 'setting');
+    drupal_add_js(array('wysiwyg' => array('plugins' => array($profile->editor => $plugins))), 'setting');
 
-    $plugins_added[$profile->settings['editor']] = TRUE;
+    $plugins_added[$profile->editor] = TRUE;
   }
 }
 
@@ -389,8 +369,8 @@ function wysiwyg_add_plugin_settings($pr
 function wysiwyg_get_editor_themes(&$profile, $selected_theme = NULL) {
   static $themes = array();
 
-  if (!isset($themes[$profile->settings['editor']])) {
-    $editor = wysiwyg_get_editor($profile->settings['editor']);
+  if (!isset($themes[$profile->editor])) {
+    $editor = wysiwyg_get_editor($profile->editor);
     if (isset($editor['themes callback']) && function_exists($editor['themes callback'])) {
       $themes[$editor['name']] = $editor['themes callback']($editor, $profile);
     }
@@ -403,12 +383,12 @@ function wysiwyg_get_editor_themes(&$pro
   // Check optional $selected_theme argument, if given.
   if (isset($selected_theme)) {
     // If the passed theme name does not exist, use the first available.
-    if (!isset($themes[$profile->settings['editor']][$selected_theme])) {
-      $selected_theme = $profile->settings['theme'] = $themes[$profile->settings['editor']][0];
+    if (!isset($themes[$profile->editor][$selected_theme])) {
+      $selected_theme = $profile->settings['theme'] = $themes[$profile->editor][0];
     }
   }
 
-  return isset($selected_theme) ? $selected_theme : $themes[$profile->settings['editor']];
+  return isset($selected_theme) ? $selected_theme : $themes[$profile->editor];
 }
 
 /**
@@ -441,7 +421,7 @@ function wysiwyg_get_plugins($editor_nam
  * Return an array of initial Wysiwyg Editor config options from the current role.
  */
 function wysiwyg_get_editor_config($profile, $theme) {
-  $editor = wysiwyg_get_editor($profile->settings['editor']);
+  $editor = wysiwyg_get_editor($profile->editor);
   $settings = array();
   if (!empty($editor['settings callback']) && function_exists($editor['settings callback'])) {
     $settings = $editor['settings callback']($editor, $profile->settings, $theme);
@@ -450,55 +430,30 @@ function wysiwyg_get_editor_config($prof
 }
 
 /**
- * Return the name of the current user's default profile.
- */
-function wysiwyg_current_profile() {
-  global $user;
-  static $profile_name;
-
-  if (!isset($profile_name)) {
-    $profile_name = db_result(db_query_range('SELECT p.name FROM {wysiwyg_profile} p INNER JOIN {wysiwyg_role} r ON r.name = p.name WHERE r.rid IN (%s) ORDER BY plugin_count DESC', implode(',', array_keys($user->roles)), 0, 1));
-  }
-  return $profile_name;
-}
-
-/**
  * Load all profiles. Just load one profile if $name is passed in.
  */
-function wysiwyg_load_profile($name = '') {
+function wysiwyg_load_profile($format = '') {
   static $profiles;
 
-  // If $name is passed from wysiwyg_current_profile(), it may be FALSE,
-  // which means the user is not allowed to use a wysiwyg editor.
-  if ($name === FALSE) {
-    return FALSE;
-  }
   if (!isset($profiles)) {
     $profiles = array();
-    $roles = user_roles();
-    $result = db_query('SELECT * FROM {wysiwyg_profile}');
+    $result = db_query('SELECT * FROM {wysiwyg}');
     while ($profile = db_fetch_object($result)) {
       $profile->settings = unserialize($profile->settings);
-      $result2 = db_query("SELECT rid FROM {wysiwyg_role} WHERE name = '%s'", $profile->name);
-      $profile_roles = array();
-      while ($role = db_fetch_object($result2)) {
-        $profile_roles[$role->rid] = $roles[$role->rid];
-      }
-      $profile->rids = $profile_roles;
-
-      $profiles[$profile->name] = $profile;
+      $profiles[$profile->format] = $profile;
     }
   }
 
-  return ($name && isset($profiles[$name]) ? $profiles[$name] : ($name ? FALSE : $profiles));
+  return ($format && isset($profiles[$format]) ? $profiles[$format] : ($format ? FALSE : $profiles));
 }
 
 /**
  * Implementation of hook_user().
  */
 function wysiwyg_user($type, &$edit, &$user, $category = NULL) {
-  if ($type == 'form' && $category == 'account' && user_access('access wysiwyg editor')) {
-    $profile = wysiwyg_user_get_profile($user);
+  if ($type == 'form' && $category == 'account') {
+    // @todo http://drupal.org/node/322433
+    $profile = new stdClass;
     if (isset($profile->settings['user_choose']) && $profile->settings['user_choose']) {
       $form['wysiwyg'] = array(
         '#type' => 'fieldset',
@@ -517,30 +472,19 @@ function wysiwyg_user($type, &$edit, &$u
       return array('wysiwyg' => $form);
     }
   }
-  if ($type == 'validate') {
+  elseif ($type == 'validate' && isset($edit['wysiwyg_status'])) {
     return array('wysiwyg_status' => $edit['wysiwyg_status']);
   }
 }
 
-function wysiwyg_user_get_profile($account) {
-  $profile_name = db_result(db_query('SELECT s.name FROM {wysiwyg_profile} s INNER JOIN {wysiwyg_role} r ON r.name = s.name WHERE r.rid IN (%s)', implode(',', array_keys($account->roles))));
-  if ($profile_name) {
-    return wysiwyg_load_profile($profile_name);
-  }
-  else {
-    return FALSE;
-  }
-}
-
 function wysiwyg_user_get_status($profile) {
   global $user;
-  $settings = $profile->settings;
 
-  if ($settings['user_choose'] && isset($user->wysiwyg_status)) {
+  if ($profile->settings['user_choose'] && isset($user->wysiwyg_status)) {
     $status = $user->wysiwyg_status;
   }
   else {
-    $status = isset($settings['default']) ? $settings['default'] : FALSE;
+    $status = isset($profile->settings['default']) ? $profile->settings['default'] : FALSE;
   }
 
   return $status;
Index: editors/js/fckeditor-2.6.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/editors/js/fckeditor-2.6.js,v
retrieving revision 1.5
diff -u -p -r1.5 fckeditor-2.6.js
--- editors/js/fckeditor-2.6.js	13 Oct 2008 23:02:30 -0000	1.5
+++ editors/js/fckeditor-2.6.js	28 Oct 2008 19:26:36 -0000
@@ -24,7 +24,7 @@ Drupal.wysiwyg.editor.attach.fckeditor =
  * See Drupal.wysiwyg.editor.detach.none() for a full desciption of this hook.
  */
 Drupal.wysiwyg.editor.detach.fckeditor = function(context, params) {
-  if (typeof params != 'undefined') {
+  if (typeof params != 'undefined' && typeof FCKeditorAPI != 'undefined') {
     var editor = FCKeditorAPI.GetInstance(params.field);
     if (editor) {
       $('#' + params.field).val(editor.GetXHTML()).show();
Index: editors/js/none.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/editors/js/none.js,v
retrieving revision 1.2
diff -u -p -r1.2 none.js
--- editors/js/none.js	11 Oct 2008 19:54:24 -0000	1.2
+++ editors/js/none.js	28 Oct 2008 19:26:43 -0000
@@ -16,6 +16,7 @@
 Drupal.wysiwyg.editor.attach.none = function(context, params, settings) {
   if (params.resizable) {
     $('#' + params.field).addClass('resizable');
+    $('#' + params.field).css({display: ''});
     Drupal.behaviors.textarea();
   }
 };
