From: <de...@de...> - 2007-10-01 13:17:01
|
Author: CrawfordCurrie Date: 2007-10-01 08:17:04 -0500 (Mon, 01 Oct 2007) New Revision: 15111 Modified: twiki/branches/MAIN/lib/TWiki/Configure/UI.pm twiki/branches/MAIN/lib/TWiki/Configure/UIs/EXTENSIONS.pm twiki/branches/MAIN/lib/TWiki/Configure/UIs/FINDEXTENSIONS.pm Log: Item4752: minor refactoring for ease-of-use. Modified: twiki/branches/MAIN/lib/TWiki/Configure/UI.pm =================================================================== --- twiki/branches/MAIN/lib/TWiki/Configure/UI.pm 2007-10-01 12:13:08 UTC (rev 15110) +++ twiki/branches/MAIN/lib/TWiki/Configure/UI.pm 2007-10-01 13:17:04 UTC (rev 15111) @@ -39,16 +39,6 @@ my $this = bless( { item => $item }, $class); $this->{item} = $item; - my $replist = ';'; - $replist .= $TWiki::cfg{ExtensionsRepositories} - if defined $TWiki::cfg{ExtensionsRepositories}; - $replist .= "$ENV{TWIKI_REPOSITORIES};" # DEPRECATED - if defined $ENV{TWIKI_REPOSITORIES}; # DEPRECATED - while ($replist =~ s/[;\s]+(.*?)=\((.*?),(.*?)(?:,(.*?),(.*?))?\)\s*;/;/) { - push(@{$this->{repositories}}, - { name => $1, data => $2, pub => $3}); - } - $this->{bin} = $FindBin::Bin; my @root = File::Spec->splitdir($this->{bin}); pop(@root); Modified: twiki/branches/MAIN/lib/TWiki/Configure/UIs/EXTENSIONS.pm =================================================================== --- twiki/branches/MAIN/lib/TWiki/Configure/UIs/EXTENSIONS.pm 2007-10-01 12:13:08 UTC (rev 15110) +++ twiki/branches/MAIN/lib/TWiki/Configure/UIs/EXTENSIONS.pm 2007-10-01 13:17:04 UTC (rev 15111) @@ -38,9 +38,23 @@ sub _getListOfExtensions { my $this = shift; + unless (defined($this->{repositories})) { + my $replist = ''; + $replist .= $TWiki::cfg{ExtensionsRepositories} + if defined $TWiki::cfg{ExtensionsRepositories}; + $replist .= "$ENV{TWIKI_REPOSITORIES};" # DEPRECATED + if defined $ENV{TWIKI_REPOSITORIES}; # DEPRECATED + $replist = ";$replist;"; + while ($replist =~ s/[;\s]+(.*?)=\((.*?),(.*?)(?:,(.*?),(.*?))?\)\s*;/;/) { + push(@{$this->{repositories}}, + { name => $1, data => $2, pub => $3}); + } + } + if (!$this->{list}) { $this->{list} = {}; foreach my $place ( @{$this->{repositories}} ) { + $place->{data} =~ s#/*$#/#; print CGI::div("Consulting $place->{name}..."); my $url = $place->{data}. 'FastReport?skin=text&contenttype=text/plain'; Modified: twiki/branches/MAIN/lib/TWiki/Configure/UIs/FINDEXTENSIONS.pm =================================================================== --- twiki/branches/MAIN/lib/TWiki/Configure/UIs/FINDEXTENSIONS.pm 2007-10-01 12:13:08 UTC (rev 15110) +++ twiki/branches/MAIN/lib/TWiki/Configure/UIs/FINDEXTENSIONS.pm 2007-10-01 13:17:04 UTC (rev 15111) @@ -20,132 +20,6 @@ use strict; use TWiki::Configure::Type; -my @tableHeads = - qw(image topic description version installedVersion testedOn install ); -my %headNames = ( - image => '', - topic => 'Extension', - description => 'Description', - version => 'Most Recent Version', - installedVersion => 'Installed Version', - testedOn => 'Tested On TWiki', - testedOnOS => 'Tested On OS', - install => 'Action', - ); - -# Download the report page from the repository, and extract a hash of -# available extensions -sub _getListOfExtensions { - my $this = shift; - - if (!$this->{list}) { - $this->{list} = {}; - foreach my $place ( @{$this->{repositories}} ) { - print CGI::div("Consulting $place->{name}..."); - my $url = $place->{data}. - 'FastReport?skin=text&contenttype=text/plain'; - my $response = $this->getUrl($url); - if (!$response->is_error()) { - my $page = $response->content(); - $page =~ s/{(.*?)}/$this->_parseRow($1, $place)/ges; - #} else { - # die "$url ".$response->message(); - } - } - } - return $this->{list}; -} - -sub _parseRow { - my ($this, $row, $place) = @_; - my %data; - return '' unless $row =~ s/^ *(\w+): *(.*?) *$/$data{$1} = $2;''/gem; - $data{installedVersion} = $this->_getInstalledVersion($data{topic}); - $data{repository} = $place->{name}; - $data{data} = $place->{data}; - $data{pub} = $place->{pub}; - die "$row: ".Data::Dumper->Dump([\%data]) unless $data{topic}; - $this->{list}->{$data{topic}} = \%data; - return ''; -} - -sub ui { - my $this = shift; - my $table = - CGI::Tr(join('', map { CGI::th({valign=>'bottom' }, - $headNames{$_}) } @tableHeads)); - - my $rows = 0; - my $installed = 0; - my $exts = $this->_getListOfExtensions(); - foreach my $key (sort keys %$exts) { - my $ext = $exts->{$key}; - my $row = ''; - foreach my $f (@tableHeads) { - my $text; - if ($f eq 'install') { - my $link = $TWiki::query->url(). - '?action=InstallExtension'. - ';repository='.$ext->{repository}. - ';extension='.$ext->{topic}; - $text = 'Install'; - if ($ext->{installedVersion}) { - $text = 'Upgrade'; - $installed++; - } - $text = CGI::a({ href => $link }, $text); - } else { - $text = $ext->{$f}||'-'; - if ($f eq 'topic') { - my $link = $ext->{data}.$ext->{topic}; - $text = CGI::a({ href => $link }, $text); - } - } - $row .= CGI::td({valign=>'top'}, $text); - } - if ($ext->{installedVersion}) { - $table .= CGI::Tr({class=>'patternAccessKeyInfo'}, $row); - } else { - $table .= CGI::Tr($row); - } - $rows++; - } - $table .= CGI::Tr({class=>'patternAccessKeyInfo'},CGI::td( - {colspan => 7}, - $installed . ' extension'. - ($installed==1?'':'s').' out of '.$rows.' already installed')); - my $page = <<INTRO; -To install an extension from this page, click on the link in the 'Action' column.<p />Note that the webserver user has to be able to -write files everywhere in your TWiki installation. Otherwise you may see -'No permission to write' errors during extension installation. -INTRO - $page .= CGI::table({class=>'twikiForm'},$table); - return $page; -} - -sub _getInstalledVersion { - my ($this, $module) = @_; - my $lib; - - return undef unless $module; - - if ($module =~ /Plugin$/) { - $lib = 'Plugins'; - } else { - $lib = 'Contrib'; - } - - my $path = 'TWiki::'.$lib.'::'.$module; - my $version; - my $check = 'use '.$path.'; $version = $'.$path.'::VERSION;'; - eval $check; - #print STDERR $@ if $@ && DEBUG; - if ($version) { - $version =~ s/^\s*\$Rev:\s*(.*?)\s*\$$/$1/; - } - return $version; -} - sub close_html { my ($this, $section) = @_; |