You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

189 lines
6.8 KiB

  1. <?php
  2. use dokuwiki\Extension\AdminPlugin;
  3. /**
  4. * DokuWiki Plugin extension (Admin Component)
  5. *
  6. * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
  7. * @author Michael Hamann <michael@content-space.de>
  8. */
  9. /**
  10. * Admin part of the extension manager
  11. */
  12. class admin_plugin_extension extends AdminPlugin
  13. {
  14. protected $infoFor;
  15. /** @var helper_plugin_extension_gui */
  16. protected $gui;
  17. /**
  18. * Constructor
  19. *
  20. * loads additional helpers
  21. */
  22. public function __construct()
  23. {
  24. $this->gui = plugin_load('helper', 'extension_gui');
  25. }
  26. /**
  27. * @return int sort number in admin menu
  28. */
  29. public function getMenuSort()
  30. {
  31. return 0;
  32. }
  33. /**
  34. * @return bool true if only access for superuser, false is for superusers and moderators
  35. */
  36. public function forAdminOnly()
  37. {
  38. return true;
  39. }
  40. /**
  41. * Execute the requested action(s) and initialize the plugin repository
  42. */
  43. public function handle()
  44. {
  45. global $INPUT;
  46. // initialize the remote repository
  47. /* @var helper_plugin_extension_repository $repository */
  48. $repository = $this->loadHelper('extension_repository');
  49. if (!$repository->hasAccess(!$INPUT->bool('purge'))) {
  50. $url = $this->gui->tabURL('', ['purge' => 1], '&');
  51. msg($this->getLang('repo_error') .
  52. ' [<a href="' . $url . '" rel="noreferrer">' . $this->getLang('repo_retry') . '</a>]', -1);
  53. }
  54. if (!in_array('ssl', stream_get_transports())) {
  55. msg($this->getLang('nossl'), -1);
  56. }
  57. /* @var helper_plugin_extension_extension $extension */
  58. $extension = $this->loadHelper('extension_extension');
  59. try {
  60. if ($INPUT->post->has('fn') && checkSecurityToken()) {
  61. $actions = $INPUT->post->arr('fn');
  62. foreach ($actions as $action => $extensions) {
  63. foreach ($extensions as $extname => $label) {
  64. switch ($action) {
  65. case 'install':
  66. case 'reinstall':
  67. case 'update':
  68. $extension->setExtension($extname);
  69. $installed = $extension->installOrUpdate();
  70. foreach ($installed as $info) {
  71. msg(sprintf(
  72. $this->getLang('msg_' . $info['type'] . '_' . $info['action'] . '_success'),
  73. $info['base']
  74. ), 1);
  75. }
  76. break;
  77. case 'uninstall':
  78. $extension->setExtension($extname);
  79. $status = $extension->uninstall();
  80. if ($status) {
  81. msg(sprintf(
  82. $this->getLang('msg_delete_success'),
  83. hsc($extension->getDisplayName())
  84. ), 1);
  85. } else {
  86. msg(sprintf(
  87. $this->getLang('msg_delete_failed'),
  88. hsc($extension->getDisplayName())
  89. ), -1);
  90. }
  91. break;
  92. case 'enable':
  93. $extension->setExtension($extname);
  94. $status = $extension->enable();
  95. if ($status !== true) {
  96. msg($status, -1);
  97. } else {
  98. msg(sprintf(
  99. $this->getLang('msg_enabled'),
  100. hsc($extension->getDisplayName())
  101. ), 1);
  102. }
  103. break;
  104. case 'disable':
  105. $extension->setExtension($extname);
  106. $status = $extension->disable();
  107. if ($status !== true) {
  108. msg($status, -1);
  109. } else {
  110. msg(sprintf(
  111. $this->getLang('msg_disabled'),
  112. hsc($extension->getDisplayName())
  113. ), 1);
  114. }
  115. break;
  116. }
  117. }
  118. }
  119. send_redirect($this->gui->tabURL('', [], '&', true));
  120. } elseif ($INPUT->post->str('installurl') && checkSecurityToken()) {
  121. $installed = $extension->installFromURL(
  122. $INPUT->post->str('installurl'),
  123. $INPUT->post->bool('overwrite')
  124. );
  125. foreach ($installed as $info) {
  126. msg(sprintf(
  127. $this->getLang('msg_' . $info['type'] . '_' . $info['action'] . '_success'),
  128. $info['base']
  129. ), 1);
  130. }
  131. send_redirect($this->gui->tabURL('', [], '&', true));
  132. } elseif (isset($_FILES['installfile']) && checkSecurityToken()) {
  133. $installed = $extension->installFromUpload('installfile', $INPUT->post->bool('overwrite'));
  134. foreach ($installed as $info) {
  135. msg(sprintf(
  136. $this->getLang('msg_' . $info['type'] . '_' . $info['action'] . '_success'),
  137. $info['base']
  138. ), 1);
  139. }
  140. send_redirect($this->gui->tabURL('', [], '&', true));
  141. }
  142. } catch (Exception $e) {
  143. msg($e->getMessage(), -1);
  144. send_redirect($this->gui->tabURL('', [], '&', true));
  145. }
  146. }
  147. /**
  148. * Render HTML output
  149. */
  150. public function html()
  151. {
  152. echo '<h1>' . $this->getLang('menu') . '</h1>' . DOKU_LF;
  153. echo '<div id="extension__manager">' . DOKU_LF;
  154. $this->gui->tabNavigation();
  155. switch ($this->gui->currentTab()) {
  156. case 'search':
  157. $this->gui->tabSearch();
  158. break;
  159. case 'templates':
  160. $this->gui->tabTemplates();
  161. break;
  162. case 'install':
  163. $this->gui->tabInstall();
  164. break;
  165. case 'plugins':
  166. default:
  167. $this->gui->tabPlugins();
  168. }
  169. echo '</div>' . DOKU_LF;
  170. }
  171. }
  172. // vim:ts=4:sw=4:et: