Index: modules/block/block.tpl.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.tpl.php,v
retrieving revision 1.6
diff -u -r1.6 block.tpl.php
--- modules/block/block.tpl.php	19 Oct 2009 01:30:06 -0000	1.6
+++ modules/block/block.tpl.php	9 Nov 2009 15:50:34 -0000
@@ -11,7 +11,6 @@
  * - $block->module: Module that generated the block.
  * - $block->delta: An ID for the block, unique within each module.
  * - $block->region: The block region embedding the current block.
- * - $contextual_links (array): An array of contextual links for the block.
  * - $classes: String of classes that can be used to style contextually through
  *   CSS. It can be manipulated through the variable $classes_array from
  *   preprocess functions. The default values can be one or more of the following:
@@ -37,11 +36,7 @@
  */
 ?>
 <div id="block-<?php print $block->module . '-' . $block->delta; ?>" class="<?php print $classes; ?>"<?php print $attributes; ?>>
- 
-<?php if ($contextual_links): ?>
-  <?php print render($contextual_links); ?>
-<?php endif; ?>
- 
+
 <?php if ($block->subject): ?>
   <h2<?php print $title_attributes; ?>><?php print $block->subject ?></h2>
 <?php endif;?>
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.838
diff -u -r1.838 system.module
--- modules/system/system.module	8 Nov 2009 10:29:23 -0000	1.838
+++ modules/system/system.module	9 Nov 2009 15:50:34 -0000
@@ -217,10 +217,6 @@
       'title' => t('Access administration pages'),
       'description' => t('View the administration panel and browse the help system.'),
     ),
-    'access contextual links' => array(
-      'title' => t('Access contextual links'),
-      'description' => t('Use contextual links to perform actions related to elements on a page.'),
-    ),
     'access site in maintenance mode' => array(
       'title' => t('Access site in maintenance mode'),
       'description' => t('Log in when the site is in maintenance mode.'),
@@ -1056,19 +1052,6 @@
     ),
   );
 
-  // Contextual links.
-  $libraries['contextual-links'] = array(
-    'title' => 'Contextual links',
-    'website' => 'http://drupal.org/node/473268',
-    'version' => '1.0',
-    'js' => array(
-      'misc/contextual_links.js' => array(),
-    ),
-    'css' => array(
-      'misc/contextual_links.css' => array(),
-    ),
-  );
-
   // Vertical Tabs.
   $libraries['vertical-tabs'] = array(
     'title' => 'Vertical Tabs',
@@ -3531,105 +3514,3 @@
   return drupal_render_children($variables['form']);
 }
 
