From a61966c55d9d0ac4b800d65cfc6ee1aea44899b5 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Sat, 16 May 2015 19:07:23 +0200 Subject: 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. --- inc/pluginutils.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'inc/pluginutils.php') 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; +} -- cgit v1.2.3