* Detect CGI configurations where PATH_INFO is set up correctly.
authorBrion Vibber <brion@users.mediawiki.org>
Thu, 16 Nov 2006 22:57:58 +0000 (22:57 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Thu, 16 Nov 2006 22:57:58 +0000 (22:57 +0000)
  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
config/index.php
includes/DefaultSettings.php

index 458d4be..9454197 100644 (file)
@@ -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 ==
index f462524..515712e 100644 (file)
@@ -350,15 +350,29 @@ case "apache":
 case "apache2handler":
        print "ok, using pretty URLs (<tt>index.php/Page_Title</tt>)";
        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 (<tt>index.php?title=Page_Title</tt>)";
+       // 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 (<tt>index.php/Page_Title</tt>)";
+} else {
+       print "using ugly URLs (<tt>index.php?title=Page_Title</tt>)";
 }
 print "</li>\n";
 
@@ -484,7 +498,14 @@ $conf->UseImageResize = $conf->HaveGD || $conf->ImageMagick;
 $conf->IP = dirname( dirname( __FILE__ ) );
 print "<li>Installation directory: <tt>" . htmlspecialchars( $conf->IP ) . "</tt></li>\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 "<li>Script URI path: <tt>" . htmlspecialchars( $conf->ScriptPath ) . "</tt></li>\n";
 
 print "<li style='font-weight:bold;color:green;font-size:110%'>Environment checked. You can install MediaWiki.</li>\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\";
index e898387..a4a71bf 100644 (file)
@@ -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