Skip to content

Commit

Permalink
Item5425: Finish off template rename support. Need to add unit tests
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@8452 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Aug 10, 2010
1 parent 3cc806e commit e310bc9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
11 changes: 7 additions & 4 deletions core/lib/Foswiki/Render.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1749,7 +1749,7 @@ sub forEachLine {
* =grep= - if true, generate a GNU-grep compatible RE instead of the * =grep= - if true, generate a GNU-grep compatible RE instead of the
default Perl RE. default Perl RE.
* =nosot= - If true, do not generate "Spaced out text" match * =nosot= - If true, do not generate "Spaced out text" match
* =template= - If true, match for template setting and strip Template suffix from topic name * =template= - If true, match for template setting in Set/Local statement
* =in_noautolink= - Only match explicit (squabbed) WikiWords. Used in <noautolink> blocks * =in_noautolink= - Only match explicit (squabbed) WikiWords. Used in <noautolink> blocks
* =url= - if set, generates an expression that will match a Foswiki * =url= - if set, generates an expression that will match a Foswiki
URL that points to the web/topic, instead of the default which URL that points to the web/topic, instead of the default which
Expand Down Expand Up @@ -1823,9 +1823,8 @@ sub getReferenceRE {
$re = "$bow$matchWeb\\.$topic$eow"; $re = "$bow$matchWeb\\.$topic$eow";
} }
elsif ( $options{template} ) { elsif ( $options{template} ) {
($topic) = $topic =~ m/(.*)Template$/; # $1 is used in replace. Can't use lookbehind because of variable length restriction
# SMELL: Incomplete - need $re = '('.$Foswiki::regex{setRegex}.'(?:VIEW|EDIT)_TEMPLATE\s*=\s*)('.$matchWeb.'\\.'.$topic.')\s*$';
# Regex to lookback match Set statement
} }
elsif ( $options{in_noautolink} ) { elsif ( $options{in_noautolink} ) {
$re = "$squabo$matchWeb\\.$topic$squabc"; $re = "$squabo$matchWeb\\.$topic$squabc";
Expand All @@ -1851,6 +1850,10 @@ sub getReferenceRE {
if ( $options{grep} ) { if ( $options{grep} ) {
$re = "(($back\[^./])|^)$bow($matchWeb\\.)?$topic$eow"; $re = "(($back\[^./])|^)$bow($matchWeb\\.)?$topic$eow";
} }
elsif ( $options{template} ) {
# $1 is used in replace. Can't use lookbehind because of variable length restriction
$re = '('.$Foswiki::regex{setRegex}.'(?:VIEW|EDIT)_TEMPLATE\s*=\s*)'."($matchWeb\\.)?$topic".'\s*$';
}
elsif ( $options{in_noautolink} ) { elsif ( $options{in_noautolink} ) {
$re = "$squabo($matchWeb\\.)?$topic$squabc"; $re = "$squabo($matchWeb\\.)?$topic$squabc";
} }
Expand Down
30 changes: 23 additions & 7 deletions core/lib/Foswiki/UI/Rename.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -850,10 +850,28 @@ sub _replaceTopicReferences {


# Do any references for Templates # Do any references for Templates
if ( $oldTopic =~ m/(.*)Template$/ ) { if ( $oldTopic =~ m/(.*)Template$/ ) {
$re = Foswiki::Render::getReferenceRE( $oldWeb, $1, my $ot = $1;
nosot => 1 # Only if the rename is also to a template, otherwise give up.
); if ($repl =~ m/(.*)Template$/) {
print STDERR "Using #$re# on $oldWeb.$oldTopic \n"; my $nt = $1;

# Handle META Preference settings
if ( $nt && $args->{_type} && $args->{_type} eq 'PREFERENCE' && $args->{_key} eq 'value' ) {
$re = Foswiki::Render::getReferenceRE( $oldWeb, $ot,
nosot => 1
);
$text =~ s/($re)/_doReplace($1, $newWeb, $nt)/ge;
}

# Handle Set/Local statements inline
$re = Foswiki::Render::getReferenceRE( $oldWeb, $ot,
nosot => 1,
template => 1
);
# SMELL: This will rewrite qualified topic names to be unqualified
# But regex is matching too much to use the _doReplace routine
$text =~ s/$re/$1$nt/g;
}
} }


# Now URL form # Now URL form
Expand Down Expand Up @@ -1338,8 +1356,6 @@ sub _getReferringTopics {
interweb => $interWeb, interweb => $interWeb,
); );
$searchString .= '|' . $refre $searchString .= '|' . $refre
#SMELL: Still needs code to change the template references.
# - this finds the topic with the references.
} }


my $matches = my $matches =
Expand Down Expand Up @@ -1392,7 +1408,7 @@ sub _updateReferringTopics {
$options->{inWeb} = $itemWeb; $options->{inWeb} = $itemWeb;
my $text = my $text =
$renderer->forEachLine( $topicObject->text(), $fn, $options ); $renderer->forEachLine( $topicObject->text(), $fn, $options );
$topicObject->forEachSelectedValue( qw/^(FIELD|FORM|TOPICPARENT)$/, $topicObject->forEachSelectedValue( qw/^(FIELD|FORM|PREFERENCE|TOPICPARENT)$/,
undef, $fn, $options ); undef, $fn, $options );
$topicObject->text($text); $topicObject->text($text);
$topicObject->save( minor => 1 ); $topicObject->save( minor => 1 );
Expand Down

0 comments on commit e310bc9

Please sign in to comment.