manual install tab now works
This commit is contained in:
parent
72dda0b437
commit
fee60c9e19
|
@ -22,7 +22,7 @@ class admin_plugin_extension extends DokuWiki_Admin_Plugin {
|
|||
*
|
||||
* loads additional helpers
|
||||
*/
|
||||
public function __construct(){
|
||||
public function __construct() {
|
||||
$this->gui = plugin_load('helper', 'extension_gui');
|
||||
}
|
||||
|
||||
|
@ -49,37 +49,36 @@ class admin_plugin_extension extends DokuWiki_Admin_Plugin {
|
|||
/* @var helper_plugin_extension_repository $repository */
|
||||
$repository = $this->loadHelper('extension_repository');
|
||||
|
||||
|
||||
if(!$repository->hasAccess()){
|
||||
$url = $this->gui->tabURL('', array('purge'=>1));
|
||||
if(!$repository->hasAccess()) {
|
||||
$url = $this->gui->tabURL('', array('purge' => 1));
|
||||
msg($this->getLang('repo_error').' [<a href="'.$url.'">'.$this->getLang('repo_retry').'</a>]', -1);
|
||||
}
|
||||
|
||||
/* @var helper_plugin_extension_extension $extension */
|
||||
$extension = $this->loadHelper('extension_extension');
|
||||
|
||||
if ($INPUT->post->has('fn')) {
|
||||
if($INPUT->post->has('fn') && checkSecurityToken()) {
|
||||
$actions = $INPUT->post->arr('fn');
|
||||
foreach ($actions as $action => $extensions) {
|
||||
foreach ($extensions as $extname => $label) {
|
||||
switch ($action) {
|
||||
foreach($actions as $action => $extensions) {
|
||||
foreach($extensions as $extname => $label) {
|
||||
switch($action) {
|
||||
case 'install':
|
||||
case 'reinstall':
|
||||
case 'update':
|
||||
try {
|
||||
$extension->setExtension($extname);
|
||||
$installed = $extension->installOrUpdate();
|
||||
foreach($installed as $extension => $info){
|
||||
foreach($installed as $ext => $info) {
|
||||
msg(sprintf($this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), $info['base']), 1);
|
||||
}
|
||||
}catch (Exception $e){
|
||||
} catch(Exception $e) {
|
||||
msg($e->getMessage(), -1);
|
||||
}
|
||||
break;
|
||||
case 'uninstall':
|
||||
$extension->setExtension($extname);
|
||||
$status = $extension->uninstall();
|
||||
if ($status !== true) {
|
||||
if($status !== true) {
|
||||
msg($status, -1);
|
||||
} else {
|
||||
msg(sprintf($this->getLang('msg_delete_success'), hsc($extension->getDisplayName())), 1);
|
||||
|
@ -88,7 +87,7 @@ class admin_plugin_extension extends DokuWiki_Admin_Plugin {
|
|||
case 'enable';
|
||||
$extension->setExtension($extname);
|
||||
$status = $extension->enable();
|
||||
if ($status !== true) {
|
||||
if($status !== true) {
|
||||
msg($status, -1);
|
||||
} else {
|
||||
msg(sprintf($this->getLang('msg_enabled'), hsc($extension->getDisplayName())), 1);
|
||||
|
@ -97,7 +96,7 @@ class admin_plugin_extension extends DokuWiki_Admin_Plugin {
|
|||
case 'disable';
|
||||
$extension->setExtension($extname);
|
||||
$status = $extension->disable();
|
||||
if ($status !== true) {
|
||||
if($status !== true) {
|
||||
msg($status, -1);
|
||||
} else {
|
||||
msg(sprintf($this->getLang('msg_disabled'), hsc($extension->getDisplayName())), 1);
|
||||
|
@ -106,6 +105,24 @@ class admin_plugin_extension extends DokuWiki_Admin_Plugin {
|
|||
}
|
||||
}
|
||||
}
|
||||
} elseif($INPUT->post->str('installurl') && checkSecurityToken()) {
|
||||
try {
|
||||
$installed = $extension->installFromURL($INPUT->post->str('installurl'));
|
||||
foreach($installed as $ext => $info) {
|
||||
msg(sprintf($this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), $info['base']), 1);
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
msg($e->getMessage(), -1);
|
||||
}
|
||||
} elseif(isset($_FILES['installfile']) && checkSecurityToken()) {
|
||||
try {
|
||||
$installed = $extension->installFromUpload('installfile');
|
||||
foreach($installed as $ext => $info) {
|
||||
msg(sprintf($this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), $info['base']), 1);
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
msg($e->getMessage(), -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,7 +135,7 @@ class admin_plugin_extension extends DokuWiki_Admin_Plugin {
|
|||
|
||||
$this->gui->tabNavigation();
|
||||
|
||||
switch($this->gui->currentTab()){
|
||||
switch($this->gui->currentTab()) {
|
||||
case 'search':
|
||||
$this->gui->tabSearch();
|
||||
break;
|
||||
|
@ -133,7 +150,6 @@ class admin_plugin_extension extends DokuWiki_Admin_Plugin {
|
|||
$this->gui->tabPlugins();
|
||||
}
|
||||
|
||||
|
||||
ptln('</div>');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -530,6 +530,67 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install an extension from a user upload
|
||||
*
|
||||
* @param string $field name of the upload file
|
||||
* @throws Exception when something goes wrong
|
||||
* @return array The list of installed extensions
|
||||
*/
|
||||
public function installFromUpload($field){
|
||||
if($_FILES[$field]['error']){
|
||||
throw new Exception($this->getLang('msg_upload_failed').' ('.$_FILES[$field]['error'].')');
|
||||
}
|
||||
|
||||
$tmp = $this->mkTmpDir();
|
||||
if(!$tmp) throw new Exception($this->getLang('error_dircreate'));
|
||||
|
||||
// filename may contain the plugin name for old style plugins...
|
||||
$basename = basename($_FILES[$field]['name']);
|
||||
$basename = preg_replace('/\.(tar\.gz|tar\.bz|tar\.bz2|tar|tgz|tbz|zip)$/', '', $basename);
|
||||
$basename = preg_replace('/[\W]+/', '', $basename);
|
||||
|
||||
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", true, $basename);
|
||||
|
||||
// purge caches
|
||||
foreach($installed as $ext => $info){
|
||||
$this->setExtension($ext);
|
||||
$this->purgeCache();
|
||||
}
|
||||
}catch (Exception $e){
|
||||
throw $e;
|
||||
}
|
||||
return $installed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install an extension from a remote URL
|
||||
*
|
||||
* @param string $url
|
||||
* @throws Exception when something goes wrong
|
||||
* @return array The list of installed extensions
|
||||
*/
|
||||
public function installFromURL($url){
|
||||
try {
|
||||
$path = $this->download($url);
|
||||
$installed = $this->installArchive($path, true);
|
||||
|
||||
// purge caches
|
||||
foreach($installed as $ext => $info){
|
||||
$this->setExtension($ext);
|
||||
$this->purgeCache();
|
||||
}
|
||||
}catch (Exception $e){
|
||||
throw $e;
|
||||
}
|
||||
return $installed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install or update the extension
|
||||
*
|
||||
|
@ -759,9 +820,10 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
* @param bool $overwrite If an already installed plugin should be overwritten
|
||||
* @param string $base The basename of the plugin if it's known
|
||||
* @throws Exception when something went wrong
|
||||
* @return bool|string True on success, an error message on failure
|
||||
* @return array list of installed extensions
|
||||
*/
|
||||
public function installArchive($file, $overwrite=false, $base = '') {
|
||||
$installed_extensions = array();
|
||||
|
||||
// create tmp directory for decompression
|
||||
if(!($tmp = $this->mkTmpDir())) {
|
||||
|
@ -774,20 +836,16 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
}
|
||||
|
||||
// decompress
|
||||
if(!$this->decompress($file, "$tmp/".$base)) {
|
||||
throw new Exception(sprintf($this->getLang('error_decompress'), $file));
|
||||
try{
|
||||
$this->decompress($file, "$tmp/".$base);
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
// search $tmp/$base for the folder(s) that has been created
|
||||
// move the folder(s) to lib/..
|
||||
$result = array('old'=>array(), 'new'=>array());
|
||||
if($base){
|
||||
// when a base was set it came from the current extension setup #fixme this is a bit hacky
|
||||
$default = ($this->isTemplate() ? 'template' : 'plugin');
|
||||
}else{
|
||||
// assume a default of plugin, find_folders will autodetect templates
|
||||
$default = 'plugin';
|
||||
}
|
||||
$default = ($this->isTemplate() ? 'template' : 'plugin');
|
||||
if(!$this->find_folders($result, $tmp.'/'.$base, $default)) {
|
||||
throw new Exception($this->getLang('error_findfolder'));
|
||||
}
|
||||
|
@ -799,6 +857,10 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
$install = $result['old'];
|
||||
}
|
||||
|
||||
if(!count($install)){
|
||||
throw new Exception($this->getLang('error_findfolder'));
|
||||
}
|
||||
|
||||
// now install all found items
|
||||
foreach($install as $item) {
|
||||
// where to install?
|
||||
|
@ -933,11 +995,15 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Decompress a given file to the given target directory
|
||||
*
|
||||
* Determines the compression type from the file extension
|
||||
*
|
||||
* @param string $file archive to extract
|
||||
* @param string $target directory to extract to
|
||||
* @throws Exception
|
||||
* @return bool
|
||||
*/
|
||||
private function decompress($file, $target) {
|
||||
// decompression library doesn't like target folders ending in "/"
|
||||
|
@ -961,7 +1027,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
$tar->open($file, $compress_type);
|
||||
$tar->extract($target);
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
throw new Exception($this->getLang('error_decompress').' '.$e->getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -970,11 +1036,15 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
$zip = new ZipLib();
|
||||
$ok = $zip->Extract($file, $target);
|
||||
|
||||
return ($ok==-1 ? 'Error extracting the zip archive' : true);
|
||||
if($ok == -1){
|
||||
throw new Exception($this->getLang('error_decompress').' Error extracting the zip archive');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// the only case when we don't get one of the recognized archive types is when the archive file can't be read
|
||||
return 'Couldn\'t read archive file';
|
||||
throw new Exception($this->getLang('error_decompress').' Couldn\'t read archive file');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,7 +16,7 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin {
|
|||
|
||||
protected $tabs = array('plugins', 'templates', 'search', 'install');
|
||||
|
||||
/** @var string the extension that should have an open info window FIXME currently broken*/
|
||||
/** @var string the extension that should have an open info window FIXME currently broken */
|
||||
protected $infoFor = '';
|
||||
|
||||
/**
|
||||
|
@ -24,12 +24,11 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin {
|
|||
*
|
||||
* initializes requested info window
|
||||
*/
|
||||
public function __construct(){
|
||||
public function __construct() {
|
||||
global $INPUT;
|
||||
$this->infoFor = $INPUT->str('info');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* display the plugin tab
|
||||
*/
|
||||
|
@ -92,10 +91,9 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin {
|
|||
|
||||
if(!$INPUT->bool('q')) return;
|
||||
|
||||
|
||||
/* @var helper_plugin_extension_repository $repository FIXME should we use some gloabl instance? */
|
||||
$repository = $this->loadHelper('extension_repository');
|
||||
$result = $repository->search($INPUT->str('q'));
|
||||
$result = $repository->search($INPUT->str('q'));
|
||||
|
||||
/* @var helper_plugin_extension_extension $extension */
|
||||
$extension = $this->loadHelper('extension_extension');
|
||||
|
@ -116,6 +114,12 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin {
|
|||
*/
|
||||
public function tabInstall() {
|
||||
echo $this->locale_xhtml('intro_install');
|
||||
|
||||
$form = new Doku_Form(array('action' => $this->tabURL('', array(), '&'), 'enctype' => 'multipart/form-data'));
|
||||
$form->addElement(form_makeTextField('installurl', '', 'Install from URL:', '', 'block'));
|
||||
$form->addElement(form_makeFileField('installfile', 'Upload Extension:', '', 'block'));
|
||||
$form->addElement(form_makeButton('submit', '', 'Install'));
|
||||
$form->printForm();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -79,6 +79,8 @@ $lang['msg_template_update_success'] = 'Template %s updated successfully';
|
|||
$lang['msg_plugin_install_success'] = 'Plugin %s installed successfully';
|
||||
$lang['msg_plugin_update_success'] = 'Plugin %s updated successfully';
|
||||
|
||||
$lang['msg_upload_failed'] = 'Uploading the file failed';
|
||||
|
||||
|
||||
$lang['msg_url_failed'] = 'URL [%s] could not be downloaded.<br /> %s';
|
||||
$lang['msg_download_failed'] = 'Plugin %s could not be downloaded.<br /> %s';
|
||||
|
@ -130,7 +132,7 @@ $lang['no_manager'] = 'Could not find manager.dat file';
|
|||
$lang['error_badurl'] = 'URL ends with slash - unable to determine file name from the url';
|
||||
$lang['error_dircreate'] = 'Unable to create temporary folder to receive download';
|
||||
$lang['error_download'] = 'Unable to download the file: %s';
|
||||
$lang['error_decompress'] = '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 manually';
|
||||
$lang['error_decompress'] = '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 manually.';
|
||||
$lang['error_findfolder'] = 'Unable to identify extension directory, you need to download and install manually';
|
||||
$lang['error_copy'] = 'There was a file copy error while attempting to install files for directory <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';
|
||||
//Setup VIM: ex: et ts=4 :
|
||||
|
|
Loading…
Reference in New Issue