ACPMenu should now behave like page menu
authorAlexander Ebert <ebert@woltlab.com>
Sun, 30 Dec 2012 02:20:06 +0000 (03:20 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 30 Dec 2012 02:20:06 +0000 (03:20 +0100)
Fixes #1030

com.woltlab.wcf/acpMenu.xml
wcfsetup/install/files/acp/templates/header.tpl
wcfsetup/install/files/lib/data/acp/menu/item/ACPMenuItem.class.php
wcfsetup/install/files/lib/system/package/plugin/ACPMenuPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/PageMenuPackageInstallationPlugin.class.php
wcfsetup/setup/db/install.sql

index 3f0056c482e4f4a371bafb287d1fd035ab169292..3dd0b167121744fbaada60a03b51ae55eac64cbe 100644 (file)
@@ -25,7 +25,7 @@
                <acpmenuitem name="wcf.acp.menu.link.option.importAndExport">
                        <parent>wcf.acp.menu.link.option.management</parent>
                        <showorder>1</showorder>
-                       <link>index.php/OptionImport/</link>
+                       <controller><![CDATA[OptionImport]]></controller>
                </acpmenuitem>
                <!-- /options -->
                
                </acpmenuitem>
                
                <acpmenuitem name="wcf.acp.menu.link.package.list">
-                       <link>index.php/PackageList/</link>
+                       <controller><![CDATA[wcf\acp\page\PackageListPage]]></controller>
                        <parent>wcf.acp.menu.link.package.management</parent>
                        <permissions>admin.system.package.canUpdatePackage,admin.system.package.canUninstallPackage</permissions>
                        <showorder>1</showorder>
                </acpmenuitem>
                
                <acpmenuitem name="wcf.acp.menu.link.package.install">
-                       <link>index.php/PackageStartInstall/?action=install</link>
+                       <controller><![CDATA[wcf\acp\form\PackageStartInstallForm]]></controller>
+                       <link><![CDATA[action=install]]></link>
                        <parent>wcf.acp.menu.link.package.management</parent>
                        <permissions>admin.system.package.canInstallPackage</permissions>
                        <showorder>2</showorder>
                </acpmenuitem>
                
                <acpmenuitem name="wcf.acp.menu.link.package.autoupdate">
-                       <link>index.php/PackageAutoUpdateList/</link>
+                       <controller><![CDATA[wcf\acp\page\PackageAutoUpdateListPage]]></controller>
                        <parent>wcf.acp.menu.link.package.update</parent>
                        <permissions>admin.system.package.canUpdatePackage</permissions>
                        <showorder>1</showorder>
                </acpmenuitem>
                
                <acpmenuitem name="wcf.acp.menu.link.package.database">
-                       <link>index.php/PackageUpdateSearch/</link>
+                       <controller><![CDATA[wcf\acp\form\PackageUpdateSearchForm]]></controller>
                        <parent>wcf.acp.menu.link.package.update</parent>
                        <permissions>admin.system.package.canInstallPackage,admin.system.package.canUpdatePackage</permissions>
                        <showorder>2</showorder>
                </acpmenuitem>
                
                <acpmenuitem name="wcf.acp.menu.link.package.server.list">
-                       <link>index.php/UpdateServerList/</link>
+                       <controller><![CDATA[wcf\acp\page\UpdateServerListPage]]></controller>
                        <parent>wcf.acp.menu.link.package.server</parent>
                        <permissions>admin.system.package.canEditServer</permissions>
                        <showorder>1</showorder>
                </acpmenuitem>
                
                <acpmenuitem name="wcf.acp.menu.link.package.server.add">
-                       <link>index.php/UpdateServerAdd/</link>
+                       <controller><![CDATA[wcf\acp\form\UpdateServerAddForm]]></controller>
                        <parent>wcf.acp.menu.link.package.server</parent>
                        <permissions>admin.system.package.canEditServer</permissions>
                        <showorder>2</showorder>
                </acpmenuitem>
                
                <acpmenuitem name="wcf.acp.menu.link.application.management">
-                       <link>index.php/ApplicationManagement/</link>
+                       <controller><![CDATA[wcf\acp\page\ApplicationManagementPage]]></controller>
                        <parent>wcf.acp.menu.link.application</parent>
                        <permissions>admin.system.canManageApplication</permissions>
                </acpmenuitem>
                
                <acpmenuitem name="wcf.acp.menu.link.application.cache">
-                       <link>index.php/CacheList/</link>
+                       <controller><![CDATA[wcf\acp\page\CacheListPage]]></controller>
                        <parent>wcf.acp.menu.link.application</parent>
                        <permissions>admin.system.canManageApplication</permissions>
                </acpmenuitem>
                </acpmenuitem>
                
                <acpmenuitem name="wcf.acp.menu.link.cronjob.list">
-                       <link>index.php/CronjobList/</link>
+                       <controller><![CDATA[wcf\acp\page\CronjobListPage]]></controller>
                        <parent>wcf.acp.menu.link.cronjob</parent>
                        <permissions>admin.system.canManageCronjob</permissions>
                        <showorder>1</showorder>
                </acpmenuitem>
                
                <acpmenuitem name="wcf.acp.menu.link.cronjob.add">
-                       <link>index.php/CronjobAdd/</link>
+                       <controller><![CDATA[wcf\acp\form\CronjobAddForm]]></controller>
                        <parent>wcf.acp.menu.link.cronjob</parent>
                        <permissions>admin.system.canManageCronjob</permissions>
                        <showorder>2</showorder>
                </acpmenuitem>
                
                <acpmenuitem name="wcf.acp.menu.link.log.session">
-                       <link>index.php/ACPSessionLogList/</link>
+                       <controller><![CDATA[wcf\acp\page\ACPSessionLogListPage]]></controller>
                        <parent>wcf.acp.menu.link.log</parent>
                        <permissions>admin.system.canViewLog</permissions>
                </acpmenuitem>
                
                <acpmenuitem name="wcf.acp.menu.link.log.cronjob">
-                       <link>index.php/CronjobLogList/</link>
+                       <controller><![CDATA[wcf\acp\page\CronjobLogListPage]]></controller>
                        <parent>wcf.acp.menu.link.log</parent>
                        <permissions>admin.system.canManageCronjob</permissions>
                </acpmenuitem>
                </acpmenuitem>
                
                <acpmenuitem name="wcf.acp.menu.link.user.list">
-                       <link>index.php/UserList/</link>
+                       <controller><![CDATA[wcf\acp\page\UserListPage]]></controller>
                        <parent>wcf.acp.menu.link.user.management.general</parent>
                        <permissions>admin.user.canSearchUser</permissions>
                        <showorder>1</showorder>
                </acpmenuitem>
                
                <acpmenuitem name="wcf.acp.menu.link.user.add">
-                       <link>index.php/UserAdd/</link>
+                       <controller><![CDATA[wcf\acp\form\UserAddForm]]></controller>
                        <parent>wcf.acp.menu.link.user.management.general</parent>
                        <permissions>admin.user.canAddUser</permissions>
                        <showorder>2</showorder>
                </acpmenuitem>
                
                <acpmenuitem name="wcf.acp.menu.link.user.search">
-                       <link>index.php/UserSearch/</link>
+                       <controller><![CDATA[wcf\acp\form\UserSearchForm]]></controller>
                        <parent>wcf.acp.menu.link.user.management.general</parent>
                        <permissions>admin.user.canSearchUser</permissions>
                        <showorder>3</showorder>
                </acpmenuitem>
                
                <acpmenuitem name="wcf.acp.menu.link.user.massProcessing">
-                       <link>index.php/UsersMassProcessing/</link>
+                       <controller><![CDATA[wcf\acp\form\UsersMassProcessingForm]]></controller>
                        <parent>wcf.acp.menu.link.user.management.additional</parent>
                        <permissions>admin.user.canEditUser,admin.user.canDeleteUser,admin.user.canMailUser</permissions>
                        <showorder>1</showorder>
                </acpmenuitem>
                
                <acpmenuitem name="wcf.acp.menu.link.user.mail">
-                       <link>index.php/UserMail/?action=all</link>
+                       <controller><![CDATA[wcf\acp\form\UserMailForm]]></controller>
+                       <link><![CDATA[action=all]]></link>
                        <parent>wcf.acp.menu.link.user.management.additional</parent>
                        <permissions>admin.user.canMailUser</permissions>
                        <showorder>2</showorder>
                </acpmenuitem>
                
                <acpmenuitem name="wcf.acp.menu.link.group.list">
-                       <link>index.php/UserGroupList/</link>
+                       <controller><![CDATA[wcf\acp\page\UserGroupListPage]]></controller>
                        <parent>wcf.acp.menu.link.group.general</parent>
                        <permissions>admin.user.canEditGroup,admin.user.canDeleteGroup</permissions>
                        <showorder>1</showorder>
                </acpmenuitem>
                
                <acpmenuitem name="wcf.acp.menu.link.group.add">
-                       <link>index.php/UserGroupAdd/</link>
+                       <controller><![CDATA[wcf\acp\form\UserGroupAddForm]]></controller>
                        <parent>wcf.acp.menu.link.group.general</parent>
                        <permissions>admin.user.canAddGroup</permissions>
                        <showorder>2</showorder>
                </acpmenuitem>
                
                <acpmenuitem name="wcf.acp.menu.link.group.mail">
-                       <link>index.php/UserMail/?action=group</link>
+                       <controller><![CDATA[wcf\acp\form\UserMailForm]]></controller>
+                       <link><![CDATA[action=group]]></link>
                        <parent>wcf.acp.menu.link.group.additional</parent>
                        <permissions>admin.user.canMailUser</permissions>
                        <showorder>1</showorder>
                </acpmenuitem>
                
                <acpmenuitem name="wcf.acp.menu.link.pageMenu.list">
-                       <link>index.php/PageMenuItemList/</link>
+                       <controller><![CDATA[wcf\acp\page\PageMenuItemListPage]]></controller>
                        <parent>wcf.acp.menu.link.pageMenu</parent>
                        <permissions>admin.display.canManagePageMenu</permissions>
                        <showorder>1</showorder>
                </acpmenuitem>
                
                <acpmenuitem name="wcf.acp.menu.link.pageMenu.add">
-                       <link>index.php/PageMenuItemAdd/</link>
+                       <controller><![CDATA[wcf\acp\form\PageMenuItemAddForm]]></controller>
                        <parent>wcf.acp.menu.link.pageMenu</parent>
                        <permissions>admin.display.canManagePageMenu</permissions>
                        <showorder>2</showorder>
index ae7a477c9307068e587f2b88a6b4c8b8cecb4952..7195abf09e57e09f23b15c8a941f1d5ead52c93e 100644 (file)
                                                                        <div id="{$_parentMenuItem->menuItem}-container" style="display: none;" class="menuGroup collapsibleMenus" data-parent-menu-item="{$_parentMenuItem->menuItem}">
                                                                                {foreach from=$__wcf->getACPMenu()->getMenuItems($_parentMenuItem->menuItem) item=_menuItem}
                                                                                        <fieldset>
-                                                                                               <legend class="menuHeader" data-menu-item="{$_menuItem->menuItem}">{lang}{@$_menuItem->menuItem}{/lang}</legend>
+                                                                                               <legend class="menuHeader" data-menu-item="{$_menuItem->menuItem}">{$_menuItem}</legend>
                                                                                                
                                                                                                <nav class="menuGroupItems">
                                                                                                        <ul id="{$_menuItem->menuItem}">
                                                                                                                {foreach from=$__wcf->getACPMenu()->getMenuItems($_menuItem->menuItem) item=menuItemCategory}
                                                                                                                        {if $__wcf->getACPMenu()->getMenuItems($menuItemCategory->menuItem)|count > 0}
                                                                                                                                {foreach from=$__wcf->getACPMenu()->getMenuItems($menuItemCategory->menuItem) item=subMenuItem}
-                                                                                                                                       <li id="{$subMenuItem->menuItem}" data-menu-item="{$subMenuItem->menuItem}"><a href="{$subMenuItem->getLink()}">{lang}{$subMenuItem->menuItem}{/lang}</a></li>
+                                                                                                                                       <li id="{$subMenuItem->menuItem}" data-menu-item="{$subMenuItem->menuItem}"><a href="{$subMenuItem->getLink()}">{$subMenuItem}</a></li>
                                                                                                                                {/foreach}
                                                                                                                        {else}
-                                                                                                                               <li id="{$menuItemCategory->menuItem}" data-menu-item="{$menuItemCategory->menuItem}"><a href="{$menuItemCategory->getLink()}">{lang}{$menuItemCategory->menuItem}{/lang}</a></li>
+                                                                                                                               <li id="{$menuItemCategory->menuItem}" data-menu-item="{$menuItemCategory->menuItem}"><a href="{$menuItemCategory->getLink()}">{$menuItemCategory}</a></li>
                                                                                                                        {/if}
                                                                                                                {/foreach}
                                                                                                        </ul>
index 0df9ac5cad1038b92ea9af93e37a41d0a4e07dea..eaf307682aeaddec0462616b085368a857bc1ff1 100644 (file)
@@ -3,6 +3,8 @@ namespace wcf\data\acp\menu\item;
 use wcf\data\DatabaseObject;
 use wcf\system\menu\ITreeMenuItem;
 use wcf\system\request\LinkHandler;
+use wcf\system\Regex;
+use wcf\system\WCF;
 
 /**
  * Represents an ACP menu item.
@@ -25,10 +27,67 @@ class ACPMenuItem extends DatabaseObject implements ITreeMenuItem {
         */
        protected static $databaseTableIndexName = 'menuItemID';
        
+       /**
+        * application abbreviation
+        * @var string
+        */
+       protected $application = '';
+       
+       /**
+        * menu item controller
+        * @var string
+        */
+       protected $controller = null;
+       
        /**
         * @see wcf\system\menu\ITreeMenuItem::getLink()
         */
        public function getLink() {
-               return LinkHandler::getInstance()->getLink(null, array(), $this->menuItemLink);
+               // external link
+               if (!$this->menuItemController) {
+                       return WCF::getLanguage()->get($this->menuItemLink);
+               }
+       
+               $this->parseController();
+               return LinkHandler::getInstance()->getLink($this->controller, array('application' => $this->application), WCF::getLanguage()->get($this->menuItemLink));
+       }
+       
+       /**
+        * Returns controller name.
+        *
+        * @return      string
+        */
+       public function getController() {
+               $this->parseController();
+       
+               return $this->controller;
+       }
+       
+       /**
+        * Parses controller name.
+        */
+       protected function parseController() {
+               if ($this->controller === null) {
+                       $this->controller = '';
+       
+                       // resolve application and controller
+                       if ($this->menuItemController) {
+                               $parts = explode('\\', $this->menuItemController);
+                               $this->application = array_shift($parts);
+                               $menuItemController = array_pop($parts);
+       
+                               // drop controller suffix
+                               $this->controller = Regex::compile('(Action|Form|Page)$')->replace($menuItemController, '');
+                       }
+               }
+       }
+       
+       /**
+        * Returns the menu item name.
+        *
+        * @return      string
+        */
+       public function __toString() {
+               return WCF::getLanguage()->get($this->menuItem);
        }
 }
