Index: path.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/path/path.module,v
retrieving revision 1.115
diff -u -r1.115 path.module
--- path.module	30 Apr 2007 17:03:26 -0000	1.115
+++ path.module	7 May 2007 11:02:08 -0000
@@ -27,7 +27,7 @@
       return $output;
     case 'admin/build/path':
     case 'admin/build/path/list':
-      return '<p>'. t("Drupal provides users complete control over URLs through aliasing. This feature is typically used to make URLs human-readable or easy to remember. For example, one could map the relative URL 'node/1' onto 'about'. Each system path can have multiple aliases.") .'</p>';
+      return '<p>'. t("Drupal provides users complete control over URLs through aliasing. This feature is typically used to make URLs human-readable or easy to remember. For example, one could map the relative URL 'node/1' onto 'about'. Each system path can have multiple aliases. The aliases can be filtered by keywords. Use '*' as a wildcard.") .'</p>';
     case 'admin/build/path/add':
       return '<p>'. t('Enter the path you wish to create the alias for, followed by the name of the new alias.') .'</p>';
   }
@@ -67,6 +67,13 @@
     'access arguments' => array('administer url aliases'),
     'type' => MENU_LOCAL_TASK,
   );
+  $items['admin/build/path/autocomplete'] = array(
+    'title' => 'Path autocomplete',
+    'page callback' => 'path_admin_filter_autocomplete',
+    'access callback' => 'user_access',
+    'access arguments' => array('administer url aliases'),
+    'type' => MENU_CALLBACK,
+  );
 
   return $items;
 }
@@ -187,7 +194,6 @@
 function path_form($edit = array('src' => '', 'dst' => '', 'language' => '', 'pid' => NULL)) {
   $form['#submit']['path_form_submit'] = array();
   $form['#validate']['path_form_validate'] = array();
-  $form['#theme'] = 'path_form';
   $form['#alias'] = $edit;
 
   $form['src'] = array(
@@ -314,13 +320,26 @@
 
 /**
  * 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_overview() {
+  // Grab the keys, if any are passed through the url.
+  $keys = path_admin_filter_get_keys();
+  // 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
   $count = db_result(db_query("SELECT COUNT(*) FROM {url_alias} WHERE language != ''"));
   $multilanguage = (module_exists('locale') || $count);
 
-  $sql = 'SELECT * FROM {url_alias}';
+  if ($keys) {
+    // Replace wildcards with MySQL/PostgreSQL wildcards.
+    $keys = preg_replace('!\*+!', '%', $keys);
+    $sql = "SELECT * FROM {url_alias} WHERE dst LIKE '%%%s%%'";
+  }
+  else {
+    $sql = 'SELECT * FROM {url_alias}';
+  }
   $header = array(
     array('data' => t('Alias'), 'field' => 'dst', 'sort' => 'asc'),
     array('data' => t('System'), 'field' => 'src'),
@@ -331,7 +350,7 @@
     $header[2] = array('data' => t('Language'), 'field' => 'language');
   }
   $sql .= tablesort_sql($header);
-  $result = pager_query($sql, 50);
+  $result = pager_query($sql, 50, 0 , NULL, $keys);
 
   $rows = array();
   $destination = drupal_get_destination();
@@ -346,11 +365,13 @@
   }
 
   if (empty($rows)) {
-    $rows[] = array(array('data' => t('No URL aliases available.'), 'colspan' => ($multilanguage ? 5 : 4)));
+    $empty_message = $keys ? t('No URL aliases found.') : t('No URL aliases available.') ;
+    $rows[] = array(array('data' => $empty_message, 'colspan' => ($multilanguage ? 5 : 4)));
   }
 
-  $output = theme('table', $header, $rows);
+  $output .= theme('table', $header, $rows);
   $output .= theme('pager', NULL, 50, 0);
+
   return $output;
 }
 
@@ -386,3 +407,58 @@
   drupal_set_message(t('The alias has been saved.'));
   return 'admin/build/path';
 }
+
+/**
+ * Return a form to filter URL aliases.
+ */
+function path_admin_filter_form($keys = '') {
+  $form['#attributes'] = array('class' => 'search-form');
+  $form['basic'] = array('#type' => 'fieldset',
+    '#title' => t('Filter aliases')
+  );
+  $form['basic']['inline'] = array('#prefix' => '<div class="container-inline">', '#suffix' => '</div>');
+  $form['basic']['inline']['filter'] = array(
+    '#type' => 'textfield',
+    '#title' => '',
+    '#default_value' => $keys,
+    '#maxlength' => 64,
+    '#size' => 45,
+    '#autocomplete_path' => 'admin/build/path/autocomplete'
+  );
+  $form['basic']['inline']['submit'] = array('#type' => 'submit', '#value' => t('Filter'));
+
+  return $form;
+}
+
+/**
+ * Process filter form submission.
+ */
+function path_admin_filter_form_submit($form_id, $form_values) {
+  return 'admin/build/path/list/'. trim($form_values['filter']);
+}
+
+/**
+ * Helper function for grabbing filter keys.
+ */
+function path_admin_filter_get_keys() {
+  // Extract keys as remainder of path
+  $path = explode('/', $_GET['q'], 5);
+  return count($path) == 5 ? $path[4] : '';
+}
+
+/**
+ * Retrieve a pipe delimited string of autocomplete suggestions for existing URL aliases.
+ */
+function path_admin_filter_autocomplete($keys = '') {
+  $matches = array();
+  if ($keys) {
+    // Replace wildcards with MySQL/PostgreSQL wildcards.
+    $keys = preg_replace('!\*+!', '%', $keys);
+    $result = db_query_range("SELECT * FROM {url_alias} WHERE dst LIKE '%%%s%%'", $keys, 0, 10);
+    while ($alias = db_fetch_object($result)) {
+      $matches[$alias->dst] = check_plain($alias->dst);
+   }
+  }
+  print drupal_to_js($matches);
+  exit();
+}

