<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[13299] trunk/wp-includes: Deprecate clean_url() for esc_url().</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13299">13299</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2010-02-22 18:25:51 +0000 (Mon, 22 Feb 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Deprecate clean_url() for esc_url(). Fixes <a href="http://trac.wordpress.org/ticket/12309">#12309</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesdeprecatedphp">trunk/wp-includes/deprecated.php</a></li>
<li><a href="#trunkwpincludesformattingphp">trunk/wp-includes/formatting.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesdeprecatedphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/deprecated.php (13298 => 13299)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/deprecated.php        2010-02-22 18:16:34 UTC (rev 13298)
+++ trunk/wp-includes/deprecated.php        2010-02-22 18:25:51 UTC (rev 13299)
</span><span class="lines">@@ -2074,6 +2074,31 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * Checks and cleans a URL.
+ *
+ * A number of characters are removed from the URL. If the URL is for displaying
+ * (the default behaviour) amperstands are also replaced. The 'clean_url' filter
+ * is applied to the returned cleaned URL.
+ *
+ * @since 1.2.0
+ * @deprecated 3.0.0
+ * @deprecated Use esc_url()
+ * @see Alias for esc_url()
+ *
+ * @param string $url The URL to be cleaned.
+ * @param array $protocols Optional. An array of acceptable protocols.
+ * @param string $context Optional. How the URL will be used. Default is 'display'.
+ * @return string The cleaned $url after the 'clean_url' filter is applied.
+ */
+function clean_url( $url, $protocols = null, $context = 'display' ) {
+        if ( $context == 'db' )
+                _deprecated_function( 'clean_url( $context = \'db\' )', '3.0', 'esc_url_raw()' );
+        else
+                _deprecated_function( __FUNCTION__, '3.0', 'esc_url()' );
+        return esc_url( $url, $protocols, $context );
+}
+
+/**
</ins><span class="cx"> * Escape single quotes, specialchar double quotes, and fix line endings.
</span><span class="cx"> *
</span><span class="cx"> * The filter 'js_escape' is also applied by esc_js()
</span></span></pre></div>
<a id="trunkwpincludesformattingphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/formatting.php (13298 => 13299)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/formatting.php        2010-02-22 18:16:34 UTC (rev 13298)
+++ trunk/wp-includes/formatting.php        2010-02-22 18:25:51 UTC (rev 13299)
</span><span class="lines">@@ -2132,53 +2132,6 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Checks and cleans a URL.
- *
- * A number of characters are removed from the URL. If the URL is for displaying
- * (the default behaviour) amperstands are also replaced. The 'clean_url' filter
- * is applied to the returned cleaned URL.
- *
- * @since 1.2.0
- * @uses wp_kses_bad_protocol() To only permit protocols in the URL set
- *                via $protocols or the common ones set in the function.
- *
- * @param string $url The URL to be cleaned.
- * @param array $protocols Optional. An array of acceptable protocols.
- *                Defaults to 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet' if not set.
- * @param string $context Optional. How the URL will be used. Default is 'display'.
- * @return string The cleaned $url after the 'clean_url' filter is applied.
- */
-function clean_url( $url, $protocols = null, $context = 'display' ) {
-        $original_url = $url;
-
-        if ('' == $url) return $url;
-        $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]|i', '', $url);
-        $strip = array('%0d', '%0a', '%0D', '%0A');
-        $url = _deep_replace($strip, $url);
-        $url = str_replace(';//', '://', $url);
-        /* If the URL doesn't appear to contain a scheme, we
-         * presume it needs http:// appended (unless a relative
-         * link starting with / or a php file).
-         */
-        if ( strpos($url, ':') === false &&
-                substr( $url, 0, 1 ) != '/' && substr( $url, 0, 1 ) != '#' && !preg_match('/^[a-z0-9-]+?\.php/i', $url) )
-                $url = 'http://' . $url;
-
-        // Replace ampersands and single quotes only when displaying.
-        if ( 'display' == $context ) {
-                $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&#038;$1', $url);
-                $url = str_replace( "'", '&#039;', $url );
-        }
-
-        if ( !is_array($protocols) )
-                $protocols = array('http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet');
-        if ( wp_kses_bad_protocol( $url, $protocols ) != $url )
-                return '';
-
-        return apply_filters('clean_url', $url, $original_url, $context);
-}
-
-/**
</del><span class="cx"> * Perform a deep string replace operation to ensure the values in $search are no longer present
</span><span class="cx"> *
</span><span class="cx"> * Repeats the replacement operation until it no longer replaces anything so as to remove "nested" values
</span><span class="lines">@@ -2229,31 +2182,57 @@
</span><span class="cx"> * is applied to the returned cleaned URL.
</span><span class="cx"> *
</span><span class="cx"> * @since 2.8.0
</span><del>- * @uses clean_url()
</del><span class="cx"> * @uses wp_kses_bad_protocol() To only permit protocols in the URL set
</span><span class="cx"> *                via $protocols or the common ones set in the function.
</span><span class="cx"> *
</span><span class="cx"> * @param string $url The URL to be cleaned.
</span><span class="cx"> * @param array $protocols Optional. An array of acceptable protocols.
</span><span class="cx"> *                Defaults to 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet' if not set.
</span><ins>+ * @param string $_context Private. Use esc_url_raw() for database usage.
</ins><span class="cx"> * @return string The cleaned $url after the 'clean_url' filter is applied.
</span><span class="cx"> */
</span><del>-function esc_url( $url, $protocols = null ) {
-        return clean_url( $url, $protocols, 'display' );
</del><ins>+function esc_url( $url, $protocols = null, $_context = 'display' ) {
+        $original_url = $url;
+
+        if ('' == $url) return $url;
+        $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]|i', '', $url);
+        $strip = array('%0d', '%0a', '%0D', '%0A');
+        $url = _deep_replace($strip, $url);
+        $url = str_replace(';//', '://', $url);
+        /* If the URL doesn't appear to contain a scheme, we
+         * presume it needs http:// appended (unless a relative
+         * link starting with / or a php file).
+         */
+        if ( strpos($url, ':') === false &&
+                substr( $url, 0, 1 ) != '/' && substr( $url, 0, 1 ) != '#' && !preg_match('/^[a-z0-9-]+?\.php/i', $url) )
+                $url = 'http://' . $url;
+
+        // Replace ampersands and single quotes only when displaying.
+        if ( 'display' == $_context ) {
+                $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&#038;$1', $url);
+                $url = str_replace( "'", '&#039;', $url );
+        }
+
+        if ( !is_array($protocols) )
+                $protocols = array('http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet');
+        if ( wp_kses_bad_protocol( $url, $protocols ) != $url )
+                return '';
+
+        return apply_filters('clean_url', $url, $original_url, $_context);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Performs esc_url() for database usage.
</span><span class="cx"> *
</span><span class="cx"> * @since 2.8.0
</span><del>- * @uses clean_url()
</del><ins>+ * @uses esc_url()
</ins><span class="cx"> *
</span><span class="cx"> * @param string $url The URL to be cleaned.
</span><span class="cx"> * @param array $protocols An array of acceptable protocols.
</span><span class="cx"> * @return string The cleaned URL.
</span><span class="cx"> */
</span><span class="cx"> function esc_url_raw( $url, $protocols = null ) {
</span><del>-        return clean_url( $url, $protocols, 'db' );
</del><ins>+        return esc_url( $url, $protocols, 'db' );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span></span></pre>
</div>
</div>
</body>
</html>