From aed615511178f53928f95993df9fae61a2c5a076 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 16 Nov 2006 22:57:58 +0000 Subject: [PATCH] * Detect CGI configurations where PATH_INFO is set up correctly. PHP config var cgi.fix_pathinfo isn't detectable through ini_get(), but we can find some side-effects. Only tested on lighttpd so far, hopefully right on Apache too! lighty documentation says you have to use the "broken-scriptfilename" => "enable" option on lighty fast-cgi config, plus set cgi.fix_pathinfo to make it work. I've found that cgi.fix_pathinfo is on by default in current PHP (tested 5.2.0), and I don't seem to have to change the defaults on lighty either. --- RELEASE-NOTES | 4 ++++ config/index.php | 37 +++++++++++++++++++++++++++++++----- includes/DefaultSettings.php | 15 +++++++++++++-- 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 458d4beef4..9454197e2f 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -186,6 +186,10 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 7932) Make sure that edit toolbar clears floats so it appears correctly. * (bug 6873) When viewing old revisions, add link to diff to current version. * (bug 3315) Allow rollback directly from history page. +* Detect CGI configurations where PATH_INFO is set up correctly. + PHP config var cgi.fix_pathinfo isn't detectable through ini_get(), but + we can find some side-effects. Only tested on lighttpd so far, hopefully + right on Apache too! == Languages updated == diff --git a/config/index.php b/config/index.php index f462524b01..515712e9ff 100644 --- a/config/index.php +++ b/config/index.php @@ -350,15 +350,29 @@ case "apache": case "apache2handler": print "ok, using pretty URLs (index.php/Page_Title)"; break; -default: - print "unknown; "; case "cgi": case "cgi-fcgi": + // For some reason cgi.fix_pathinfo isn't retrievable via ini_get() + if( isset( $_SERVER['ORIG_PATH_INFO'] ) ) { + echo "cgi.fix_pathinfo is set, good; "; + } else { + echo "cgi.fix_pathinfo is not set, assuming PATH_INFO broken; "; + $conf->prettyURLs = false; + } + break; case "apache2filter": case "isapi": - print "using ugly URLs (index.php?title=Page_Title)"; + // Pretty sure these two break from past tests $conf->prettyURLs = false; break; +default: + print "unknown, assuming PATH_INFO broken for safety; "; + $conf->prettyURLs = false; +} +if( $conf->prettyURLs ) { + print "ok, using pretty URLs (index.php/Page_Title)"; +} else { + print "using ugly URLs (index.php?title=Page_Title)"; } print "\n"; @@ -484,7 +498,14 @@ $conf->UseImageResize = $conf->HaveGD || $conf->ImageMagick; $conf->IP = dirname( dirname( __FILE__ ) ); print "
  • Installation directory: " . htmlspecialchars( $conf->IP ) . "
  • \n"; -$conf->ScriptPath = preg_replace( '{^(.*)/config.*$}', '$1', $_SERVER["PHP_SELF"] ); # was SCRIPT_NAME + +// PHP_SELF isn't available sometimes, such as when PHP is CGI but +// cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME +// to get the path to the current script... hopefully it's reliable. SIGH +$path = ($_SERVER["PHP_SELF"] === '') + ? $_SERVER["SCRIPT_NAME"] + : $_SERVER["PHP_SELF"]; +$conf->ScriptPath = preg_replace( '{^(.*)/config.*$}', '$1', $path ); print "
  • Script URI path: " . htmlspecialchars( $conf->ScriptPath ) . "
  • \n"; print "
  • Environment checked. You can install MediaWiki.
  • \n"; @@ -1374,8 +1395,14 @@ if ( \$wgCommandLineMode ) { ## For more information on customizing the URLs please see: ## http://meta.wikimedia.org/wiki/Eliminating_index.php_from_the_url -## If using PHP as a CGI module, the ?title= style usually must be used. + +## 'Pretty' URLs using PATH_INFO work on most configurations with +## PHP configured as an Apache module. {$pretty}\$wgArticlePath = \"\$wgScript/\$1\"; + +## If using PHP as a CGI module, the ?title= style might have to be used +## depending on the configuration. If it fails, try enabling the option +## cgi.fix_pathinfo in php.ini, then switch to pretty URLs. {$ugly}\$wgArticlePath = \"\$wgScript?title=\$1\"; \$wgStylePath = \"\$wgScriptPath/skins\"; diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index e898387c94..a4a71bfdfe 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -87,10 +87,21 @@ $wgScriptPath = '/wiki'; /** * Whether to support URLs like index.php/Page_title + * These often break when PHP is set up in CGI mode, so + * ignore PATH_INFO for CGI unless cgi.fix_pathinfo is + * set. + * + * Override this to false if $_SERVER['PATH_INFO'] + * contains unexpectedly incorrect garbage. + * + * Note that having this incorrectly set to true can + * cause redirect loops when "pretty URLs" are used. + * * @global bool $wgUsePathInfo */ -$wgUsePathInfo = ( strpos( php_sapi_name(), 'cgi' ) === false ); - +$wgUsePathInfo = + ( strpos( php_sapi_name(), 'cgi' ) === false ) || + isset( $_SERVER['ORIG_PATH_INFO'] ); /**#@+ * Script users will request to get articles -- 2.20.1