Added automatic URL rewrite test
authorAlexander Ebert <ebert@woltlab.com>
Mon, 17 Jul 2017 11:45:35 +0000 (13:45 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 17 Jul 2017 11:48:07 +0000 (13:48 +0200)
See #2320

wcfsetup/install/files/acp/templates/option.tpl
wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Option/RewriteTest.js [new file with mode: 0644]
wcfsetup/install/files/lib/action/CoreRewriteTestAction.class.php [new file with mode: 0644]
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 6de4f3d26419ae1fcd76f970fd17065bc00b8476..81696ce8efad8ee49cd06d1fa5cf6a6abb203b80 100644 (file)
        </div>
 </form>
 
+{if $category->categoryName === 'general'}
+       <div id="dialogRewriteTest" style="display: none">
+               <div id="dialogRewriteTestRunning" class="box24">
+                       <span class="icon icon24 fa-spinner"></span>
+                       <p>{lang}wcf.acp.option.url_omit_index_php.test.running{/lang}</p>
+               </div>
+               <div id="dialogRewriteTestSuccess" class="box24" style="display: none">
+                       <span class="icon icon24 fa-check green"></span>
+                       <p>{lang}wcf.acp.option.url_omit_index_php.test.success{/lang}</p>
+               </div>
+               
+               <div id="dialogRewriteTestFailure" style="display: none">
+                       <div class="box24">
+                               <span class="icon icon24 fa-times red"></span>
+                               <p>{lang}wcf.acp.option.url_omit_index_php.test.failure{/lang}</p>
+                       </div>
+                       <p>{lang}wcf.acp.option.url_omit_index_php.test.failure.description{/lang}</p>
+               </div>
+               
+               <div class="formSubmit">
+                       <button id="rewriteTestStart" class="buttonPrimary">{lang}wcf.acp.option.url_omit_index_php.button.runTestAgain{/lang}</button>
+               </div>
+       </div>
+       <script data-relocate="true">
+               require(['Language', 'WoltLabSuite/Core/Acp/Ui/Option/RewriteTest'], function (Language, AcpUiOptionRewriteTest) {
+                       Language.addObject({
+                               'wcf.acp.option.url_omit_index_php': '{lang}wcf.acp.option.url_omit_index_php{/lang}'
+                       });
+                       
+                       AcpUiOptionRewriteTest.init('{$__wcf->getPath()}core-rewrite-test/?uuidHash={'sha256'|hash:WCF_UUID}');
+               });
+       </script>
+{/if}
+
 {include file='footer'}
diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Option/RewriteTest.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Option/RewriteTest.js
new file mode 100644 (file)
index 0000000..c5b6082
--- /dev/null
@@ -0,0 +1,141 @@
+/**
+ * Automatic URL rewrite support testing.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2017 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module     WoltLabSuite/Core/Acp/Ui/Option/RewriteTest
+ */
+define(['AjaxRequest', 'Language', 'Ui/Dialog'], function (AjaxRequest, Language, UiDialog) {
+       "use strict";
+       
+       var _buttonStartTest = elById('rewriteTestStart');
+       var _callbackChange = null;
+       var _option = elById('url_omit_index_php');
+       var _testPassed = false;
+       var _testUrl = '';
+       
+       /**
+        * @exports     WoltLabSuite/Core/Acp/Ui/Option/RewriteTest
+        */
+       return {
+               /**
+                * Initializes the rewrite test, but aborts early if URL rewriting was
+                * enabled at page init.
+                * 
+                * @param       {string}        testUrl
+                */
+               init: function (testUrl) {
+                       if (_option.checked) {
+                               // option is already enabled, ignore it
+                               return;
+                       }
+                       
+                       _callbackChange = this.onChange.bind(this);
+                       _option.addEventListener('change', _callbackChange);
+                       _testUrl = testUrl;
+               },
+               
+               /**
+                * Forces the rewrite test when attempting to enable the URL rewriting.
+                * 
+                * @param       {Event}         event
+                */
+               onChange: function (event) {
+                       event.preventDefault();
+                       
+                       UiDialog.open(this);
+               },
+               
+               /**
+                * Runs the actual rewrite test.
+                * 
+                * @param       {Event?}        event
+                * @protected
+                */
+               _runTest: function (event) {
+                       if (event instanceof Event) event.preventDefault();
+                       
+                       if (_buttonStartTest.disabled) return;
+                       
+                       _buttonStartTest.disabled = true;
+                       this._setStatus('running');
+                       
+                       var failure = (function () {
+                               window.setTimeout((function() {
+                                       _buttonStartTest.disabled = false;
+                                       
+                                       this._setStatus('failure');
+                               }).bind(this), 500);
+                       }).bind(this);
+                       
+                       var request = new AjaxRequest({
+                               ignoreError: true,
+                               // bypass the LinkHandler, because rewrites aren't enabled yet
+                               url: _testUrl,
+                               success: (function (data) {
+                                       if (!data.hasOwnProperty('core_rewrite_test') || data.core_rewrite_test !== 'passed') {
+                                               failure();
+                                               return;
+                                       }
+                                       
+                                       window.setTimeout((function() {
+                                               _testPassed = true;
+                                               
+                                               this._setStatus('success');
+                                               
+                                               _option.removeEventListener('change', _callbackChange);
+                                               
+                                               window.setTimeout((function () {
+                                                       if (UiDialog.isOpen(this)) {
+                                                               UiDialog.close(this);
+                                                       }
+                                               }).bind(this), 1000);
+                                       }).bind(this), 500);
+                               }).bind(this),
+                               
+                               failure: failure
+                       });
+                       request.sendRequest(false);
+               },
+               
+               /**
+                * Displays the appropriate dialog message.
+                * 
+                * @param       {string}        status
+                * @protected
+                */
+               _setStatus: function (status) {
+                       var containers = [
+                               elById('dialogRewriteTestRunning'),
+                               elById('dialogRewriteTestSuccess'),
+                               elById('dialogRewriteTestFailure')
+                       ];
+                       
+                       containers.forEach(elHide);
+                       
+                       var i = 0;
+                       if (status === 'success') i = 1;
+                       else if (status === 'failure') i = 2;
+                       
+                       elShow(containers[i]);
+               },
+               
+               _dialogSetup: function () {
+                       return {
+                               id: 'dialogRewriteTest',
+                               options: {
+                                       onClose: function () {
+                                               if (!_testPassed) elById('url_omit_index_php_no').checked = true;
+                                       },
+                                       onSetup: (function () {
+                                               _buttonStartTest.addEventListener(WCF_CLICK_EVENT, this._runTest.bind(this));
+                                       }).bind(this),
+                                       onShow: this._runTest.bind(this),
+                                       silent: true,
+                                       title: Language.get('wcf.acp.option.url_omit_index_php')
+                               }
+                       };
+               }
+       };
+});
diff --git a/wcfsetup/install/files/lib/action/CoreRewriteTestAction.class.php b/wcfsetup/install/files/lib/action/CoreRewriteTestAction.class.php
new file mode 100644 (file)
index 0000000..6f43873
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+namespace wcf\action;
+use wcf\system\exception\IllegalLinkException;
+use wcf\util\CryptoUtil;
+use wcf\util\JSON;
+
+/**
+ * Internal action used to run a test for url rewriting.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2017 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\Action
+ * @since       3.1
+ */
+class CoreRewriteTestAction extends AbstractAction {
+       /**
+        * @inheritDoc
+        * 
+        * @throws      IllegalLinkException
+        */
+       public function readParameters() {
+               parent::readParameters();
+               
+               if (!isset($_GET['uuidHash']) || !CryptoUtil::secureCompare(hash('sha256', WCF_UUID), $_GET['uuidHash'])) {
+                       throw new IllegalLinkException();
+               }
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function execute() {
+               parent::execute();
+               
+               header('Content-type: application/json');
+               echo JSON::encode(['core_rewrite_test' => 'passed']);
+               exit;
+       }
+}
index cbd456bb887048282abfa7bf8a29a998b139db2a..72140416401350def7f834333fb1a4a5bb265600 100644 (file)
@@ -1242,7 +1242,14 @@ 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.show_update_notice_frontend"><![CDATA[Hinweis bei neuen Updates für Pakete im Frontend anzeigen]]></item>
                <item name="wcf.acp.option.url_omit_index_php"><![CDATA[Link-Umschreibungen aktivieren]]></item>
+               <item name="wcf.acp.option.url_omit_index_php.button.runTestAgain"><![CDATA[Test erneut durchführen]]></item>
                <item name="wcf.acp.option.url_omit_index_php.description"><![CDATA[Wandelt Links in eine vereinfachte Form um, aus „http://example.com/index.php?thread/1-dies-ist-ein-test/“ wird „http://example.com/thread/1-dies-ist-ein-test/“ und vergleichbar. Achtung: Die Aktivierung der Link-Umschreibungen erfordert Rewrite-Unterstützung in {if LANGUAGE_USE_INFORMAL_VARIANT}deinem{else}Ihrem{/if} Webserver sowie eine entsprechende Konfiguration. Fehlerhafte Einstellungen können hier dazu führen, dass Links nicht mehr aufrufbar sind.<br>Eine Anleitung zur Einrichtung {if LANGUAGE_USE_INFORMAL_VARIANT}deines{else}Ihres{/if} Webservers {if LANGUAGE_USE_INFORMAL_VARIANT}findest du{else}finden Sie{/if} in diesem Artikel: <a href="{@$__wcf->getPath()}acp/dereferrer.php?url=https%3A%2F%2Fwww.woltlab.com%2Farticle%2F24-konfiguration-von-benutzerfreundlichen-urls-seo-urls%2F" class="externalURL">Konfiguration von benutzerfreundlichen URLs (SEO-URLs)</a>]]></item>
+               <item name="wcf.acp.option.url_omit_index_php.test.failure"><![CDATA[Test fehlgeschlagen]]></item>
+               <item name="wcf.acp.option.url_omit_index_php.test.failure.description"><![CDATA[Die Rewrite-Unterstützung des Webservers fehlt oder wurde nicht korrekt konfiguriert.<br>
+<br>
+Bitte {if LANGUAGE_USE_INFORMAL_VARIANT}befolge{else}befolgen Sie{/if} die Anleitung zur <a href="{@$__wcf->getPath()}acp/dereferrer.php?url=https%3A%2F%2Fwww.woltlab.com%2Farticle%2F24-konfiguration-von-benutzerfreundlichen-urls-seo-urls%2F" class="externalURL">Konfiguration von benutzerfreundlichen URLs (SEO-URLs)</a> oder {if LANGUAGE_USE_INFORMAL_VARIANT}wende dich an deinen{else}wenden Sie sich an Ihren{/if} Anbieter um Unterstütznung bei der Einrichtung zu erhalten.]]></item>
+               <item name="wcf.acp.option.url_omit_index_php.test.running"><![CDATA[Test läuft &hellip;]]></item>
+               <item name="wcf.acp.option.url_omit_index_php.test.success"><![CDATA[Test erfolgreich]]></item>
                <item name="wcf.acp.option.module_wcf_ad"><![CDATA[Werbung]]></item>
                <item name="wcf.acp.option.module_wcf_ad.description"><![CDATA[Aktiviert die <a href="{link controller='AdList'}{/link}">Verwaltung von Werbe-Anzeigen</a>.]]></item>
                <item name="wcf.acp.option.captcha_type"><![CDATA[Captcha-Art]]></item>
index cebdf6667fce51b006de1a26f32f915ed8b95e30..b27cfb99201f7c3a7c472e8dd41f34b51e5dd273 100644 (file)
                <item name="wcf.acp.option.module_cookie_policy_page.description"><![CDATA[Displays a notice on cookie usage according to EU Directive 2009/136/EG upon first visit.]]></item>
                <item name="wcf.acp.option.show_update_notice_frontend"><![CDATA[Display a notice for outstanding updates on the frontend]]></item>
                <item name="wcf.acp.option.url_omit_index_php"><![CDATA[Enable url-rewrite]]></item>
+               <item name="wcf.acp.option.url_omit_index_php.button.runTestAgain"><![CDATA[Rerun Test]]></item>
                <item name="wcf.acp.option.url_omit_index_php.description"><![CDATA[Attention! This option requires a rewrite module installed on your webserver and an appropriate configuration; It will not work without any prior configuration applied by you! Please read the following article for instructions: <a href="{@$__wcf->getPath()}acp/dereferrer.php?url=https%3A%2F%2Fwww.woltlab.com%2Farticle%2F25-setting-up-user-friendly-urls%2F" class="externalURL">Setting up user friendly URLs</a>. Enabling this option will rewrite URLs into a better readable representation. Examples: 
 <ul class="nativeList">
 <li>the link “http://example.com/index.php?thread/1-hello-i-am-john-doe/” will turn into “http://example.com/thread/1-hello-i-am-john-doe/”</li>
 <li>the link “http://example.com/index.php?members-list/” will turn into “http://example.com/members-list/”</li>
 </ul>]]></item>
+               
+               
+               
+               <item name="wcf.acp.option.url_omit_index_php.test.failure"><![CDATA[The test has failed.]]></item>
+               <item name="wcf.acp.option.url_omit_index_php.test.failure.description"><![CDATA[The webserver cannot handle rewrites or it has not been configured correctly.<br>
+<br>
+Please follow the instructions described in <a href="{@$__wcf->getPath()}acp/dereferrer.php?url=https%3A%2F%2Fwww.woltlab.com%2Farticle%2F25-setting-up-user-friendly-urls%2F" class="externalURL">Setting up user friendly URLs</a> or contact your hosting provider for assistance.]]></item>
+               <item name="wcf.acp.option.url_omit_index_php.test.running"><![CDATA[The test is currently running &hellip;]]></item>
+               <item name="wcf.acp.option.url_omit_index_php.test.success"><![CDATA[The test was successful.]]></item>
+               
                <item name="wcf.acp.option.module_wcf_ad"><![CDATA[Ads]]></item>
                <item name="wcf.acp.option.module_wcf_ad.description"><![CDATA[Enables the <a href="{link controller='AdList'}{/link}">advertisement management</a>.]]></item>
                <item name="wcf.acp.option.captcha_type"><![CDATA[Captcha Type]]></item>