From 875f9efe0c294b53cdde087b617be4e88510de2f Mon Sep 17 00:00:00 2001 From: chris <chris@jalakai.co.uk> Date: Fri, 13 Jan 2006 03:34:14 +0100 Subject: [PATCH] plugin manager update, remove js & css file aggregation, improve error handling darcs-hash:20060113023414-9b6ab-76bd7b12af34e8f32135c32c22403bd0fb14c98a.gz --- lib/plugins/plugin/admin.php | 73 +++++++++++------------------ lib/plugins/plugin/lang/de/lang.php | 1 - lib/plugins/plugin/lang/en/lang.php | 5 +- lib/plugins/plugin/lang/pl/lang.php | 1 - 4 files changed, 30 insertions(+), 50 deletions(-) diff --git a/lib/plugins/plugin/admin.php b/lib/plugins/plugin/admin.php index c767654ee..cffcf8057 100644 --- a/lib/plugins/plugin/admin.php +++ b/lib/plugins/plugin/admin.php @@ -17,9 +17,8 @@ require_once(DOKU_PLUGIN.'admin.php'); //--------------------------[ GLOBALS ]------------------------------------------------ // note: probably should be dokuwiki wide globals, where they can be accessed by pluginutils.php - global $common_plugin_files, $common_plugin_types; + global $common_plugin_types; $common_plugin_types = array('syntax', 'admin'); - $common_plugin_files = array("style.css", "screen.css", "print.css", "script.js"); /** * All DokuWiki plugins to extend the admin function @@ -190,7 +189,7 @@ class ap_manage { } function html_pluginlist() { - global $ID; + global $ID; foreach ($this->manager->plugin_list as $plugin) { @@ -205,8 +204,9 @@ class ap_manage { ptln(' <input type="hidden" name="plugin" value="'.$plugin.'" />'); $this->html_button('info', false, 6); - if (in_array('settings', $this->manager->functions)) - $this->html_button('settings', !@file_exists(DOKU_PLUGIN.$plugin.'/settings.php'), 6); + if (in_array('settings', $this->manager->functions)) { + $this->html_button('settings', !@file_exists(DOKU_PLUGIN.$plugin.'/settings.php'), 6); + } $this->html_button('update', !$this->plugin_readlog($plugin, 'url'), 6); $this->html_button('delete', false, 6); @@ -221,39 +221,12 @@ class ap_manage { } /** - * Rebuild aggregated files & update latest plugin date + * Refresh plugin list */ function refresh() { - global $lang; - global $common_plugin_files; sort($this->manager->plugin_list = plugin_list()); - foreach ($common_plugin_files as $file) { - $aggregate = ''; - - // could replace with an class/object based aggregator, - // that way special files could have their own aggregator - foreach ($this->manager->plugin_list as $plugin) { - if (@file_exists(DOKU_PLUGIN."$plugin/$file")) { - $contents = @file_get_contents(DOKU_PLUGIN."$plugin/$file")."\n"; - - // url conversion for css files - if (is_css($file)) { - $contents = preg_replace('/(url\([\'\"]?)([^\/](?![a-zA-Z0-9]+:\/\/).*?)([\'\"]?\))/','$1'.$plugin.'/$2$3',$contents); - } - - $aggregate .= $contents; - } - } - - if (trim($aggregate)) { - if (!io_savefile(DOKU_PLUGIN."plugin_$file", $aggregate)) { - $this->manager->error .= sprintf($this->lang['error_write'],$file); - } - } - } - // update latest plugin date - FIXME return (!$this->manager->error); } @@ -408,7 +381,7 @@ class ap_manage { ptln('<h2>'.$this->lang['downloading'].'</h2>'); if ($this->manager->error) { - ptln('<p class="error">'.str_replace("\n","<br />",$this->manager->error).'</p>'); + ptln('<div class="error">'.str_replace("\n","<br />",$this->manager->error).'</div>'); } else if (count($this->downloaded) == 1) { ptln('<p>'.sprintf($this->lang['downloaded'],$this->downloaded[0]).'</p>'); } else if (count($this->downloaded)) { // more than one plugin in the download @@ -430,16 +403,24 @@ class ap_manage { function process() { - ap_delete(DOKU_PLUGIN.$this->manager->plugin); - $this->refresh(); + if (!ap_delete(DOKU_PLUGIN.$this->manager->plugin)) { + $this->manager->error = sprintf($this->lang['error_delete'],$this->manager->plugin); + } else { + $this->refresh(); + } } function html() { parent::html(); ptln('<div class="pm_info">'); - ptln('<h2>'.$this->lang['deleting'].'</h2>'); - ptln('<p>'.sprintf($this->lang['deleted'],$this->plugin).'</p>'); + ptln('<h2>'.$this->lang['deleting'].'</h2>'); + + if ($this->manager->error) { + ptln('<div class="error">'.str_replace("\n","<br />",$this->manager->error).'</div>'); + } else { + ptln('<p>'.sprintf($this->lang['deleted'],$this->plugin).'</p>'); + } ptln('</div>'); } } @@ -558,7 +539,7 @@ class ap_manage { ptln('<h2>'.$this->lang['updating'].'</h2>'); if ($this->manager->error) { - ptln('<p class="error">'.str_replace("\n","<br />", $this->manager->error).'</p>'); + ptln('<div class="error">'.str_replace("\n","<br />", $this->manager->error).'</div>'); } else if (count($this->downloaded) == 1) { ptln('<p>'.sprintf($this->lang['updated'],$this->downloaded[0]).'</p>'); } else if (count($this->downloaded)) { // more than one plugin in the download @@ -664,23 +645,23 @@ class ap_manage { // delete, with recursive sub-directory support function ap_delete($path) { - if (!is_string($path) || $path == "") return; + if (!is_string($path) || $path == "") return false; if (is_dir($path)) { - if (!$dh = @opendir($path)) return; + if (!$dh = @opendir($path)) return false; while ($f = readdir($dh)) { if ($f == '..' || $f == '.') continue; ap_delete("$path/$f"); } - + closedir($dh); - rmdir($path); - return; - + return @rmdir($path); } else { - unlink($path); + return @unlink($path); } + + return false; } // return a list (name & type) of all the component plugins that make up this plugin diff --git a/lib/plugins/plugin/lang/de/lang.php b/lib/plugins/plugin/lang/de/lang.php index e48a70a73..462a0264f 100644 --- a/lib/plugins/plugin/lang/de/lang.php +++ b/lib/plugins/plugin/lang/de/lang.php @@ -49,7 +49,6 @@ $lang['download_none'] = 'Keine Plugins gefunden oder es trat ein Fehler beim // error messages $lang['error_download'] = 'Konnte das Plugin %s nicht installieren'; -$lang['error_write'] = 'Konnte keine vereinigte Datei für %s erstellen'; $lang['error_badurl'] = 'Wahrscheinlich ungültige URL, konnte keinen Dateinamen ausfindig machen'; $lang['error_dircreate'] = 'Konnte keinen temporären Ordner für die Downloads erstellen'; //$lang['error_'] = ''; diff --git a/lib/plugins/plugin/lang/en/lang.php b/lib/plugins/plugin/lang/en/lang.php index 57550d72e..665cd8d18 100644 --- a/lib/plugins/plugin/lang/en/lang.php +++ b/lib/plugins/plugin/lang/en/lang.php @@ -68,15 +68,16 @@ $lang['www'] = 'Web:'; // error messages $lang['error'] = 'An unknown error occurred.'; $lang['error_download'] = 'Unable to download the plugin file: %s'; -$lang['error_write'] = 'Unable to create aggregate file %s'; $lang['error_badurl'] = 'Suspect bad url - unable to determine file name from the url'; $lang['error_dircreate'] = 'Unable to create temporary folder to receive download'; $lang['error_decompress'] = 'The plugin manager was unable to decompress the downloaded file. '. 'This maybe as a result of a bad download, in which case you should try again; '. 'or the compression format may be unknown, in which case you will need to download and install the plugin manually.'; -$lang['error_copy'] = 'There was a file copy error while attempting to install files for plugin %s: '. +$lang['error_copy'] = 'There was a file copy error while attempting to install files for plugin <em>%s</em>: '. 'the disk could be full or file access permissions may be incorrect. '. 'This may have resulted in a partially installed plugin and leave your wiki installation unstable.'; +$lang['error_delete'] = 'There was an error while attempting to delete plugin <em>%s</em>. '. + 'The most probably cause is insufficient file or directory access permissions'; //$lang['error_'] = ''; //Setup VIM: ex: et ts=2 enc=utf-8 : diff --git a/lib/plugins/plugin/lang/pl/lang.php b/lib/plugins/plugin/lang/pl/lang.php index 518095351..a73438816 100644 --- a/lib/plugins/plugin/lang/pl/lang.php +++ b/lib/plugins/plugin/lang/pl/lang.php @@ -68,7 +68,6 @@ $lang['www'] = 'WWW:'; // error messages $lang['error'] = 'Wystąpił nieznany błąd.'; $lang['error_download'] = 'Nie powiodło się ściągnięcie pliku wtyczki: %s'; -$lang['error_write'] = 'Nie powiodło się stworzenie pliku aggregate %s'; $lang['error_badurl'] = 'Prawdopodobnie zły url - nie da się ustalić nazwy pliku na podstawie urla'; $lang['error_dircreate'] = 'Nie powiodło się stworzenie tymczasowego katalogu na pobrane pliki'; $lang['error_decompress'] = 'Menadżer wtyczek nie był w stanie rozpakować ściągniętego pliku. '. -- GitLab