Changed signature for LinkHandler's getLink()
authorAlexander Ebert <ebert@woltlab.com>
Wed, 12 Oct 2011 19:06:11 +0000 (21:06 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 12 Oct 2011 19:06:11 +0000 (21:06 +0200)
14 files changed:
wcfsetup/install/files/lib/acp/form/MasterPasswordForm.class.php
wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php
wcfsetup/install/files/lib/acp/form/PackageUpdateForm.class.php
wcfsetup/install/files/lib/acp/form/PackageUpdateSearchForm.class.php
wcfsetup/install/files/lib/acp/form/UserSearchForm.class.php
wcfsetup/install/files/lib/acp/form/UsersMassProcessingForm.class.php
wcfsetup/install/files/lib/data/acp/menu/item/ACPMenuItem.class.php
wcfsetup/install/files/lib/data/page/menu/item/PageMenuItem.class.php
wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php
wcfsetup/install/files/lib/system/package/PackageUninstallationDispatcher.class.php
wcfsetup/install/files/lib/system/request/LinkHandler.class.php
wcfsetup/install/files/lib/system/request/Route.class.php
wcfsetup/install/files/lib/system/template/plugin/LinkBlockTemplatePlugin.class.php
wcfsetup/install/files/lib/system/template/plugin/PagesFunctionTemplatePlugin.class.php

index f5f3c1fad9010344326bf85137535f0ee1964359..6d8e095d952fa509e9ebbb22300d23a6ac147909 100755 (executable)
@@ -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;
index bd017f99ae3820fcac02dda4aff1ff82cabf30d4..70c64570abdf60297b955acc6695e054e4afb5af 100755 (executable)
@@ -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;
        }
index 4a194185554370e7dfb89fdbdcf849575d03fea6..893f7cd21bbc0d4f978a18f796a161dddb861864 100755 (executable)
@@ -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;
                }
index 6eb1acf7636c3cb951ab3f066f17ca359d2665dd..c0fc0c55e9ce19b7709cb72a654ac6a3e792c656 100644 (file)
@@ -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;
        }
index 2012578b2daf2b92034bc1ad22e8226184c3b5c4..990289a95069c864d647d358197476deae4a05d5 100755 (executable)
@@ -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;
        }
index 05c8dba48daea3ca296d011a0d0c0d808e0b14b7..eedbb91bd3337c6ad74a23f4577398e09e1cfff3 100644 (file)
@@ -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(
index 0a951ccde3a298d14d7723d8f50b4290902bca2f..128965570ae39656042095d46b741b9428427c9a 100644 (file)
@@ -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);
        }
 }
index 2c7cb6eaddfeb9af237e97c45981fa5ac6df9f54..ffedc4ddf705c9b5ad56498c7cc91324e8baa259 100644 (file)
@@ -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);
        }
 }
index e1df4166e15e5bb83f2b32a8af44aa1ab342a066..014c7e1d3ca64ef8d21d94cc9c09e637d61a9547 100644 (file)
@@ -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;
                }
index 8465a50fa30711c529fa79cc920b2b07bbd5cd4c..8e308eaa6a2a2e83592b93968890e384817229bf 100644 (file)
@@ -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;
        }
index 09ccf76bd6ba8b018537177ff896eb6757225080..9ab4ae52995a7818548558205e13bc130feeb41d 100644 (file)
@@ -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;
index 56ba929a32e914ab7a457135e4af0bae0d7718c0..d5c41128941f98a5d008fafc9b15898cb2777cfa 100644 (file)
@@ -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, '', '&');
                }
index 52fc18519e04f95ba2531675e841db50822ff135..8d1c9751da12d7dbeb0c9961d6fa2916f7b866d2 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\template\plugin;
+use wcf\system\exception\SystemException;
 use wcf\system\request\LinkHandler;
 use wcf\system\template\TemplateEngine;
 use wcf\util\StringUtil;
@@ -28,15 +29,16 @@ class LinkBlockTemplatePlugin implements IBlockTemplatePlugin {
         * @see wcf\system\template\IBlockTemplatePlugin::execute()
         */
        public function execute($tagArgs, $blockContent, TemplateEngine $tplObj) {
+               if (!isset($tagArgs['controller'])) throw new SystemException("missing 'controller' argument in pages tag");
                if (!isset($tagArgs['application']) || empty($tagArgs['application'])) {
                        $tagArgs['application'] = 'wcf';
                }
                
                if (isset($tagArgs['encode']) && !$tagArgs['encode']) {
-                       return LinkHandler::getInstance()->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));
        }
        
        /**
index 3bfba7a85f2d65b65e39ac6e72a152e981a5956c..c07560be134b4b7a338d0ba84145a9ff0994426a 100644 (file)
@@ -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'])) {