From 4c466d5e1c6f551196f220901d6b84a4b8b9e675 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 17 Jul 2017 13:45:35 +0200 Subject: [PATCH] Added automatic URL rewrite test See #2320 --- .../install/files/acp/templates/option.tpl | 34 +++++ .../Core/Acp/Ui/Option/RewriteTest.js | 141 ++++++++++++++++++ .../action/CoreRewriteTestAction.class.php | 40 +++++ wcfsetup/install/lang/de.xml | 7 + wcfsetup/install/lang/en.xml | 11 ++ 5 files changed, 233 insertions(+) create mode 100644 wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Option/RewriteTest.js create mode 100644 wcfsetup/install/files/lib/action/CoreRewriteTestAction.class.php diff --git a/wcfsetup/install/files/acp/templates/option.tpl b/wcfsetup/install/files/acp/templates/option.tpl index 6de4f3d264..81696ce8ef 100644 --- a/wcfsetup/install/files/acp/templates/option.tpl +++ b/wcfsetup/install/files/acp/templates/option.tpl @@ -93,4 +93,38 @@ +{if $category->categoryName === 'general'} + + +{/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 index 0000000000..c5b608218b --- /dev/null +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Option/RewriteTest.js @@ -0,0 +1,141 @@ +/** + * Automatic URL rewrite support testing. + * + * @author Alexander Ebert + * @copyright 2001-2017 WoltLab GmbH + * @license GNU Lesser General Public License + * @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 index 0000000000..6f43873294 --- /dev/null +++ b/wcfsetup/install/files/lib/action/CoreRewriteTestAction.class.php @@ -0,0 +1,40 @@ + + * @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; + } +} diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index cbd456bb88..7214041640 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -1242,7 +1242,14 @@ GmbH=Gesellschaft mit beschränkter Haftung]]> + 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: Konfiguration von benutzerfreundlichen URLs (SEO-URLs)]]> + + +
+Bitte {if LANGUAGE_USE_INFORMAL_VARIANT}befolge{else}befolgen Sie{/if} die Anleitung zur Konfiguration von benutzerfreundlichen URLs (SEO-URLs) 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.]]>
+ + Verwaltung von Werbe-Anzeigen.]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index cebdf6667f..b27cfb9920 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -1228,11 +1228,22 @@ + 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. Enabling this option will rewrite URLs into a better readable representation. Examples:
  • 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/”
  • the link “http://example.com/index.php?members-list/” will turn into “http://example.com/members-list/”
]]>
+ + + + + +
+Please follow the instructions described in Setting up user friendly URLs or contact your hosting provider for assistance.]]>
+ + + advertisement management.]]> -- 2.20.1