? includes/database/install.inc
? sites/all/modules/cvs
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.865
diff -u -p -r1.865 common.inc
--- includes/common.inc	9 Feb 2009 03:29:53 -0000	1.865
+++ includes/common.inc	11 Feb 2009 06:58:37 -0000
@@ -2573,7 +2573,7 @@ function drupal_get_js($scope = 'header'
   $embed_suffix = "\n//--><!]]>\n";
 
   // Sort the JavaScript by weight so that it appears in the correct order.
-  uasort($items, 'drupal_sort_weight');
+  drupal_sort_array($items, 'weight');
 
   // Loop through the JavaScript to construct the rendered output.
   foreach ($items as $item) {
@@ -3386,15 +3386,30 @@ function drupal_render_children(&$elemen
 }
 
 /**
- * Function used by uasort to sort structured arrays by weight.
- */
-function element_sort($a, $b) {
-  $a_weight = (is_array($a) && isset($a['#weight'])) ? $a['#weight'] : 0;
-  $b_weight = (is_array($b) && isset($b['#weight'])) ? $b['#weight'] : 0;
-  if ($a_weight == $b_weight) {
-    return 0;
+* Generic sorting mechanism.
+*
+* @param $array
+*   The array to sort.
+* @param $key
+*   The index to retrieve. Child keys are passed by comma-seperated values ('item,#weight').
+*/
+function drupal_sort_array(&$array, $key) {
+  static $sort_functions = array();
+
+  if (!isset($sort_functions[$key])) {
+    $sort_functions[$key] = create_function('$a,$b', '
+      $keys = explode(",","'.$key.'");
+      foreach ($keys as $key) {
+        $a = is_array($a) && isset($a[$key]) ? $a[$key] : 0;
+        $b = is_array($b) && isset($b[$key]) ? $b[$key] : 0;
+      }
+      if ($a == $b) {
+        return 0;
+      }
+      return ($a < $b) ? -1 : 1;');
   }
-  return ($a_weight < $b_weight) ? -1 : 1;
+
+  return uasort($array, $sort_functions[$key]);
 }
 
 /**
@@ -3436,18 +3451,6 @@ function element_basic_defaults() {
 }
 
 /**
- * Function used by uasort to sort structured arrays by weight, without the property weight prefix.
- */
-function drupal_sort_weight($a, $b) {
-  $a_weight = (is_array($a) && isset($a['weight'])) ? $a['weight'] : 0;
-  $b_weight = (is_array($b) && isset($b['weight'])) ? $b['weight'] : 0;
-  if ($a_weight == $b_weight) {
-    return 0;
-  }
-  return ($a_weight < $b_weight) ? -1 : 1;
-}
-
-/**
  * Check if the key is a property.
  */
 function element_property($key) {
@@ -3495,7 +3498,7 @@ function element_children(&$elements, $s
   }
   // Sort the element if necessary.
   if ($sort && $sortable) {
-    uasort($children, 'element_sort');
+    drupal_sort_array($children, '#weight');
   }
   $elements['#sorted'] = TRUE;
   return array_keys($children);
Index: modules/field/field.form.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/field.form.inc,v
retrieving revision 1.3
diff -u -p -r1.3 field.form.inc
--- modules/field/field.form.inc	10 Feb 2009 03:16:14 -0000	1.3
+++ modules/field/field.form.inc	11 Feb 2009 06:58:39 -0000
@@ -244,7 +244,7 @@ function theme_field_multiple_value_form
         $items[] = &$element[$key];
       }
     }
-    usort($items, '_field_sort_items_value_helper');
+    drupal_sort_array($items, '_weight,#value');
 
     // Add the items as table rows.
     foreach ($items as $key => $item) {
Index: modules/field/field.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/field.module,v
retrieving revision 1.4
diff -u -p -r1.4 field.module
--- modules/field/field.module	10 Feb 2009 03:16:14 -0000	1.4
+++ modules/field/field.module	11 Feb 2009 06:58:39 -0000
@@ -255,7 +255,7 @@ function field_set_empty($field, $items)
  */
 function _field_sort_items($field, $items) {
   if (($field['cardinality'] > 1 || $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) && isset($items[0]['_weight'])) {
-    usort($items, '_field_sort_items_helper');
+    drupal_sort_array($items, '_weight');
     foreach ($items as $delta => $item) {
       if (is_array($items[$delta])) {
         unset($items[$delta]['_weight']);
@@ -266,31 +266,6 @@ function _field_sort_items($field, $item
 }
 
 /**
- * Sort function for items order.
- * (copied form element_sort(), which acts on #weight keys)
- */
-function _field_sort_items_helper($a, $b) {
-  $a_weight = (is_array($a) && isset($a['_weight'])) ? $a['_weight'] : 0;
-  $b_weight = (is_array($b) && isset($b['_weight'])) ? $b['_weight'] : 0;
-  if ($a_weight == $b_weight) {
-    return 0;
-  }
-  return ($a_weight < $b_weight) ? -1 : 1;
-}
-
-/**
- * Same as above, using ['_weight']['#value']
- */
-function _field_sort_items_value_helper($a, $b) {
-  $a_weight = (is_array($a) && isset($a['_weight']['#value'])) ? $a['_weight']['#value'] : 0;
-  $b_weight = (is_array($b) && isset($b['_weight']['#value'])) ? $b['_weight']['#value'] : 0;
-  if ($a_weight == $b_weight) {
-    return 0;
-  }
-  return ($a_weight < $b_weight) ? -1 : 1;
-}
-
-/**
  * Registry of available build modes.
  * TODO : move into hook_fieldable_info() ?
  */
@@ -597,4 +572,4 @@ function template_preprocess_field(&$var
 
 /**
  * @} End of "defgroup field"
- */
\ No newline at end of file
+ */
Index: modules/upload/upload.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/upload/upload.module,v
retrieving revision 1.227
diff -u -p -r1.227 upload.module
--- modules/upload/upload.module	3 Feb 2009 18:55:32 -0000	1.227
+++ modules/upload/upload.module	11 Feb 2009 06:59:03 -0000
@@ -207,7 +207,7 @@ function upload_node_form_submit(&$form,
         $microweight += 0.001;
       }
     }
-    uasort($form_state['values']['files'], 'element_sort');
+    drupal_sort_array($form_state['values']['files'], '#weight');
   }
 }
 
Index: modules/user/user.pages.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.pages.inc,v
retrieving revision 1.28
diff -u -p -r1.28 user.pages.inc
--- modules/user/user.pages.inc	3 Feb 2009 17:30:13 -0000	1.28
+++ modules/user/user.pages.inc	11 Feb 2009 06:59:04 -0000
@@ -167,7 +167,7 @@ function user_view($account) {
 function template_preprocess_user_profile(&$variables) {
   $variables['profile'] = array();
   // Sort sections by weight
-  uasort($variables['account']->content, 'element_sort');
+  drupal_sort_array($variables['account']->content, '#weight');
   // Provide keyed variables so themers can print each section independently.
   foreach (element_children($variables['account']->content) as $key) {
     $variables['profile'][$key] = drupal_render($variables['account']->content[$key]);
