Skip to content

Commit

Permalink
Item10659: keep tweaking link checker to remove false reports
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/ImportExportPlugin@14029 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed Feb 19, 2012
1 parent 3de10c5 commit 57d5bba
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
6 changes: 6 additions & 0 deletions data/System/ImportExportPlugin.txt
Expand Up @@ -58,6 +58,12 @@ __you need to be foswiki admin to use this__
<option value="twiki">convert from twiki</option>
</select>
</td>
</tr>
<td align="right">
%MAKETEXT{"Web names to import (comma separated)"}%
</td><td>
<input type="text" name="webs" value="Bugs,Know,Hsa,Plugins,Templates,Support,Sven" size="50" />
</td>
</tr>
<tr>
<td align="right">
Expand Down
21 changes: 16 additions & 5 deletions lib/Foswiki/Plugins/ImportExportPlugin.pm
Expand Up @@ -17,7 +17,7 @@ use Foswiki::Func (); # The plugins API
use Foswiki::Plugins (); # For the API version

our $VERSION = '$Rev$';
our $RELEASE = '1.0.0';
our $RELEASE = '0.0.5';
our $SHORTDESCRIPTION = 'Import and export wiki data';
our $NO_PREFS_IN_TOPIC = 1;

Expand Down Expand Up @@ -117,7 +117,8 @@ sub doCheck {
#TODO: this will eventually be a multi-phase thing - show list of candidates to import, then doit
my $output = $handler->check();
$output .= "\n\n" . $handler->finish();
Foswiki::Func::saveTopicText('Sandbox', 'ImportExportPluginCheckReport', $output);
$webs =~ s/;/-/g;
Foswiki::Func::saveTopicText('Sandbox', 'ImportExportPluginCheck'.$webs.'Report', $output);
return $output;

}
Expand Down Expand Up @@ -153,13 +154,22 @@ sub doImport {
my $query = $session->{request};
my $filterlist =
Foswiki::Sandbox::untaintUnchecked( $query->{param}->{filterlist}[0] );
$filterlist = ',selectwebs(Know; Hsa), '.$filterlist;

my $webs =
Foswiki::Sandbox::untaintUnchecked( $query->{param}->{webs}[0] );
$webs =~ s/,/;/g;

if (!defined($webs)) {
#presume a vague demad for docco
print "./rest /ImportExportPlugin/import filterlist=twiki webs=Technology,Support fromtype=fs fspath=/home/sven/src/twiki_backup\n";
exit;
}

$filterlist = 'selectwebs('.$webs.'), '.$filterlist;

my @filter_funcs;

foreach my $filter ( split( /,\s*/, $filterlist ) ) {

next if ($filter eq 'none');
#parameters to filters: skip(Delete*) or similar
my $f = getFilterFunc($filter);
if ( defined($f) ) {
Expand All @@ -179,6 +189,7 @@ sub doImport {
#TODO: this will eventually be a multi-phase thing - show list of candidates to import, then doit
my $output = $handler->import();
$output .= "\n\n" . $handler->finish();
Foswiki::Func::saveTopicText('Sandbox', 'ImportExportPluginImportReport', $output);
return $output;

}
Expand Down
27 changes: 21 additions & 6 deletions lib/Foswiki/Plugins/ImportExportPlugin/Filters.pm
Expand Up @@ -13,7 +13,8 @@ package Foswiki::Plugins::ImportExportPlugin::Filters;
# Always use strict to enforce variable scoping
use strict;
use warnings;

use Foswiki::Plurals;

our %switchboard = (
selectwebs => \&selectwebs,
skiptopics => \&skiptopics,
Expand Down Expand Up @@ -61,7 +62,7 @@ my %testedLinkCache;

sub chkLinks {
my ( $result, $web, $topic, $text, $params ) = @_;
#return ('nochange', , $web, $topic, $text, \()) unless ($topic eq 'CommandAndCGIScripts');
#return ('nochange', , $web, $topic, $text, \()) unless ($topic eq 'PatternSkinElements');
#print STDERR "====================== $web, $topic\n";
#TODO: search url links to topics (and add fixup)
#TODO: does not do plurals, even thought Foswiki core does
Expand All @@ -85,6 +86,13 @@ sub chkLinks {
#print STDERR "OOOOOOOOOO $link($web, $webtopic): $lweb, $ltopic => $renderedlink\n"
if (not exists $testedLinkCache{$link}) {
$testedLinkCache{$link} = Foswiki::Func::topicExists($lweb, $ltopic);
if (not $testedLinkCache{$link} ) {
# topic not found - try to singularise
my $singular = Foswiki::Plurals::singularForm( $lweb, $ltopic );
if ($singular) {
$testedLinkCache{$link} = Foswiki::Func::topicExists( $lweb, $singular );
}
}
}
}

Expand All @@ -105,15 +113,18 @@ sub chkLinks {
my $editBasePath = Foswiki::Func::getScriptUrlPath(undef, undef, 'edit');
my $scriptBase = Foswiki::Func::getScriptUrl();
my $scriptBasePath = Foswiki::Func::getScriptUrlPath();
#TODO: validate that bin URL's are to scripts that exist? this might be dangerous wrt apache rewrites

my $pubPath = Foswiki::Func::getPubUrlPath();
my $pubDir = Foswiki::Func::getPubDir();
my $urlHost = Foswiki::Func::getUrlHost();

$urlHost =~ s/\//\\\//g;

foreach my $link (keys(%links)) {

if (not exists $testedLinkCache{$link}) {
if ($link =~ /^(mailto|ftp|file)/) {
if ($link =~ /^(mailto|ftp|file|irc)/) {
#ignoring email, ftp, file ... links
$testedLinkCache{$link} = $1; #fake it being OK
} elsif ($link =~ /^[#\?]/) {
Expand All @@ -136,12 +147,12 @@ sub chkLinks {
#this is an edit link to a topic thats listed in a WikiWord link so we don't want to list it twice
$testedLinkCache{$link} = 'duplicate';
# }
} elsif ($webtopic =~ /($scriptBase|$scriptBasePath)\/(configure|statistics)/) {
} elsif ($webtopic =~ /($scriptBase|$scriptBasePath)\/(configure|statistics|rdiff)/) {
$testedLinkCache{$link} = $2; #fake it being OK
} elsif ($webtopic =~ /($scriptBase|$scriptBasePath)(\/[a-z]+\/)(.*)$/) {
my ($web, $topic) = Foswiki::Func::normalizeWebTopicName('', $3);
$testedLinkCache{$link} = Foswiki::Func::topicExists($web, $topic);
$testedLinkCache{$link} = 'rest' if ($web eq 'ImportExportPlugin' && $topic eq 'Check');
$testedLinkCache{$link} = 'rest' if ($web eq 'ImportExportPlugin' || $topic eq 'Check');
} elsif ($webtopic =~ /.*$pubPath(.*)/) {
if (-e $pubDir.$1) {
$testedLinkCache{$link} = 'attachment exists';
Expand Down Expand Up @@ -229,7 +240,7 @@ sub twiki {
#TODO: apply conversions from TCP..

#rename user topics that contain 'TWiki'
if ( $topic =~ /TWiki/ ) {
if ( $topic =~ /^TWiki/ ) {
$topic =~ s/^TWiki/Wiki/g;
$result .= ', convert topic name from TWiki to Wiki';
}
Expand Down Expand Up @@ -260,6 +271,10 @@ sub twiki {
)
) . ')';
$text =~ s/$oldtopics/replace('Main', $1, \$result)/gem;

#special variables
$text =~ s/TWIKIWEB/$result.='textchange';'SYSTEMWEB'/ge;
$text =~ s/MAINWEB/$result.='textchange';'USERSWEB'/ge;

#not sure how to pick Main and TWiki web names to convert..

Expand Down
4 changes: 2 additions & 2 deletions lib/Foswiki/Plugins/ImportExportPlugin/FoswikiHandler.pm
Expand Up @@ -84,15 +84,15 @@ sub check {
}

#list of links for each topic
push(@output, " 1 $filteredweb.$filteredtopic: $result");
#push(@output, " 1 $filteredweb.$filteredtopic: $result");

SKIPTOPIC:
}
}

#list of links and how often they are used in that web
my $linkCount = scalar(keys(%links));
#push( @output, map { $_ . ' : ' . join(' , ', @{$links{$_}}) } sort(keys(%links)) );
push( @output, map { ' 1 '. $_ . ' : ' . join(' , ', @{$links{$_}}) } sort(keys(%links)) );

return join( "<br>\n", ( @output, "\n<hr>\nnumber of broken links: $linkCount\n<hr>\n" ) );

Expand Down

0 comments on commit 57d5bba

Please sign in to comment.