diff options
author | Christopher Smith <chris@jalakai.co.uk> | 2015-05-16 19:07:23 +0200 |
---|---|---|
committer | Christopher Smith <chris@jalakai.co.uk> | 2015-05-16 19:07:23 +0200 |
commit | a61966c55d9d0ac4b800d65cfc6ee1aea44899b5 (patch) | |
tree | ac4dc0bb88c5efe6e0fdcb834f3a185eb6741fe7 | |
parent | c248bda1dcbef2068071904057b8410aa1eb0200 (diff) | |
download | rpg-a61966c55d9d0ac4b800d65cfc6ee1aea44899b5.tar.gz rpg-a61966c55d9d0ac4b800d65cfc6ee1aea44899b5.tar.bz2 |
Provide a function to return admin plugin for the page request.
This was previously carried out in three separate places. Refactor
that code to use the new function.
Update tpl_pageTitle test to use a manager level admin plugin.
-rw-r--r-- | _test/tests/inc/template_include_page.test.php | 8 | ||||
-rw-r--r-- | inc/actions.php | 17 | ||||
-rw-r--r-- | inc/pluginutils.php | 31 | ||||
-rw-r--r-- | inc/template.php | 30 |
4 files changed, 45 insertions, 41 deletions
diff --git a/_test/tests/inc/template_include_page.test.php b/_test/tests/inc/template_include_page.test.php index 580221979..7dd13ba23 100644 --- a/_test/tests/inc/template_include_page.test.php +++ b/_test/tests/inc/template_include_page.test.php @@ -34,17 +34,17 @@ class template_pagetitle_test extends DokuWikiTest { function test_adminPluginTitle() { global $ID,$ACT,$INPUT,$conf; - if (!plugin_load('admin','config')) { - $this->markTestSkipped('Plugin Config not found, unable to test admin plugin titles'); + if (!plugin_load('admin','revert')) { + $this->markTestSkipped('Revert plugin not found, unable to test admin plugin titles'); return; } $ID = 'foo:bar'; $ACT = 'admin'; $conf['lang'] = 'en'; - $INPUT->set('page','config'); + $INPUT->set('page','revert'); - $this->assertEquals('Configuration Settings', tpl_pagetitle(null, true)); + $this->assertEquals('Revert Manager', tpl_pagetitle(null, true)); } function test_nonPageFunctionTitle() { diff --git a/inc/actions.php b/inc/actions.php index 709c19ddd..b0753b22e 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -162,20 +162,9 @@ function act_dispatch(){ if($ACT == 'admin'){ // retrieve admin plugin name from $_REQUEST['page'] if (($page = $INPUT->str('page', '', true)) != '') { - $pluginlist = plugin_list('admin'); - if (in_array($page, $pluginlist)) { - // attempt to load the plugin - - if (($plugin = plugin_load('admin',$page)) !== null){ - /** @var DokuWiki_Admin_Plugin $plugin */ - if($plugin->forAdminOnly() && !$INFO['isadmin']){ - // a manager tried to load a plugin that's for admins only - $INPUT->remove('page'); - msg('For admins only',-1); - }else{ - $plugin->handle(); - } - } + /** @var $plugin DokuWiki_Admin_Plugin */ + if ($plugin = plugin_getRequestAdminPlugin()){ + $plugin->handle(); } } } diff --git a/inc/pluginutils.php b/inc/pluginutils.php index 4d591869d..60f79869f 100644 --- a/inc/pluginutils.php +++ b/inc/pluginutils.php @@ -103,3 +103,34 @@ function plugin_getcascade() { global $plugin_controller; return $plugin_controller->getCascade(); } + + +/** + * Return the currently operating admin plugin or null + * if not on an admin plugin page + * + * @return Doku_Plugin_Admin + */ +function plugin_getRequestAdminPlugin(){ + static $admin_plugin = false; + global $ACT,$INPUT,$INFO; + + if ($admin_plugin === false) { + if (($ACT == 'admin') && ($page = $INPUT->str('page', '', true)) != '') { + $pluginlist = plugin_list('admin'); + if (in_array($page, $pluginlist)) { + // attempt to load the plugin + /** @var $admin_plugin DokuWiki_Admin_Plugin */ + $admin_plugin = plugin_load('admin', $page); + // verify + if ($admin_plugin && $admin_plugin->forAdminOnly() && !$INFO['isadmin']) { + $admin_plugin = null; + $INPUT->remove('page'); + msg('For admins only',-1); + } + } + } + } + + return $admin_plugin; +} diff --git a/inc/template.php b/inc/template.php index 39d06e895..95dc52deb 100644 --- a/inc/template.php +++ b/inc/template.php @@ -218,18 +218,9 @@ function tpl_toc($return = false) { $toc = array(); } } elseif($ACT == 'admin') { - // try to load admin plugin TOC FIXME: duplicates code from tpl_admin - $plugin = null; - $class = $INPUT->str('page'); - if(!empty($class)) { - $pluginlist = plugin_list('admin'); - if(in_array($class, $pluginlist)) { - // attempt to load the plugin - /** @var $plugin DokuWiki_Admin_Plugin */ - $plugin = plugin_load('admin', $class); - } - } - if( ($plugin !== null) && (!$plugin->forAdminOnly() || $INFO['isadmin']) ) { + // try to load admin plugin TOC + /** @var $plugin DokuWiki_Admin_Plugin */ + if ($plugin = plugin_getRequestAdminPlugin()) { $toc = $plugin->getTOC(); $TOC = $toc; // avoid later rebuild } @@ -1054,17 +1045,10 @@ function tpl_pagetitle($id = null, $ret = false) { case 'admin' : $page_title = $lang['btn_admin']; // try to get the plugin name - // retrieve admin plugin name from $_REQUEST['page'] - if (($page = $INPUT->str('page', '', true)) != '') { - $pluginlist = plugin_list('admin'); - if (in_array($page, $pluginlist)) { - // attempt to load the plugin - - if (($plugin = plugin_load('admin',$page)) !== null){ - $plugin_title = $plugin->getMenuText($conf['lang']); - $page_title = $plugin_title ? $plugin_title : $page; - } - } + /** @var $plugin DokuWiki_Admin_Plugin */ + if ($plugin = plugin_getRequestAdminPlugin()){ + $plugin_title = $plugin->getMenuText($conf['lang']); + $page_title = $plugin_title ? $plugin_title : $plugin->getPluginName(); } break; |