Tags:
create new tag
view all tags
This idea sprung from doing more with mu Bug / Support system and FormTopicsFailAcrossWebs....

I noticed that in a few places in the code I was putting in extra code before come readTopic calls to see if the $topic value contained a web specification. This made me wonder what would happen if I changed readTopicRaw to check if the $topic contained a webname, and then seperate them out and over-ride the $webName.

eg....


# =========================
# Given a full topic name, split into Web and Topic
# e.g. Test.TestTopic1 -> ("Test", "TestTopic1")
# NOTE: if the input is not in Web.Topic form both return values will be empty
sub getWebTopic
{
   my( $fullTopic ) = @_;
   my $web = "";
   my $topic = "";
   if ( $fullTopic =~ m|^([^.]+)[./](.*)$| ) {
     $web = $1;
     $topic = $2;
   }
 return ($web, $topic );
}

sub readTopicRaw
{
    my( $theWeb, $theTopic, $theVersion ) = @_;

#SVEN - test if theTopic contains a webName to override theWeb
my ( $innerWeb ) = "";
my ( $innerTopic ) = "";
( $innerWeb, $innerTopic ) = getWebTopic( $theTopic );
#if (( !$innerWeb ) || ( !$innerTopic )) {
if (( !$innerTopic )) {
    $innerWeb = $theWeb;
    $innerTopic = $theTopic;


}

    my $text = "";
    if( ! $theVersion ) {
        $text = &readFile( "$TWiki::dataDir/$innerWeb/$innerTopic.txt" );
    } else {
        $text = _readVersionNoMeta( $innerWeb, $innerTopic, $theVersion);
    }
    
    return $text;
}

So far its working fine on our production twiki that we use for our internal Bug system and information sharing system.

I am using this idea to allow $theWeb to be used as the currently active web, but that $theTopic could over-ride this setting. I use it for specifying FormTemplates and TopicTemplates from another web, with FormOptionValues from yet another web.

The next thing I'm probably going to need is to be to be able to get the data fields for a dropdown box by specfying a SEARCH with a table output (I wonder how slow that will be).

-- SvenDowideit - 28 Nov 2002

That is a useful enhancement. Is in TWikiAlphaRelease with some little changes:

  • Renamed TWiki::Store::getWebTopic to TWiki::Store::normalizeWebTopic. This function normalizes the Web.Topic name
  • Funtion is called by readTopicRaw.
  • Fixed the only reference to getWebTopic in rename script.

# =========================
# Normalize a Web.TopicName
# Input:                      Return:
#   ( "Web",  "Topic" )         ( "Web",  "Topic" )
#   ( "",     "Topic" )         ( "Main", "Topic" )
#   ( "",     "" )              ( "Main", "WebHome" )
#   ( "",     "Web/Topic" )     ( "Web",  "Topic" )
#   ( "",     "Web.Topic" )     ( "Web",  "Topic" )
#   ( "Web1", "Web2.Topic" )    ( "Web2", "Topic" )
# Note: Function renamed from getWebTopic
sub normalizeWebTopicName
{
   my( $theWeb, $theTopic ) = @_;

   if( $theTopic =~ m|^([^.]+)[\.\/](.*)$| ) {
       $theWeb = $1;
       $theTopic = $2;
   }
   $theWeb = $TWiki::webName unless( $theWeb );
   $theTopic = $TWiki::topicName unless( $theTopic );

   return( $theWeb, $theTopic );
}

-- PeterThoeny - 29 Nov 2002

Yep, works a charm.... sneaky way to get me to use the Alpha too smile Thanks for the perl lesson too - I haven't used it in ages and so I'm no better than last time i worked on the TWiki

next move DynamicFormOptionDefinitions

-- SvenDowideit - 29 Nov 2002

Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2002-11-29 - SvenDowideit
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.