diff -uwbBr twiki/bin/installpasswd twiki.patched/bin/installpasswd
--- twiki/bin/installpasswd	2004-10-08 14:46:30.000000000 +0500
+++ twiki.patched/bin/installpasswd	2004-11-03 17:53:37.000000000 +0500
@@ -65,7 +65,7 @@
 use TWiki::User;
 use TWiki::User::HtPasswdUser;
  
-$query= new CGI;
+my $query= new CGI;
  
 &main();
  
diff -uwbBr twiki/bin/rename twiki.patched/bin/rename
--- twiki/bin/rename	2004-10-08 14:46:30.000000000 +0500
+++ twiki.patched/bin/rename	2004-11-03 17:53:38.000000000 +0500
@@ -26,6 +26,9 @@
     # Set library paths in @INC at compile time
     unshift @INC, '.';
     require 'setlib.cfg';
+}
+
+sub init_config {
 
     # 'Use locale' for internationalisation of Perl regexes -
     # main locale settings are done in TWiki::setupLocale
diff -uwbBr twiki/bin/statistics twiki.patched/bin/statistics
--- twiki/bin/statistics	2004-10-08 14:46:30.000000000 +0500
+++ twiki.patched/bin/statistics	2004-11-03 17:53:38.000000000 +0500
@@ -31,6 +31,9 @@
     # Set library paths in @INC at compile time
     unshift @INC, '.';
     require 'setlib.cfg';
+}
+
+sub init_config {
 
     # 'Use locale' for internationalisation of Perl regexes -
     # main locale settings are done in TWiki::setupLocale
diff -uwbBr twiki/bin/testenv twiki.patched/bin/testenv
--- twiki/bin/testenv	2004-10-08 14:46:30.000000000 +0500
+++ twiki.patched/bin/testenv	2004-11-03 17:53:38.000000000 +0500
@@ -34,7 +34,7 @@
 
 my $brokenTWikiCfg;
 
-BEGIN {
+sub init_config {
     # Set default current working directory
     if( $ENV{"SCRIPT_FILENAME"} && $ENV{"SCRIPT_FILENAME"} =~ /^(.+)\/[^\/]+$/ ) {
         chdir $1;
@@ -61,6 +61,9 @@
 			( $! ? "$!\n" : '') .	# $! if not readable,
 			( $@ ? "$@\n" : '');	# $@ if not compileable
     }
+    $config->{TWikicfg} = TWikicfg->new( $config );
+    $config->{TWikicfg}->TWikicfg ();            # Includes OS detection
+
 
     # Do a dynamic 'use locale' for this script
     if( $useLocale ) {
diff -uwbBr twiki/lib/Algorithm/Diff.pm twiki.patched/lib/Algorithm/Diff.pm
--- twiki/lib/Algorithm/Diff.pm	2004-10-08 14:46:34.000000000 +0500
+++ twiki.patched/lib/Algorithm/Diff.pm	2004-11-03 17:53:38.000000000 +0500
@@ -1,12 +1,8 @@
 package Algorithm::Diff;
 use strict;
-use vars qw($VERSION @EXPORT_OK @ISA @EXPORT);
+use vars qw($VERSION);
 use integer;    # see below in _replaceNextLargerWith() for mod to make
                 # if you don't use this
-require Exporter;
-@ISA       = qw(Exporter);
-@EXPORT    = qw();
-@EXPORT_OK = qw(LCS diff traverse_sequences traverse_balanced sdiff);
 $VERSION = sprintf('%d.%02d', (q$Revision: 1.2 $ =~ /\d+/g));
 
 # McIlroy-Hunt diff algorithm
@@ -345,7 +341,7 @@
 
   package Person;
 
-  sub new
+  sub new
   {
     my $package = shift;
     return bless { name => '', ssn => '', @_ }, $package;
diff -uwbBr twiki/lib/TWiki/Meta.pm twiki.patched/lib/TWiki/Meta.pm
--- twiki/lib/TWiki/Meta.pm	2004-10-08 14:46:34.000000000 +0500
+++ twiki.patched/lib/TWiki/Meta.pm	2004-11-03 17:53:38.000000000 +0500
@@ -69,7 +69,7 @@
    my( $self, $type, %args ) = @_;
    
    my $data = $self->{$type};
-   my $key = _key( $type );
+   my $key = $self->_key( $type );
    
    if( $data ) {
        if( $key ) {
@@ -112,7 +112,7 @@
 
 sub _key
 {
-   my( $type ) = @_;
+   my( $self, $type ) = @_;
    
    my $key = "";
    
@@ -139,7 +139,7 @@
    my %args = ();
 
    my $data = $self->{$type};
-   my $key = _key( $type );
+   my $key = $self->_key( $type );
 
    if( $data ) {
        if( $key ) {
@@ -201,7 +201,7 @@
     
     my %args = ();
     my $key = "";
-    $key = _key( $type ) if( $type );
+    $key = $self->_key( $type ) if( $type );
     
     if( $keyValue && $key ) {
        my $data = $self->{$type};
@@ -273,9 +273,9 @@
 
 sub _writeKeyValue
 {
-    my( $key, $value ) = @_;
+    my( $self, $key, $value ) = @_;
     
-    $value = cleanValue( $value );
+    $value = $self->cleanValue( $value );
     
     my $text = "$key=\"$value\"";
     
@@ -314,13 +314,13 @@
             my $name = $item->{"name"};
             if( $name ) {
                 # If there's a name field, put first to make regexp based searching easier
-                $text .= _writeKeyValue( "name", $item->{"name"} );
+                $text .= $self->_writeKeyValue( "name", $item->{"name"} );
                 $sep = " ";
             }
             foreach my $key ( sort keys %$item ) {
                 if( $key ne "name" ) {
                     $text .= $sep;
-                    $text .= _writeKeyValue( $key, $item->{$key} );
+                    $text .= $self->_writeKeyValue( $key, $item->{$key} );
                     $sep = " ";
                 }
             }
@@ -341,7 +341,7 @@
 
 sub cleanValue
 {
-    my( $value ) = @_;
+    my( $self, $value ) = @_;
 
     $value =~ s/\r\r\n/%_N_%/go;
     $value =~ s/\r\n/%_N_%/go;
@@ -364,7 +364,7 @@
 
 sub restoreValue
 {
-    my( $value ) = @_;
+    my( $self, $value ) = @_;
 
     $value =~ s/%_N_%/\n/go;
     $value =~ s/%_Q_%/"/go;
@@ -385,7 +385,7 @@
 
 sub _keyValue2Hash
 {
-    my( $args ) = @_;
+    my( $self, $args ) = @_;
     
     my %res = ();
     
@@ -393,7 +393,7 @@
     while( $args =~ s/\s*([^=]+)=\"([^"]*)\"//o ) {
         my $key = $1;
         my $value = $2;
-        $value = restoreValue( $value );
+        $value = $self->restoreValue( $value );
         $res{$key} = $value;
     }
     
@@ -417,10 +417,10 @@
     my $newText = "";
 
     foreach ( split( /\r?\n/, $text ) ) {
-        if( /^%META:([^{]+){(.*)}%$/ ) {   # greedy match for ending "}%"
+        if( /^%META:([^{]+){(.*)}%$/ ) {   
             my $type = $1;
             my $args = $2;
-            my %list = _keyValue2Hash( $args );
+            my %list = $self->_keyValue2Hash( $args );
             $self->put( $type, %list );
         } else {
             $newText .= "$_\n";
@@ -463,7 +463,7 @@
     
     my $text = $self->_writeTypes( qw/FORM FIELD FILEATTACHMENT TOPICMOVED/ );
     # append remaining meta data
-    $text .= $self->_writeTypes( qw/not TOPICINFO TOPICPARENT FORM FIELD FILEATTACHMENT TOPICMOVED/ );
+    $text .= $self->_writeTypes( qw/not config TOPICINFO TOPICPARENT FORM FIELD FILEATTACHMENT TOPICMOVED/ );
     return $text;
 }
 
diff -uwbBr twiki/lib/TWiki/Plugins/InterwikiPlugin.pm twiki.patched/lib/TWiki/Plugins/InterwikiPlugin.pm
--- twiki/lib/TWiki/Plugins/InterwikiPlugin.pm	2004-10-08 14:46:34.000000000 +0500
+++ twiki.patched/lib/TWiki/Plugins/InterwikiPlugin.pm	2004-11-03 17:53:38.000000000 +0500
@@ -50,6 +50,10 @@
     }
 }
 
+$VERSION = '1.003'; # 18 Jan 2003
+$interSiteLinkRulesTopicName = "InterWikis";
+
+
 # Regexes for the Site:page format InterWiki reference - updated to support
 # 8-bit characters in both parts - see Codev.InternationalisationEnhancements
 $prefixPattern  = '(^|[\s\-\*\(])';
diff -uwbBr twiki/lib/TWiki/Plugins/SmiliesPlugin.pm twiki.patched/lib/TWiki/Plugins/SmiliesPlugin.pm
--- twiki/lib/TWiki/Plugins/SmiliesPlugin.pm	2004-10-08 14:46:34.000000000 +0500
+++ twiki.patched/lib/TWiki/Plugins/SmiliesPlugin.pm	2004-11-03 17:53:38.000000000 +0500
@@ -46,17 +46,17 @@
     $smiliesFormat = &TWiki::Func::getPreferencesValue( "SMILIESPLUGIN_FORMAT" ) 
 					|| '<img src="$url" alt="$tooltip" title="$tooltip" border="0" />';
 
-    my $topic = &TWiki::Func::getPreferencesValue( "SMILIESPLUGIN_TOPIC" ) 
+    my $topicLoc = &TWiki::Func::getPreferencesValue( "SMILIESPLUGIN_TOPIC" ) 
 					|| "$installWeb.SmiliesPlugin"; 
 
-    my $web = $installWeb;
-    if( $topic =~ /(.+)\.(.+)/ ) {
-        $web = $1;
-        $topic = $2;
+    my $webLoc = $installWeb;
+    if( $topicLoc =~ /(.+)\.(.+)/ ) {
+        $webLoc = $1;
+        $topicLoc = $2;
     }
 
     $allPattern = "(";
-    foreach( split( /\n/, TWiki::Func::readTopic( $web, $topic ) ) ) {
+    foreach( split( /\n/, TWiki::Func::readTopic( $webLoc, $topicLoc ) ) ) {
         if( m/$smiliesPattern/ ) {
             $allPattern .= "\Q$1\E|";
             $smiliesUrls{$1}     = $2;
diff -uwbBr twiki/lib/TWiki/Plugins.pm twiki.patched/lib/TWiki/Plugins.pm
--- twiki/lib/TWiki/Plugins.pm	2004-10-08 14:46:34.000000000 +0500
+++ twiki.patched/lib/TWiki/Plugins.pm	2004-11-03 17:53:38.000000000 +0500
@@ -233,6 +233,8 @@
 	return;
     }
     
+    $config->{TWiki}->{Plugins}->{$plugin}=$p->new ( $config );
+
     my $h   = "";
     my $sub = "";
     my $prefix = "";
@@ -242,7 +244,9 @@
             return;
         }
         $sub = $p. '::initializeUserHandler';
-        $user = &$sub( $theLoginName );
+        #$user = &$sub( $theLoginName );
+        $user = $config->{TWiki}->{Plugins}->{$plugin}->initializeUserHandler( $theLoginName );
+
         return $user;
 
     }
@@ -256,10 +260,11 @@
     $prefix = uc( $plugin ) . "_";
     &TWiki::Prefs::getPrefsFromTopic( $installWeb, $plugin, $prefix );
 
-    if( &$sub( $topic, $web, $user, $installWeb ) ) {
+    if( $config->{TWiki}->{Plugins}->{$plugin}->initPlugin( $topic, $web, $user, $installWeb ) ) {
         foreach $h ( @registrableHandlers ) {
-            $sub = $p.'::'.$h;
-            &registerHandler( $h, $sub ) if defined( &$sub );
+            #$sub = $p.'::'.$h;
+            $sub = "\$config->{TWiki}->{Plugins}->{$plugin}->$h" ;
+            &registerHandler( $h, $sub ) if defined( $sub );
         }
         $activePluginWebs{$plugin} = $installWeb;
         push( @activePlugins, $plugin );;
@@ -286,11 +291,17 @@
     
     foreach $theHandler ( @{$registeredHandlers{$handlerName}} ) {
         # apply handler on the remaining list of args
-        $status = &$theHandler;
+        my @rec_plug = split ( '->', $theHandler );
+        my $sub_plug = $rec_plug[$#rec_plug];
+        my $plug = $rec_plug[$#rec_plug-1];
+        $plug =~ s/[\{\}]//g ;
+
+        eval { $status = $config->{TWiki}->{Plugins}->{$plug}->$sub_plug( @_ ) };
+
         if( $onlyOnceHandlers{$handlerName} ) {
-            if( $status ) {
-                return $status;
-            }
+        #    if( $status ) {
+        #        return $status;
+        #    }
         }
     }
     
@@ -492,10 +503,10 @@
 #   my( $theLoginName, $theUrl, $thePathInfo ) = @_;
 
     unshift @_, ( 'initializeUserHandler' );
-    my $user = &applyHandlers;
+    my $user = &applyHandlers( @_ );
 
     if( ! defined( $user ) ) {
-        $user = &TWiki::initializeRemoteUser( $_[0] );
+        $user = &TWiki::initializeRemoteUser( $_[1] );
     }
 
     return $user;
@@ -515,7 +526,7 @@
     # Called by the register script
 #    my( $web, $wikiName, $loginName ) = @_;
     unshift @_, ( 'registrationHandler' );
-    &applyHandlers;
+    &applyHandlers( @_ );
 }
 
 # =========================
@@ -532,7 +543,7 @@
     # Called by sub handleCommonTags at the beginning (for cache Plugins only)
 #    my( $text, $topic, $theWeb ) = @_;
     unshift @_, ( 'beforeCommonTagsHandler' );
-    &applyHandlers;
+    &applyHandlers( @_ );
 }
 
 # =========================
@@ -549,10 +560,10 @@
     # Called by sub handleCommonTags, after %INCLUDE:"..."%
 #    my( $text, $topic, $theWeb ) = @_;
     unshift @_, ( 'commonTagsHandler' );
-    &applyHandlers;
-    $_[0] =~ s/%PLUGINDESCRIPTIONS%/&handlePluginDescription()/geo;
-    $_[0] =~ s/%ACTIVATEDPLUGINS%/&handleActivatedPlugins()/geo;
-    $_[0] =~ s/%FAILEDPLUGINS%/&handleFailedPlugins()/geo;
+    &applyHandlers( @_ );
+    $_[1] =~ s/%PLUGINDESCRIPTIONS%/&handlePluginDescription()/geo;
+    $_[1] =~ s/%ACTIVATEDPLUGINS%/&handleActivatedPlugins()/geo;
+    $_[1] =~ s/%FAILEDPLUGINS%/&handleFailedPlugins()/geo;
 }
 
 # =========================
@@ -569,7 +580,7 @@
     # Called by sub handleCommonTags at the end (for cache Plugins only)
 #    my( $text, $topic, $theWeb ) = @_;
     unshift @_, ( 'afterCommonTagsHandler' );
-    &applyHandlers;
+    &applyHandlers( @_ );
 }
 
 # =========================
@@ -586,7 +597,7 @@
     # Called by getRenderedVersion just before the line loop
 #    my ( $text, $web ) = @_;
     unshift @_, ( 'startRenderingHandler' );
-    &applyHandlers;
+    &applyHandlers( @_ );
 }
 
 # =========================
@@ -603,7 +614,7 @@
     # Called by sub getRenderedVersion, in loop outside of <PRE> tag
 #    my( $text ) = @_;
     unshift @_, ( 'outsidePREHandler' );
-    &applyHandlers;
+    &applyHandlers( @_ );
 }
 
 # =========================
@@ -620,7 +631,7 @@
     # Called by sub getRenderedVersion, in loop inside of <PRE> tag
 #    my( $text ) = @_;
     unshift @_, ( 'insidePREHandler' );
-    &applyHandlers;
+    &applyHandlers( @_ );
 }
 
 # =========================
@@ -637,7 +648,7 @@
     # Called by getRenderedVersion just after the line loop
 #    my ( $text ) = @_;
     unshift @_, ( 'endRenderingHandler' );
-    &applyHandlers;
+    &applyHandlers( @_ );
 }
 
 # =========================
@@ -654,7 +665,7 @@
     # Called by edit
 #    my( $text, $topic, $web ) = @_;
     unshift @_, ( 'beforeEditHandler' );
-    &applyHandlers;
+    &applyHandlers( @_ );
 }
 
 # =========================
@@ -671,7 +682,7 @@
     # Called by edit
 #    my( $text, $topic, $web ) = @_;
     unshift @_, ( 'afterEditHandler' );
-    &applyHandlers;
+    &applyHandlers( @_ );
 }
 
 # =========================
@@ -688,7 +699,7 @@
     # Called by TWiki::Store::saveTopic before the save action
 #    my ( $theText, $theTopic, $theWeb ) = @_;
     unshift @_, ( 'beforeSaveHandler' );
-    &applyHandlers;
+    &applyHandlers( @_ );
 }
 
 =pod
@@ -703,7 +714,7 @@
 # Called by TWiki::Store::saveTopic after the save action
 #    my ( $theText, $theTopic, $theWeb ) = @_;
     unshift @_, ( 'afterSaveHandler' );
-    &applyHandlers;
+    &applyHandlers( @_ );
 }
 
 =pod
@@ -739,7 +750,7 @@
     # Called by TWiki::Store::saveAttachment before the save action
 #    my ( $theAttrHash, $theTopic, $theWeb ) = @_;
     unshift @_, ( 'beforeAttachmentSaveHandler' );
-    &applyHandlers;
+    &applyHandlers( @_ );
 }
 
 =pod
@@ -770,7 +781,7 @@
 # Called by TWiki::Store::saveAttachment after the save action
 #    my ( $theText, $theTopic, $theWeb ) = @_;
     unshift @_, ( 'afterAttachmentSaveHandler' );
-    &applyHandlers;
+    &applyHandlers( @_ );
 }
 
 
@@ -787,7 +798,7 @@
 {
     # Called by TWiki::writeHeader
     unshift @_, ( 'writeHeaderHandler' );
-    return &applyHandlers;
+    return &applyHandlers( @_ );
 }
 
 # =========================
@@ -803,7 +814,7 @@
 {
     # Called by TWiki::redirect
     unshift @_, ( 'redirectCgiQueryHandler' );
-    return &applyHandlers;
+    return &applyHandlers( @_ );
 }
 
 # =========================
@@ -819,7 +830,7 @@
 {
     # Called by TWiki::getSessionValue
     unshift @_, ( 'getSessionValueHandler' );
-    return &applyHandlers;
+    return &applyHandlers( @_ );
 }
 
 # =========================
@@ -835,7 +846,7 @@
 {
     # Called by TWiki::setSessionValue
     unshift @_, ( 'setSessionValueHandler' );
-    return &applyHandlers;
+    return &applyHandlers( @_ );
 }
 
 # ========================
@@ -878,7 +889,7 @@
 {
     # Called by Form.TODO
     unshift @_, ( 'renderFormFieldForEditHandler' );
-    return &applyHandlers;
+    return &applyHandlers( @_ );
 }
 
 =pod
@@ -894,7 +905,7 @@
 sub renderWikiWordHandler
 {
     unshift @_, ( 'renderWikiWordHandler' );
-    return &applyHandlers;
+    return &applyHandlers( @_ );
 }
 
 
diff -uwbBr twiki/lib/TWiki/Prefs.pm twiki.patched/lib/TWiki/Prefs.pm
--- twiki/lib/TWiki/Prefs.pm	2004-10-08 14:46:34.000000000 +0500
+++ twiki.patched/lib/TWiki/Prefs.pm	2004-11-03 17:53:38.000000000 +0500
@@ -254,7 +254,6 @@
 # =============================================================================
 package TWiki::Prefs::PrefsCache;
 
-use vars qw( %topicCache );
 
 =pod
 
@@ -263,22 +262,6 @@
 The PrefsCache package holds a cache of topics that have been read in, using
 the TopicPrefs class.  These functions manage that cache.
 
----+++ sub clearCache()
-
-This non-member function clears cached topic preferences, forcing all settings
-to be reread.
-
----+++ sub invalidateCache( $web, $topic )
-
-This non-member function invalidates the cache on a particular topic.
-
-=cut
-
-sub clearCache { undef %topicCache; }
-sub invalidateCache { delete $topicCache{$_[0]}{$_[1]}; }
-
-=pod
-
 ---++ PrefsCache Object
 
 This defines an object used internally by the functions in TWiki::Prefs to hold
@@ -531,9 +514,11 @@
 # =============================================================================
 package TWiki::Prefs;
 
+use vars qw( %topicCache );
+
 use vars qw(
     $globalPrefs %webPrefs $requestPrefs $requestWeb
-    $finalPrefsName
+    $finalPrefsName $formPrefPrefix
 );
 
 
@@ -544,6 +529,26 @@
 This is the external interface to the Prefs module, and is how the rest of the
 TWiki code accesses preferences.
 
+---+++ sub clearCache()
+
+This non-member function clears cached topic preferences, forcing all settings
+to be reread.
+
+---+++ sub invalidateCache( $web, $topic )
+
+This non-member function invalidates the cache on a particular topic.
+
+=cut
+
+sub clearCache { 
+   undef %topicCache; 
+}
+sub invalidateCache { 
+   delete $topicCache{$_[0]}{$_[1]}; 
+}
+
+=pod
+
 ---+++ sub initializePrefs( $webName )
 
 Resets all preference globals (for mod_perl compatibility), and reads
@@ -556,7 +561,7 @@
 {
     my( $theWebName ) = @_;
     
-    TWiki::Prefs::PrefsCache::clearCache(); # for mod_perl compatibility
+    TWiki::Prefs::clearCache(); # for mod_perl compatibility
 
     $requestWeb = $theWebName;
     $globalPrefs = TWiki::Prefs::PrefsCache->new("global");
diff -uwbBr twiki/lib/TWiki/Render.pm twiki.patched/lib/TWiki/Render.pm
--- twiki/lib/TWiki/Render.pm	2004-10-08 14:46:34.000000000 +0500
+++ twiki.patched/lib/TWiki/Render.pm	2004-11-03 17:53:38.000000000 +0500
@@ -36,7 +36,7 @@
 
 use strict;
 
-use TWiki qw(:renderflags %regex $TranslationToken);
+use TWiki ;
 
 # Globals used in rendering
 use vars qw(
diff -uwbBr twiki/lib/TWiki/Store/RcsFile.pm twiki.patched/lib/TWiki/Store/RcsFile.pm
--- twiki/lib/TWiki/Store/RcsFile.pm	2004-10-08 14:46:34.000000000 +0500
+++ twiki.patched/lib/TWiki/Store/RcsFile.pm	2004-11-03 17:53:38.000000000 +0500
@@ -333,7 +333,7 @@
 
 sub _epochToRcsDateTime
 {
-   my( $dateTime ) = @_;
+   my( $self, $dateTime ) = @_;
    # TODO: should this be gmtime or local time?
    my( $sec,$min,$hour,$mday,$mon,$year,$wday,$yday ) = gmtime( $dateTime );
    $year += 1900 if( $year > 99 );
@@ -353,7 +353,7 @@
 
 sub _rcsDateTimeToEpoch
 {
-    my( $rcsDate ) = @_;    
+    my( $self, $rcsDate ) = @_;    
     return TWiki::revDate2EpSecs( $rcsDate );
 }
 
@@ -861,8 +861,9 @@
 
 sub _mkTmpFilename
 {
+    my( $self ) = @_;
     my $tmpdir = File::Spec->tmpdir();
-    my $file = _mktemp( "twikiAttachmentXXXXXX", $tmpdir );
+    my $file = $self->_mktemp( "twikiAttachmentXXXXXX", $tmpdir );
     return File::Spec->catfile($tmpdir, $file);
 }
 
@@ -876,7 +877,7 @@
 =cut to implementation
 
 sub _mktemp {
-   my ($template,$dir,$ext,$keepgen,$lookup);
+   my ( $self, $template,$dir,$ext,$keepgen,$lookup);
    my (@template,@letters);
 
    croak("Usage: mktemp('templateXXXXXX',['/dir'],['ext']) ") 
diff -uwbBr twiki/lib/TWiki/Store/RcsLite.pm twiki.patched/lib/TWiki/Store/RcsLite.pm
--- twiki/lib/TWiki/Store/RcsLite.pm	2004-10-08 14:46:34.000000000 +0500
+++ twiki.patched/lib/TWiki/Store/RcsLite.pm	2004-11-03 17:53:38.000000000 +0500
@@ -151,7 +151,7 @@
 
 sub _readTo
 {
-    my( $file, $char ) = @_;
+    my( $self, $file, $char ) = @_;
     my $buf = "";
     my $ch;
     my $space = 0;
@@ -259,7 +259,7 @@
     my @text = ();
     my $dnum = "";
     while( $going ) {
-       ($_, $string) = _readTo( $fh, $term );
+       ($_, $string) = $self->_readTo( $fh, $term );
        last if( ! $_ );
       
        my $lastWhere = $where;
@@ -309,7 +309,7 @@
           if( /^([0-9]+)\.([0-9]+)\s+date\s+(\d\d(\d\d)?(\.\d\d){5}?);$/o ) {
              $where = "delta.author";
              $num = $2;
-             $date[$num] = TWiki::Store::RcsFile::_rcsDateTimeToEpoch ($3 );
+             $date[$num] = $self->_rscDateTimeToEpoch ($3 );
           }
        } elsif( $where eq "delta.author" ) {
           if( /^author\s+(.*);$/o ) {
@@ -366,7 +366,7 @@
 
 sub _formatString
 {
-    my( $str ) = @_;
+    my( $self, $str ) = @_;
     $str =~ s/@/@@/go;
     return "\@$str\@";
 }
@@ -390,7 +390,7 @@
     print $file "access" . $self->access() . ";\n";
     print $file "symbols" . $self->{symbols} . ";\n";
     print $file "locks; strict;\n";
-    printf $file "comment\t%s;\n", ( _formatString( $self->comment() ) );
+    printf $file "comment\t%s;\n", ( $self->_formatString( $self->comment() ) );
     printf $file "expand\t@%s@;\n", ( $self->{expand} ) if ( $self->{expand} );
     
     print $file "\n";
@@ -398,7 +398,7 @@
     # delta
     for( my $i=$self->numRevisions(); $i>0; $i--) {
        printf $file "\n1.%d\ndate\t%s;\tauthor %s;\tstate Exp;\nbranches;\n", 
-              ($i, TWiki::Store::RcsFile::_epochToRcsDateTime( ${$self->{date}}[$i] ), $self->author($i) );
+              ($i, $self->_epochToRcsDateTime( ${$self->{date}}[$i] ), $self->author($i) );
        if( $i == 1 ) {
            print $file "next\t;\n";
        } else {
@@ -406,11 +406,11 @@
        }
     }
     
-    printf $file "\n\ndesc\n%s\n\n", ( _formatString( $self->description() ) );
+    printf $file "\n\ndesc\n%s\n\n", ( $self->_formatString( $self->description() ) );
     
     for( my $i=$self->numRevisions(); $i>0; $i--) {
        printf $file "\n1.$i\nlog\n%s\ntext\n%s\n",
-              ( _formatString( $self->log($i) ), _formatString( $self->delta($i) ) );
+              ( _formatString( $self->log($i) ), $self->_formatString( $self->delta($i) ) );
     }
 }
 
@@ -586,7 +586,7 @@
     $text = $self->_readFile( $self->{file} ) if( $self->{attachment} );
     my $head = $self->numRevisions();
     if( $head ) {
-        my $delta = _diffText( \$text, \$self->delta($head), "", 0 );
+        my $delta = $self->_diffText( \$text, \$self->delta($head), "", 0 );
         ${$self->{"delta"}}[$head] = $delta;
     }   
     $head++;
@@ -715,8 +715,8 @@
     my $text1 = $self->getRevision( $rev1 );
     my $text2 = $self->getRevision( $rev2 );
 	
-    my @lNew = _mySplit( \$text1 );
-    my @lOld = _mySplit( \$text2 );
+    my @lNew = $self->_mySplit( \$text1 );
+    my @lOld = $self->_mySplit( \$text2 );
 	my $diff = Algorithm::Diff::sdiff( \@lNew, \@lOld );
 
 	#the Diff::sdiff algol seems to work better with \n, and the rendering currently needs no \n's
@@ -774,7 +774,7 @@
         return $self->delta( $version );
     } else {
         my $headText = $self->delta( $head );
-        my @text = _mySplit( \$headText, 1 );
+        my @text = $self->_mySplit( \$headText, 1 );
         return $self->_patchN( \@text, $head-1, $version );
     }
 }
@@ -826,7 +826,7 @@
 sub _patch
 {
    # Both params are references to arrays
-   my( $text, $delta ) = @_;
+   my( $self, $text, $delta ) = @_;
    my $adj = 0;
    my $pos = 0;
    my $last = "";
@@ -880,8 +880,8 @@
     my( $self, $text, $version, $target ) = @_;
 
     my $deltaText= $self->delta( $version );
-    my @delta = _mySplit( \$deltaText );
-    _patch( $text, \@delta );
+    my @delta = $self->_mySplit( \$deltaText );
+    $self->_patch( $text, \@delta );
     if( $version <= $target ) {
         return join( "", @$text );
     } else {
@@ -901,7 +901,7 @@
 
 sub _mySplit
 {
-    my( $text, $addEntries ) = @_;
+    my( $self, $text, $addEntries ) = @_;
 
     my $ending = "";
     if( $$text =~ /(\n+)$/o ) {
@@ -948,7 +948,7 @@
 
 sub _diffText
 {
-    my( $new, $old, $type, $contextLines ) = @_;
+    my( $self, $new, $old, $type, $contextLines ) = @_;
     
     my @lNew = _mySplit( $new );
     my @lOld = _mySplit( $old );
@@ -966,7 +966,7 @@
 
 sub _lastNoEmptyItem
 {
-   my( $items ) = @_;
+   my( $self, $items ) = @_;
    my $pos = $#$items;
    my $count = 0;
    my $item;
@@ -991,7 +991,7 @@
 
 sub _diffEnd
 {
-   my( $new, $old, $type ) = @_;
+   my( $self, $new, $old, $type ) = @_;
    return if( $type ); # FIXME
    
    my( $posNew, $countNew ) = _lastNoEmptyItem( $new );
@@ -1038,7 +1038,7 @@
 
 sub _diff
 {
-    my( $new, $old, $type, $contextLines ) = @_;
+    my( $self, $new, $old, $type, $contextLines ) = @_;
     # Work out diffs to change new to old, params are refs to lists
     my $diffs = Algorithm::Diff::diff( $new, $old );
 	
@@ -1072,7 +1072,7 @@
                      $start1 = $pos;
                   }
                }
-               $adj += _addChunk( $chunkSign, \$out, \@lines, $start, $adj, $type, $start1, $last ) if( $chunkSign ne "c" );
+               $adj += $self->_addChunk( $chunkSign, \$out, \@lines, $start, $adj, $type, $start1, $last ) if( $chunkSign ne "c" );
            }
            if( ! @lines ) {
                $start = $pos;
@@ -1103,7 +1103,7 @@
                push @lines, ("");
            }
        }
-       $adj += _addChunk( $chunkSign, \$out, \@lines, $start, $adj, $type, $start1, $last, $lengthNew );
+       $adj += $self->_addChunk( $chunkSign, \$out, \@lines, $start, $adj, $type, $start1, $last, $lengthNew );
        print "]\n" if( $DIFF_DEBUG );
     }
     # Make sure we have the correct number of carriage returns at the end
@@ -1124,7 +1124,7 @@
 
 sub _range
 {
-   my( $start, $end ) = @_;
+   my( $self, $start, $end ) = @_;
    if( $start == $end ) {
       return "$start";
    } else {
@@ -1143,7 +1143,7 @@
 
 sub _addChunk
 {
-   my( $chunkSign, $out, $lines, $start, $adj, $type, $start1, $last, $newLines ) = @_;
+   my( $self, $chunkSign, $out, $lines, $start, $adj, $type, $start1, $last, $newLines ) = @_;
    my $nLines = @$lines;
    if( $lines->[$#$lines] =~ /(\n+)$/o ) {
       $nLines += ( ( length( $1 ) == 0 ) ? 0 : length( $1 ) -1 );
@@ -1153,9 +1153,9 @@
              "last=$last newLines=$newLines nLines=$nLines\n" if( $DIFF_DEBUG );
        $$out .= "\n" if( $$out && $$out !~ /\n$/o );
        if( $chunkSign eq "c" ) {
-          $$out .= _range( $start+1, $start+$nLines/2 );
+          $$out .= $self->_range( $start+1, $start+$nLines/2 );
           $$out .= "c";
-          $$out .= _range( $start1+1, $start1+$nLines/2 );
+          $$out .= $self->_range( $start1+1, $start1+$nLines/2 );
           $$out .= "\n";
           $$out .= "< " . join( "< ", @$lines[0..$nLines/2-1] );
           $$out .= "\n" if( $lines->[$nLines/2-1] !~ /\n$/o );
@@ -1165,7 +1165,7 @@
        } elsif( $chunkSign eq "+" ) {
           if( $type eq "diff" ) {
               $$out .= $start-$adj . "a";
-              $$out .= _range( $start+1, $start+$nLines ) . "\n";
+              $$out .= $self->_range( $start+1, $start+$nLines ) . "\n";
               $$out .= "> " . join( "> ", @$lines );
           } else {
               $$out .= "a";
@@ -1176,7 +1176,7 @@
        } else {
           print "Start nLines newLines: $start $nLines $newLines\n" if( $DIFF_DEBUG );
           if( $type eq "diff" ) {
-              $$out .= _range( $start+1, $start+$nLines );
+              $$out .= $self->_range( $start+1, $start+$nLines );
               $$out .= "d";
               $$out .= $start + $adj . "\n";
               $$out .= "< " . join( "< ", @$lines );
diff -uwbBr twiki/lib/TWiki/Store/RcsWrap.pm twiki.patched/lib/TWiki/Store/RcsWrap.pm
--- twiki/lib/TWiki/Store/RcsWrap.pm	2004-10-08 14:46:34.000000000 +0500
+++ twiki.patched/lib/TWiki/Store/RcsWrap.pm	2004-11-03 17:53:38.000000000 +0500
@@ -33,6 +33,11 @@
 @ISA = qw(TWiki::Store::RcsFile);
 
 use strict;
+use vars qw( $cmdQuote );
+
+#TODO set from TWiki.cfg
+$cmdQuote = "'";
+
 
 ## Details of settings
 #
@@ -72,7 +77,7 @@
    my $self = TWiki::Store::RcsFile->new( $web, $topic, $attachment, %settings );
    bless( $self, $class );
    $self->_settings( %settings );
-   $self->_init();
+#   $self->_init();
    return $self;
 }
 
@@ -103,8 +108,6 @@
     $self->{tagCmd}      = $settings{tagCmd};
 }
 
-#TODO set from TWiki.cfg
-my $cmdQuote = "'";
 
 # ======================
 =pod
@@ -164,7 +167,7 @@
         $cmd = "$1";       # safe, so untaint variable
         my $rcsOutput = `$cmd`;
         my $exit = $? >> 8;
-        _traceExec( $cmd, $rcsOutput, $exit );
+        #_traceExec( $cmd, $rcsOutput, $exit );
         if( $exit && $rcsOutput ) {
            $rcsOutput = "$cmd\n$rcsOutput";
            return $rcsOutput;
@@ -237,7 +240,7 @@
     $cmd = $1;       # safe, so untaint variable
     $rcsOut = `$cmd`;
     my $exit = $? >> 8;
-    _traceExec( $cmd, $rcsOut, $exit );
+    #_traceExec( $cmd, $rcsOut, $exit );
     #$rcsOut =~ s/^Warning\: missing newline.*//os; # forget warning
     if( $exit ) {
         $rcsOut = "$cmd\n$rcsOut";
@@ -286,7 +289,7 @@
     $cmd = $1;       # safe, so untaint
     my $rcsOut = `$cmd`; # capture stderr
     my $exit = $? >> 8;
-    _traceExec( $cmd, $rcsOut, $exit );
+    #_traceExec( $cmd, $rcsOut, $exit );
     #$rcsOut =~ s/^Warning\: missing newline.*//os; # forget warning
     if( $exit ) {
         $rcsOut = "$cmd\n$rcsOut";
@@ -299,7 +302,7 @@
     $cmd = $1;       # safe, so untaint variable
     $rcsOut = `$cmd`;
     $exit = $? >> 8;
-    _traceExec( $cmd, $rcsOut, $exit );
+    #_traceExec( $cmd, $rcsOut, $exit );
     #$rcsOut =~ s/^Warning\: missing newline.*//os; # forget warning
     if( $exit ) {
         $rcsOut = "$cmd\n$rcsOut";
@@ -311,7 +314,7 @@
     $cmd =~ /(.*)/;
     $cmd = $1;       # safe, so untaint variable
     $rcsOut = `$cmd`;
-    _traceExec( $cmd, $rcsOut, $exit );
+    #_traceExec( $cmd, $rcsOut, $exit );
     #$rcsOut =~ s/^Warning\: missing newline.*//os; # forget warning
     if( $exit ) {
         $rcsOut = "$cmd\n$rcsOut";
@@ -348,7 +351,7 @@
         $cmd1 =~ /(.*)/;
         $cmd1 = "$1";
         my $tmp = `$cmd1`;
-        _traceExec( $cmd1, $tmp );
+        #_traceExec( $cmd1, $tmp );
         $file = $tmpfile;
         $cmd =~ s/-p%REVISION%/-r%REVISION%/;
     }    
@@ -366,7 +369,7 @@
         $tmpRevFile = "$1"; # untaint		
         unlink $tmpRevFile;
     }
-    _traceExec( $cmd, $text );
+    #_traceExec( $cmd, $text );
     return $text;
 }
 
@@ -392,7 +395,7 @@
     $cmd =~ /(.*)/;
     $cmd = $1;       # now safe, so untaint variable
     my $rcsOutput = `$cmd`;
-    _traceExec( $cmd, $rcsOutput );
+    #_traceExec( $cmd, $rcsOutput );
     if( $rcsOutput =~ /head:\s+\d+\.(\d+)\n/ ) {
         return $1;
     } else {
@@ -438,14 +441,14 @@
        $cmd =~ /(.*)/; $cmd = $1;       # Untaint
        my $rcsOut = `$cmd`;
        my $exit = $? >> 8;
-       _traceExec( $cmd, $cmd, $exit );
+       #_traceExec( $cmd, $cmd, $exit );
        $rcsError = "Error with $cmd, output: $rcsOut" if( $exit );
        if( ! $rcsError ) {
             $rcsOut =~ /date: (.*?);  author: (.*?);.*\n(.*)\n/;
             $date = $1 || "";
             $user = $2 || "";
             $comment = $3 || "";
-            $date = TWiki::Store::RcsFile::_rcsDateTimeToEpoch( $date );
+            $date = $self->_rcsDateTimeToEpoch( $date );
             $rcsOut =~ /revision 1.([0-9]*)/;
             $rev = $1 || "";
             $rcsError = "Rev missing from revision file $rcsFile" if( ! $rev );
@@ -496,8 +499,8 @@
         $tmp = `$cmd`;
         my $exit = $? >> 8;
         $error = "Error $exit when runing $cmd";
-        _traceExec( $cmd, $tmp, $exit );       
-        _trace( "and now $tmp" );
+        #_traceExec( $cmd, $tmp, $exit );       
+        #_trace( "and now $tmp" );
         # Avoid showing change in revision number!
         # I'm not too happy with this implementation, I think it may be better to filter before sending to diff command,
         # possibly using Algorithm::Diff from CPAN.
@@ -506,7 +509,7 @@
 #        $tmp =~ s/[+-<>]\s*%META:TOPICINFO{[^}]*}%\s*//go;
     }
 	
-    return ($error, parseRevisionDiff( $tmp ) );
+    return ($error, $self->parseRevisionDiff( $tmp ) );
 }
 
 # =========================
@@ -524,7 +527,7 @@
 # -------------------------
 sub parseRevisionDiff
 {
-    my( $text ) = @_;
+    my( $self, $text ) = @_;
 
     my ( $diffFormat ) = "normal"; #or rcs, unified...
     my ( @diffArray );
@@ -604,18 +607,18 @@
     $cmd = $1;       # safe, so untaint variable
     $rcsOutput = `$cmd`; # capture stderr  (S.Knutson)
     my $exit = $? >> 8;
-    _traceExec( $cmd, $rcsOutput );
+    #_traceExec( $cmd, $rcsOutput );
     if( $exit && $rcsOutput =~ /no lock set by/ ) {
           # Try and break lock, setting new one and doing ci again
           my $cmd = $self->{"breakLockCmd"};
           $cmd =~ s/%FILENAME%/$cmdQuote$file$cmdQuote/go;
           $cmd =~ /(.*)/;
           my $out = `$cmd`;
-          _traceExec( $cmd, $out );
+          #_traceExec( $cmd, $out );
           # Assume it worked, as not sure how to trap failure
           $rcsOutput = `$cmd`; # capture stderr  (S.Knutson)
           $exit = $? >> 8;
-          _traceExec( $cmd, $rcsOutput );
+          #_traceExec( $cmd, $rcsOutput );
           if( ! $exit ) {
               $rcsOutput = "";
           }
@@ -656,7 +659,7 @@
        $cmd =~ /(.*)/; $cmd = $1;       # Untaint
        my $rcsOut = `$cmd`;
        my $exit = $? >> 8;
-       _traceExec( $cmd, $cmd, $exit );
+       #_traceExec( $cmd, $cmd, $exit );
 		if( $exit && $rcsOut ) { # oops, stderr was not empty, return error
 			$rcsOut = "$cmd\n$$rcsOut";
 			TWiki:writeDebug("RCSWrap::setTopicRevisionTag error - $rcsOut");
diff -uwbBr twiki/lib/TWiki/Store.pm twiki.patched/lib/TWiki/Store.pm
--- twiki/lib/TWiki/Store.pm	2004-10-08 14:46:34.000000000 +0500
+++ twiki.patched/lib/TWiki/Store.pm	2004-11-03 17:53:38.000000000 +0500
@@ -113,7 +113,14 @@
 
    my $handlerName = "TWiki::Store::$TWiki::storeTopicImpl";
 
-   my $handler = $handlerName->new( $web, $topic, $attachment, @TWiki::storeSettings );
+   eval "use $handlerName;";
+   if ($@) {
+        TWiki::Store::writeWarning ("Store \"$handlerName\" could not be loaded by Perl.  Errors were:\n----\n$@----");
+        return;
+   }
+
+   my $handler = $handlerName->new( $config, $web, $topic, $attachment, @TWiki::storeSettings );
+
    return $handler;
 }
 
@@ -699,7 +706,7 @@
     # FIXME: Inefficient code that hides meta data from Plugin callback
     $text = $meta->write( $text );  # add meta data for Plugin callback
     TWiki::Plugins::beforeSaveHandler( $text, $topic, $web );
-    $meta = TWiki::Meta->remove();  # remove all meta data
+    $meta = $meta->remove();  # remove all meta data
     $text = $meta->read( $text );   # restore meta data
 
     my $error = saveNew( $web, $topic, $text, $meta, $saveCmd, $attachment, $dontLogSave, $doUnlock, $dontNotify, $comment, $forceDate );
diff -uwbBr twiki/lib/TWiki/UI/Oops.pm twiki.patched/lib/TWiki/UI/Oops.pm
--- twiki/lib/TWiki/UI/Oops.pm	2004-10-08 14:46:34.000000000 +0500
+++ twiki.patched/lib/TWiki/UI/Oops.pm	2004-11-03 17:53:38.000000000 +0500
@@ -26,6 +26,7 @@
 
 use strict;
 use TWiki;
+use TWiki::Render;
 
 =pod
 
diff -uwbBr twiki/lib/TWiki/UI/RDiff.pm twiki.patched/lib/TWiki/UI/RDiff.pm
--- twiki/lib/TWiki/UI/RDiff.pm	2004-10-08 14:46:34.000000000 +0500
+++ twiki.patched/lib/TWiki/UI/RDiff.pm	2004-11-03 17:53:38.000000000 +0500
@@ -32,7 +32,8 @@
 #TODO: this needs to be exposed to plugins and whoever might want to over-ride the rendering of diffs
 #Hash, indexed by diffType (+,-,c,u,l.....)
 #contains {colour, CssClassName}
-my %diffColours = ( "+" => [ "#ccccff", "twikiDiffAddedMarker"],
+use vars qw ( %diffColours );
+%diffColours = ( "+" => [ "#ccccff", "twikiDiffAddedMarker"],
                     "-" => [ "#ff9999", "twikiDiffDeletedMarker"],
                     "c" => [ "#99ff99", "twikiDiffChangedText"],
                     "u" => [ "#ffffff", "twikiDiffUnchangedText"],
diff -uwbBr twiki/lib/TWiki/User/HtPasswdUser.pm twiki.patched/lib/TWiki/User/HtPasswdUser.pm
--- twiki/lib/TWiki/User/HtPasswdUser.pm	2004-10-08 14:46:34.000000000 +0500
+++ twiki.patched/lib/TWiki/User/HtPasswdUser.pm	2004-11-03 17:53:38.000000000 +0500
@@ -76,6 +76,7 @@
 # ===========================
 sub writeDebug
 {
+    my ( $self ) = @_;
 #   TWiki::writeDebug( "User: $_[0]" );
 }
 
@@ -93,7 +94,7 @@
 =cut
 sub _htpasswdGeneratePasswd
 {
-    my ( $user, $passwd , $useOldSalt ) = @_;
+    my ( $self, $user, $passwd , $useOldSalt ) = @_;
 
 	my $encodedPassword = '';
 
@@ -146,7 +147,7 @@
 =cut
 sub _htpasswdReadPasswd
 {
-    my ( $user ) = @_;
+    my ( $self, $user ) = @_;
  
     if( ! $user ) {
         return "";
diff -uwbBr twiki/lib/TWiki/User/NoPasswdUser.pm twiki.patched/lib/TWiki/User/NoPasswdUser.pm
--- twiki/lib/TWiki/User/NoPasswdUser.pm	2004-10-08 14:46:34.000000000 +0500
+++ twiki.patched/lib/TWiki/User/NoPasswdUser.pm	2004-11-03 17:53:38.000000000 +0500
@@ -69,6 +69,7 @@
 # ===========================
 sub writeDebug
 {
+    my ( $self )= @_;
 #   TWiki::writeDebug( "User: $_[0]" );
 }
  
diff -uwbBr twiki/lib/TWiki/User.pm twiki.patched/lib/TWiki/User.pm
--- twiki/lib/TWiki/User.pm	2004-10-08 14:46:34.000000000 +0500
+++ twiki.patched/lib/TWiki/User.pm	2004-11-03 17:53:38.000000000 +0500
@@ -100,7 +100,7 @@
 
    my $handlerName = $UserImpl;
 
-   my $handler = $handlerName->new( );
+   my $handler = $handlerName->new( $config );
    return $handler;
 }
 
diff -uwbBr twiki/lib/TWiki.cfg twiki.patched/lib/TWiki.cfg
--- twiki/lib/TWiki.cfg	2004-10-08 14:46:34.000000000 +0500
+++ twiki.patched/lib/TWiki.cfg	2004-11-03 17:53:38.000000000 +0500
@@ -1,3 +1,7 @@
+package TWikicfg ;
+use vars qw ( $detailedOS );
+sub TWikicfg
+{
 # Module of TWiki Collaboration Platform, http://your.domain.com/twiki
 #
 # Configuration file for TWiki, held in 'lib' directory.
@@ -76,6 +80,8 @@
 $dataDir          = "/home/httpd/twiki/data";
 #                   Log directory for log files, debug and warning files. Default "$dataDir" :
 $logDir           = "$dataDir";
+#                   Library directory of TWiki:
+$libDir          = "/home/httpd/twiki/lib";
 
 
 # FIGURE OUT THE OS WE'RE RUNNING UNDER - from CGI.pm
@@ -466,3 +472,6 @@
 #    - ignore preview output
 #    - when you press save last revision will be deleted
 #
+
+}
+1;
diff -uwbBr twiki/lib/TWiki.pm twiki.patched/lib/TWiki.pm
--- twiki/lib/TWiki.pm	2004-10-08 14:46:34.000000000 +0500
+++ twiki.patched/lib/TWiki.pm	2004-11-03 17:53:38.000000000 +0500
@@ -55,11 +55,24 @@
 
 require 5.005;		# For regex objects and internationalisation
 
+{
+    $config->{fileConfig} =~ /(.*)/ ;
+    require "$1.pm";
+    $config->{TWikicfg} = TWikicfg->new( $config );
+    &TWikicfg::TWikicfg();
+
+    # Do a dynamic 'use locale' for this module
+    if( $useLocale ) {
+        require locale;
+      import locale ();
+    }
+}
+
 # ===========================
 # TWiki config variables from TWiki.cfg:
 use vars qw(
         $defaultUserName $wikiHomeUrl $defaultUrlHost
-        $scriptUrlPath $pubUrlPath $pubDir $templateDir $dataDir $logDir
+        $scriptUrlPath $pubUrlPath $pubDir $templateDir $dataDir $logDir $detailedOS $libDir
         $siteWebTopicName $wikiToolName $securityFilter $uploadFilter
         $debugFilename $warningFilename $htpasswdFilename
         $logFilename $remoteUserFilename $wikiUsersTopicname
@@ -78,6 +91,7 @@
         $superAdminGroup $doSuperAdminGroup $OS
         $disableAllPlugins $attachAsciiPath $displayTimeValues
         $dispScriptUrlPath $dispViewPath
+        $htpasswdFormatFamily $htpasswdEncoding
     );
 
 # Internationalisation (I18N) config from TWiki.cfg:
@@ -88,7 +102,7 @@
 
 # TWiki::Store config:
 use vars qw(
-        $rcsDir $rcsArg $nullDev $endRcsCmd $storeTopicImpl $keywordMode
+        $rcsDir $rcsArg $nullDev $endRcsCmd $storeTopicImpl $keywordMode $useRcsDir
         $storeImpl @storeSettings
     );
 
@@ -128,29 +142,31 @@
 	$pageMode $readTopicPermissionFailed $cgiQuery $basicInitDone
     );
     
-# ===========================
-# Exports
-
-# The Render module needs to access a lot of configuration flags from
-# TWiki.cfg, so we export them here.  We also export the %regex hash
-# and a few other useful constants.
-
-use vars qw(@EXPORT_OK %EXPORT_TAGS @ISA);
-
-BEGIN {
-    require Exporter;
-    @ISA = qw(Exporter);
-    
-    %EXPORT_TAGS = (
-	renderflags => [qw($siteLang $securityFilter $twikiWebname $mainWebname
-	    $mainTopicname $scriptSuffix $doPluralToSingular
-	    $dispScriptUrlPath $dispViewPath
-	)]
-    );
-    
-    @EXPORT_OK = qw(%regex $TranslationToken);
-    Exporter::export_ok_tags('renderflags');
-}
+#
+# Remark this part to have no var global
+## ===========================
+## Exports
+##
+## The Render module needs to access a lot of configuration flags from
+## TWiki.cfg, so we export them here.  We also export the %regex hash
+## and a few other useful constants.
+#
+#use vars qw(@EXPORT_OK %EXPORT_TAGS @ISA);
+#
+#BEGIN {
+#    require Exporter;
+#    @ISA = qw(Exporter);
+#    
+#    %EXPORT_TAGS = (
+#	renderflags => [qw($siteLang $securityFilter $twikiWebname $mainWebname
+#	    $mainTopicname $scriptSuffix $doPluralToSingular
+#	    $dispScriptUrlPath $dispViewPath
+#	)]
+#    );
+#    
+#    @EXPORT_OK = qw(%regex $TranslationToken);
+#    Exporter::export_ok_tags('renderflags');
+#}
 
 # ===========================
 # TWiki version:
@@ -167,17 +183,19 @@
     %mon2num = map { $_ => $count++ } @isoMonth; 
 }
 
-# ===========================
-# Read the configuration file at compile time in order to set locale
-BEGIN {
-    do "TWiki.cfg";
-
-    # Do a dynamic 'use locale' for this module
-    if( $useLocale ) {
-        require locale;
-	import locale ();
-    }
-}
+#
+# Configuration file is read in another part
+## ===========================
+## Read the configuration file at compile time in order to set locale
+#BEGIN {
+#    do "TWiki.cfg";
+#
+#    # Do a dynamic 'use locale' for this module
+#    if( $useLocale ) {
+#        require locale;
+#	import locale ();
+#    }
+#}
 
 sub writeDebug;
 sub writeWarning;
@@ -197,6 +215,29 @@
 use TWiki::Net;       # SMTP, get URL
 use TWiki::User;
 use TWiki::Render;
+use TWiki::UI;
+use TWiki::UI::Changes;
+use TWiki::UI::Edit;
+use TWiki::UI::Manage;
+use TWiki::UI::Oops;
+use TWiki::UI::Preview;
+use TWiki::UI::RDiff;
+use TWiki::UI::Save;
+use TWiki::UI::Search;
+use TWiki::UI::Statistics;
+use TWiki::UI::Upload;
+use TWiki::UI::Viewfile;
+use TWiki::UI::View;
+use TWiki::User::HtPasswdUser;
+use TWiki::User::NoPasswdUser;
+use TWiki::Prefs::Parser;
+
+
+TWiki::Net::init_config();
+TWiki::Prefs::init_config();
+TWiki::Search::init_config();
+TWiki::Plugins::init_config();
+
 
 
 # ===========================
@@ -485,7 +526,7 @@
 
 =cut
 
-sub basicInitialize() {
+sub basicInitialize {
     # Set up locale for internationalisation and pre-compile regexes
     setupLocale();
     setupRegexes();
@@ -691,10 +732,10 @@
 =cut
 
 sub convertUtf8URLtoSiteCharset {
-    my ( $webName, $topicName ) = @_;
+    my ( $webNameLoc, $topicNameLoc ) = @_;
 
     ##writeDebug "URL web.topic is $webName.$topicName";
-    my $fullTopicName = "$webName.$topicName";
+    my $fullTopicName = "$webNameLoc.$topicNameLoc";
     my $charEncoding;
 
     # Detect character encoding of the full topic name from URL
@@ -757,7 +798,7 @@
 		}
 	    }
 	}
-	($webName, $topicName) = split /\./, $fullTopicName;
+	($webNameLoc, $topicNameLoc) = split /\./, $fullTopicName;
 
     } else {
 	# Non-ASCII and non-UTF-8 - assume in site character set, 
@@ -767,7 +808,7 @@
     }
     ##writeDebug "Final web and topic are $webName $topicName ($urlCharEncoding URL -> $siteCharset)";
 
-    return ($webName, $topicName);
+    return ($webNameLoc, $topicNameLoc);
 }
 
 =pod
@@ -1032,16 +1073,16 @@
 
 sub getEmailOfUser
 {
-    my( $wikiName ) = @_;		# WikiName without web prefix
+    my( $wikiNameLoc ) = @_;		# WikiName without web prefix
 
     my @list = ();
     # Ignore guest entry and non-existent pages
-    if ( $wikiName ne "TWikiGuest" && 
-		TWiki::Store::topicExists( $mainWebname, $wikiName ) ) {
-        if ( $wikiName =~ /Group$/ ) {
+    if ( $wikiNameLoc ne "TWikiGuest" && 
+		TWiki::Store::topicExists( $mainWebname, $wikiNameLoc ) ) {
+        if ( $wikiNameLoc =~ /Group$/ ) {
             # Page is for a group, get all users in group
-	    ##writeDebug "using group: $mainWebname . $wikiName";
-	    my @userList = TWiki::Access::getUsersOfGroup( $wikiName ); 
+	    ##writeDebug "using group: $mainWebname . $wikiNameLoc";
+	    my @userList = TWiki::Access::getUsersOfGroup( $wikiNameLoc ); 
 	    foreach my $user ( @userList ) {
 		$user =~ s/^.*\.//;	# Get rid of 'Main.' part.
 		foreach my $email ( getEmailOfUser($user) ) {
@@ -1050,9 +1091,9 @@
 	    }
         } else {
 	    # Page is for a user
-	    ##writeDebug "reading home page: $mainWebname . $wikiName";
+	    ##writeDebug "reading home page: $mainWebname . $wikiNameLoc";
             foreach ( split ( /\n/, &TWiki::Store::readWebTopic( 
-					    $mainWebname, $wikiName ) ) ) {
+					    $mainWebname, $wikiNameLoc ) ) ) {
                 if (/^\s\*\sEmail:\s+([\w\-\.\+]+\@[\w\-\.\+]+)/) {   
 		    # Add email address to list
                     push @list, $1;
@@ -1225,11 +1266,11 @@
 
 sub wikiToUserName
 {
-    my( $wikiUser ) = @_;
-    $wikiUser =~ s/^.*\.//g;
-    my $userName =  $wikiToUserList{"$wikiUser"} || $wikiUser;
+    my( $wikiUserLoc ) = @_;
+    $wikiUserLoc =~ s/^.*\.//g;
+    my $userNameLoc =  $wikiToUserList{"$wikiUserLoc"} || $wikiUserLoc;
     ##writeDebug( "TWiki::wikiToUserName: $wikiUser->$userName" );
-    return $userName;
+    return $userNameLoc;
 }
 
 =pod
@@ -1403,6 +1444,7 @@
 
 sub getTWikiLibDir
 {
+    return $libDir;
     if( $twikiLibDir ) {
         return $twikiLibDir;
     }
@@ -2323,7 +2365,7 @@
     $value =~ s/\$min[u]?[t]?[e]?[s]?/sprintf("%.2u",$min)/geoi;
     $value =~ s/\$hou[r]?[s]?/sprintf("%.2u",$hour)/geoi;
     $value =~ s/\$day/sprintf("%.2u",$day)/geoi;
-    my @weekDay = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
+#    my @weekDay = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
     $value =~ s/\$wday/$weekDay[$wday]/geoi;
     $value =~ s/\$mon[t]?[h]?/$isoMonth[$mon]/goi;
     $value =~ s/\$mo/sprintf("%.2u",$mon+1)/geoi;
@@ -2354,14 +2396,14 @@
                  || "r1.\$rev - \$date - \$wikiusername";
     my $web    = extractNameValuePair( $theArgs, "web" ) || $theWeb;
     my $topic  = extractNameValuePair( $theArgs, "topic" ) || $theTopic;
-    my $cgiQuery = getCgiQuery();
+    my $cgiQueryLoc = getCgiQuery();
     my $cgiRev = "";
-    $cgiRev = $cgiQuery->param('rev') if( $cgiQuery );
+    $cgiRev = $cgiQueryLoc->param('rev') if( $cgiQueryLoc );
     my $revnum = $cgiRev || extractNameValuePair( $theArgs, "rev" ) || "";
 
     my( $date, $user, $rev, $comment ) = TWiki::Store::getRevisionInfo( $web, $topic, $revnum );
-    my $wikiName     = userToWikiName( $user, 1 );
-    my $wikiUserName = userToWikiName( $user );
+    my $wikiNameLoc     = userToWikiName( $user, 1 );
+    my $wikiUserNameLoc = userToWikiName( $user );
 
     my $value = $format;
     $value =~ s/\$web/$web/goi;
@@ -2370,8 +2412,8 @@
     $value =~ s/\$date/&formatTime($date)/geoi;
     $value =~ s/\$comment/$comment/goi;
     $value =~ s/\$username/$user/goi;
-    $value =~ s/\$wikiname/$wikiName/goi;
-    $value =~ s/\$wikiusername/$wikiUserName/goi;
+    $value =~ s/\$wikiname/$wikiNameLoc/goi;
+    $value =~ s/\$wikiusername/$wikiUserNameLoc/goi;
  
     return $value;        
 }
