<!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" />
<title>[25396] trunk/src: Fix wp_guess_url() to work in every scenario I could find, allows us to use it to determine the correct path to the WordPress Site URL before installation for install.php and setup-config.php redirects.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { 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 #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#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>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/25396">25396</a></dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2013-09-12 06:56:20 +0000 (Thu, 12 Sep 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>Fix wp_guess_url() to work in every scenario I could find, allows us to use it to determine the correct path to the WordPress Site URL before installation for install.php and setup-config.php redirects. Fixes <a href="http://core.trac.wordpress.org/ticket/24480">#24480</a> Fixes <a href="http://core.trac.wordpress.org/ticket/16884">#16884</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminsetupconfigphp">trunk/src/wp-admin/setup-config.php</a></li>
<li><a href="#trunksrcwpincludesfunctionsphp">trunk/src/wp-includes/functions.php</a></li>
<li><a href="#trunksrcwpincludesloadphp">trunk/src/wp-includes/load.php</a></li>
<li><a href="#trunksrcwploadphp">trunk/src/wp-load.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminsetupconfigphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/setup-config.php (25395 => 25396)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/setup-config.php 2013-09-12 06:46:35 UTC (rev 25395)
+++ trunk/src/wp-admin/setup-config.php 2013-09-12 06:56:20 UTC (rev 25396)
</span><span class="lines">@@ -55,6 +55,9 @@
</span><span class="cx"> // Turn register_globals off.
</span><span class="cx"> wp_unregister_GLOBALS();
</span><span class="cx">
</span><ins>+// Standardize $_SERVER variables across setups.
+wp_fix_server_vars();
+
</ins><span class="cx"> require_once(ABSPATH . WPINC . '/compat.php');
</span><span class="cx"> require_once(ABSPATH . WPINC . '/class-wp-error.php');
</span><span class="cx"> require_once(ABSPATH . WPINC . '/formatting.php');
</span><span class="lines">@@ -198,12 +201,11 @@
</span><span class="cx"> if ( ! $no_api ) {
</span><span class="cx"> require_once( ABSPATH . WPINC . '/class-http.php' );
</span><span class="cx"> require_once( ABSPATH . WPINC . '/http.php' );
</span><del>- wp_fix_server_vars();
</del><span class="cx"> /**#@+
</span><span class="cx"> * @ignore
</span><span class="cx"> */
</span><span class="cx"> function get_bloginfo() {
</span><del>- return ( ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . str_replace( $_SERVER['PHP_SELF'], '/wp-admin/setup-config.php', '' ) );
</del><ins>+ return wp_guess_url();
</ins><span class="cx"> }
</span><span class="cx"> /**#@-*/
</span><span class="cx"> $secret_keys = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
</span></span></pre></div>
<a id="trunksrcwpincludesfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/functions.php (25395 => 25396)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/functions.php 2013-09-12 06:46:35 UTC (rev 25395)
+++ trunk/src/wp-includes/functions.php 2013-09-12 06:56:20 UTC (rev 25396)
</span><span class="lines">@@ -3231,8 +3231,31 @@
</span><span class="cx"> if ( defined('WP_SITEURL') && '' != WP_SITEURL ) {
</span><span class="cx"> $url = WP_SITEURL;
</span><span class="cx"> } else {
</span><ins>+ // The request is for the admin
+ if ( strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) !== false || strpos( $_SERVER['REQUEST_URI'], 'wp-login.php' ) !== false ) {
+ $path = preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', $_SERVER['REQUEST_URI'] );
+
+ // The request is for a file in ABSPATH
+ } elseif ( dirname( $_SERVER['SCRIPT_FILENAME'] ) . '/' == ABSPATH ) {
+ // Strip off any file/query params in the path
+ $path = preg_replace( '#/[^/]*$#i', '', $_SERVER['PHP_SELF'] );
+
+ } else {
+ if ( false !== strpos( $_SERVER['SCRIPT_FILENAME'], ABSPATH ) ) {
+ // Request is hitting a file inside ABSPATH
+ $directory = str_replace( ABSPATH, '', dirname( $_SERVER['SCRIPT_FILENAME'] ) );
+ // Strip off the sub directory, and any file/query paramss
+ $path = preg_replace( '#/' . preg_quote( $directory, '#' ) . '/[^/]*$#i', '' , $_SERVER['REQUEST_URI'] );
+ } else {
+ // Request is hitting a file above ABSPATH
+ $subdirectory = str_replace( dirname( $_SERVER['SCRIPT_FILENAME'] ), '', ABSPATH );
+ // Strip off any file/query params from the path, appending the sub directory to the install
+ $path = preg_replace( '#/[^/]*$#i', '' , $_SERVER['REQUEST_URI'] ) . $subdirectory;
+ }
+ }
+
</ins><span class="cx"> $schema = is_ssl() ? 'https://' : 'http://'; // set_url_scheme() is not defined yet
</span><del>- $url = preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
</del><ins>+ $url = $schema . $_SERVER['HTTP_HOST'] . $path;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> return rtrim($url, '/');
</span></span></pre></div>
<a id="trunksrcwpincludesloadphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/load.php (25395 => 25396)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/load.php 2013-09-12 06:46:35 UTC (rev 25395)
+++ trunk/src/wp-includes/load.php 2013-09-12 06:56:20 UTC (rev 25396)
</span><span class="lines">@@ -445,12 +445,12 @@
</span><span class="cx"> if ( ! is_blog_installed() && ! defined( 'WP_INSTALLING' ) )
</span><span class="cx"> wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) );
</span><span class="cx"> } elseif ( ! is_blog_installed() && false === strpos( $_SERVER['PHP_SELF'], 'install.php' ) && !defined( 'WP_INSTALLING' ) ) {
</span><ins>+ require( ABSPATH . WPINC . '/kses.php' );
+ require( ABSPATH . WPINC . '/pluggable.php' );
+ require( ABSPATH . WPINC . '/formatting.php' );
</ins><span class="cx">
</span><span class="cx"> $link = wp_guess_url() . '/wp-admin/install.php';
</span><span class="cx">
</span><del>- require( ABSPATH . WPINC . '/kses.php' );
- require( ABSPATH . WPINC . '/pluggable.php' );
- require( ABSPATH . WPINC . '/formatting.php' );
</del><span class="cx"> wp_redirect( $link );
</span><span class="cx"> die();
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunksrcwploadphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-load.php (25395 => 25396)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-load.php 2013-09-12 06:46:35 UTC (rev 25395)
+++ trunk/src/wp-load.php 2013-09-12 06:56:20 UTC (rev 25396)
</span><span class="lines">@@ -50,15 +50,7 @@
</span><span class="cx">
</span><span class="cx"> require_once( ABSPATH . WPINC . '/functions.php' );
</span><span class="cx">
</span><del>- // Set a path for the link to the installer
- if ( strpos( $_SERVER['PHP_SELF'], 'wp-admin' ) !== false ) {
- $path = 'setup-config.php';
- } elseif ( file_exists( dirname( $_SERVER['SCRIPT_FILENAME'] ) . '/wp-admin/setup-config.php' ) ) {
- $path = 'wp-admin/setup-config.php';
- } else {
- // WordPress files are in a sub directory, and the user is hitting the index.php in the parent directory
- $path = str_replace( dirname( $_SERVER['SCRIPT_FILENAME'] ) . '/', '', dirname( __FILE__ ) . '/wp-admin/setup-config.php' );
- }
</del><ins>+ $path = wp_guess_url() . '/wp-admin/setup-config.php';
</ins><span class="cx">
</span><span class="cx"> // Die with an error message
</span><span class="cx"> $die = __( "There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started." ) . '</p>';
</span></span></pre>
</div>
</div>
</body>
</html>