index 62672059e10fc0ca6a444befc24501ebaded9646..69e7e237eb7abcc387103d9086d2edd9b6ed7373 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 namespace wcf\system\package\plugin;
+use wcf\system\exception\SystemException;
+use wcf\util\ClassUtil;
 
 /**
  * Installs, updates and deletes ACP menu items.
@@ -16,4 +18,26 @@ class ACPMenuPackageInstallationPlugin extends AbstractMenuPackageInstallationPl
         * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::$className
         */
        public $className = 'wcf\data\acp\menu\item\ACPMenuItemEditor';
+       
+       /**
+        * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::prepareImport()
+        */
+       protected function prepareImport(array $data) {
+               $result = parent::prepareImport($data);
+               
+               // controller
+               $result['menuItemController'] = (isset($data['elements']['controller'])) ? $data['elements']['controller'] : '';
+               if (!empty($result['menuItemController'])) {
+                       if (!ClassUtil::isInstanceOf($result['menuItemController'], 'wcf\action\IAction') && !ClassUtil::isInstanceOf($result['menuItemController'], 'wcf\page\IPage')) {
+                               throw new SystemException("Menu item controller '".$result['menuItemController']."' is not a valid page controller");
+                       }
+               }
+               
+               // validate controller and link (cannot be empty at the same time)
+               if (empty($result['menuItemLink']) && empty($result['menuItemController'])) {
+                       throw new SystemException("Menu item '".$result['menuItem']."' neither has a link nor a controller given");
+               }
+               
+               return $result;
+       }
 }
