*** ../../TWiki20000909beta/bin/wikicfg.pm	Sun Sep 10 09:22:21 2000
--- wikicfg.pm	Tue Sep 26 10:25:38 2000
***************
*** 57,75 ****
  # variables that need to be changed when installing on a new server:
  # ==================================================================
  #                   %WIKIHOMEURL% : link of TWiki icon in upper left corner :
! $wikiHomeUrl      = "http://your.domain.com/twiki";
  #                   Host of TWiki URL :    (Example "http://myhost.com:123")
! $defaultUrlHost   = "http://your.domain.com";
  #                   %SCRIPTURLPATH% : cgi-bin path of TWiki URL:
  $scriptUrlPath    = "/twiki/bin";
  #                   %PUBURLPATH% : Public data path of TWiki URL (root of attachments) :
  $pubUrlPath       = "/twiki/pub";
  #                   Public data directory, must match $pubUrlPath :
! $pubDir           = "/home/httpd/twiki/pub";
  #                   Template directory :
! $templateDir      = "/home/httpd/twiki/templates";
  #                   Data (topic files) root directory :
! $dataDir          = "/home/httpd/twiki/data";
  
  # variables that might need to be changed:
  # ==================================================================
--- 57,75 ----
  # variables that need to be changed when installing on a new server:
  # ==================================================================
  #                   %WIKIHOMEURL% : link of TWiki icon in upper left corner :
! $wikiHomeUrl      = "http://didattica.dma.unifi.it/twiki";
  #                   Host of TWiki URL :    (Example "http://myhost.com:123")
! $defaultUrlHost   = "http://didattica.dma.unifi.it";
  #                   %SCRIPTURLPATH% : cgi-bin path of TWiki URL:
  $scriptUrlPath    = "/twiki/bin";
  #                   %PUBURLPATH% : Public data path of TWiki URL (root of attachments) :
  $pubUrlPath       = "/twiki/pub";
  #                   Public data directory, must match $pubUrlPath :
! $pubDir           = "/home/httpd/realtwiki/pub";
  #                   Template directory :
! $templateDir      = "/home/httpd/realtwiki/templates";
  #                   Data (topic files) root directory :
! $dataDir          = "/home/httpd/realtwiki/data";
  
  # variables that might need to be changed:
  # ==================================================================
***************
*** 111,117 ****
  # variables that probably do not change:
  # ==================================================================
  #                   %WIKITOOLNAME% : TWiki tool name, default "TWiki" :
! $wikiToolName       = "TWikibeta";
  #                   Regex security filter for web name, topic name, user name :
  $securityFilter     = "[\\\*\?\~\^\$\@\%\`\"\'\&\;\|\<\>\x00-\x1F]";
  #                   Default user name, default "guest" :
--- 111,117 ----
  # variables that probably do not change:
  # ==================================================================
  #                   %WIKITOOLNAME% : TWiki tool name, default "TWiki" :
! $wikiToolName       = "TWiki";
  #                   Regex security filter for web name, topic name, user name :
  $securityFilter     = "[\\\*\?\~\^\$\@\%\`\"\'\&\;\|\<\>\x00-\x1F]";
  #                   Default user name, default "guest" :
***************
*** 183,188 ****
--- 183,272 ----
  
  # NOTE: Don't forget to customize also the TWiki.TWikiPreferences topic.
  
