From 441b63accda0538e7257eebabc9796df06630a80 Mon Sep 17 00:00:00 2001
From: Steven Wittens <steven@10.no-reply.drupal.org>
Date: Thu, 12 Aug 2004 15:12:26 +0000
Subject: [PATCH] Moving all legacy handlers into legacy.module.

---
 database/updates.inc         |   7 +-
 modules/filter.module        |  72 +--------------
 modules/filter/filter.module |  72 +--------------
 modules/legacy.module        | 164 +++++++++++++++++++++++++++++++++++
 modules/legacy/legacy.module | 164 +++++++++++++++++++++++++++++++++++
 modules/node.module          |  10 ---
 modules/node/node.module     |  10 ---
 7 files changed, 336 insertions(+), 163 deletions(-)
 create mode 100644 modules/legacy.module
 create mode 100644 modules/legacy/legacy.module

diff --git a/database/updates.inc b/database/updates.inc
index a2d5400dfb42..21064d78283f 100644
--- a/database/updates.inc
+++ b/database/updates.inc
@@ -72,7 +72,8 @@
   "2004-08-07" => "update_98",
   "2004-08-09" => "update_99",
   "2004-08-10" => "update_100",
-  "2004-08-11" => "update_101"
+  "2004-08-11" => "update_101",
+  "2004-08-12" => "update_102"
 );
 
 function update_32() {
@@ -1545,6 +1546,10 @@ function update_101() {
   return $ret;
 }
 
+function update_102() {
+  INSERT INTO {system} (filename, name, type, description, status, throttle, bootstrap) VALUES ('modules/legacy.module', 'legacy', 'module', '', 1, 0, 0);
+}
+
 function update_sql($sql) {
   $edit = $_POST["edit"];
   $result = db_query($sql);
diff --git a/modules/filter.module b/modules/filter.module
index ad6e00d13bd9..6e779546ba7e 100644
--- a/modules/filter.module
+++ b/modules/filter.module
@@ -768,15 +768,13 @@ function theme_filter_tips($tips, $long = false, $extra = '') {
  *     Validates user-supplied HTML, transforming it as necessary.
  * - PHP evaluator:
  *     Executes PHP code.
- * - Legacy filter:
- *     Handles URL upgrades from Drupal 4.1.
  * - Line break converter:
  *     Converts newlines into paragraph and break tags.
  */
 function filter_filter($op, $delta = 0, $format = -1, $text = '') {
   switch ($op) {
     case 'list':
-      return array(0 => t('HTML filter'), 1 => t('PHP evaluator'), 2 => t('Legacy filter'), 3 => t('Line break converter'));
+      return array(0 => t('HTML filter'), 1 => t('PHP evaluator'), 3 => t('Line break converter'));
 
     case 'no cache':
       return $delta == 1; // No caching for the PHP evaluator.
@@ -787,8 +785,6 @@ function filter_filter($op, $delta = 0, $format = -1, $text = '') {
           return t('Allows you to restrict if users can post HTML and which tags to filter out.');
         case 1:
           return t('Runs a piece of PHP code. The usage of this filter should be restricted to administrators only!');
-        case 2:
-          return t('Replaces URLs from Drupal 4.1 (and lower) with updated equivalents.');
         case 3:
           return t('Converts line breaks into HTML (i.e. &lt;br&gt; and &lt;p&gt; tags).');
         default:
@@ -801,8 +797,6 @@ function filter_filter($op, $delta = 0, $format = -1, $text = '') {
           return _filter_html($text, $format);
         case 1:
           return drupal_eval($text);
-        case 2:
-          return _filter_old_urls($text, $format);
         case 3:
           return _filter_autop($text);
         default:
@@ -855,70 +849,6 @@ function _filter_html($text, $format) {
   return trim($text);
 }
 
-/**
- * Rewrite legacy URLs.
- *
- * This is a *temporary* filter to rewrite old-style URLs to new-style
- * URLs (clean URLs).  Currently, URLs are being rewritten dynamically
- * (ie. "on output"), however when these rewrite rules have been tested
- * enough, we will use them to permanently rewrite the links in node
- * and comment bodies.
- */
-function _filter_old_urls($text) {
-  if (!variable_get('rewrite_old_urls', 0)) {
-    return $text;
-  }
-
-  global $base_url;
-
-  $end = substr($base_url, 12);
-
-  if (variable_get('clean_url', '0') == '0') {
-    // Relative URLs:
-
-    // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
-    $text = eregi_replace("\"(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "\"?q=\\1/view/\\2/\\4", $text);
-
-    // rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
-    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2/\\4/\\6" , $text);
-    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2/\\4", $text);
-    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2", $text);
-
-    // Absolute URLs:
-
-    // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
-    $text = eregi_replace("$end/(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "$end/?q=\\1/view/\\2/\\4", $text);
-
-    // rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
-    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/?q=\\2/\\4/\\6" , $text);
-    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/?q=\\2/\\4", $text);
-    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"$end/?q=\\2", $text);
-  }
-  else {
-    // Relative URLs:
-
-    // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
-    $text = eregi_replace("\"(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "\"\\1/view/\\2/\\4", $text);
-
-    // rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
-    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2/\\4/\\6", $text);
-    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2/\\4", $text);
-    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2", $text);
-
-    // Absolute URLs:
-
-    // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
-    $text = eregi_replace("$end/(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "$end/\\1/view/\\2/\\4", $text);
-
-    // rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
-    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/\\2/\\4/\\6", $text);
-    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/\\2/\\4", $text);
-    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/\\2", $text);
-  }
-
-  return $text;
-}
-
 /**
  * Convert line breaks into <p> and <br> in an intelligent fashion.
  * From: http://photomatt.net/scripts/autop
diff --git a/modules/filter/filter.module b/modules/filter/filter.module
index ad6e00d13bd9..6e779546ba7e 100644
--- a/modules/filter/filter.module
+++ b/modules/filter/filter.module
@@ -768,15 +768,13 @@ function theme_filter_tips($tips, $long = false, $extra = '') {
  *     Validates user-supplied HTML, transforming it as necessary.
  * - PHP evaluator:
  *     Executes PHP code.
- * - Legacy filter:
- *     Handles URL upgrades from Drupal 4.1.
  * - Line break converter:
  *     Converts newlines into paragraph and break tags.
  */
 function filter_filter($op, $delta = 0, $format = -1, $text = '') {
   switch ($op) {
     case 'list':
-      return array(0 => t('HTML filter'), 1 => t('PHP evaluator'), 2 => t('Legacy filter'), 3 => t('Line break converter'));
+      return array(0 => t('HTML filter'), 1 => t('PHP evaluator'), 3 => t('Line break converter'));
 
     case 'no cache':
       return $delta == 1; // No caching for the PHP evaluator.
@@ -787,8 +785,6 @@ function filter_filter($op, $delta = 0, $format = -1, $text = '') {
           return t('Allows you to restrict if users can post HTML and which tags to filter out.');
         case 1:
           return t('Runs a piece of PHP code. The usage of this filter should be restricted to administrators only!');
-        case 2:
-          return t('Replaces URLs from Drupal 4.1 (and lower) with updated equivalents.');
         case 3:
           return t('Converts line breaks into HTML (i.e. &lt;br&gt; and &lt;p&gt; tags).');
         default:
@@ -801,8 +797,6 @@ function filter_filter($op, $delta = 0, $format = -1, $text = '') {
           return _filter_html($text, $format);
         case 1:
           return drupal_eval($text);
-        case 2:
-          return _filter_old_urls($text, $format);
         case 3:
           return _filter_autop($text);
         default:
@@ -855,70 +849,6 @@ function _filter_html($text, $format) {
   return trim($text);
 }
 
-/**
- * Rewrite legacy URLs.
- *
- * This is a *temporary* filter to rewrite old-style URLs to new-style
- * URLs (clean URLs).  Currently, URLs are being rewritten dynamically
- * (ie. "on output"), however when these rewrite rules have been tested
- * enough, we will use them to permanently rewrite the links in node
- * and comment bodies.
- */
-function _filter_old_urls($text) {
-  if (!variable_get('rewrite_old_urls', 0)) {
-    return $text;
-  }
-
-  global $base_url;
-
-  $end = substr($base_url, 12);
-
-  if (variable_get('clean_url', '0') == '0') {
-    // Relative URLs:
-
-    // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
-    $text = eregi_replace("\"(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "\"?q=\\1/view/\\2/\\4", $text);
-
-    // rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
-    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2/\\4/\\6" , $text);
-    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2/\\4", $text);
-    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2", $text);
-
-    // Absolute URLs:
-
-    // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
-    $text = eregi_replace("$end/(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "$end/?q=\\1/view/\\2/\\4", $text);
-
-    // rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
-    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/?q=\\2/\\4/\\6" , $text);
-    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/?q=\\2/\\4", $text);
-    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"$end/?q=\\2", $text);
-  }
-  else {
-    // Relative URLs:
-
-    // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
-    $text = eregi_replace("\"(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "\"\\1/view/\\2/\\4", $text);
-
-    // rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
-    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2/\\4/\\6", $text);
-    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2/\\4", $text);
-    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2", $text);
-
-    // Absolute URLs:
-
-    // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
-    $text = eregi_replace("$end/(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "$end/\\1/view/\\2/\\4", $text);
-
-    // rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
-    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/\\2/\\4/\\6", $text);
-    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/\\2/\\4", $text);
-    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/\\2", $text);
-  }
-
-  return $text;
-}
-
 /**
  * Convert line breaks into <p> and <br> in an intelligent fashion.
  * From: http://photomatt.net/scripts/autop
diff --git a/modules/legacy.module b/modules/legacy.module
new file mode 100644
index 000000000000..662eaf81f61a
--- /dev/null
+++ b/modules/legacy.module
@@ -0,0 +1,164 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Provides legacy handlers for upgrades from older Drupal installations.
+ */
+
+/**
+ * Implementation of hook_help().
+ */
+function legacy_help($section) {
+  switch ($section) {
+    case 'admin/modules#description':
+      return t('Provides legacy handlers for upgrades from older Drupal installations.');
+  }
+}
+
+/**
+ * Implementation of hook_menu().
+ *
+ * Registers menu paths used in earlier Drupal versions.
+ */
+function legacy_menu() {
+  $items = array();
+
+  // Map "node/view/52" to "node/52".
+  $items[] = array('path' => 'node/view', 'title' => t('view'),
+    'callback' => 'drupal_goto',
+    'callback arguments' => array('node/'. arg(2), NULL, NULL),
+    'access' => TRUE, 'type' => MENU_CALLBACK);
+
+  // Map "book/view/52" to "node/52".
+  $items[] = array('path' => 'book/view', 'title' => t('view'),
+    'callback' => 'drupal_goto',
+    'callback arguments' => array('node/'. arg(2), NULL, NULL),
+    'access' => TRUE, 'type' => MENU_CALLBACK);
+
+  // Map "user/view/52" to "user/52".
+  $items[] = array('path' => 'user/view', 'title' => t('view'),
+    'callback' => 'drupal_goto',
+    'callback arguments' => array('user/'. arg(2), NULL, NULL),
+    'access' => TRUE, 'type' => MENU_CALLBACK);
+
+  // Map "taxonomy/page/or/52,97" to "taxonomy/term/52+97".
+  $items[] = array('path' => 'taxonomy/page', 'title' => t('taxonomy'),
+    'callback' => 'legacy_taxonomy_page',
+    'access' => TRUE, 'type' => MENU_CALLBACK);
+
+  // Map "taxonomy/feed/or/52,97" to "taxonomy/term/52+97/0/feed".
+  $items[] = array('path' => 'taxonomy/feed', 'title' => t('taxonomy'),
+    'callback' => 'legacy_taxonomy_feed',
+    'access' => TRUE, 'type' => MENU_CALLBACK);
+
+  return $items;
+}
+
+/**
+ * Menu callback; redirects users to new taxonomy page paths.
+ */
+function legacy_taxonomy_page($operation = 'or', $str_tids = '') {
+  if ($operation == 'or') {
+    $str_tids = str_replace(',', '+', $str_tids);
+  }
+  drupal_goto('taxonomy/term/'. $str_tids);
+}
+
+/**
+ * Menu callback; redirects users to new taxonomy feed paths.
+ */
+function legacy_taxonomy_feed($operation = 'or', $str_tids = '') {
+  if ($operation == 'or') {
+    $str_tids = str_replace(',', '+', $str_tids);
+  }
+  drupal_goto('taxonomy/term/'. $str_tids .'/0/feed');
+}
+
+/**
+ * Implementation of hook_filter(). Handles URL upgrades from Drupal 4.1.
+ */
+function legacy_filter($op, $delta = 0, $format = -1, $text = '') {
+  switch ($op) {
+    case 'list':
+      return array(t('Legacy filter'));
+
+    case 'description':
+      return t('Replaces URLs from Drupal 4.1 (and lower) with updated equivalents.');
+
+    case 'process':
+      return _legacy_filter_old_urls($text, $format);
+
+    case 'settings':
+      return;
+
+    default:
+      return $text;
+  }
+}
+
+/**
+ * Rewrite legacy URLs.
+ *
+ * This is a *temporary* filter to rewrite old-style URLs to new-style
+ * URLs (clean URLs).  Currently, URLs are being rewritten dynamically
+ * (ie. "on output"), however when these rewrite rules have been tested
+ * enough, we will use them to permanently rewrite the links in node
+ * and comment bodies.
+ */
+function _legacy_filter_old_urls($text) {
+  if (!variable_get('rewrite_old_urls', 0)) {
+    return $text;
+  }
+
+  global $base_url;
+
+  $end = substr($base_url, 12);
+
+  if (variable_get('clean_url', '0') == '0') {
+    // Relative URLs:
+
+    // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
+    $text = eregi_replace("\"(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "\"?q=\\1/view/\\2/\\4", $text);
+
+    // rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
+    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2/\\4/\\6" , $text);
+    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2/\\4", $text);
+    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2", $text);
+
+    // Absolute URLs:
+
+    // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
+    $text = eregi_replace("$end/(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "$end/?q=\\1/view/\\2/\\4", $text);
+
+    // rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
+    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/?q=\\2/\\4/\\6" , $text);
+    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/?q=\\2/\\4", $text);
+    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"$end/?q=\\2", $text);
+  }
+  else {
+    // Relative URLs:
+
+    // Rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
+    $text = eregi_replace("\"(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "\"\\1/view/\\2/\\4", $text);
+
+    // Rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
+    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2/\\4/\\6", $text);
+    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2/\\4", $text);
+    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2", $text);
+
+    // Absolute URLs:
+
+    // Rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
+    $text = eregi_replace("$end/(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "$end/\\1/view/\\2/\\4", $text);
+
+    // Rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
+    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/\\2/\\4/\\6", $text);
+    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/\\2/\\4", $text);
+    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/\\2", $text);
+  }
+
+  return $text;
+}
+
+?>
diff --git a/modules/legacy/legacy.module b/modules/legacy/legacy.module
new file mode 100644
index 000000000000..662eaf81f61a
--- /dev/null
+++ b/modules/legacy/legacy.module
@@ -0,0 +1,164 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Provides legacy handlers for upgrades from older Drupal installations.
+ */
+
+/**
+ * Implementation of hook_help().
+ */
+function legacy_help($section) {
+  switch ($section) {
+    case 'admin/modules#description':
+      return t('Provides legacy handlers for upgrades from older Drupal installations.');
+  }
+}
+
+/**
+ * Implementation of hook_menu().
+ *
+ * Registers menu paths used in earlier Drupal versions.
+ */
+function legacy_menu() {
+  $items = array();
+
+  // Map "node/view/52" to "node/52".
+  $items[] = array('path' => 'node/view', 'title' => t('view'),
+    'callback' => 'drupal_goto',
+    'callback arguments' => array('node/'. arg(2), NULL, NULL),
+    'access' => TRUE, 'type' => MENU_CALLBACK);
+
+  // Map "book/view/52" to "node/52".
+  $items[] = array('path' => 'book/view', 'title' => t('view'),
+    'callback' => 'drupal_goto',
+    'callback arguments' => array('node/'. arg(2), NULL, NULL),
+    'access' => TRUE, 'type' => MENU_CALLBACK);
+
+  // Map "user/view/52" to "user/52".
+  $items[] = array('path' => 'user/view', 'title' => t('view'),
+    'callback' => 'drupal_goto',
+    'callback arguments' => array('user/'. arg(2), NULL, NULL),
+    'access' => TRUE, 'type' => MENU_CALLBACK);
+
+  // Map "taxonomy/page/or/52,97" to "taxonomy/term/52+97".
+  $items[] = array('path' => 'taxonomy/page', 'title' => t('taxonomy'),
+    'callback' => 'legacy_taxonomy_page',
+    'access' => TRUE, 'type' => MENU_CALLBACK);
+
+  // Map "taxonomy/feed/or/52,97" to "taxonomy/term/52+97/0/feed".
+  $items[] = array('path' => 'taxonomy/feed', 'title' => t('taxonomy'),
+    'callback' => 'legacy_taxonomy_feed',
+    'access' => TRUE, 'type' => MENU_CALLBACK);
+
+  return $items;
+}
+
+/**
+ * Menu callback; redirects users to new taxonomy page paths.
+ */
+function legacy_taxonomy_page($operation = 'or', $str_tids = '') {
+  if ($operation == 'or') {
+    $str_tids = str_replace(',', '+', $str_tids);
+  }
+  drupal_goto('taxonomy/term/'. $str_tids);
+}
+
+/**
+ * Menu callback; redirects users to new taxonomy feed paths.
+ */
+function legacy_taxonomy_feed($operation = 'or', $str_tids = '') {
+  if ($operation == 'or') {
+    $str_tids = str_replace(',', '+', $str_tids);
+  }
+  drupal_goto('taxonomy/term/'. $str_tids .'/0/feed');
+}
+
+/**
+ * Implementation of hook_filter(). Handles URL upgrades from Drupal 4.1.
+ */
+function legacy_filter($op, $delta = 0, $format = -1, $text = '') {
+  switch ($op) {
+    case 'list':
+      return array(t('Legacy filter'));
+
+    case 'description':
+      return t('Replaces URLs from Drupal 4.1 (and lower) with updated equivalents.');
+
+    case 'process':
+      return _legacy_filter_old_urls($text, $format);
+
+    case 'settings':
+      return;
+
+    default:
+      return $text;
+  }
+}
+
+/**
+ * Rewrite legacy URLs.
+ *
+ * This is a *temporary* filter to rewrite old-style URLs to new-style
+ * URLs (clean URLs).  Currently, URLs are being rewritten dynamically
+ * (ie. "on output"), however when these rewrite rules have been tested
+ * enough, we will use them to permanently rewrite the links in node
+ * and comment bodies.
+ */
+function _legacy_filter_old_urls($text) {
+  if (!variable_get('rewrite_old_urls', 0)) {
+    return $text;
+  }
+
+  global $base_url;
+
+  $end = substr($base_url, 12);
+
+  if (variable_get('clean_url', '0') == '0') {
+    // Relative URLs:
+
+    // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
+    $text = eregi_replace("\"(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "\"?q=\\1/view/\\2/\\4", $text);
+
+    // rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
+    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2/\\4/\\6" , $text);
+    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2/\\4", $text);
+    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2", $text);
+
+    // Absolute URLs:
+
+    // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
+    $text = eregi_replace("$end/(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "$end/?q=\\1/view/\\2/\\4", $text);
+
+    // rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
+    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/?q=\\2/\\4/\\6" , $text);
+    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/?q=\\2/\\4", $text);
+    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"$end/?q=\\2", $text);
+  }
+  else {
+    // Relative URLs:
+
+    // Rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
+    $text = eregi_replace("\"(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "\"\\1/view/\\2/\\4", $text);
+
+    // Rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
+    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2/\\4/\\6", $text);
+    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2/\\4", $text);
+    $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2", $text);
+
+    // Absolute URLs:
+
+    // Rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
+    $text = eregi_replace("$end/(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "$end/\\1/view/\\2/\\4", $text);
+
+    // Rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
+    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/\\2/\\4/\\6", $text);
+    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/\\2/\\4", $text);
+    $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/\\2", $text);
+  }
+
+  return $text;
+}
+
+?>
diff --git a/modules/node.module b/modules/node.module
index f7ccc13f4708..f6e7c5869738 100644
--- a/modules/node.module
+++ b/modules/node.module
@@ -681,12 +681,6 @@ function node_menu() {
     }
   }
 
-  // Legacy handler for old "node/view/52" paths.
-  $items[] = array('path' => 'node/view', 'title' => t('view'),
-    'callback' => 'node_old_url',
-    'access' => user_access('access content'),
-    'type' => MENU_CALLBACK);
-
   return $items;
 }
 
@@ -1435,10 +1429,6 @@ function node_page_default() {
   return $output;
 }
 
-function node_old_url($nid = 0) {
-  drupal_goto("node/$nid");
-}
-
 /**
  * Menu callback; dispatches control to the appropriate operation handler.
  */
diff --git a/modules/node/node.module b/modules/node/node.module
index f7ccc13f4708..f6e7c5869738 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -681,12 +681,6 @@ function node_menu() {
     }
   }
 
-  // Legacy handler for old "node/view/52" paths.
-  $items[] = array('path' => 'node/view', 'title' => t('view'),
-    'callback' => 'node_old_url',
-    'access' => user_access('access content'),
-    'type' => MENU_CALLBACK);
-
   return $items;
 }
 
@@ -1435,10 +1429,6 @@ function node_page_default() {
   return $output;
 }
 
-function node_old_url($nid = 0) {
-  drupal_goto("node/$nid");
-}
-
 /**
  * Menu callback; dispatches control to the appropriate operation handler.
  */
-- 
GitLab