AdminPlugin.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace dokuwiki\Extension;
  3. /**
  4. * Admin Plugin Prototype
  5. *
  6. * Implements an admin interface in a plugin
  7. *
  8. * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  9. * @author Christopher Smith <chris@jalakai.co.uk>
  10. */
  11. abstract class AdminPlugin extends Plugin
  12. {
  13. /**
  14. * Return the text that is displayed at the main admin menu
  15. * (Default localized language string 'menu' is returned, override this function for setting another name)
  16. *
  17. * @param string $language language code
  18. * @return string menu string
  19. */
  20. public function getMenuText($language)
  21. {
  22. $menutext = $this->getLang('menu');
  23. if (!$menutext) {
  24. $info = $this->getInfo();
  25. $menutext = $info['name'] . ' ...';
  26. }
  27. return $menutext;
  28. }
  29. /**
  30. * Return the path to the icon being displayed in the main admin menu.
  31. * By default it tries to find an 'admin.svg' file in the plugin directory.
  32. * (Override this function for setting another image)
  33. *
  34. * Important: you have to return a single path, monochrome SVG icon! It has to be
  35. * under 2 Kilobytes!
  36. *
  37. * We recommend icons from https://materialdesignicons.com/ or to use a matching
  38. * style.
  39. *
  40. * @return string full path to the icon file
  41. */
  42. public function getMenuIcon()
  43. {
  44. $plugin = $this->getPluginName();
  45. return DOKU_PLUGIN . $plugin . '/admin.svg';
  46. }
  47. /**
  48. * Determine position in list in admin window
  49. * Lower values are sorted up
  50. *
  51. * @return int
  52. */
  53. public function getMenuSort()
  54. {
  55. return 1000;
  56. }
  57. /**
  58. * Carry out required processing
  59. */
  60. public function handle()
  61. {
  62. // some plugins might not need this
  63. }
  64. /**
  65. * Output html of the admin page
  66. */
  67. abstract public function html();
  68. /**
  69. * Checks if access should be granted to this admin plugin
  70. *
  71. * @return bool true if the current user may access this admin plugin
  72. */
  73. public function isAccessibleByCurrentUser() {
  74. $data = [];
  75. $data['instance'] = $this;
  76. $data['hasAccess'] = false;
  77. $event = new Event('ADMINPLUGIN_ACCESS_CHECK', $data);
  78. if($event->advise_before()) {
  79. if ($this->forAdminOnly()) {
  80. $data['hasAccess'] = auth_isadmin();
  81. } else {
  82. $data['hasAccess'] = auth_ismanager();
  83. }
  84. }
  85. $event->advise_after();
  86. return $data['hasAccess'];
  87. }
  88. /**
  89. * Return true for access only by admins (config:superuser) or false if managers are allowed as well
  90. *
  91. * @return bool
  92. */
  93. public function forAdminOnly()
  94. {
  95. return true;
  96. }
  97. /**
  98. * Return array with ToC items. Items can be created with the html_mktocitem()
  99. *
  100. * @see html_mktocitem()
  101. * @see tpl_toc()
  102. *
  103. * @return array
  104. */
  105. public function getTOC()
  106. {
  107. return array();
  108. }
  109. }