Changed URL structure to be no longer dependent on PATH_INFO
authorAlexander Ebert <ebert@woltlab.com>
Wed, 6 Aug 2014 23:47:27 +0000 (01:47 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 6 Aug 2014 23:47:27 +0000 (01:47 +0200)
com.woltlab.wcf/option.xml
com.woltlab.wcf/templates/headIncludeJavaScript.tpl
wcfsetup/install/files/acp/templates/header.tpl
wcfsetup/install/files/js/WCF.js
wcfsetup/install/files/lib/system/request/RequestHandler.class.php
wcfsetup/install/files/lib/system/request/Route.class.php
wcfsetup/install/files/lib/system/request/RouteHandler.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 6cf09935d5093b7ebc619c34715b1b1b194f7444..3ab21a856a84a0c80868b82b1fab61d19a06aab8 100644 (file)
                                <optiontype>textarea</optiontype>
                        </option>
                        
+                       <option name="url_legacy_mode">
+                               <categoryname>general.page.seo</categoryname>
+                               <optiontype>boolean</optiontype>
+                               <defaultvalue>0</defaultvalue>
+                               <enableoptions><![CDATA[url_omit_index_php]]></enableoptions>
+                       </option>
                        <option name="url_omit_index_php">
                                <categoryname>general.page.seo</categoryname>
                                <optiontype>boolean</optiontype>
index 38cee50bbbed49e1cefa4228c0b03fd4e59831ad..500b07d5a1d9bb6075d485e5e7fb2110d39a11ba 100644 (file)
@@ -9,6 +9,7 @@
        var SECURITY_TOKEN = '{@SECURITY_TOKEN}';
        var LANGUAGE_ID = {@$__wcf->getLanguage()->languageID};
        var TIME_NOW = {@TIME_NOW};
+       var URL_LEGACY_MODE = {if URL_LEGACY_MODE}true{else}false{/if};
        //]]>
 </script>
 {if JQUERY_SOURCE == 'google'}
index 7ad9a52b1f12e02bc522c970b12b1e04c42cc411..a2b21c58636928eb0ea9ec1dee1041230fcbcad6 100644 (file)
@@ -11,6 +11,7 @@
                var SECURITY_TOKEN = '{@SECURITY_TOKEN}';
                var LANGUAGE_ID = {@$__wcf->getLanguage()->languageID};
                var TIME_NOW = {@TIME_NOW};
+               var URL_LEGACY_MODE = {if URL_LEGACY_MODE}true{else}false{/if};
                //]]>
        </script>
        <script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/jquery.min.js?v={@$__wcfVersion}"></script>
index 4db5c04e678c52f5d47cbc9a30c02a8f82a8f145..b4c105ea0eb4845ca2b1984c00f1225f3a8479ad 100755 (executable)
@@ -2148,6 +2148,10 @@ WCF.Action.Proxy = Class.extend({
                        autoAbortPrevious: false
                }, options);
                
+               if (!URL_LEGACY_MODE) {
+                       this.options.url = this.options.url.replace(/^index\.php\/(.*?)\/\?/, '?$1/&');
+               }
+               
                this.confirmationDialog = null;
                this.loading = null;
                this._showLoadingOverlayOnce = false;
index c2bae2546ab793bb3b8aa3e9d7b9b08e3e2b6a90..87679b3ad757ac9d145efe4ad6b2f2fe1606b005 100644 (file)
@@ -1,6 +1,5 @@
 <?php
 namespace wcf\system\request;
-use wcf\system\application\AbstractApplication;
 use wcf\system\application\ApplicationHandler;
 use wcf\system\exception\AJAXException;
 use wcf\system\exception\IllegalLinkException;
@@ -169,10 +168,12 @@ class RequestHandler extends SingletonFactory {
                                                // build URL, e.g. http://example.net/forum/
                                                $url = FileUtil::addTrailingSlash(RouteHandler::getProtocol() . $applicationObject->domainName . RouteHandler::getPath());
                                                
-                                               // add path info, e.g. index.php/Board/2/
-                                               $pathInfo = RouteHandler::getPathInfo();
-                                               if (!empty($pathInfo)) {
-                                                       $url .= 'index.php' . $pathInfo;
+                                               if (URL_LEGACY_MODE) {
+                                                       // add path info, e.g. index.php/Board/2/
+                                                       $pathInfo = RouteHandler::getPathInfo();
+                                                       if (!empty($pathInfo)) {
+                                                               $url .= 'index.php' . $pathInfo;
+                                                       }
                                                }
                                                
                                                // query string, e.g. ?foo=bar
index fc765e958c4b1d2a745b8cc04dc31bd9d5335191..2e531acccca09a5a2692300337f428ec76f825c7 100644 (file)
@@ -301,12 +301,20 @@ class Route {
                        }
                }
                
-               if (!empty($link) && ($this->isACP() || !URL_OMIT_INDEX_PHP)) {
-                       $link = 'index.php/' . $link;
+               if (URL_LEGACY_MODE) {
+                       if (!empty($link) && ($this->isACP() || !URL_OMIT_INDEX_PHP)) {
+                               $link = 'index.php/' . $link;
+                       }
+               }
+               else {
+                       if (!empty($link)) {
+                               $link = '?' . $link;
+                       }
                }
                
                if (!empty($components)) {
-                       $link .= '?' . http_build_query($components, '', '&');
+                       if (strpos($link, '?') === false) $link .= '?';
+                       $link .= http_build_query($components, '', '&');
                }
                
                return $link;
index d3ec22d7de346418a582625929fad88bc0a1d628..14b71041fa7406eff80e3f017cc59b20da78aac5 100644 (file)
@@ -35,7 +35,7 @@ class RouteHandler extends SingletonFactory {
         * current path info component
         * @var string
         */
-       protected static $pathInfo = '';
+       protected static $pathInfo = null;
        
        /**
         * HTTP protocol, either 'http://' or 'https://'
@@ -260,26 +260,48 @@ class RouteHandler extends SingletonFactory {
         * @return      string
         */
        public static function getPathInfo() {
-               if (empty(self::$pathInfo)) {
-                       if (isset($_SERVER['PATH_INFO'])) {
-                               self::$pathInfo = $_SERVER['PATH_INFO'];
+               if (self::$pathInfo === null) {
+                       self::$pathInfo = '';
+                       
+                       // WCF 2.0: index.php/Foo/Bar/
+                       if (URL_LEGACY_MODE) {
+                               if (isset($_SERVER['PATH_INFO'])) {
+                                       self::$pathInfo = $_SERVER['PATH_INFO'];
+                               }
+                               else if (isset($_SERVER['ORIG_PATH_INFO'])) {
+                                       self::$pathInfo = $_SERVER['ORIG_PATH_INFO'];
+                                               
+                                       // in some configurations ORIG_PATH_INFO contains the path to the file
+                                       // if the intended PATH_INFO component is empty
+                                       if (!empty(self::$pathInfo)) {
+                                               if (isset($_SERVER['SCRIPT_NAME']) && (self::$pathInfo == $_SERVER['SCRIPT_NAME'])) {
+                                                       self::$pathInfo = '';
+                                               }
+                                               
+                                               if (isset($_SERVER['PHP_SELF']) && (self::$pathInfo == $_SERVER['PHP_SELF'])) {
+                                                       self::$pathInfo = '';
+                                               }
+                                               
+                                               if (isset($_SERVER['SCRIPT_URL']) && (self::$pathInfo == $_SERVER['SCRIPT_URL'])) {
+                                                       self::$pathInfo = '';
+                                               }
+                                       }
+                               }
                        }
-                       else if (isset($_SERVER['ORIG_PATH_INFO'])) {
-                               self::$pathInfo = $_SERVER['ORIG_PATH_INFO'];
-                                       
-                               // in some configurations ORIG_PATH_INFO contains the path to the file
-                               // if the intended PATH_INFO component is empty
-                               if (!empty(self::$pathInfo)) {
-                                       if (isset($_SERVER['SCRIPT_NAME']) && (self::$pathInfo == $_SERVER['SCRIPT_NAME'])) {
-                                               self::$pathInfo = '';
+                       else {
+                               // WCF 2.1: ?Foo/Bar/
+                               if (!empty($_SERVER['QUERY_STRING'])) {
+                                       $pos = mb_strpos($_SERVER['QUERY_STRING'], '&');
+                                       $route = '';
+                                       if ($pos === false) {
+                                               $route = $_SERVER['QUERY_STRING'];
                                        }
-                                       
-                                       if (isset($_SERVER['PHP_SELF']) && (self::$pathInfo == $_SERVER['PHP_SELF'])) {
-                                               self::$pathInfo = '';
+                                       else {
+                                               $route = mb_substr($_SERVER['QUERY_STRING'], 0, $pos);
                                        }
                                        
-                                       if (isset($_SERVER['SCRIPT_URL']) && (self::$pathInfo == $_SERVER['SCRIPT_URL'])) {
-                                               self::$pathInfo = '';
+                                       if (mb_strpos($route, '=') === false) {
+                                               self::$pathInfo = $route;
                                        }
                                }
                        }
index bba7bfccc0d6ce100f94560cffe900c18afc9f91..19191552bfbae722bc7bd7eb304f1f15424dcc58 100644 (file)
@@ -1000,6 +1000,12 @@ GmbH=Gesellschaft mit beschränkter Haftung]]></item>
                <item name="wcf.acp.option.module_cookie_policy_page.description"><![CDATA[Weist Besucher beim ersten Aufruf der Seite gemäß EU-Richtlinie 2009/136/EG auf den Einsatz von Cookies hin.]]></item>
                <item name="wcf.acp.option.url_omit_index_php"><![CDATA[„index.php“ aus URLs entfernen]]></item>
                <item name="wcf.acp.option.url_omit_index_php.description"><![CDATA[TODO]]></item>
+               <item name="wcf.acp.option.url_legacy_mode"><![CDATA[Kompatibilitätsmodus für Links aktivieren]]></item>
+               <item name="wcf.acp.option.url_legacy_mode.description"><![CDATA[Die Aktivierung dieses Modus erzwingt die URL-Struktur von WoltLab Community Framework 2.0 und sollte nur aus Kompatibilitätsgründen zur Beibehaltung der Link-Gültigkeit aktiviert werden:
+<ul class="nativeList">
+       <li>WCF 2.0: „index.php/Thread/123-Title/“</li>
+       <li>WCF 2.1+: „?Thread/123-Title/“</li>
+</ul>]]></item>
                <item name="wcf.acp.option.module_ad"><![CDATA[Werbung]]></item>
                <item name="wcf.acp.option.captcha_type"><![CDATA[Captcha-Art]]></item>
                <item name="wcf.acp.option.register_use_captcha"><![CDATA[Captcha in Registrierung aktivieren]]></item>
index 9f0a6365fe9799b0c9d8e90a40cd8a33fb44f8eb..c07e115c229031d82852d97733d7b2220d64aa6d 100644 (file)
@@ -999,6 +999,12 @@ GmbH=Gesellschaft mit beschränkter Haftung]]></item>
                <item name="wcf.acp.option.module_cookie_policy_page.description"><![CDATA[TODO: Weist Besucher beim ersten Aufruf der Seite gemäß EU-Richtlinie 2009/136/EG auf den Einsatz von Cookies hin.]]></item>
                <item name="wcf.acp.option.url_omit_index_php"><![CDATA[TODO: „index.php“ aus URLs entfernen]]></item>
                <item name="wcf.acp.option.url_omit_index_php.description"><![CDATA[TODO]]></item>
+               <item name="wcf.acp.option.url_legacy_mode"><![CDATA[Enable link compatibility mode]]></item>
+               <item name="wcf.acp.option.url_legacy_mode.description"><![CDATA[Enabling this option forces the system to use WoltLab Community Framework 2.0-compilant URLs and should only be used to ensure compatibility with legacy URLs:
+<ul class="nativeList">
+       <li>WCF 2.0: „index.php/Thread/123-Title/“</li>
+       <li>WCF 2.1+: „?Thread/123-Title/“</li>
+</ul>]]></item>
                <item name="wcf.acp.option.module_ad"><![CDATA[Ads]]></item>
                <item name="wcf.acp.option.captcha_type"><![CDATA[Captcha Type]]></item>
                <item name="wcf.acp.option.register_use_captcha"><![CDATA[Enable Captcha protection during registration]]></item>