+ #AS
+ # =========================
+ sub renderSubWebNames
+ {
+     # 18-08-00 (c) Andrea Sterbini a.sterbini@flashnet.it
+     # Sub to format subweb names (web/web1 -> web.web1)
+     # with automatic construction of links to the above webs
+     # It transforms a dotted or slashed name to a rendered link
+     # $theWeb is the string to be transformed
+     # if $lastIsTopic is true then the last piece is a topic instead than a web
+     
+     my( $theWeb, $lastIsTopic ) = @_;
+     $theWeb =~ s/\./\//go ;
+ 
+     my $topic   = $theWeb;
+     
+     if( $lastIsTopic ) {
+         $topic  =~ s/(.*)\/([^\/]*)/$2/go ;
+         $theWeb =~ s/(.*)\/([^\/]*)/$1/go ;
+     };
+     
+     my ($item , @list) = split(/\//, $theWeb);
+         
+     my $webPath = $item;
+     my $webName = internalLink("$webPath","$mainTopicname",$item,"",1);
+     foreach $item (@list){
+         $webPath = $webPath . "/" . $item ; 
+         $webName = $webName . "." . internalLink("$webPath","$mainTopicname",$item,"",1) ;
+     }
+     
+     if( $lastIsTopic ) {
+         $webName = $webName . "." . internalLink("$webPath","$topic","$topic","",1) ;
+     }
+ 
+     return "$webName";
+ }
+ #/AS
+ #FB latex
+ # ======================== LaTeX
+ sub handleLaTeX
+ {
+     my( $arg ) = @_;
+     # to do: check syntax
+     open FILE, ">$pubDir/hevea.tex";
+     print FILE $arg;
+     close FILE;	
+     return `/usr/bin/hevea < $pubDir/hevea.tex`;
+ }         
+ #/FB
+ #FB gnuplot
+ # ======================== GNUPLOT
+ sub handleGnuplot
+ {
+     my( $arg ) = @_;
+     # to do: check syntax
+     $arg =~ s/(shell|\!)//g;
+     $arg =~ s/\s/%20/g;
+     $arg =~ s/\+/%2B/g;
+     $arg =~ s/\;/%3B/g;
+     return "<img src=\"$scriptUrlPath/gnuplot?commands=$arg\">"; 
+ }         
+ #/FB
+ 
+ #FB extend_wiki
+ # =========================
+ sub externalNormalLink
+ {
+     my( $pre, $url, $text) = @_;
+     if( $url =~ /\.(gif|jpg|jpeg)$/ ) {
+         my $filename = $url;
+         $filename =~ s@.*/([^/]*)@$1@go;
+         return "$pre<IMG src=\"$url\" alt=\"$filename\">";
+     }
+ 
+     return "$pre<A href=\"$url\" target=\"_top\">$text</A>";
+ }
+ 
+ sub isSubWeb
+ {
+     my( $web, $name ) = @_;
+     return -d "$dataDir/$web/$name";
+ }
+ 
+ #/FB
  
  # =========================
  sub extendHandleCommonTags
***************
*** 199,204 ****
--- 283,309 ----
      # do custom extension rule, like for example:
      # $text=~ s/%WIKIWEB%/$wikiToolName.$theWeb/go;
  
+ #AS
+     $text=~ s/%WEBNAME%/&renderSubWebNames("$theWeb",0)/geo;
+ #/AS
+ #FB latex
+     $text =~ s/%LATEX{(.*?)}%/&handleLaTeX($1)/ges;
+     $text =~ s/%LATEX%/&handleLaTeX('\LaTeX')/geo; # logo      
+ #/FB
+ #FB gnuplot
+     $text =~ s/%GNUPLOT{(.*?)}%/&handleGnuplot($1)/ges;
+ #/FB
+ #FB extend_wiki notation, see  http://TWiki.SourceForge.net/cgi-bin/view/Codev/FlexibleWikiWords
+ # links can be: 
+ #[[this is a link]] -> <a href=this_is_a_link>this is a link</a>
+ #[[this is a link|http://link]] -> <a href=http://link>this is a link</a>
+ #[[this is a link||rellink]] -> <a href=rellink>this is a link</a>
+ # in the latter case one has to distinguish between internal and external links
+     $text=~s/([\*\s][\(\-\*\s]*)\[\[([a-zA-Z\s]*)\|((http|ftp|gopher|news|https)\:(\S+[^\s\.,!\?;:]))\]\]/&externalNormalLink($1,$3,$2)/geo; 
+     $text=~s/([\*\s][\(\-\*\s]*)\[\[([a-zA-Z\s]*)\|\|(\S+[^\s\.,!\?;:])\]\]/&externalNormalLink($1,$3,$2)/geo; 
+     $text =~ s/([\*\s][\(\-\*\s]*)\[\[([a-zA-Z\s]*)\|([a-zA-Z\s]*)\]\]/&internalLink($webName,$3,$2,$1,1)/geo; 
+     $text =~ s/([\*\s][\(\-\*\s]*)\[\[([a-zA-Z_\s]*)\]\]/&internalLink($webName,$2,$2,$1,1)/geo; 
+ #/FB
      return $text;
  }
  
***************
*** 217,222 ****
--- 322,333 ----
      # render *_text_* as "bold italic" text:
      s/(^|\s)\*_([^\s].*?[^\s])_\*(\s|$)/$1<STRONG><EM>$2<\/EM><\/STRONG>$3/go;
  
+ #AS
+     # render a dotted topic name as a link (with links to the above webs)
+    s/(^|\s)([A-Z][a-zA-Z0-9]*((\.|\/)[A-Z][a-zA-Z0-9]*)*((\.|\/)[A-Z][a-zA-Z0-9]*[A-Z][a-zA-Z0-9]*))(\s|$)/$1.&renderSubWebNames("$2",1)/geo;
+ #AS
+  
+ 
      # Use alternate %Web:WikiName% syntax (versus the standard Web.WikiName).
      # This is an old JosWiki render option. (Uncomment for JosWiki compatibility)
  #    s/(^|\s|\()\%([^\s].*?[^\s]):([^\s].*?[^\s])\%/&internalLink($2,$3,"$2:$3",$1,1)/geo;
***************
*** 230,235 ****
--- 341,368 ----
      # (Uncomment for JosWiki compatibility)
  #    s/(^|\s|\()\%([a-zA-Z0-9]+)\.(.*?[^\s])\%(\s|\)|$)/&internalLink($2,$3,$3,$1,1)/geo;
  
+ #FB  italian accented letters 
+ # avoid accents with \'
+ # first replace common apotrophes
+ 		s/(\s)po\'/$1po\\\'/go;
+ #now regular accents		
+ 		s/a\'/&agrave;/go;
+ 		s/i\'/&igrave;/go;
+ 		s/o\'/&ograve;/go;
+ 		s/u\'/&ugrave;/go;
+ 		s/he\'/h&eacute;/go;
+ 		s/e\'/&egrave;/go;
+ 
+ 		s/A\'/&Agrave;/go;
+ 		s/I\'/&Igrave;/go;
+ 		s/O\'/&Ograve;/go;
+ 		s/U\'/&Ugrave;/go;
+ 		s/HE\'/H&Eacute;/go;
+ 		s/E\'/&Egrave;/go;
+ #and finally the escaped apostrophes
+ 		s/\\\'/\'/go;
+ #/FB		
+ 
      return $_;
  }
  
***************
*** 247,249 ****
--- 380,383 ----
  
      return $_;
  }
+ 
*** ../../TWiki20000909beta/bin/wiki.pm	Sun Sep 10 09:21:19 2000
--- wiki.pm	Tue Sep 26 10:48:46 2000
***************
*** 50,56 ****
  #
  #    See http://twiki.sourceforge.net/cgi-bin/view/Codev/UniqueTopicTemplates
  #    for further details    
! 
  package wiki;
  
  ## 0501 kk : vvv Added for revDate2EpSecs
--- 50,66 ----
  #
  #    See http://twiki.sourceforge.net/cgi-bin/view/Codev/UniqueTopicTemplates
  #    for further details    
! #
! # 19 Aug 2000	AndreaSterbini : a.sterbini@flashnet.it
! #    With this patches WebPreferences, templates and include files are looked 
! #    for in all directories along the path contained in $webName.
! #    (templates and includes starting from the leaf to the root, 
! #    WebPreferences starting from the root to the leaf)    
! #    This is helpful for having hyerarchical webs with default 
! #    template/includes/WebPreferences
! #
! #    See   Codev.MultiLevelWikiWebs for further details
! #
  package wiki;
  
  ## 0501 kk : vvv Added for revDate2EpSecs
***************
*** 95,100 ****
--- 105,116 ----
  # read the search engine part
  do "wikisearch.pm";
  
+ #FB reply
+ # =================================
+ # read the reply engine part
+ do "wikireply.pm";  
+ #/FB
+ 
  # ===========================
  # variables: (new variables must be declared in "use vars qw(..)" above)
  @isoMonth     = ( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" );
***************
*** 165,171 ****
      @prefsKeys = ();
      @prefsValues = ();
      getPrefsList( "$twikiWebname\.$wikiPrefsTopicname" ); # site-level
!     getPrefsList( "$webName\.$webPrefsTopicname" );      # web-level
      getPrefsList( $wikiUserName );                       # user-level
  
      # some remaining init
--- 181,199 ----
      @prefsKeys = ();
      @prefsValues = ();
      getPrefsList( "$twikiWebname\.$wikiPrefsTopicname" ); # site-level
! 
! #AS
!     # look for preferences in all path from the root to the web
!     my ($pathItem, @pathList) = split(/\//, $webName);
!     my $path     = "$pathItem";
!     getPrefsList( "$path\.$webPrefsTopicname" );    
!     foreach $pathItem (@pathList)
!     {
!         $path    = "$path/$pathItem";
!         getPrefsList( "$path\.$webPrefsTopicname" );    
!     };    
! #    getPrefsList( "$webName\.$webPrefsTopicname" );      # web-level
! #/AS
      getPrefsList( $wikiUserName );                       # user-level
  
      # some remaining init
***************
*** 529,534 ****
--- 557,563 ----
      return -e "$dataDir/$web/$name.txt";
  }
  
+ 
  # =========================
  sub readTopic
  {
***************
*** 601,617 ****
      if( -e $webtmpl ) {
          return &readFile( $webtmpl );
      }
-     
      $webtmpl = "$templateDir/$webName/$name.tmpl";
      if( -e $webtmpl ) {
          return &readFile( $webtmpl );
      }
!     
      $webtmpl = "$templateDir/$name.$topic.tmpl";
      if( -e $webtmpl ) {
          return &readFile( $webtmpl );
      }
      return &readFile( "$templateDir/$name.tmpl" );
  }
  
  # =========================
--- 630,663 ----
      if( -e $webtmpl ) {
          return &readFile( $webtmpl );
      }
      $webtmpl = "$templateDir/$webName/$name.tmpl";
      if( -e $webtmpl ) {
          return &readFile( $webtmpl );
      }
! #AS
!     # look for template in all path from the web to the templates root dir -- Andrea Sterbini
!     my $webPath = "$webName";
!     foreach (split(/\//, $webPath))
!     {
!        $webPath =~ s#(\.*)\/[^\/]*#$1#;
!    $webtmpl = "$templateDir/$webPath/$name.$topic.tmpl";
!        if( -e $webtmpl )
!        {
!    return &readFile( $webtmpl);
!        }
!    $webtmpl = "$templateDir/$webPath/$name.tmpl";
!        if( -e $webtmpl )
!        { 
!    return &readFile( $webtmpl);
!        }
!     };
! #/AS  
      $webtmpl = "$templateDir/$name.$topic.tmpl";
      if( -e $webtmpl ) {
          return &readFile( $webtmpl );
      }
      return &readFile( "$templateDir/$name.tmpl" );
+ 
  }
  
  # =========================
***************
*** 941,951 ****
                  $incfile =~ s/\.([^\.]*)$/\/$1/go;
                  $fileName = "$dataDir/$incfile.txt";   # Web.TopicName
                  if( ! -e $fileName ) {
!                     return "";
                  }
              }
          }
      }
      my $text = &readFile( $fileName );
  
      $fileName =~ s/\/([^\/]*)\/([^\/]*)(\.txt)$/$1/go;
--- 987,1021 ----
                  $incfile =~ s/\.([^\.]*)$/\/$1/go;
                  $fileName = "$dataDir/$incfile.txt";   # Web.TopicName
                  if( ! -e $fileName ) {
! #AS
!         		    $fileName = "";
! #                    return "";
! #/AS 
                  }
              }
          }
      }