-/**
- * Template variable preprocessor for contextual links.
- *
- * @see system_build_contextual_links()
- */
-function system_preprocess(&$variables, $hook) {
-  static $hooks;
-
-  // Initialize the $contextual_links template variable.
-  $variables['contextual_links'] = array();
-
-  // Nothing to do here if the user is not permitted to access contextual links.
-  if (!user_access('access contextual links')) {
-    return;
-  }
-
-  if (!isset($hooks)) {
-    $hooks = theme_get_registry();
-  }
-
-  // Determine the primary theme function argument.
-  if (isset($hooks[$hook]['variables'])) {
-    $keys = array_keys($hooks[$hook]['variables']);
-    $key = $keys[0];
-  }
-  else {
-    $key = $hooks[$hook]['render element'];
-  }
-  if (isset($variables[$key])) {
-    $element = $variables[$key];
-  }
-
-  if (isset($element) && is_array($element) && !empty($element['#contextual_links'])) {
-    $variables['contextual_links'] = system_build_contextual_links($element);
-    if (!empty($variables['contextual_links'])) {
-      $variables['classes_array'][] = 'contextual-links-region';
-    }
-  }
-}
-
-/**
- * Build a renderable array for contextual links.
- *
- * @param $element
- *   A renderable array containing a #contextual_links property, which is a
- *   keyed array. Each key is the name of the implementing module, and each
- *   value is an array that forms the function arguments for
- *   menu_contextual_links(). For example:
- *   @code
- *     array('#contextual_links' => array(
- *       'block' => array('admin/structure/block/manage', array('system', 'navigation')),
- *       'menu' => array('admin/structure/menu/manage', array('navigation')),
- *     ))
- *   @endcode
- *
- * @return
- *   A renderable array representing contextual links.
- *
- * @see menu_contextual_links()
- */
-function system_build_contextual_links($element) {
-  static $destination;
-
-  // Retrieve contextual menu links.
-  $items = array();
-  foreach ($element['#contextual_links'] as $module => $args) {
-    $items += menu_contextual_links($module, $args[0], $args[1]);
-  }
-
-  // Transform contextual links into parameters suitable for theme_link().
-  if (!isset($destination)) {
-    $destination = drupal_get_destination();
-  }
-
-  $links = array();
-  foreach ($items as $class => $item) {
-    $class = drupal_html_class($class);
-    $links[$class] = array(
-      'title' => $item['title'],
-      'href' => $item['href'],
-    );
-    // @todo theme_links() should *really* use the same parameters as l()...
-    if (!isset($item['localized_options']['query'])) {
-      $item['localized_options']['query'] = array();
-    }
-    $item['localized_options']['query'] += $destination;
-    $links[$class] += $item['localized_options'];
-  }
-  $build = array();
-  if ($links) {
-    $build = array(
-      '#theme' => 'links',
-      '#links' => $links,
-      '#attributes' => array('class' => array('contextual-links')),
-      '#attached' => array(
-        'library' => array(array('system', 'contextual-links')),
-      ),
-    );
-  }
-  return $build;
-}
-
Index: misc/contextual_links.css
===================================================================
RCS file: misc/contextual_links.css
diff -N misc/contextual_links.css
--- misc/contextual_links.css	17 Oct 2009 05:50:27 -0000	1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,38 +0,0 @@
-/* $Id: contextual_links.css,v 1.1 2009/10/17 05:50:27 webchick Exp $ */
-
-/**
- * Contextual links regions.
- */
-.contextual-links-region {
-  outline: none;
-  position: relative;
-}
-.contextual-links-region-active {
-  outline: #000 dashed 1px;
-}
-
-/**
- * Contextual links.
- */
-ul.contextual-links {
-  float: right;
-  font-size: 90%;
-  margin: 0;
-  padding: 0;
-}
-ul.contextual-links li {
-  border-left: 1px solid #ccc;
-  display: inline;
-  line-height: 100%;
-  list-style: none;
-  margin: 0 0 0 0.3em;
-  padding: 0 0 0 0.6em;
-}
-ul.contextual-links li.first {
-  border-left: 0;
-  margin: 0;
-  padding: 0;
-}
-ul.contextual-links li a {
-  text-decoration: none;
-}
Index: misc/contextual_links.js
===================================================================
RCS file: misc/contextual_links.js
diff -N misc/contextual_links.js
--- misc/contextual_links.js	17 Oct 2009 05:50:27 -0000	1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,33 +0,0 @@
-// $Id: contextual_links.js,v 1.1 2009/10/17 05:50:27 webchick Exp $
-(function ($) {
-
-Drupal.contextualLinks = Drupal.contextualLinks || {};
-
-/**
- * Attach outline behavior for regions associated with contextual links.
- */
-Drupal.behaviors.contextualLinks = {
-  attach: function (context) {
-    $('ul.contextual-links', context).once('contextual-links', function () {
-      $(this).hover(Drupal.contextualLinks.hover, Drupal.contextualLinks.hoverOut);
-    });
-  }
-};
-
-/**
- * Enables outline for the region contextual links are associated with.
- */
-Drupal.contextualLinks.hover = function () {
-  $(this).addClass('contextual-links-link-active')
-    .closest('.contextual-links-region').addClass('contextual-links-region-active');
-};
-
-/**
- * Disables outline for the region contextual links are associated with.
- */
-Drupal.contextualLinks.hoverOut = function () {
-  $(this).removeClass('contextual-links-link-active')
-    .closest('.contextual-links-region').removeClass('contextual-links-region-active');
-};
-
-})(jQuery);
Index: modules/contextual_links/contextual_links.css
===================================================================
RCS file: modules/contextual_links/contextual_links.css
diff -N modules/contextual_links/contextual_links.css
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/contextual_links/contextual_links.css	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,38 @@
+/* $Id$ */
+
+/**
+ * Contextual links regions.
+ */
+.contextual-links-region {
+  outline: none;
+  position: relative;
+}
+.contextual-links-region-active {
+  outline: #000 dashed 1px;
+}
+
+/**
+ * Contextual links.
+ */
+ul.contextual-links {
+  float: right;
+  font-size: 90%;
+  margin: 0;
+  padding: 0;
+}
+ul.contextual-links li {
+  border-left: 1px solid #ccc;
+  display: inline;
+  line-height: 100%;
+  list-style: none;
+  margin: 0 0 0 0.3em;
+  padding: 0 0 0 0.6em;
+}
+ul.contextual-links li.first {
+  border-left: 0;
+  margin: 0;
+  padding: 0;
+}
+ul.contextual-links li a {
+  text-decoration: none;
+}
Index: modules/contextual_links/contextual_links.js
===================================================================
RCS file: modules/contextual_links/contextual_links.js
diff -N modules/contextual_links/contextual_links.js
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/contextual_links/contextual_links.js	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,33 @@
+// $Id$
+(function ($) {
+
+Drupal.contextualLinks = Drupal.contextualLinks || {};
+
+/**
+ * Attach outline behavior for regions associated with contextual links.
+ */
+Drupal.behaviors.contextualLinks = {
+  attach: function (context) {
+    $('ul.contextual-links', context).once('contextual-links', function () {
+      $(this).hover(Drupal.contextualLinks.hover, Drupal.contextualLinks.hoverOut);
+    });
+  }
+};
+
+/**
+ * Enables outline for the region contextual links are associated with.
+ */
+Drupal.contextualLinks.hover = function () {
+  $(this).addClass('contextual-links-link-active')
+    .closest('.contextual-links-region').addClass('contextual-links-region-active');
+};
+
+/**
+ * Disables outline for the region contextual links are associated with.
+ */
+Drupal.contextualLinks.hoverOut = function () {
+  $(this).removeClass('contextual-links-link-active')
+    .closest('.contextual-links-region').removeClass('contextual-links-region-active');
+};
+
+})(jQuery);
Index: modules/contextual_links/contextual_links.info
===================================================================
RCS file: modules/contextual_links/contextual_links.info
diff -N modules/contextual_links/contextual_links.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/contextual_links/contextual_links.info	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,7 @@
+; $Id$
+name = Contextual links
+description = Allows to use contextual links to perform actions related to elements on a page.
+package = Core
+version = VERSION
+core = 7.x
+files[] = contextual_links.module
Index: modules/contextual_links/contextual_links.module
===================================================================
RCS file: modules/contextual_links/contextual_links.module
diff -N modules/contextual_links/contextual_links.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/contextual_links/contextual_links.module	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,141 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Adds contextual links to perform actions related to elements on a page.
+ */
+
+/**
+ * Implement hook_permission().
+ */
+function contextual_links_permission() {
+  return array(
+    'access contextual links' => array(
+      'title' => t('Access contextual links'),
+      'description' => t('Use contextual links to perform actions related to elements on a page.'),
+    ),
+  );
+}
+
+/**
+ * Implementation of hook_library().
+ */
+function contextual_links_library() {
+  $path = drupal_get_path('module', 'contextual_links');
+  $libraries['contextual-links'] = array(
+    'title' => 'Contextual links',
+    'website' => 'http://drupal.org/node/473268',
+    'version' => '1.0',
+    'js' => array(
+      $path . '/contextual_links.js' => array(),
+    ),
+    'css' => array(
+      $path . '/contextual_links.css' => array(),
+    ),
+  );
+  return $libraries;
+}
+
+/**
+ * Template variable preprocessor for contextual links.
+ *
+ * @see contextual_links_build_links()
+ */
+function contextual_links_preprocess(&$variables, $hook) {
+  static $hooks;
+
+  // Initialize the $contextual_links template variable.
+  $variables['contextual_links'] = array();
+
+  // Nothing to do here if the user is not permitted to access contextual links.
+  if (!user_access('access contextual links')) {
+    return;
+  }
+
+  if (!isset($hooks)) {
+    $hooks = theme_get_registry();
+  }
+
+  // Determine the primary theme function argument.
+  if (isset($hooks[$hook]['variables'])) {
+    $keys = array_keys($hooks[$hook]['variables']);
+    $key = $keys[0];
+  }
+  else {
+    $key = $hooks[$hook]['render element'];
+  }
+  if (isset($variables[$key])) {
+    $element = $variables[$key];
+  }
+
+  if (isset($element) && is_array($element) && !empty($element['#contextual_links'])) {
+    $variables['contextual_links'] = contextual_links_build_links($element);
+    if (!empty($variables['contextual_links'])) {
+      $variables['classes_array'][] = 'contextual-links-region';
+    }
+  }
+}
+
+/**
+ * Build a renderable array for contextual links.
+ *
+ * @param $element
+ *   A renderable array containing a #contextual_links property, which is a
+ *   keyed array. Each key is the name of the implementing module, and each
+ *   value is an array that forms the function arguments for
+ *   menu_contextual_links(). For example:
+ *   @code
+ *     array('#contextual_links' => array(
+ *       'block' => array('admin/structure/block/manage', array('system', 'navigation')),
+ *       'menu' => array('admin/structure/menu/manage', array('navigation')),
+ *     ))
+ *   @endcode
+ *
+ * @return
+ *   A renderable array representing contextual links.
+ *
+ * @see menu_contextual_links()
+ */
+function contextual_links_build_links($element) {
+  static $destination;
+
+  // Retrieve contextual menu links.
+  $items = array();
+  foreach ($element['#contextual_links'] as $module => $args) {
+    $items += menu_contextual_links($module, $args[0], $args[1]);
+  }
+
+  // Transform contextual links into parameters suitable for theme_link().
+  if (!isset($destination)) {
+    $destination = drupal_get_destination();
+  }
+
+  $links = array();
+  foreach ($items as $class => $item) {
+    $class = drupal_html_class($class);
+    $links[$class] = array(
+      'title' => $item['title'],
+      'href' => $item['href'],
+    );
+    // @todo theme_links() should *really* use the same parameters as l()...
+    if (!isset($item['localized_options']['query'])) {
+      $item['localized_options']['query'] = array();
+    }
+    $item['localized_options']['query'] += $destination;
+    $links[$class] += $item['localized_options'];
+  }
+  $build = array();
+  if ($links) {
+    $build = array(
+      '#theme' => 'links',
+      '#links' => $links,
+      '#attributes' => array('class' => array('contextual-links')),
+      '#attached' => array(
+        'library' => array(array('contextual_links', 'contextual-links')),
+      ),
+    );
+  }
+  return $build;
+}
+