index a9ee513d85f5c4934981075bcc411b7151c56dff..555be9db07ae06b5fb4d89ecabe352f2776ab6a9 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\system\package\plugin;
 use wcf\system\exception\SystemException;
+use wcf\util\ClassUtil;
 
 /**
  * Installs, updates and deletes page page menu items.
@@ -29,6 +30,11 @@ class PageMenuPackageInstallationPlugin extends AbstractMenuPackageInstallationP
                
                // controller
                $result['menuItemController'] = (isset($data['elements']['controller'])) ? $data['elements']['controller'] : '';
+               if (!empty($result['menuItemController'])) {
+                       if (!ClassUtil::isInstanceOf($result['menuItemController'], 'wcf\action\IAction') && !ClassUtil::isInstanceOf($result['menuItemController'], 'wcf\page\IPage')) {
+                               throw new SystemException("Menu item controller '".$result['menuItemController']."' is not a valid page controller");
+                       }
+               }
                
                // class name
                if (!empty($data['elements']['classname'])) {
index 75acbd3e4310584dbc23a4991f73315d359dddae..a84db208c1eee052566d503634271cc9ed20fe92 100644 (file)
@@ -5,6 +5,7 @@ CREATE TABLE wcf1_acp_menu_item (
        packageID INT(10) NOT NULL,
        menuItem VARCHAR(255) NOT NULL DEFAULT '',
        parentMenuItem VARCHAR(255) NOT NULL DEFAULT '',
+       menuItemController VARCHAR(255) NOT NULL DEFAULT '',
        menuItemLink VARCHAR(255) NOT NULL DEFAULT '',
        showOrder INT(10) NOT NULL DEFAULT 0,
        permissions TEXT,