Index: modules/field/modules/text/text.test =================================================================== RCS file: /cvs/drupal/drupal/modules/field/modules/text/text.test,v retrieving revision 1.29 diff -u -p -r1.29 text.test --- modules/field/modules/text/text.test 24 Sep 2010 00:37:42 -0000 1.29 +++ modules/field/modules/text/text.test 18 Oct 2010 10:34:28 -0000 @@ -198,7 +198,10 @@ class TextFieldTestCase extends DrupalWe // Create a new text format that does not escape HTML, and grant the user // access to it. $this->drupalLogin($this->admin_user); - $edit = array('name' => $this->randomName()); + $edit = array( + 'name' => $this->randomName(), + 'machine_name' => drupal_strtolower($this->randomName()), + ); $this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration')); filter_formats_reset(); $this->checkPermissions(array(), TRUE); @@ -386,8 +389,15 @@ class TextTranslationTestCase extends Dr function setUp() { parent::setUp('locale', 'translation'); - $this->format = 3; - $this->admin = $this->drupalCreateUser(array('administer languages', 'administer content types', 'access administration pages', 'bypass node access', "use text format $this->format")); + $full_html_format = db_query_range('SELECT * FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Full HTML'))->fetchObject(); + $this->format = $full_html_format->format; + $this->admin = $this->drupalCreateUser(array( + 'administer languages', + 'administer content types', + 'access administration pages', + 'bypass node access', + filter_permission_name($full_html_format), + )); $this->translator = $this->drupalCreateUser(array('create article content', 'edit own article content', 'translate content')); // Enable an additional language. Index: modules/filter/filter.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/filter/filter.admin.inc,v retrieving revision 1.66 diff -u -p -r1.66 filter.admin.inc --- modules/filter/filter.admin.inc 29 Sep 2010 19:52:12 -0000 1.66 +++ modules/filter/filter.admin.inc 18 Oct 2010 10:34:28 -0000 @@ -96,7 +96,11 @@ function theme_filter_admin_overview($va function filter_admin_format_page($format = NULL) { if (!isset($format->name)) { drupal_set_title(t('Add text format')); - $format = (object) array('name' => '', 'format' => 0); + $format = (object) array( + 'format' => 0, + 'machine_name' => '', + 'name' => '', + ); } return drupal_get_form('filter_admin_format_form', $format); } @@ -122,6 +126,16 @@ function filter_admin_format_form($form, '#default_value' => $format->name, '#required' => TRUE, ); + $form['machine_name'] = array( + '#type' => 'machine_name', + '#default_value' => $format->machine_name, + '#machine_name' => array( + 'exists' => 'filter_format_load_by_machine_name', + ), + // Since the machine name needs to relate to the text format ID, it cannot + // be changed after initial creation. + '#disabled' => !empty($format->format), + ); // Add user role access selection. $form['roles'] = array( Index: modules/filter/filter.install =================================================================== RCS file: /cvs/drupal/drupal/modules/filter/filter.install,v retrieving revision 1.46 diff -u -p -r1.46 filter.install --- modules/filter/filter.install 28 Sep 2010 03:30:37 -0000 1.46 +++ modules/filter/filter.install 18 Oct 2010 10:34:28 -0000 @@ -19,6 +19,13 @@ function filter_schema() { 'default' => 0, 'description' => 'Foreign key: The {filter_format}.format to which this filter is assigned.', ), + 'format_machine_name' => array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + 'description' => 'Foreign key: The {filter_format}.machine_name to which this filter is assigned.', + ), 'module' => array( 'type' => 'varchar', 'length' => 64, @@ -66,12 +73,19 @@ function filter_schema() { 'not null' => TRUE, 'description' => 'Primary Key: Unique ID for format.', ), + 'machine_name' => array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + 'description' => 'Machine name of the format.', + ), 'name' => array( 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', - 'description' => 'Name of the text format (Filtered HTML).', + 'description' => 'Name of the format.', 'translatable' => TRUE, ), 'cache' => array( @@ -98,6 +112,7 @@ function filter_schema() { ), 'primary key' => array('format'), 'unique keys' => array( + 'machine_name' => array('machine_name'), 'name' => array('name'), ), 'indexes' => array( @@ -121,6 +136,7 @@ function filter_install() { // installation profiles to have other properties. $plain_text_format = array( 'name' => 'Plain text', + 'machine_name' => 'plain_text', 'weight' => 10, 'filters' => array( // Escape all HTML. @@ -189,6 +205,24 @@ function filter_update_7000() { 'status_weight' => array('status', 'weight'), ), )); + // Add a new {filter_format}.machine_name column. + db_add_field('filter_format', 'machine_name', array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + 'description' => 'Machine name of the format.', + )); + // Auto-generate machine names. + $formats = db_query('SELECT format, name FROM {filter_format}')->fetchAllKeyed(); + foreach ($formats as $format => $name) { + $machine_name = preg_replace('@[^a-z0-9]+@', '_', drupal_strtolower($name)); + db_update('filter_format') + ->fields(array('machine_name' => $machine_name)) + ->condition('format', $format) + ->execute(); + } + db_add_unique_key('filter_format', 'machine_name', array('machine_name')); } /** @@ -231,6 +265,13 @@ function filter_update_7003() { 'default' => 0, 'description' => 'Foreign key: The {filter_format}.format to which this filter is assigned.', ), + 'format_machine_name' => array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + 'description' => 'Foreign key: The {filter_format}.machine_name to which this filter is assigned.', + ), 'module' => array( 'type' => 'varchar', 'length' => 64, @@ -285,6 +326,7 @@ function filter_update_7003() { '0' => 'php_code', ), ); + $machine_names = db_query('SELECT format, machine_name FROM {filter_format}')->fetchAllKeyed(); // Loop through each filter and make changes to the core filter table by // each record from the old to the new table. @@ -323,6 +365,7 @@ function filter_update_7003() { db_insert('filter') ->fields(array( 'format' => $record->format, + 'format_machine_name' => $machine_names[$record->format], 'module' => $module, 'name' => $new_name, 'weight' => $record->weight, @@ -359,7 +402,7 @@ function filter_update_7005() { $format_roles = ($format->format == $default_format ? $all_roles : explode(',', $format->roles)); foreach ($format_roles as $format_role) { if (in_array($format_role, $all_roles)) { - _update_7000_user_role_grant_permissions($format_role, array('use text format ' . $format->format), 'filter'); + _update_7000_user_role_grant_permissions($format_role, array('use text format ' . $format->machine_name), 'filter'); } } } @@ -445,9 +488,9 @@ function filter_update_7005() { function filter_update_7008() { // Build the list of permissions to grant. $permissions = array(); - foreach (db_query('SELECT format FROM {filter_format}')->fetchCol() as $format_id) { + foreach (db_query('SELECT format, machine_name FROM {filter_format}')->fetchAllKeyed() as $format_id => $machine_name) { if ($format_id != variable_get('filter_fallback_format')) { - $permissions[] = 'use text format ' . $format_id; + $permissions[] = 'use text format ' . $machine_name; } } // Grant text format permissions to all roles that can 'administer filters'. Index: modules/filter/filter.module =================================================================== RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v retrieving revision 1.353 diff -u -p -r1.353 filter.module --- modules/filter/filter.module 13 Oct 2010 02:10:50 -0000 1.353 +++ modules/filter/filter.module 18 Oct 2010 10:34:28 -0000 @@ -161,6 +161,25 @@ function filter_format_load($format_id) } /** + * Load a text format object from the database by it's machine name. + * + * @param $machine_name + * The format's machine-readable name. + * + * @return + * A fully-populated text format object. + */ +function filter_format_load_by_machine_name($machine_name) { + $formats = filter_formats(); + foreach ($formats as $format) { + if ($format->machine_name == $machine_name) { + return $format; + } + } + return FALSE; +} + +/** * Save a text format object to the database. * * @param $format @@ -220,6 +239,7 @@ function filter_format_save(&$format) { } $fields = array(); + $fields['format_machine_name'] = $format->machine_name; $fields['weight'] = $format->filters[$name]['weight']; $fields['status'] = $format->filters[$name]['status']; $fields['module'] = $format->filters[$name]['module']; @@ -322,8 +342,8 @@ function filter_permission() { * is malformed or is the fallback format (which is available to all users). */ function filter_permission_name($format) { - if (isset($format->format) && $format->format != filter_fallback_format()) { - return 'use text format ' . $format->format; + if (isset($format->format) && isset($format->machine_name) && $format->format != filter_fallback_format()) { + return 'use text format ' . $format->machine_name; } return FALSE; } @@ -389,6 +409,9 @@ function filter_formats($account = NULL) } } + // Allow other modules to alter the list of formats. + drupal_alter('filter_formats', $formats['all']); + // Build a list of user-specific formats. if (isset($account) && !isset($formats['user'][$account->uid])) { $formats['user'][$account->uid] = array(); Index: modules/filter/filter.test =================================================================== RCS file: /cvs/drupal/drupal/modules/filter/filter.test,v retrieving revision 1.77 diff -u -p -r1.77 filter.test --- modules/filter/filter.test 28 Sep 2010 03:30:37 -0000 1.77 +++ modules/filter/filter.test 18 Oct 2010 10:34:28 -0000 @@ -24,6 +24,7 @@ class FilterCRUDTestCase extends DrupalW // Add a text format with minimum data only. $format = new stdClass(); $format->name = 'Empty format'; + $format->machine_name = 'empty_format'; filter_format_save($format); $this->verifyTextFormat($format); $this->verifyFilters($format); @@ -31,6 +32,7 @@ class FilterCRUDTestCase extends DrupalW // Add another text format specifying all possible properties. $format = new stdClass(); $format->name = 'Custom format'; + $format->machine_name = 'custom_format'; $format->filters = array( 'filter_url' => array( 'status' => 1, @@ -78,6 +80,7 @@ class FilterCRUDTestCase extends DrupalW ->execute() ->fetchObject(); $this->assertEqual($db_format->format, $format->format, t('Database: Proper format id for text format %format.', $t_args)); + $this->assertEqual($db_format->machine_name, $format->machine_name, t('Database: Proper machine name for text format %format.', $t_args)); $this->assertEqual($db_format->name, $format->name, t('Database: Proper title for text format %format.', $t_args)); $this->assertEqual($db_format->cache, $format->cache, t('Database: Proper cache indicator for text format %format.', $t_args)); $this->assertEqual($db_format->weight, $format->weight, t('Database: Proper weight for text format %format.', $t_args)); @@ -85,6 +88,7 @@ class FilterCRUDTestCase extends DrupalW // Verify filter_format_load(). $filter_format = filter_format_load($format->format); $this->assertEqual($filter_format->format, $format->format, t('filter_format_load: Proper format id for text format %format.', $t_args)); + $this->assertEqual($filter_format->machine_name, $format->machine_name, t('filter_format_load: Proper machine name for text format %format.', $t_args)); $this->assertEqual($filter_format->name, $format->name, t('filter_format_load: Proper title for text format %format.', $t_args)); $this->assertEqual($filter_format->cache, $format->cache, t('filter_format_load: Proper cache indicator for text format %format.', $t_args)); $this->assertEqual($filter_format->weight, $format->weight, t('filter_format_load: Proper weight for text format %format.', $t_args)); @@ -120,7 +124,8 @@ class FilterCRUDTestCase extends DrupalW // Verify that filter settings were properly stored. $this->assertEqual(unserialize($filter->settings), isset($format_filters[$name]['settings']) ? $format_filters[$name]['settings'] : array(), t('Database: Proper filter settings for %filter in text format %format.', $t_args)); - // Verify that each filter has a module name assigned. + // Verify that each filter has a machine and module name assigned. + $this->assertEqual($filter->format_machine_name, $format->machine_name, t('Database: Proper machine name for %filter in text format %format.', $t_args)); $this->assertTrue(!empty($filter->module), t('Database: Proper module name for %filter in text format %format.', $t_args)); // Remove the filter from the copy of saved $format to check whether all @@ -142,7 +147,8 @@ class FilterCRUDTestCase extends DrupalW // Verify that filter settings were properly stored. $this->assertEqual($filter->settings, isset($format_filters[$name]['settings']) ? $format_filters[$name]['settings'] : array(), t('filter_list_format: Proper filter settings for %filter in text format %format.', $t_args)); - // Verify that each filter has a module name assigned. + // Verify that each filter has a machine and module name assigned. + $this->assertEqual($filter->format_machine_name, $format->machine_name, t('filter_list_format: Proper machine name for %filter in text format %format.', $t_args)); $this->assertTrue(!empty($filter->module), t('filter_list_format: Proper module name for %filter in text format %format.', $t_args)); // Remove the filter from the copy of saved $format to check whether all @@ -269,6 +275,7 @@ class FilterAdminTestCase extends Drupal // Add format. $edit = array(); $edit['name'] = $this->randomName(); + $edit['machine_name'] = drupal_strtolower($this->randomName()); $edit['roles[2]'] = 1; $edit['filters[' . $second_filter . '][status]'] = TRUE; $edit['filters[' . $first_filter . '][status]'] = TRUE; @@ -424,7 +431,10 @@ class FilterFormatAccessTestCase extends $this->drupalLogin($this->filter_admin_user); $formats = array(); for ($i = 0; $i < 2; $i++) { - $edit = array('name' => $this->randomName()); + $edit = array( + 'name' => $this->randomName(), + 'machine_name' => drupal_strtolower($this->randomName()), + ); $this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration')); $this->resetFilterCaches(); $format_id = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $edit['name']))->fetchField(); @@ -656,7 +666,10 @@ class FilterDefaultFormatTestCase extend $this->drupalLogin($admin_user); $formats = array(); for ($i = 0; $i < 2; $i++) { - $edit = array('name' => $this->randomName()); + $edit = array( + 'name' => $this->randomName(), + 'machine_name' => drupal_strtolower($this->randomName()), + ); $this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration')); $this->resetFilterCaches(); $format_id = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $edit['name']))->fetchField(); @@ -1685,6 +1698,7 @@ class FilterHooksTestCase extends Drupal $name = $this->randomName(); $edit = array(); $edit['name'] = $name; + $edit['machine_name'] = drupal_strtolower($this->randomName()); $edit['roles[1]'] = 1; $this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration')); $this->assertRaw(t('Added text format %format.', array('%format' => $name)), t('New format created.')); Index: modules/php/php.install =================================================================== RCS file: /cvs/drupal/drupal/modules/php/php.install,v retrieving revision 1.18 diff -u -p -r1.18 php.install --- modules/php/php.install 13 Sep 2010 01:11:08 -0000 1.18 +++ modules/php/php.install 18 Oct 2010 10:34:28 -0000 @@ -18,6 +18,7 @@ function php_enable() { if (!$format_exists) { $php_format = array( 'name' => 'PHP code', + 'machine_name' => 'php_code', // 'Plain text' format is installed with a weight of 10 by default. Use a // higher weight here to ensure that this format will not be the default // format for anyone. Index: modules/search/search.test =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search.test,v retrieving revision 1.76 diff -u -p -r1.76 search.test --- modules/search/search.test 5 Oct 2010 06:17:29 -0000 1.76 +++ modules/search/search.test 18 Oct 2010 10:34:29 -0000 @@ -712,9 +712,9 @@ class SearchCommentTestCase extends Drup // Enable check_plain() for 'Filtered HTML' text format. $filtered_html_format_id = db_query_range('SELECT format FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Filtered HTML'))->fetchField(); $edit = array( - 'filters[filter_html_escape][status]' => $filtered_html_format_id, + 'filters[filter_html_escape][status]' => TRUE, ); - $this->drupalPost('admin/config/content/formats/1', $edit, t('Save configuration')); + $this->drupalPost('admin/config/content/formats/' . $filtered_html_format_id, $edit, t('Save configuration')); // Allow anonymous users to search content. $edit = array( DRUPAL_ANONYMOUS_RID . '[search content]' => 1, Index: profiles/standard/standard.install =================================================================== RCS file: /cvs/drupal/drupal/profiles/standard/standard.install,v retrieving revision 1.26 diff -u -p -r1.26 standard.install --- profiles/standard/standard.install 5 Oct 2010 06:17:29 -0000 1.26 +++ profiles/standard/standard.install 18 Oct 2010 10:34:29 -0000 @@ -10,6 +10,7 @@ function standard_install() { // Add text formats. $filtered_html_format = array( 'name' => 'Filtered HTML', + 'machine_name' => 'filtered_html', 'weight' => 0, 'filters' => array( // URL filter. @@ -39,6 +40,7 @@ function standard_install() { $full_html_format = array( 'name' => 'Full HTML', + 'machine_name' => 'full_html', 'weight' => 1, 'filters' => array( // URL filter.