Index: modules/locale/locale.module =================================================================== RCS file: /cvs/drupal/drupal/modules/locale/locale.module,v retrieving revision 1.196 diff -u -p -r1.196 locale.module --- modules/locale/locale.module 21 Oct 2007 18:59:02 -0000 1.196 +++ modules/locale/locale.module 24 Oct 2007 16:21:09 -0000 @@ -227,9 +227,8 @@ function locale_user($type, $edit, &$use */ function locale_form_alter(&$form, $form_state, $form_id) { switch ($form_id) { - // Language field for paths - case 'path_admin_edit': + case 'path_admin_form': $form['language'] = array( '#type' => 'select', '#title' => t('Language'), Index: modules/path/path.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/path/path.admin.inc,v retrieving revision 1.4 diff -u -p -r1.4 path.admin.inc --- modules/path/path.admin.inc 12 Aug 2007 16:34:56 -0000 1.4 +++ modules/path/path.admin.inc 24 Oct 2007 16:21:09 -0000 @@ -6,16 +6,32 @@ * Administrative page callbacks for the path module. */ +function path_admin_overview($callback_arg = '') { + if (!empty($_POST['paths']) && isset($_POST['operation']) && ($_POST['operation'] == 'delete')) { + $output = drupal_get_form('path_multiple_delete_confirm'); + } + else { + $output = drupal_get_form('path_admin_filter_form'); + $output .= drupal_get_form('path_admin_overview_form'); + } + + return $output; +} + /** * Return a listing of all defined URL aliases. * When filter key passed, perform a standard search on the given key, * and return the list of matching URL aliases. */ -function path_admin_overview($keys = NULL) { - // Add the filter form above the overview table. - $output = drupal_get_form('path_admin_filter_form', $keys); - // Enable language column if locale is enabled or if we have any alias with language +function path_admin_overview_form(&$form_state) { + if (arg(3) == 'list' && arg(4)) { + $form_state['values']['filter'] = arg(4); + } + $keys = isset($form_state['values']['filter']) ? $form_state['values']['filter'] : NULL; + + // Enable language column if locale is enabled or if we have any alias with language. $count = db_result(db_query("SELECT COUNT(*) FROM {url_alias} WHERE language != ''")); + $multilanguage = (module_exists('locale') || $count); if ($keys) { @@ -26,39 +42,44 @@ function path_admin_overview($keys = NUL else { $sql = 'SELECT * FROM {url_alias}'; } + $header = array( + array(), array('data' => t('Alias'), 'field' => 'dst', 'sort' => 'asc'), array('data' => t('System'), 'field' => 'src'), - array('data' => t('Operations'), 'colspan' => '2') ); if ($multilanguage) { - $header[3] = $header[2]; - $header[2] = array('data' => t('Language'), 'field' => 'language'); + $header[] = array('data' => t('Language'), 'field' => 'language'); } + $header[] = array('data' => t('Operations')); + $sql .= tablesort_sql($header); $result = pager_query($sql, 50, 0 , NULL, $keys); $rows = array(); + $paths = array(); $destination = drupal_get_destination(); while ($data = db_fetch_object($result)) { - $row = array(check_plain($data->dst), check_plain($data->src), l(t('edit'), "admin/build/path/edit/$data->pid", array('query' => $destination)), l(t('delete'), "admin/build/path/delete/$data->pid", array('query' => $destination))); + $paths[$data->pid] = ''; + $form['dst'][$data->pid] = array('#value' => check_plain($data->dst)); + $form['src'][$data->pid] = array('#value' => check_plain($data->src)); + + $form['operations'][$data->pid] = array('#value' => l(t('edit'), "admin/build/path/edit/$data->pid", array('query' => $destination))); + if ($multilanguage) { - $row[4] = $row[3]; - $row[3] = $row[2]; - $row[2] = module_invoke('locale', 'language_name', $data->language); + $form['language'][$data->pid] = array('#value' => module_invoke('locale', 'language_name', $data->language)); } - $rows[] = $row; - } - - if (empty($rows)) { - $empty_message = $keys ? t('No URL aliases found.') : t('No URL aliases available.') ; - $rows[] = array(array('data' => $empty_message, 'colspan' => ($multilanguage ? 5 : 4))); } + $form['paths'] = array( + '#type' => 'checkboxes', + '#options' => $paths + ); + $form['pager'] = array('#value' => theme('pager', NULL, 50, 0)); - $output .= theme('table', $header, $rows); - $output .= theme('pager', NULL, 50, 0); + $form['delete'] = array('#type' => 'submit', '#value' => t('Delete selected')); + $form['operation'] = array('#type' => 'hidden', '#value' => 'delete'); - return $output; + return $form; } /** @@ -81,8 +102,8 @@ function path_admin_edit($pid = 0) { * Return a form for editing or creating an individual URL alias. * * @ingroup forms - * @see path_admin_form_validate(). - * @see path_admin_form_submit(). + * @see path_admin_form_validate() + * @see path_admin_form_submit() */ function path_admin_form(&$form_state, $edit = array('src' => '', 'dst' => '', 'language' => '', 'pid' => NULL)) { @@ -95,7 +116,8 @@ function path_admin_form(&$form_state, $ '#maxlength' => 64, '#size' => 45, '#description' => t('Specify the existing path you wish to alias. For example: node/28, forum/1, taxonomy/term/1+2.'), - '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=') + '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='), + '#required' => TRUE, ); $form['dst'] = array( '#type' => 'textfield', @@ -104,9 +126,10 @@ function path_admin_form(&$form_state, $ '#maxlength' => 64, '#size' => 45, '#description' => t('Specify an alternative path by which this data can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'), - '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=') + '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='), + '#required' => TRUE, ); - // This will be a hidden value unless locale module is enabled + // This will be a hidden value unless locale module is enabled. $form['language'] = array( '#type' => 'value', '#value' => $edit['language'] @@ -118,13 +141,12 @@ function path_admin_form(&$form_state, $ else { $form['submit'] = array('#type' => 'submit', '#value' => t('Create new alias')); } - return $form; } /** - * Verify that a new URL alias is valid + * Verify that a new URL alias is valid. */ function path_admin_form_validate($form, &$form_state) { $src = $form_state['values']['src']; @@ -136,13 +158,17 @@ function path_admin_form_validate($form, if (db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE pid != %d AND dst = '%s' AND language = '%s'", $pid, $dst, $language))) { form_set_error('dst', t('The alias %alias is already in use in this language.', array('%alias' => $dst))); } + $item = menu_get_item($src); + if (!$item || !$item['access']) { + form_set_error('src', t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $src))); + } } /** * Save a new URL alias to the database. */ function path_admin_form_submit($form, &$form_state) { - // Language is only set if locale module is enabled + // Language is only set if locale module is enabled. path_set_alias($form_state['values']['src'], $form_state['values']['dst'], isset($form_state['values']['pid']) ? $form_state['values']['pid'] : 0, isset($form_state['values']['language']) ? $form_state['values']['language'] : ''); drupal_set_message(t('The alias has been saved.')); @@ -151,7 +177,7 @@ function path_admin_form_submit($form, & } /** - * Menu callback; confirms deleting an URL alias + * Menu callback; confirms deleting an URL alias. **/ function path_admin_delete_confirm($form_state, $pid) { $path = path_load($pid); @@ -165,7 +191,7 @@ function path_admin_delete_confirm($form } /** - * Execute URL alias deletion + * Execute URL alias deletion. **/ function path_admin_delete_confirm_submit($form, &$form_state) { if ($form_state['values']['confirm']) { @@ -180,9 +206,18 @@ function path_admin_delete_confirm_submi * Return a form to filter URL aliases. * * @ingroup forms - * @see path_admin_filter_form_submit(). + * @see path_admin_filter_form_submit() */ -function path_admin_filter_form(&$form_state, $keys = '') { +function path_admin_filter_form(&$form_state) { + if (isset($form_state['post']['filter'])) { + $form_state['values']['filter'] = $form_state['post']['filter']; + } + if (arg(3) == 'list' && arg(4)) { + $form_state['values']['filter'] = arg(4); + } + $keys = isset($form_state['values']['filter']) ? $form_state['values']['filter'] : NULL; + + $form['#attributes'] = array('class' => 'search-form'); $form['basic'] = array('#type' => 'fieldset', '#title' => t('Filter aliases') @@ -195,23 +230,98 @@ function path_admin_filter_form(&$form_s '#maxlength' => 64, '#size' => 25, ); - $form['basic']['inline']['submit'] = array('#type' => 'submit', '#value' => t('Filter')); - + $form['basic']['inline']['submit'] = array( + '#type' => 'submit', + '#value' => t('Filter'), + '#submit' => array('path_admin_filter_form_submit_filter'), + ); + if ($keys) { + $form['basic']['inline']['reset'] = array( + '#type' => 'submit', + '#value' => t('Reset'), + '#submit' => array('path_admin_filter_form_submit_reset'), + ); + } return $form; } /** - * Process filter form submission. + * Process filter form submission when the Filter button is pressed. + */ +function path_admin_filter_form_submit_filter($form, &$form_state) { + $form_state['redirect'] = 'admin/build/path/list/'. trim($form_state['values']['filter']); +} + +/** + * Process filter form submission when the Reset button is pressed. */ -function path_admin_filter_form_submit($form, &$form_state) { - return 'admin/build/path/list/'. trim($form_state['values']['filter']); +function path_admin_filter_form_submit_reset($form, &$form_state) { + $form_state['redirect'] = 'admin/build/path/list'; } /** * Helper function for grabbing filter keys. */ function path_admin_filter_get_keys() { - // Extract keys as remainder of path + // Extract keys as remainder of path. $path = explode('/', $_GET['q'], 5); return count($path) == 5 ? $path[4] : ''; } + +/** + * Theme the path alias overview. + * + * @ingroup themeable + **/ +function theme_path_admin_overview_form($form) { + if (arg(3) == 'list' && arg(4)) { + $form_state['values']['filter'] = arg(4); + } + $keys = isset($form_state['values']['filter']) ? $form_state['values']['filter'] : NULL; + + // Enable language column if locale is enabled or if we have any alias with language. + $count = db_result(db_query("SELECT COUNT(*) FROM {url_alias} WHERE language != ''")); + + $multilanguage = (module_exists('locale') || $count); + + // Overview table: + $header = array( + theme('table_select_header_cell'), + array('data' => t('Alias'), 'field' => 'dst', 'sort' => 'asc'), + array('data' => t('System'), 'field' => 'src'), + ); + if ($multilanguage) { + $header[] = array('data' => t('Language'), 'field' => 'language'); + } + $header[] = t('Operations'); + + $rows = array(); + $colspan = 5; + if (isset($form['dst']) && is_array($form['dst'])) { + foreach (element_children($form['dst']) as $key) { + $row = array( + drupal_render($form['paths'][$key]), + drupal_render($form['dst'][$key]), + drupal_render($form['src'][$key]), + ); + if (isset($form['language'][$key])) { + $row[] = drupal_render($form['language'][$key]); + $colspan = 6; + } + $row[] = drupal_render($form['operations'][$key]); + $rows[] = $row; + } + } + else { + $rows[] = array(array('data' => ($keys ? t('No URL aliases found.') : t('No URL aliases available.')), 'colspan' => $colspan)); + } + + $output = theme('table', $header, $rows, array('summary' => t('URL aliases'))); + if ($form['pager']['#value']) { + $output .= drupal_render($form['pager']); + } + + $output .= drupal_render($form); + + return $output; +} Index: modules/path/path.module =================================================================== RCS file: /cvs/drupal/drupal/modules/path/path.module,v retrieving revision 1.131 diff -u -p -r1.131 path.module --- modules/path/path.module 12 Aug 2007 16:34:56 -0000 1.131 +++ modules/path/path.module 24 Oct 2007 16:21:12 -0000 @@ -77,7 +77,6 @@ function path_menu() { */ function path_admin_delete($pid = 0) { db_query('DELETE FROM {url_alias} WHERE pid = %d', $pid); - drupal_set_message(t('The alias has been deleted.')); } /** @@ -85,12 +84,12 @@ function path_admin_delete($pid = 0) { */ function path_set_alias($path = NULL, $alias = NULL, $pid = NULL, $language = '') { if ($path && !$alias) { - // Delete based on path - db_query("DELETE FROM {url_alias} WHERE src = '%s' AND language = '%s'", $path, $language); + // Delete the most fitting result based on path falling back on path without language. + db_query("DELETE FROM {url_alias} WHERE src = '%s' AND language IN('%s', '')", $path, $language); drupal_clear_path_cache(); } else if (!$path && $alias) { - // Delete based on alias + // Delete based on alias. db_query("DELETE FROM {url_alias} WHERE dst = '%s' AND language = '%s'", $alias, $language); drupal_clear_path_cache(); } @@ -103,27 +102,17 @@ function path_set_alias($path = NULL, $a if ($alias_count == 0) { if ($pid) { - // Existing path changed data + // Existing path changed data. db_query("UPDATE {url_alias} SET src = '%s', dst = '%s', language = '%s' WHERE pid = %d", $path, $alias, $language, $pid); } else { - // No such alias yet in this language + // No such alias yet in this language. db_query("INSERT INTO {url_alias} (src, dst, language) VALUES ('%s', '%s', '%s')", $path, $alias, $language); } } - // The alias exists. + // The alias exist, update the path. else { - // This path has no alias yet, so we redirect the alias here. - if ($path_count == 0) { - db_query("UPDATE {url_alias} SET src = '%s' WHERE dst = '%s' AND language = '%s'", $path, $alias, $language); - } - else { - // This will delete the path that alias was originally pointing to. - path_set_alias(NULL, $alias, NULL, $language); - // This will remove the current aliases of the path. - path_set_alias($path, NULL, NULL, $language); - path_set_alias($path, $alias, NULL, $language); - } + db_query("UPDATE {url_alias} SET src = '%s' WHERE dst = '%s' AND language = '%s'", $path, $alias, $language); } if ($alias_count == 0 || $path_count == 0) { drupal_clear_path_cache(); @@ -139,10 +128,10 @@ function path_set_alias($path = NULL, $a */ function path_nodeapi(&$node, $op, $arg) { if (user_access('create url aliases') || user_access('administer url aliases')) { + $language = isset($node->language) ? $node->language : ''; switch ($op) { case 'validate': $node->path = trim($node->path); - $language = isset($node->language) ? $node->language : ''; if (db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE dst = '%s' AND src != '%s' AND language = '%s'", $node->path, "node/$node->nid", $language))) { form_set_error('path', t('The path is already in use.')); } @@ -150,7 +139,6 @@ function path_nodeapi(&$node, $op, $arg) case 'load': $path = "node/$node->nid"; - $language = isset($node->language) ? $node->language : ''; $alias = drupal_get_path_alias($path, $language); if ($path != $alias) { $node->path = $alias; @@ -161,17 +149,17 @@ function path_nodeapi(&$node, $op, $arg) // Don't try to insert if path is NULL. We may have already set // the alias ahead of time. if (isset($node->path)) { - path_set_alias("node/$node->nid", $node->path); + path_set_alias("node/$node->nid", $node->path, NULL, $language); } break; case 'update': - path_set_alias("node/$node->nid", isset($node->path) ? $node->path : NULL, isset($node->pid) ? $node->pid : NULL); + path_set_alias("node/$node->nid", isset($node->path) ? $node->path : NULL, isset($node->pid) ? $node->pid : NULL, $language); break; case 'delete': $path = "node/$node->nid"; - if (drupal_get_path_alias($path) != $path) { + if (drupal_get_path_alias($path, $language) != $path) { path_set_alias($path); } break; @@ -223,3 +211,40 @@ function path_perm() { function path_load($pid) { return db_fetch_array(db_query('SELECT * FROM {url_alias} WHERE pid = %d', $pid)); } + +function path_multiple_delete_confirm(&$form_state) { + $edit = $form_state['post']; + + $form['paths'] = array('#prefix' => '