+ #AS
+     # look for the include file in all path from the web to the data root dir -- Andrea Sterbini   
+     my $webPath = "$webName";
+     foreach (split(/\//, $webPath)) {
+         if( $fileName eq "" ) {             # file not yet found
+             $webPath  =~ s#(\.*)\/[^\/]*#$1#;
+             # test for different usage
+             $fileName = "$dataDir/$webPath/$incfile";       # TopicName.txt
+                 if( ! -e $fileName ) {
+                     $fileName = "$dataDir/$webPath/$incfile.txt";   # TopicName
+                     if( ! -e $fileName ) {
+                         $fileName = "";
+                     }
+                 }
+         }
+     }
+ 
+     if( $fileName eq "" ) {                # file not yet found
+         return "";
+     }
+ #/AS        
      my $text = &readFile( $fileName );
  
      $fileName =~ s/\/([^\/]*)\/([^\/]*)(\.txt)$/$1/go;
***************
*** 1031,1036 ****
--- 1101,1125 ----
      return $value;
  }
  
+ #FB reply 
+ 
+ # =========================
+ 
+ sub handleReplyWeb
+ {
+     my( $attributes ) = @_;
+     my $replyVal = extractNameValuePair( $attributes );
+     if( ! $replyVal ) {
+         $replyVal = extractNameValuePair( $attributes, "reply" );
+     }
+ 
+     return &replyWikiWeb( "$replyVal",
+        extractNameValuePair( $attributes, "web" ),
+     );
+ }
+ #/FB
+ 
+ 
  # =========================
  sub handlePrefsValue
  {
***************
*** 1102,1107 ****
--- 1191,1199 ----
      $text =~ s/%NOTIFYTOPIC%/$notifyTopicname/go;
      $text =~ s/%STATISTICSTOPIC%/$statisticsTopicname/go;
      $text =~ s/%SEARCH{(.*?)}%/&handleSearchWeb($1)/geo;
+ #FB reply
+     $text =~ s/%REPLY{(.*?)}%/&handleReplyWeb($1)/geo;	
+ #/FB
  
      return $text;
  }
