diff options
author | Andreas Gohr <andi@splitbrain.org> | 2023-08-29 20:47:52 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2023-08-29 20:47:52 +0200 |
commit | fe2dcfd59ce1d20fda206fc686ee7860088d80a2 (patch) | |
tree | 7474c61c8608cc32016fab49cca47100f7c30ab5 /lib/plugins | |
parent | 467c14277e38168cb2f99ade7ae4bda5b3a20cb1 (diff) | |
download | dokuwiki-fe2dcfd59ce1d20fda206fc686ee7860088d80a2.tar.gz dokuwiki-fe2dcfd59ce1d20fda206fc686ee7860088d80a2.zip |
Apply rector fixes to extension plugin
Diffstat (limited to 'lib/plugins')
-rw-r--r-- | lib/plugins/extension/action.php | 8 | ||||
-rw-r--r-- | lib/plugins/extension/admin.php | 8 | ||||
-rw-r--r-- | lib/plugins/extension/cli.php | 26 | ||||
-rw-r--r-- | lib/plugins/extension/helper/extension.php | 141 | ||||
-rw-r--r-- | lib/plugins/extension/helper/gui.php | 8 | ||||
-rw-r--r-- | lib/plugins/extension/helper/list.php | 42 | ||||
-rw-r--r-- | lib/plugins/extension/helper/repository.php | 27 |
7 files changed, 126 insertions, 134 deletions
diff --git a/lib/plugins/extension/action.php b/lib/plugins/extension/action.php index b57fe558e..b399e1d5f 100644 --- a/lib/plugins/extension/action.php +++ b/lib/plugins/extension/action.php @@ -66,14 +66,14 @@ class action_plugin_extension extends DokuWiki_Action_Plugin $extension->$act(); //enables/disables $reverse = ($act == 'disable') ? 'enable' : 'disable'; - $return = array( + $return = [ 'state' => $act.'d', // isn't English wonderful? :-) 'reverse' => $reverse, - 'label' => $extension->getLang('btn_'.$reverse) - ); + 'label' => $extension->getLang('btn_'.$reverse), + ]; header('Content-Type: application/json'); - echo json_encode($return); + echo json_encode($return, JSON_THROW_ON_ERROR); break; case 'info': diff --git a/lib/plugins/extension/admin.php b/lib/plugins/extension/admin.php index 7e7eb60d4..1a8cb5b64 100644 --- a/lib/plugins/extension/admin.php +++ b/lib/plugins/extension/admin.php @@ -11,7 +11,7 @@ */ class admin_plugin_extension extends DokuWiki_Admin_Plugin { - protected $infoFor = null; + protected $infoFor; /** @var helper_plugin_extension_gui */ protected $gui; @@ -76,7 +76,7 @@ class admin_plugin_extension extends DokuWiki_Admin_Plugin case 'update': $extension->setExtension($extname); $installed = $extension->installOrUpdate(); - foreach ($installed as $ext => $info) { + foreach ($installed as $info) { msg(sprintf( $this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), $info['base']), 1 @@ -130,7 +130,7 @@ class admin_plugin_extension extends DokuWiki_Admin_Plugin $installed = $extension->installFromURL( $INPUT->post->str('installurl'), $INPUT->post->bool('overwrite')); - foreach ($installed as $ext => $info) { + foreach ($installed as $info) { msg(sprintf( $this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), $info['base']), 1 @@ -139,7 +139,7 @@ class admin_plugin_extension extends DokuWiki_Admin_Plugin send_redirect($this->gui->tabURL('', [], '&', true)); } elseif (isset($_FILES['installfile']) && checkSecurityToken()) { $installed = $extension->installFromUpload('installfile', $INPUT->post->bool('overwrite')); - foreach ($installed as $ext => $info) { + foreach ($installed as $info) { msg(sprintf( $this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), $info['base']), 1 diff --git a/lib/plugins/extension/cli.php b/lib/plugins/extension/cli.php index 0e1bf83d5..fed54e6bd 100644 --- a/lib/plugins/extension/cli.php +++ b/lib/plugins/extension/cli.php @@ -1,5 +1,7 @@ <?php +use splitbrain\phpcli\Options; +use splitbrain\phpcli\TableFormatter; use splitbrain\phpcli\Colors; /** @@ -13,7 +15,7 @@ use splitbrain\phpcli\Colors; class cli_plugin_extension extends DokuWiki_CLI_Plugin { /** @inheritdoc */ - protected function setup(\splitbrain\phpcli\Options $options) + protected function setup(Options $options) { // general setup $options->setHelp( @@ -62,7 +64,7 @@ class cli_plugin_extension extends DokuWiki_CLI_Plugin } /** @inheritdoc */ - protected function main(\splitbrain\phpcli\Options $options) + protected function main(Options $options) { /** @var helper_plugin_extension_repository $repo */ $repo = plugin_load('helper', 'extension_repository'); @@ -145,7 +147,7 @@ class cli_plugin_extension extends DokuWiki_CLI_Plugin $ext->setExtension($extname); if (!$ext->isInstalled()) { $this->error(sprintf('Extension %s is not installed', $ext->getID())); - $ok += 1; + ++$ok; continue; } @@ -159,7 +161,7 @@ class cli_plugin_extension extends DokuWiki_CLI_Plugin if ($status !== true) { $this->error($status); - $ok += 1; + ++$ok; continue; } else { $this->success(sprintf($this->getLang($msg), $ext->getID())); @@ -185,7 +187,7 @@ class cli_plugin_extension extends DokuWiki_CLI_Plugin $ext->setExtension($extname); if (!$ext->isInstalled()) { $this->error(sprintf('Extension %s is not installed', $ext->getID())); - $ok += 1; + ++$ok; continue; } @@ -221,13 +223,13 @@ class cli_plugin_extension extends DokuWiki_CLI_Plugin $installed = $ext->installFromURL($extname, true); } catch (Exception $e) { $this->error($e->getMessage()); - $ok += 1; + ++$ok; } } else { $ext->setExtension($extname); if (!$ext->getDownloadURL()) { - $ok += 1; + ++$ok; $this->error( sprintf('Could not find download for %s', $ext->getID()) ); @@ -238,11 +240,11 @@ class cli_plugin_extension extends DokuWiki_CLI_Plugin $installed = $ext->installOrUpdate(); } catch (Exception $e) { $this->error($e->getMessage()); - $ok += 1; + ++$ok; } } - foreach ($installed as $name => $info) { + foreach ($installed as $info) { $this->success( sprintf( $this->getLang('msg_' . $info['type'] . '_' . $info['action'] . '_success'), @@ -301,9 +303,7 @@ class cli_plugin_extension extends DokuWiki_CLI_Plugin global $plugin_controller; $pluginlist = $plugin_controller->getList('', true); $tpllist = glob(DOKU_INC . 'lib/tpl/*', GLOB_ONLYDIR); - $tpllist = array_map(function ($path) { - return 'template:' . basename($path); - }, $tpllist); + $tpllist = array_map(static fn($path) => 'template:' . basename($path), $tpllist); $list = array_merge($pluginlist, $tpllist); sort($list); return $list; @@ -321,7 +321,7 @@ class cli_plugin_extension extends DokuWiki_CLI_Plugin { /** @var helper_plugin_extension_extension $ext */ $ext = $this->loadHelper('extension_extension'); - $tr = new \splitbrain\phpcli\TableFormatter($this->colors); + $tr = new TableFormatter($this->colors); foreach ($list as $name) { diff --git a/lib/plugins/extension/helper/extension.php b/lib/plugins/extension/helper/extension.php index 1d06f0482..1ce1c2dfa 100644 --- a/lib/plugins/extension/helper/extension.php +++ b/lib/plugins/extension/helper/extension.php @@ -5,7 +5,11 @@ * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html * @author Michael Hamann <michael@content-space.de> */ - +use dokuwiki\Extension\PluginInterface; +use dokuwiki\Utf8\PhpString; +use splitbrain\PHPArchive\Tar; +use splitbrain\PHPArchive\ArchiveIOException; +use splitbrain\PHPArchive\Zip; use dokuwiki\HTTP\DokuHTTPClient; use dokuwiki\Extension\PluginController; @@ -21,10 +25,10 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin private $remoteInfo; private $managerData; /** @var helper_plugin_extension_repository $repository */ - private $repository = null; + private $repository; /** @var array list of temporary directories */ - private $temporary = array(); + private $temporary = []; /** @var string where templates are installed to */ private $tpllib = ''; @@ -67,6 +71,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { $id = cleanID($id); $this->id = $id; + $this->base = $id; if (substr($id, 0, 9) == 'template:') { @@ -76,9 +81,9 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin $this->is_template = false; } - $this->localInfo = array(); - $this->managerData = array(); - $this->remoteInfo = array(); + $this->localInfo = []; + $this->managerData = []; + $this->remoteInfo = []; if ($this->isInstalled()) { $this->readLocalData(); @@ -125,12 +130,24 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin if (!empty($this->remoteInfo['bundled'])) return $this->remoteInfo['bundled']; return in_array( $this->id, - array( - 'authad', 'authldap', 'authpdo', 'authplain', - 'acl', 'config', 'extension', 'info', 'popularity', 'revert', - 'safefnrecode', 'styling', 'testing', 'usermanager', 'logviewer', - 'template:dokuwiki', - ) + [ + 'authad', + 'authldap', + 'authpdo', + 'authplain', + 'acl', + 'config', + 'extension', + 'info', + 'popularity', + 'revert', + 'safefnrecode', + 'styling', + 'testing', + 'usermanager', + 'logviewer', + 'template:dokuwiki' + ] ); } @@ -352,7 +369,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin public function getDependencies() { if (!empty($this->remoteInfo['dependencies'])) return $this->remoteInfo['dependencies']; - return array(); + return []; } /** @@ -365,7 +382,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin /* @var PluginController $plugin_controller */ global $plugin_controller; $dependencies = $this->getDependencies(); - $missing_dependencies = array(); + $missing_dependencies = []; foreach ($dependencies as $dependency) { if (!$plugin_controller->isEnabled($dependency)) { $missing_dependencies[] = $dependency; @@ -382,7 +399,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin public function getConflicts() { if (!empty($this->remoteInfo['conflicts'])) return $this->remoteInfo['conflicts']; - return array(); + return []; } /** @@ -393,7 +410,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin public function getSimilarExtensions() { if (!empty($this->remoteInfo['similar'])) return $this->remoteInfo['similar']; - return array(); + return []; } /** @@ -404,7 +421,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin public function getTags() { if (!empty($this->remoteInfo['tags'])) return $this->remoteInfo['tags']; - return array(); + return []; } /** @@ -537,8 +554,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin public function getTypes() { if (!empty($this->remoteInfo['types'])) return $this->remoteInfo['types']; - if ($this->isTemplate()) return array(32 => 'template'); - return array(); + if ($this->isTemplate()) return [32 => 'template']; + return []; } /** @@ -549,7 +566,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin public function getCompatibleVersions() { if (!empty($this->remoteInfo['compatible'])) return $this->remoteInfo['compatible']; - return array(); + return []; } /** @@ -636,16 +653,10 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin if (!move_uploaded_file($_FILES[$field]['tmp_name'], "$tmp/upload.archive")) { throw new Exception($this->getLang('msg_upload_failed')); } - - try { - $installed = $this->installArchive("$tmp/upload.archive", $overwrite, $basename); - $this->updateManagerData('', $installed); - $this->removeDeletedfiles($installed); - // purge cache - $this->purgeCache(); - } catch (Exception $e) { - throw $e; - } + $installed = $this->installArchive("$tmp/upload.archive", $overwrite, $basename); + $this->updateManagerData('', $installed); + $this->removeDeletedfiles($installed); + $this->purgeCache(); return $installed; } @@ -659,17 +670,11 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin */ public function installFromURL($url, $overwrite = true) { - try { - $path = $this->download($url); - $installed = $this->installArchive($path, $overwrite); - $this->updateManagerData($url, $installed); - $this->removeDeletedfiles($installed); - - // purge cache - $this->purgeCache(); - } catch (Exception $e) { - throw $e; - } + $path = $this->download($url); + $installed = $this->installArchive($path, $overwrite); + $this->updateManagerData($url, $installed); + $this->removeDeletedfiles($installed); + $this->purgeCache(); return $installed; } @@ -781,7 +786,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin foreach (PluginController::PLUGIN_TYPES as $type) { if (file_exists($path.$type.'.php')) { $plugin = plugin_load($type, $this->base); - if ($plugin) break; + if ($plugin instanceof PluginInterface) break; } if ($dh = @opendir($path.$type.'/')) { @@ -789,14 +794,14 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin if ($cp == '.' || $cp == '..' || strtolower(substr($cp, -4)) != '.php') continue; $plugin = plugin_load($type, $this->base.'_'.substr($cp, 0, -4)); - if ($plugin) break; + if ($plugin instanceof PluginInterface) break; } - if ($plugin) break; + if ($plugin instanceof PluginInterface) break; closedir($dh); } } - if ($plugin) { + if ($plugin instanceof PluginInterface) { /* @var DokuWiki_Plugin $plugin */ $this->localInfo = $plugin->getInfo(); } @@ -814,10 +819,10 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin $origID = $this->getID(); if (is_null($installed)) { - $installed = array($origID); + $installed = [$origID]; } - foreach ($installed as $ext => $info) { + foreach (array_keys($installed) as $ext) { if ($this->getID() != $ext) $this->setExtension($ext); if ($url) { $this->managerData['downloadurl'] = $url; @@ -845,7 +850,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin $file = @file($managerpath); if (!empty($file)) { foreach ($file as $line) { - list($key, $value) = sexplode('=', trim($line, DOKU_LF), 2, ''); + [$key, $value] = sexplode('=', trim($line, DOKU_LF), 2, ''); $key = trim($key); $value = trim($value); // backwards compatible with old plugin manager @@ -913,11 +918,11 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin $name = ''; if (isset($http->resp_headers['content-disposition'])) { $content_disposition = $http->resp_headers['content-disposition']; - $match = array(); + $match = []; if (is_string($content_disposition) && preg_match('/attachment;\s*filename\s*=\s*"([^"]*)"/i', $content_disposition, $match) ) { - $name = \dokuwiki\Utf8\PhpString::basename($match[1]); + $name = PhpString::basename($match[1]); } } @@ -927,14 +932,14 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin $name = $defaultName; } - $file = $file.$name; + $file .= $name; $fileexists = file_exists($file); $fp = @fopen($file,"w"); if (!$fp) return false; fwrite($fp, $data); fclose($fp); - if (!$fileexists and $conf['fperm']) chmod($file, $conf['fperm']); + if (!$fileexists && $conf['fperm']) chmod($file, $conf['fperm']); return $name; } @@ -957,7 +962,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin if (is_null($file)) { $file = md5($url); } else { - $file = \dokuwiki\Utf8\PhpString::basename($file); + $file = PhpString::basename($file); } // create tmp directory for download @@ -985,7 +990,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin */ public function installArchive($file, $overwrite = false, $base = '') { - $installed_extensions = array(); + $installed_extensions = []; // create tmp directory for decompression if (!($tmp = $this->mkTmpDir())) { @@ -1002,7 +1007,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin // search $tmp/$base for the folder(s) that has been created // move the folder(s) to lib/.. - $result = array('old'=>array(), 'new'=>array()); + $result = ['old'=>[], 'new'=>[]]; $default = ($this->isTemplate() ? 'template' : 'plugin'); if (!$this->findFolders($result, $tmp.'/'.$base, $default)) { throw new Exception($this->getLang('error_findfolder')); @@ -1057,11 +1062,11 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin if ($item['type'] == 'template') { $id = 'template:'.$id; } - $installed_extensions[$id] = array( + $installed_extensions[$id] = [ 'base' => $item['base'], 'type' => $item['type'], 'action' => $action - ); + ]; } else { throw new Exception(sprintf($this->getLang('error_copy').DOKU_LF, '<bdi>'.$item['base'].'</bdi>') @@ -1105,7 +1110,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin $dh = @opendir($this_dir); if (!$dh) return false; - $found_dirs = array(); + $found_dirs = []; $found_files = 0; $found_template_parts = 0; while (false !== ($f = readdir($dh))) { @@ -1120,7 +1125,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin case 'plugin.info.txt': case 'template.info.txt': // we have found a clear marker, save and return - $info = array(); + $info = []; $type = explode('.', $f, 2); $info['type'] = $type[0]; $info['tmp'] = $this_dir; @@ -1142,7 +1147,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin // files where found but no info.txt - use old method if ($found_files) { - $info = array(); + $info = []; $info['tmp'] = $this_dir; // does this look like a template or should we use the default type? if ($found_template_parts >= 2) { @@ -1178,23 +1183,23 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin if (substr($target, -1) == "/") $target = substr($target, 0, -1); $ext = $this->guessArchiveType($file); - if (in_array($ext, array('tar', 'bz', 'gz'))) { + if (in_array($ext, ['tar', 'bz', 'gz'])) { try { - $tar = new \splitbrain\PHPArchive\Tar(); + $tar = new Tar(); $tar->open($file); $tar->extract($target); - } catch (\splitbrain\PHPArchive\ArchiveIOException $e) { - throw new Exception($this->getLang('error_decompress').' '.$e->getMessage()); + } catch (ArchiveIOException $e) { + throw new Exception($this->getLang('error_decompress').' '.$e->getMessage(), $e->getCode(), $e); } return true; } elseif ($ext == 'zip') { try { - $zip = new \splitbrain\PHPArchive\Zip(); + $zip = new Zip(); $zip->open($file); $zip->extract($target); - } catch (\splitbrain\PHPArchive\ArchiveIOException $e) { - throw new Exception($this->getLang('error_decompress').' '.$e->getMessage()); + } catch (ArchiveIOException $e) { + throw new Exception($this->getLang('error_decompress').' '.$e->getMessage(), $e->getCode(), $e); } return true; @@ -1269,7 +1274,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin */ private function removeDeletedfiles($installed) { - foreach ($installed as $id => $extension) { + foreach ($installed as $extension) { // only on update if ($extension['action'] == 'install') continue; diff --git a/lib/plugins/extension/helper/gui.php b/lib/plugins/extension/helper/gui.php index 919eb2c0b..1391774ef 100644 --- a/lib/plugins/extension/helper/gui.php +++ b/lib/plugins/extension/helper/gui.php @@ -13,7 +13,7 @@ use dokuwiki\Form\Form; */ class helper_plugin_extension_gui extends DokuWiki_Plugin { - protected $tabs = array('plugins', 'templates', 'search', 'install'); + protected $tabs = ['plugins', 'templates', 'search', 'install']; /** @var string the extension that should have an open info window FIXME currently broken */ protected $infoFor = ''; @@ -225,11 +225,11 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin global $INPUT; if (!$tab) $tab = $this->currentTab(); - $defaults = array( + $defaults = [ 'do' => 'admin', 'page' => 'extension', - 'tab' => $tab, - ); + 'tab' => $tab + ]; if ($tab == 'search') $defaults['q'] = $INPUT->str('q'); return wl($ID, array_merge($defaults, $params), $absolute, $sep); diff --git a/lib/plugins/extension/helper/list.php b/lib/plugins/extension/helper/list.php index 647575b10..9ec1123ad 100644 --- a/lib/plugins/extension/helper/list.php +++ b/lib/plugins/extension/helper/list.php @@ -155,13 +155,13 @@ class helper_plugin_extension_list extends DokuWiki_Plugin } else { $linktype = 'extern'; } - $param = array( + $param = [ 'href' => $url, 'title' => $url, 'class' => ($linktype == 'extern') ? 'urlextern' : 'interwiki iw_doku', 'target' => $conf['target'][$linktype], - 'rel' => ($linktype == 'extern') ? 'noopener' : '', - ); + 'rel' => ($linktype == 'extern') ? 'noopener' : '' + ]; if ($linktype == 'extern' && $conf['relnofollow']) { $param['rel'] = implode(' ', [$param['rel'], 'ugc nofollow']); } @@ -201,7 +201,7 @@ class helper_plugin_extension_list extends DokuWiki_Plugin if ($extension->getAuthor()) { $mailid = $extension->getEmailID(); if ($mailid) { - $url = $this->gui->tabURL('search', array('q' => 'authorid:'.$mailid)); + $url = $this->gui->tabURL('search', ['q' => 'authorid:'.$mailid]); $html = '<a href="'.$url.'" class="author" title="'.$this->getLang('author_hint').'" >'. '<img src="//www.gravatar.com/avatar/'.$mailid. '?s=20&d=mm" width="20" height="20" alt="" /> '. @@ -288,7 +288,7 @@ class helper_plugin_extension_list extends DokuWiki_Plugin $url = $this->gui->tabURL(''); $class = 'close'; } else { - $url = $this->gui->tabURL('', array('info' => $extension->getID())); + $url = $this->gui->tabURL('', ['info' => $extension->getID()]); $class = ''; } $html .= ' <a href="'.$url.'#extensionplugin__'.$extension->getID(). @@ -322,13 +322,13 @@ class helper_plugin_extension_list extends DokuWiki_Plugin } else { $linktype = 'extern'; } - $param = array( + $param = [ 'href' => $bugtrackerURL, 'title' => $bugtrackerURL, 'class' => 'bugs', 'target' => $conf['target'][$linktype], - 'rel' => ($linktype == 'extern') ? 'noopener' : '', - ); + 'rel' => ($linktype == 'extern') ? 'noopener' : '' + ]; if ($conf['relnofollow']) { $param['rel'] = implode(' ', [$param['rel'], 'ugc nofollow']); } @@ -544,7 +544,7 @@ class helper_plugin_extension_list extends DokuWiki_Plugin $html = ''; foreach ($ext as $link) { $html .= '<bdi><a href="'. - $this->gui->tabURL('search', array('q'=>'ext:'.$link)).'">'. + $this->gui->tabURL('search', ['q'=>'ext:'.$link]).'">'. hsc($link).'</a></bdi>, '; } return rtrim($html, ', '); @@ -577,7 +577,6 @@ class helper_plugin_extension_list extends DokuWiki_Plugin } else { $errors .= '<p class="permerror">'.$this->getLang($canmod).'</p>'; } - if (!$extension->isProtected() && !$extension->isTemplate()) { // no enable/disable for templates if ($extension->isEnabled()) { $html .= $this->makeAction('disable', $extension); @@ -585,25 +584,21 @@ class helper_plugin_extension_list extends DokuWiki_Plugin $html .= $this->makeAction('enable', $extension); } } - if ($extension->isGitControlled()) { $errors .= '<p class="permerror">'.$this->getLang('git').'</p>'; } - if ($extension->isEnabled() && in_array('Auth', $extension->getTypes()) && $conf['authtype'] != $extension->getID() ) { $errors .= '<p class="permerror">'.$this->getLang('auth').'</p>'; } - } else { - if (($canmod = $extension->canModify()) === true) { - if ($extension->getDownloadURL()) { - $html .= $this->makeAction('install', $extension); - } - } else { - $errors .= '<div class="permerror">'.$this->getLang($canmod).'</div>'; + } elseif (($canmod = $extension->canModify()) === true) { + if ($extension->getDownloadURL()) { + $html .= $this->makeAction('install', $extension); } + } else { + $errors .= '<div class="permerror">'.$this->getLang($canmod).'</div>'; } if (!$extension->isInstalled() && $extension->getDownloadURL()) { @@ -627,11 +622,8 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { $title = ''; - switch ($action) { - case 'install': - case 'reinstall': - $title = 'title="'.hsc($extension->getDownloadURL()).'"'; - break; + if ($action == 'install' || $action == 'reinstall') { + $title = 'title="'.hsc($extension->getDownloadURL()).'"'; } $classes = 'button '.$action; @@ -650,7 +642,7 @@ class helper_plugin_extension_list extends DokuWiki_Plugin */ public function makeStatus(helper_plugin_extension_extension $extension) { - $status = array(); + $status = []; if ($extension->isInstalled()) { $status[] = $this->getLang('status_installed'); diff --git a/lib/plugins/extension/helper/repository.php b/lib/plugins/extension/helper/repository.php index 0bca6c975..dfebd3a51 100644 --- a/lib/plugins/extension/helper/repository.php +++ b/lib/plugins/extension/helper/repository.php @@ -18,8 +18,8 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin const EXTENSION_REPOSITORY_API = 'https://www.dokuwiki.org/lib/plugins/pluginrepo/api.php'; - private $loaded_extensions = array(); - private $has_access = null; + private $loaded_extensions = []; + private $has_access; /** * Initialize the repository (cache), fetches data for all installed plugins @@ -30,14 +30,14 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin global $plugin_controller; if ($this->hasAccess()) { $list = $plugin_controller->getList('', true); - $request_data = array('fmt' => 'php'); + $request_data = ['fmt' => 'php']; $request_needed = false; foreach ($list as $name) { $cache = new Cache('##extension_manager##'.$name, '.repo'); if (!isset($this->loaded_extensions[$name]) && $this->hasAccess() && - !$cache->useCache(array('age' => 3600 * 24)) + !$cache->useCache(['age' => 3600 * 24]) ) { $this->loaded_extensions[$name] = true; $request_data['ext'][] = $name; @@ -71,7 +71,7 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin if ($this->has_access === null) { $cache = new Cache('##extension_manager###hasAccess', '.repo'); - if (!$cache->useCache(array('age' => 60*10, 'purge' => !$usecache))) { + if (!$cache->useCache(['age' => 60*10, 'purge' => !$usecache])) { $httpclient = new DokuHTTPClient(); $httpclient->timeout = 5; $data = $httpclient->get(self::EXTENSION_REPOSITORY_API.'?cmd=ping'); @@ -101,7 +101,7 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin if (!isset($this->loaded_extensions[$name]) && $this->hasAccess() && - !$cache->useCache(array('age' => 3600 * 24)) + !$cache->useCache(['age' => 3600 * 24]) ) { $this->loaded_extensions[$name] = true; $httpclient = new DokuHTTPClient(); @@ -112,7 +112,7 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin $cache->storeCache(serialize($result[0])); return $result[0]; } - return array(); + return []; } else { $this->has_access = false; } @@ -120,7 +120,7 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin if (file_exists($cache->cache)) { return unserialize($cache->retrieveCache(false)); } - return array(); + return []; } /** @@ -136,10 +136,10 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin $httpclient = new DokuHTTPClient(); $data = $httpclient->post(self::EXTENSION_REPOSITORY_API, $query); - if ($data === false) return array(); + if ($data === false) return []; $result = unserialize($data); - $ids = array(); + $ids = []; // store cache info for each extension foreach ($result as $ext) { @@ -160,12 +160,7 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin */ protected function parseQuery($q) { - $parameters = array( - 'tag' => array(), - 'mail' => array(), - 'type' => array(), - 'ext' => array() - ); + $parameters = ['tag' => [], 'mail' => [], 'type' => [], 'ext' => []]; // extract tags if (preg_match_all('/(^|\s)(tag:([\S]+))/', $q, $matches, PREG_SET_ORDER)) { |