From 6dcaf9018d39d6d39f32d7f358157dcbe8862942 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 12 Oct 2011 21:06:11 +0200 Subject: [PATCH] Changed signature for LinkHandler's getLink() --- .../lib/acp/form/MasterPasswordForm.class.php | 2 +- .../form/PackageStartInstallForm.class.php | 2 +- .../lib/acp/form/PackageUpdateForm.class.php | 2 +- .../form/PackageUpdateSearchForm.class.php | 5 +--- .../lib/acp/form/UserSearchForm.class.php | 5 +--- .../form/UsersMassProcessingForm.class.php | 5 +--- .../data/acp/menu/item/ACPMenuItem.class.php | 2 +- .../page/menu/item/PageMenuItem.class.php | 2 +- .../PackageInstallationDispatcher.class.php | 4 +-- .../PackageUninstallationDispatcher.class.php | 2 +- .../lib/system/request/LinkHandler.class.php | 10 ++++--- .../files/lib/system/request/Route.class.php | 26 ++++++++++++++----- .../plugin/LinkBlockTemplatePlugin.class.php | 6 +++-- .../PagesFunctionTemplatePlugin.class.php | 2 +- 14 files changed, 42 insertions(+), 33 deletions(-) diff --git a/wcfsetup/install/files/lib/acp/form/MasterPasswordForm.class.php b/wcfsetup/install/files/lib/acp/form/MasterPasswordForm.class.php index f5f3c1fad9..6d8e095d95 100755 --- a/wcfsetup/install/files/lib/acp/form/MasterPasswordForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/MasterPasswordForm.class.php @@ -84,7 +84,7 @@ class MasterPasswordForm extends ACPForm { // forward if (empty($this->url)) { - $this->url = LinkHandler::getInstance()->getLink('', array('controller' => 'Index')); + $this->url = LinkHandler::getInstance()->getLink('Index'); } HeaderUtil::redirect($this->url, false); exit; diff --git a/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php b/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php index bd017f99ae..70c64570ab 100755 --- a/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php @@ -232,7 +232,7 @@ class PackageStartInstallForm extends ACPForm { $this->saved(); // open queue - $url = LinkHandler::getInstance()->getLink('action=openQueue&processNo='.$processNo, array('controller' => 'Package')); + $url = LinkHandler::getInstance()->getLink('Package', array(), 'action=openQueue&processNo='.$processNo); HeaderUtil::redirect($url); exit; } diff --git a/wcfsetup/install/files/lib/acp/form/PackageUpdateForm.class.php b/wcfsetup/install/files/lib/acp/form/PackageUpdateForm.class.php index 4a19418555..893f7cd21b 100755 --- a/wcfsetup/install/files/lib/acp/form/PackageUpdateForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PackageUpdateForm.class.php @@ -104,7 +104,7 @@ class PackageUpdateForm extends ACPForm { $this->saved(); // open queue - $url = LinkHandler::getInstance()->getLink('action=openQueue&processNo='.$processNo, array('controller' => 'Package')); + $url = LinkHandler::getInstance()->getLink('Package', array(), 'action=openQueue&processNo='.$processNo); HeaderUtil::redirect($url); exit; } diff --git a/wcfsetup/install/files/lib/acp/form/PackageUpdateSearchForm.class.php b/wcfsetup/install/files/lib/acp/form/PackageUpdateSearchForm.class.php index 6eb1acf763..c0fc0c55e9 100644 --- a/wcfsetup/install/files/lib/acp/form/PackageUpdateSearchForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PackageUpdateSearchForm.class.php @@ -243,10 +243,7 @@ class PackageUpdateSearchForm extends ACPForm { $this->saved(); // forward - $url = LinkHandler::getInstance()->getLink('', array( - 'controller' => 'PackageUpdateSearchResult', - 'id' => $search->searchID - )); + $url = LinkHandler::getInstance()->getLink('PackageUpdateSearchResult', array('id' => $search->searchID)); HeaderUtil::redirect($url); exit; } diff --git a/wcfsetup/install/files/lib/acp/form/UserSearchForm.class.php b/wcfsetup/install/files/lib/acp/form/UserSearchForm.class.php index 2012578b2d..990289a950 100755 --- a/wcfsetup/install/files/lib/acp/form/UserSearchForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserSearchForm.class.php @@ -215,10 +215,7 @@ class UserSearchForm extends UserOptionListForm { $this->saved(); // forward to result page - $url = LinkHandler::getInstance()->getLink('sortField='.rawurlencode($this->sortField).'&sortOrder='.rawurlencode($this->sortOrder), array( - 'controller' => 'UserList', - 'id' => $this->searchID - )); + $url = LinkHandler::getInstance()->getLink('UserList', array('id' => $this->searchID), 'sortField='.rawurlencode($this->sortField).'&sortOrder='.rawurlencode($this->sortOrder)); HeaderUtil::redirect($url); exit; } diff --git a/wcfsetup/install/files/lib/acp/form/UsersMassProcessingForm.class.php b/wcfsetup/install/files/lib/acp/form/UsersMassProcessingForm.class.php index 05c8dba48d..eedbb91bd3 100644 --- a/wcfsetup/install/files/lib/acp/form/UsersMassProcessingForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UsersMassProcessingForm.class.php @@ -195,10 +195,7 @@ class UsersMassProcessingForm extends UserOptionListForm { WCF::getSession()->register('userMailData', $userMailData); $this->saved(); - $url = LinkHandler::getInstance()->getLink('', array( - 'controller' => 'UserMail', - 'id' => $mailID - )); + $url = LinkHandler::getInstance()->getLink('UserMail', array('id' => $mailID)); // show worker template WCF::getTPL()->assign(array( diff --git a/wcfsetup/install/files/lib/data/acp/menu/item/ACPMenuItem.class.php b/wcfsetup/install/files/lib/data/acp/menu/item/ACPMenuItem.class.php index 0a951ccde3..128965570a 100644 --- a/wcfsetup/install/files/lib/data/acp/menu/item/ACPMenuItem.class.php +++ b/wcfsetup/install/files/lib/data/acp/menu/item/ACPMenuItem.class.php @@ -29,6 +29,6 @@ class ACPMenuItem extends DatabaseObject implements ITreeMenuItem { * @see wcf\system\menu\ITreeMenuItem::getLink() */ public function getLink() { - return LinkHandler::getInstance()->getLink($this->menuItemLink); + return LinkHandler::getInstance()->getLink(null, array(), $this->menuItemLink); } } diff --git a/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItem.class.php b/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItem.class.php index 2c7cb6eadd..ffedc4ddf7 100644 --- a/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItem.class.php +++ b/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItem.class.php @@ -46,6 +46,6 @@ class PageMenuItem extends ProcessibleDatabaseObject implements ITreeMenuItem { * @see wcf\system\menu\ITreeMenuItem::getLink() */ public function getLink() { - return LinkHandler::getInstance()->getLink($this->menuItemLink); + return LinkHandler::getInstance()->getLink(null, array(), $this->menuItemLink); } } diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php index e1df4166e1..014c7e1d3c 100644 --- a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php @@ -535,12 +535,12 @@ class PackageInstallationDispatcher { $packageInstallation = $statement->fetchArray(); if (!isset($packageInstallation['queueID'])) { - $url = LinkHandler::getInstance()->getLink('', array('controller' => 'PackageList')); + $url = LinkHandler::getInstance()->getLink('PackageList'); HeaderUtil::redirect($url); exit; } else { - $url = LinkHandler::getInstance()->getLink('action='.$packageInstallation['action'].'&queueID='.$packageInstallation['queueID'], array('controller' => 'Package')); + $url = LinkHandler::getInstance()->getLink('Package', array(), 'action='.$packageInstallation['action'].'&queueID='.$packageInstallation['queueID']); HeaderUtil::redirect($url); exit; } diff --git a/wcfsetup/install/files/lib/system/package/PackageUninstallationDispatcher.class.php b/wcfsetup/install/files/lib/system/package/PackageUninstallationDispatcher.class.php index 8465a50fa3..8e308eaa6a 100644 --- a/wcfsetup/install/files/lib/system/package/PackageUninstallationDispatcher.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageUninstallationDispatcher.class.php @@ -281,7 +281,7 @@ class PackageUninstallationDispatcher extends PackageInstallationDispatcher { )); } - $url = LinkHandler::getInstance()->getLink('action=openQueue&processNo='.$processNo, array('controller' => 'Package')); + $url = LinkHandler::getInstance()->getLink('Package', array(), 'action=openQueue&processNo='.$processNo); HeaderUtil::redirect($url); exit; } diff --git a/wcfsetup/install/files/lib/system/request/LinkHandler.class.php b/wcfsetup/install/files/lib/system/request/LinkHandler.class.php index 09ccf76bd6..9ab4ae5299 100644 --- a/wcfsetup/install/files/lib/system/request/LinkHandler.class.php +++ b/wcfsetup/install/files/lib/system/request/LinkHandler.class.php @@ -18,11 +18,12 @@ class LinkHandler extends SingletonFactory { /** * Returns a relative link. * - * @param string $url + * @param string $controller * @param array $parameters + * @param string $url * @return string */ - public function getLink($url, array $parameters = array()) { + public function getLink($controller = null, array $parameters = array(), $url = '') { $abbreviation = 'wcf'; $isRaw = false; if (isset($parameters['application'])) { @@ -35,9 +36,10 @@ class LinkHandler extends SingletonFactory { } // build route - if (isset($parameters['controller'])) { + if ($controller !== null) { + $parameters['controller'] = $controller; $routeURL = RouteHandler::getInstance()->buildRoute($parameters); - if (!$isRaw) { + if (!$isRaw && !empty($url)) { $routeURL .= (strpos($routeURL, '?') === false) ? '?' : '&'; } $url = $routeURL . $url; diff --git a/wcfsetup/install/files/lib/system/request/Route.class.php b/wcfsetup/install/files/lib/system/request/Route.class.php index 56ba929a32..d5c4112894 100644 --- a/wcfsetup/install/files/lib/system/request/Route.class.php +++ b/wcfsetup/install/files/lib/system/request/Route.class.php @@ -222,16 +222,30 @@ class Route { * @return string */ public function buildLink(array $components) { - $link = 'index.php/'; - foreach ($this->routeSchema as $component) { - if (!isset($components[$component])) { - continue; + $link = ''; + + // handle default values for controller + $buildRoute = true; + if (count($components) == 1) { + if (isset($this->parameterOptions['controller']) && strcasecmp($this->parameterOptions['controller']['default'], $components['controller']) == 0) { + // only the controller was given and matches default, omit routing + $buildRoute = false; } + } + + if ($buildRoute) { + foreach ($this->routeSchema as $component) { + if (!isset($components[$component])) { + continue; + } - $link .= $components[$component] . '/'; - unset($components[$component]); + $link .= $components[$component] . '/'; + unset($components[$component]); + } } + $link = 'index.php' . (!empty($link) ? '/' : ''); + if (!empty($components)) { $link .= '?' . html_build_query($components, '', '&'); } diff --git a/wcfsetup/install/files/lib/system/template/plugin/LinkBlockTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/LinkBlockTemplatePlugin.class.php index 52fc18519e..8d1c9751da 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/LinkBlockTemplatePlugin.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/LinkBlockTemplatePlugin.class.php @@ -1,5 +1,6 @@ getLink($blockContent, $tagArgs); + return LinkHandler::getInstance()->getLink($tagArgs['controller'], $tagArgs, $blockContent); } - return StringUtil::encodeHTML(LinkHandler::getInstance()->getLink($blockContent, $tagArgs)); + return StringUtil::encodeHTML(LinkHandler::getInstance()->getLink($tagArgs['controller'], $tagArgs, $blockContent)); } /** diff --git a/wcfsetup/install/files/lib/system/template/plugin/PagesFunctionTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/PagesFunctionTemplatePlugin.class.php index 3bfba7a85f..c07560be13 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/PagesFunctionTemplatePlugin.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/PagesFunctionTemplatePlugin.class.php @@ -84,7 +84,7 @@ class PagesFunctionTemplatePlugin implements IFunctionTemplatePlugin { // create and encode route link $routeComponents = array('controller' => $tagArgs['controller']); if (isset($tagArgs['id'])) $routeComponents['id'] = $tagArgs['id']; - $routeURL = RouteHandler::getInstance()->buildRoute($routeComponents); + $routeURL = RouteHandler::getInstance()->buildRoute($tagArgs['controller'], $routeComponents); $tagArgs['link'] = StringUtil::encodeHTML($routeURL . $tagArgs['link']); if (!isset($tagArgs['page'])) { -- 2.20.1