*/ // must be run within Dokuwiki use dokuwiki\plugin\issuelinks\classes\ServiceProvider; use dokuwiki\plugin\issuelinks\services\ServiceInterface; class admin_plugin_issuelinks_repoadmin extends DokuWiki_Admin_Plugin { private $orgs = []; private $configNeeded = []; /** * @return int sort number in admin menu */ public function getMenuSort() { return 500; } /** * Return the text that is displayed at the main admin menu * (Default localized language string 'menu' is returned, override this function for setting another name) * * @param string $language language code * * @return string menu string */ public function getMenuText($language) { return $this->getLang('menu:repo-admin'); } public function getMenuIcon() { $plugin = $this->getPluginName(); return DOKU_PLUGIN . $plugin . '/images/issue-opened.svg'; } /** * @return bool true if only access for superuser, false is for superusers and moderators */ public function forAdminOnly() { return true; } /** * Should carry out any processing required by the plugin. */ public function handle() { global $INPUT; $serviceProvider = ServiceProvider::getInstance(); /** @var ServiceInterface[] $services */ $services = $serviceProvider->getServices(); if ($INPUT->has('authorize')) { $serviceID = $INPUT->str('authorize'); $service = $services[$serviceID]::getInstance(); $service->handleAuthorization(); } foreach ($services as $serviceID => $serviceClass) { $service = $serviceClass::getInstance(); $this->orgs[$serviceID] = []; if ($INPUT->str('reconfigureService') === $serviceID || !$service->isConfigured()) { $this->configNeeded[] = $serviceID; continue; } $this->orgs[$serviceID] = $service->getListOfAllUserOrganisations(); sort($this->orgs[$serviceID]); } } /** * Render HTML output, e.g. helpful text and a form */ public function html() { $activeServices = array_keys($this->orgs); $html = "
No organisations available for ' . $serviceName . '
'; } else { global $INPUT; $reconfigureURL = $INPUT->server->str('REQUEST_URI') . '&reconfigureService=' . $serviceID; $reconfigureLink = "{$this->getLang('label: reconfigure service')}"; $authorizedUserLabel = sprintf($this->getLang('label: authorized with user'), $service->getUserString()); $form = new \dokuwiki\Form\Form(['data-service' => $serviceID]); $form->addFieldsetOpen($this->getLang('legend:user')); $form->addTagOpen('p'); $form->addHTML($authorizedUserLabel . ' ' . $reconfigureLink); $form->addTagClose('p'); $form->addFieldsetClose(); $form->addFieldsetOpen($this->getLang("legend:group $serviceID")); $form->addDropdown( 'mm_organisation', array_merge([''], $this->orgs[$serviceID]), $this->getLang("label $serviceID:choose organisation") ); $form->addFieldsetClose(); $html .= $form->toHTML(); $html .= ""; } $html .= '