***************
*** 1144,1163 ****
      my( $web, $page, $text, $bar, $foo ) = @_;
      # bar is heading space
      # foo is boolean, false suppress link for non-existing pages
  
-     $page =~ s/\s/_/;
- 
-     if( $doPluralToSingular && $page =~ /s$/ && ! topicExists( $web, $page) ) {
-         # page is a non-existing plural
-         my $tmp = $page;
-         $tmp =~ s/ies$/y/;      # plurals like policy / policies
-         $tmp =~ s/sses$/ss/;    # plurals like address / addresses
-         $tmp =~ s/xes$/x/;      # plurals like box / boxes
-         $tmp =~ s/([A-Za-rt-z])s$/$1/; # others, excluding ending ss like address(es)
-         if( topicExists( $web, $tmp ) ) {
-             $page = $tmp;
-         }
-     }
  
      # PTh 22 Jul 2000: Added <nop> before topic with question link
      # (prevent double question when rendered twice by inline search)
--- 1236,1262 ----
      my( $web, $page, $text, $bar, $foo ) = @_;
      # bar is heading space
      # foo is boolean, false suppress link for non-existing pages
+ #FB extend_wiki
+ #    $page =~ s/\s/_/;
+     $page =~ s/\s/_/g;
+     $text =~ s/_/ /g;
+ #this is irrelevant in Italian
+ #    if( $doPluralToSingular && $page =~ /s$/ && ! topicExists( $web, $page) ) {
+ #        # page is a non-existing plural
+ #        my $tmp = $page;
+ #        $tmp =~ s/ies$/y/;      # plurals like policy / policies
+ #        $tmp =~ s/sses$/ss/;    # plurals like address / addresses
+ #        $tmp =~ s/xes$/x/;      # plurals like box / boxes
+ #        $tmp =~ s/([A-Za-rt-z])s$/$1/; # others, excluding ending ss like address(es)
+ #        if( topicExists( $web, $tmp ) ) {
+ #            $page = $tmp;
+ #        }
+ #    }
+ 	if (isSubWeb($web,$page)) {
+ 		$page .= "/$mainTopicname";
+ 	}
+ 			
  
  
      # PTh 22 Jul 2000: Added <nop> before topic with question link
      # (prevent double question when rendered twice by inline search)
