Index: TWiki.pm
===================================================================
--- TWiki.pm	(revision 13172)
+++ TWiki.pm	(working copy)
@@ -68,7 +68,6 @@
             $VERSION $RELEASE
             $TRUE
             $FALSE
-            $sharedSandbox
            );
 
 # Token character that must not occur in any normal text - converted
@@ -137,6 +136,11 @@
     return $twikiLibDir;
 }
 
+# these vars are specifically designed to be overridden using local
+# for execution in sub-contexts.
+use vars qw( $SESSION $PREFS $SESSION $SANDBOX $PLUGINS $NET $STORE $SEARCH
+             $TEMPLATES $ATTACH $LOGIN $USERS $ACCESS $I18N );
+
 BEGIN {
 
     use TWiki::Sandbox;   # system command sandbox
@@ -447,10 +451,6 @@
 
     # initialize lib directory early because of later 'cd's
     getTWikiLibDir();
-
-    # "shared" between mod_perl instances
-    $sharedSandbox = new TWiki::Sandbox(
-        $TWiki::cfg{OS}, $TWiki::cfg{DetailedOS} );
 };
 
 use TWiki::Access;    # access control
@@ -657,7 +657,7 @@
 
     # DEPRECATED plugins header handler. Plugins should use
     # modifyHeaderHandler instead.
-    $pluginHeaders = $this->{plugins}->writeHeaderHandler( $query ) || '';
+    $pluginHeaders = $TWiki::PLUGINS->writeHeaderHandler( $query ) || '';
     if( $pluginHeaders ) {
         foreach ( split /\r\n/, $pluginHeaders ) {
             if ( m/^([\-a-z]+): (.*)$/i ) {
@@ -675,10 +675,10 @@
     $hopts->{'Content-Type'} = $contentType;
 
     # New (since 1.026)
-    $this->{plugins}->modifyHeaderHandler( $hopts, $this->{cgiQuery} );
+    $TWiki::PLUGINS->modifyHeaderHandler( $hopts, $this->{cgiQuery} );
 
     # add cookie(s)
-    $this->{loginManager}->modifyHeader( $hopts );
+    $TWiki::LOGIN->modifyHeader( $hopts );
 
     my $hdr = CGI::header( $hopts );
 
@@ -691,7 +691,7 @@
 
 Redirects the request to =$url=, *unless*
    1 It is overridden by a plugin declaring a =redirectCgiQueryHandler=.
-   1 =$session->{cgiQuery}= is =undef= or
+   1 =$TWiki::SESSION->{cgiQuery}= is =undef= or
    1 $query->param('noredirect') is set to a true value.
 Thus a redirect is only generated when in a CGI context.
 
@@ -748,8 +748,8 @@
         }
     }
 
-    return if( $this->{plugins}->redirectCgiQueryHandler( $query, $url ) );
-    return if( $this->{loginManager}->redirectCgiQuery( $query, $url ) );
+    return if( $TWiki::PLUGINS->redirectCgiQueryHandler( $query, $url ) );
+    return if( $TWiki::LOGIN->redirectCgiQuery( $query, $url ) );
     die "Login manager returned 0 from redirectCgiQuery";
 }
 
@@ -780,7 +780,7 @@
     $md5->add($$, time(), rand(time));
     my $uid = $md5->hexdigest();
     my $passthruFilename = $TWiki::cfg{TempfileDir} . '/passthru_' . $uid;
-    
+
     unless ( -d $TWiki::cfg{TempfileDir} ) {
         unless ( mkdir($TWiki::cfg{TempfileDir}) ) {
             die "Could not create $TWiki::cfg{TempfileDir} for passthrough files";
@@ -869,18 +869,18 @@
     my @mirrorInfo = ( '', '', '', '' );
     if( $TWiki::cfg{SiteWebTopicName} ) {
         my $mirrorSiteName =
-          $this->{prefs}->getWebPreferencesValue( 'MIRRORSITENAME', $theWeb );
+          $TWiki::PREFS->getWebPreferencesValue( 'MIRRORSITENAME', $theWeb );
         if( $mirrorSiteName && $mirrorSiteName ne $TWiki::cfg{SiteWebTopicName} ) {
             my $mirrorViewURL  =
-              $this->{prefs}->getWebPreferencesValue( 'MIRRORVIEWURL', $theWeb );
-            my $mirrorLink = $this->{templates}->readTemplate( 'mirrorlink' );
+              $TWiki::PREFS->getWebPreferencesValue( 'MIRRORVIEWURL', $theWeb );
+            my $mirrorLink = $TWiki::TEMPLATES->readTemplate( 'mirrorlink' );
             $mirrorLink =~ s/%MIRRORSITENAME%/$mirrorSiteName/g;
             $mirrorLink =~ s/%MIRRORVIEWURL%/$mirrorViewURL/g;
             $mirrorLink =~ s/\s*$//g;
-            my $mirrorNote = $this->{templates}->readTemplate( 'mirrornote' );
+            my $mirrorNote = $TWiki::TEMPLATES->readTemplate( 'mirrornote' );
             $mirrorNote =~ s/%MIRRORSITENAME%/$mirrorSiteName/g;
             $mirrorNote =~ s/%MIRRORVIEWURL%/$mirrorViewURL/g;
-            $mirrorNote = $this->{renderer}->getRenderedVersion
+            $mirrorNote = $TWiki::RENDER->getRenderedVersion
               ( $mirrorNote, $theWeb, $TWiki::cfg{HomeTopic} );
             $mirrorNote =~ s/\s*$//g;
             @mirrorInfo = ( $mirrorSiteName, $mirrorViewURL, $mirrorLink, $mirrorNote );
@@ -902,14 +902,14 @@
 
     ASSERT($this->isa( 'TWiki')) if DEBUG;
 
-    my $skinpath = $this->{prefs}->getPreferencesValue( 'SKIN' ) || '';
+    my $skinpath = $TWiki::PREFS->getPreferencesValue( 'SKIN' ) || '';
 
     if( $this->{cgiQuery} ) {
         my $resurface = $this->{cgiQuery}->param( 'skin' );
         $skinpath = $resurface if $resurface;
     }
 
-    my $epidermis = $this->{prefs}->getPreferencesValue( 'COVER' );
+    my $epidermis = $TWiki::PREFS->getPreferencesValue( 'COVER' );
     $skinpath = $epidermis.','.$skinpath if $epidermis;
 
     if( $this->{cgiQuery} ) {
@@ -1059,7 +1059,7 @@
 sub getIconUrl {
     my( $this, $absolute, $iconName ) = @_;
 
-    my $iconTopic = $this->{prefs}->getPreferencesValue( 'ICONTOPIC' );
+    my $iconTopic = $TWiki::PREFS->getPreferencesValue( 'ICONTOPIC' );
     my( $web, $topic) = $this->normalizeWebTopicName(
         $this->{webName}, $iconTopic );
     $iconName =~ s/^.*\.(.*?)$/$1/;
@@ -1082,12 +1082,12 @@
     my $fileExt = lc $bits[$#bits];
 
     unless( $this->{_ICONMAP} ) {
-        my $iconTopic = $this->{prefs}->getPreferencesValue( 'ICONTOPIC' );
+        my $iconTopic = $TWiki::PREFS->getPreferencesValue( 'ICONTOPIC' );
         my( $web, $topic) = $this->normalizeWebTopicName(
             $this->{webName}, $iconTopic );
         local $/ = undef;
         try {
-            my $icons = $this->{store}->getAttachmentStream(
+            my $icons = $TWiki::STORE->getAttachmentStream(
                 undef, $web, $topic, '_filetypes.txt' );
             %{$this->{_ICONMAP}} = split( /\s+/, <$icons> );
             close( $icons );
@@ -1236,19 +1236,28 @@
     $this->{htmlHeaders} = {};
     $this->{context} = $initialContext || {};
 
-    # create the various sub-objects
-    $this->{sandbox} = $sharedSandbox;
-    $this->{plugins} = new TWiki::Plugins( $this );
-    $this->{net} = new TWiki::Net( $this );
-    $this->{store} = new TWiki::Store( $this );
-    $this->{search} = new TWiki::Search( $this );
-    $this->{templates} = new TWiki::Templates( $this );
-    $this->{attach} = new TWiki::Attach( $this );
-    $this->{loginManager} = TWiki::Client::makeLoginManager( $this );
+    # Clear the session during initialisation so that we trap any attempts
+    # to use it during singleton creation
+    local $TWiki::SESSION = undef;
+
+    # create the various singletons, shared in this namespace
+    $TWiki::SANDBOX ||= new TWiki::Sandbox();
+    $TWiki::PLUGINS ||= new TWiki::Plugins();
+    $TWiki::NET ||= new TWiki::Net();
+    $TWiki::STORE ||= new TWiki::Store();
+    $TWiki::SEARCH ||= new TWiki::Search();
+    $TWiki::TEMPLATES ||= new TWiki::Templates();
+    $TWiki::ATTACH ||= new TWiki::Attach();
+
+    # OK, the session object is built up enough now that we can use it
+    local $TWiki::SESSION = $this;
+
+    $TWiki::LOGIN = TWiki::Client::makeLoginManager();
+
     # cache CGI information in the session object
     $this->{cgiQuery} = $query;
 
-    $this->{users} = new TWiki::Users( $this );
+    $TWiki::USERS ||= new TWiki::Users();
 
     # Make %ENV safer, preventing hijack of the search path
     # SMELL: can this be done in a BEGIN block? Or is the environment
@@ -1258,7 +1267,7 @@
     }
     delete @ENV{ qw( IFS CDPATH ENV BASH_ENV ) };
 
-    $this->{security} = new TWiki::Access( $this );
+    $TWiki::ACCESS = new TWiki::Access();
 
     my $web = '';
     my $topic = $query->param( 'topic' );
@@ -1370,14 +1379,13 @@
     # setup the cgi session, from a cookie or the url. this may return
     # the login, but even if it does, plugins will get the chance to override
     # it below.
-    my $login = $this->{remoteUser} = $this->{loginManager}->loadSession($loginName);
-    my $prefs = new TWiki::Prefs( $this );
-    $this->{prefs} = $prefs;
+    my $login = $this->{remoteUser} = $TWiki::LOGIN->loadSession($loginName);
+    $TWiki::PREFS = new TWiki::Prefs();
 
     # Push global preferences from TWiki.TWikiPreferences
-    $prefs->pushGlobalPreferences();
+    $TWiki::PREFS->pushGlobalPreferences();
 
-    my $plogin = $this->{plugins}->load( $TWiki::cfg{DisableAllPlugins} );
+    my $plogin = $TWiki::PLUGINS->load( $TWiki::cfg{DisableAllPlugins} );
     $login = $plogin if $plogin;
     $login ||= $TWiki::cfg{DefaultUserLogin};
     unless( $login =~ /$TWiki::cfg{LoginNameFilterIn}/) {
@@ -1385,7 +1393,7 @@
     }
     $login = TWiki::Sandbox::untaintUnchecked( $login );
 
-    my $user = $this->{users}->findUser( $login );
+    my $user = $TWiki::USERS->findUser( $login );
     $this->{user} = $user;
 
     # Static session variables that can be expanded in topics when they
@@ -1400,32 +1408,32 @@
     $this->{SESSION_TAGS}{INCLUDINGWEB}   = $this->{webName};
 
     # Push plugin settings
-    $this->{plugins}->settings();
+    $TWiki::PLUGINS->settings();
 
     # Now the rest of the preferences
-    $prefs->pushGlobalPreferencesSiteSpecific();
+    $TWiki::PREFS->pushGlobalPreferencesSiteSpecific();
 
-    $prefs->pushPreferences(
+    $TWiki::PREFS->pushPreferences(
         $TWiki::cfg{UsersWebName}, $user->wikiName(),
         'USER '.$user->wikiName() );
 
-    $prefs->pushWebPreferences( $this->{webName} );
+    $TWiki::PREFS->pushWebPreferences( $this->{webName} );
 
-    $prefs->pushPreferences(
+    $TWiki::PREFS->pushPreferences(
         $this->{webName}, $this->{topicName}, 'TOPIC' );
 
-    $prefs->pushPreferenceValues( 'SESSION',
-                                  $this->{loginManager}->getSessionValues() );
+    $TWiki::PREFS->pushPreferenceValues( 'SESSION',
+                                  $TWiki::LOGIN->getSessionValues() );
 
     # requires preferences (such as NEWTOPICBGCOLOR)
-    $this->{renderer} = new TWiki::Render( $this );
+    $TWiki::RENDER = new TWiki::Render( $this );
 
     # Finish plugin initialization - register handlers
-    $this->{plugins}->enable();
+    $TWiki::PLUGINS->enable();
 
     # language information; must be loaded after
     # *all possible preferences sources* are available
-    $this->{i18n} = TWiki::I18N::get( $this );
+    $TWiki::I18N = TWiki::I18N::get();
 
     return $this;
 }
@@ -1447,16 +1455,16 @@
 
 sub finish {
     my $this = shift;
-    $this->{loginManager}->finish();
+    $TWiki::LOGIN->finish();
 
 #    use Data::Dumper;
 #    $Data::Dumper::Indent = 1;
 #    warn "prepared to finish";
 #    warn Dumper($this);
 
-    $this->{prefs}->finish();
-    $this->{users}->finish();
-    $this->{store}->finish();
+    $TWiki::PREFS->finish();
+    $TWiki::USERS->finish();
+    $TWiki::STORE->finish();
 
     %$this = ();
  }
@@ -1656,19 +1664,19 @@
         my $incAtt = $3;
         # FIXME: Check for MIME type, not file suffix
         if( $incAtt =~ m/\.(txt|html?)$/i ) {
-            unless( $this->{store}->attachmentExists(
+            unless( $TWiki::STORE->attachmentExists(
                 $incWeb, $incTopic, $incAtt )) {
                 return $this->_includeWarning( $warn, 'bad_attachment', $url );
             }
             if( $incWeb ne $web || $incTopic ne $topic ) {
                 # CODE_SMELL: Does not account for not yet authenticated user
-                unless( $this->{security}->checkAccessPermission(
+                unless( $TWiki::ACCESS->checkAccessPermission(
                     'VIEW', $this->{user}, undef, undef, $incTopic, $incWeb ) ) {
                     return $this->_includeWarning( $warn, 'access_denied',
                                                    "$incWeb.$incTopic" );
                 }
             }
-            $text = $this->{store}->readAttachment( undef, $incWeb, $incTopic,
+            $text = $TWiki::STORE->readAttachment( undef, $incWeb, $incTopic,
                                                     $incAtt );
             $text = _cleanupIncludedHTML( $text, $this->{urlHost},
                                           $TWiki::cfg{PubUrlPath}, $options )
@@ -1691,7 +1699,7 @@
         return $text;
     }
 
-    my $response = $this->{net}->getExternalResource( $url );
+    my $response = $TWiki::NET->getExternalResource( $url );
     if( !$response->is_error()) {
         my $contentType = $response->header('content-type');
         $text = $response->content();
@@ -1761,14 +1769,14 @@
     $title = CGI::span( { class => 'twikiTocTitle' }, $title ) if( $title );
 
     if( $web ne $defaultWeb || $topic ne $defaultTopic ) {
-        unless( $this->{security}->checkAccessPermission
+        unless( $TWiki::ACCESS->checkAccessPermission
                 ( 'VIEW', $this->{user}, undef, undef, $topic, $web ) ) {
             return $this->inlineAlert( 'alerts', 'access_denied',
                                        $web, $topic );
         }
         my $meta;
         ( $meta, $text ) =
-          $this->{store}->readTopic( $this->{user}, $web, $topic );
+          $TWiki::STORE->readTopic( $this->{user}, $web, $topic );
     }
 
     my $insidePre = 0;
@@ -1776,9 +1784,9 @@
     my $highest = 99;
     my $result  = '';
     my $verbatim = {};
-    $text = $this->{renderer}->takeOutBlocks( $text, 'verbatim',
+    $text = $TWiki::RENDER->takeOutBlocks( $text, 'verbatim',
                                                $verbatim);
-    $text = $this->{renderer}->takeOutBlocks( $text, 'pre',
+    $text = $TWiki::RENDER->takeOutBlocks( $text, 'pre',
                                                $verbatim);
 
     # Find URL parameters
@@ -1809,7 +1817,7 @@
             # cut TOC exclude '---+ heading !! exclude this bit'
             $line =~ s/\s*$regex{headerPatternNoTOC}.+$//go;
             next unless $line;
-            my $anchor = $this->{renderer}->makeAnchorName( $line );
+            my $anchor = $TWiki::RENDER->makeAnchorName( $line );
             $highest = $level if( $level < $highest );
             my $tabs = "\t" x $level;
             # Remove *bold*, _italic_ and =fixed= formatting
@@ -1860,10 +1868,10 @@
     my $template = shift;
     my $def = shift;
 
-    my $text = $this->{templates}->readTemplate( 'oops'.$template,
+    my $text = $TWiki::TEMPLATES->readTemplate( 'oops'.$template,
                                                  $this->getSkin() );
     if( $text ) {
-        my $blah = $this->{templates}->expandTemplate( $def );
+        my $blah = $TWiki::TEMPLATES->expandTemplate( $def );
         $text =~ s/%INSTANTIATE%/$blah/;
         # web and topic can be anything; they are not used
         $text = $this->handleCommonTags( $text, $this->{webName},
@@ -2262,7 +2270,7 @@
     }
 
     my $verbatim = {};
-    $text = $this->{renderer}->takeOutBlocks( $text, 'verbatim',
+    $text = $TWiki::RENDER->takeOutBlocks( $text, 'verbatim',
                                                $verbatim);
 
     # See Item1442
@@ -2357,7 +2365,7 @@
 
     #$stackTop =~ s/$percent/%/go;
 
-    $this->{renderer}->putBackBlocks( \$stackTop, $verbatim, 'verbatim' );
+    $TWiki::RENDER->putBackBlocks( \$stackTop, $verbatim, 'verbatim' );
 
     #print STDERR "FINAL $stackTop\n" if $tell;
 
@@ -2375,7 +2383,7 @@
     my $args = shift;
     # my( $topic, $web ) = @_;
 
-    my $e = $this->{prefs}->getPreferencesValue( $tag );
+    my $e = $TWiki::PREFS->getPreferencesValue( $tag );
     unless( defined( $e )) {
         $e = $this->{SESSION_TAGS}{$tag};
         unless( defined( $e )) {
@@ -2434,7 +2442,7 @@
 relevant when rendering.
 
 Contexts are intended for use mainly by plugins. Core modules can
-use $session->inContext( $id ) to determine if a context is active.
+use $TWiki::SESSION->inContext( $id ) to determine if a context is active.
 
 =cut
 
@@ -2567,12 +2575,12 @@
     return $text unless $text;
     my $verbatim={};
     # Plugin Hook (for cache Plugins only)
-    $this->{plugins}->beforeCommonTagsHandler(
+    $TWiki::PLUGINS->beforeCommonTagsHandler(
         $text, $theTopic, $theWeb, $meta );
 
     #use a "global var", so included topics can extract and putback 
     #their verbatim blocks safetly.
-    $text = $this->{renderer}->takeOutBlocks( $text, 'verbatim',
+    $text = $TWiki::RENDER->takeOutBlocks( $text, 'verbatim',
                                               $verbatim);
 
     my $memW = $this->{SESSION_TAGS}{INCLUDINGWEB};
@@ -2582,12 +2590,12 @@
 
     $this->_expandAllTags( \$text, $theTopic, $theWeb );
 
-    $text = $this->{renderer}->takeOutBlocks( $text, 'verbatim',
+    $text = $TWiki::RENDER->takeOutBlocks( $text, 'verbatim',
                                               $verbatim);
 
 
     # Plugin Hook
-    $this->{plugins}->commonTagsHandler( $text, $theTopic, $theWeb, 0, $meta );
+    $TWiki::PLUGINS->commonTagsHandler( $text, $theTopic, $theWeb, 0, $meta );
 
     # process tags again because plugin hook may have added more in
     $this->_expandAllTags( \$text, $theTopic, $theWeb );
@@ -2605,10 +2613,10 @@
     # table rows properly
     $text =~ s/^<nop>\r?\n//gm;
 
-    $this->{renderer}->putBackBlocks( \$text, $verbatim, 'verbatim' );
+    $TWiki::RENDER->putBackBlocks( \$text, $verbatim, 'verbatim' );
 
     # TWiki Plugin Hook (for cache Plugins only)
-    $this->{plugins}->afterCommonTagsHandler(
+    $TWiki::PLUGINS->afterCommonTagsHandler(
         $text, $theTopic, $theWeb, $meta );
 
     return $text;
@@ -2709,12 +2717,12 @@
     my $cgiQuery = $this->{cgiQuery};
     my $cgiRev = $cgiQuery->param('rev') if( $cgiQuery );
     $params->{rev} = $cgiRev;
-    return $this->{renderer}->renderFORMFIELD( $params, $topic, $web );
+    return $TWiki::RENDER->renderFORMFIELD( $params, $topic, $web );
 }
 
 sub _TMPLP {
     my( $this, $params ) = @_;
-    return $this->{templates}->tmplP( $params );
+    return $TWiki::TEMPLATES->tmplP( $params );
 }
 
 sub _VAR {
@@ -2724,12 +2732,12 @@
     # handle %MAINWEB%-type cases
     ( $web, $topic ) = $this->normalizeWebTopicName( $web, $topic );
     # always return a value, even when the key isn't defined
-    return $this->{prefs}->getWebPreferencesValue( $key, $web ) || '';
+    return $TWiki::PREFS->getWebPreferencesValue( $key, $web ) || '';
 }
 
 sub _PLUGINVERSION {
     my( $this, $params ) = @_;
-    $this->{plugins}->getPluginVersion( $params->{_DEFAULT} );
+    $TWiki::PLUGINS->getPluginVersion( $params->{_DEFAULT} );
 }
 
 my $ifFactory;
@@ -2795,7 +2803,7 @@
     my $section = $params->remove('section');
     my $raw = $params->remove('raw') || '';
     my $warn = $params->remove('warn')
-      || $this->{prefs}->getPreferencesValue( 'INCLUDEWARNING' );
+      || $TWiki::PREFS->getPreferencesValue( 'INCLUDEWARNING' );
 
     if( $path =~ /^https?\:/ ) {
         # include web page
@@ -2832,7 +2840,7 @@
       $this->normalizeWebTopicName($includingWeb, $includedTopic);
 
     # See Codev.FailedIncludeWarning for the history.
-    unless( $this->{store}->topicExists($includedWeb, $includedTopic)) {
+    unless( $TWiki::STORE->topicExists($includedWeb, $includedTopic)) {
         return $this->_includeWarning( $warn, 'topic_not_found',
                                        $includedWeb, $includedTopic );
     }
@@ -2849,7 +2857,7 @@
     }
 
     my %saveTags = %{$this->{SESSION_TAGS}};
-    my $prefsMark = $this->{prefs}->mark();
+    my $prefsMark = $TWiki::PREFS->mark();
 
     $this->{includes}->{$key} = 1;
     $this->{SESSION_TAGS}{INCLUDINGWEB} = $includingWeb;
@@ -2861,10 +2869,10 @@
     }
 
     ( $meta, $text ) =
-      $this->{store}->readTopic( undef, $includedWeb, $includedTopic,
+      $TWiki::STORE->readTopic( undef, $includedWeb, $includedTopic,
                                  $rev );
 
-    unless( $this->{security}->checkAccessPermission(
+    unless( $TWiki::ACCESS->checkAccessPermission(
         'VIEW', $this->{user}, $text, $meta, $includedTopic, $includedWeb )) {
         if( isTrue( $warn )) {
             return $this->inlineAlert( 'alerts', 'access_denied',
@@ -2906,7 +2914,7 @@
     $this->_expandAllTags( \$text, $includedTopic, $includedWeb );
 
     # 4th parameter tells plugin that its called for an included file
-    $this->{plugins}->commonTagsHandler( $text, $includedTopic,
+    $TWiki::PLUGINS->commonTagsHandler( $text, $includedTopic,
                                          $includedWeb, 1, $meta );
 
     # We have to expand tags again, because a plugin may have inserted additional
@@ -2924,9 +2932,9 @@
         # '[[TopicName][...]]' to '[[Web.TopicName][...]]'
         $text =~ s/\[\[([^\]]+)\]\[([^\]]+)\]\]/&_fixIncludeLink( $includedWeb, $1, $2 )/geo;
 
-	    unless( TWiki::isTrue( $this->{prefs}->getPreferencesValue('NOAUTOLINK')) ) {
+	    unless( TWiki::isTrue( $TWiki::PREFS->getPreferencesValue('NOAUTOLINK')) ) {
 	        # Handle WikiWords
-	        $text = $this->{renderer}->takeOutBlocks( $text, 'noautolink', $removed );
+	        $text = $TWiki::RENDER->takeOutBlocks( $text, 'noautolink', $removed );
 	    }
 
         # 'TopicName' to 'Web.TopicName'
@@ -2934,7 +2942,7 @@
         $text =~ s/(^|[\s(])($regex{wikiWordRegex})/$1$includedWeb\.$2/go;
         $text =~ s/(^|[\s(])$TranslationToken/$1/go;
 
-        $this->{renderer}->putBackBlocks( \$text, $removed, 'noautolink' );
+        $TWiki::RENDER->putBackBlocks( \$text, $removed, 'noautolink' );
     }
 
     # handle tags again because of plugin hook
@@ -2944,7 +2952,7 @@
     delete $this->{includes}->{$key};
     %{$this->{SESSION_TAGS}} = %saveTags;
 
-    $this->{prefs}->restore( $prefsMark );
+    $TWiki::PREFS->restore( $prefsMark );
     $text =~ s/^[\r\n]+/\n/;
     $text =~ s/[\r\n]+$/\n/;
 
@@ -3002,7 +3010,7 @@
 sub _METASEARCH {
     my( $this, $params ) = @_;
 
-    return $this->{store}->searchMetaData( $params );
+    return $TWiki::STORE->searchMetaData( $params );
 }
 
 sub _DATE {
@@ -3038,7 +3046,7 @@
     $cgiRev = $cgiQuery->param('rev') if( $cgiQuery );
     my $rev = $cgiRev || $params->{rev} || '';
 
-    return $this->{renderer}->renderRevisionInfo( $web, $topic, undef,
+    return $TWiki::RENDER->renderRevisionInfo( $web, $topic, undef,
                                                   $rev, $format );
 }
 
@@ -3078,9 +3086,9 @@
     $params->{baseweb} = $web;
     $params->{basetopic} = $topic;
     $params->{search} = $params->{_DEFAULT} if( $params->{_DEFAULT} );
-    $params->{type} = $this->{prefs}->getPreferencesValue( 'SEARCHVARDEFAULTTYPE' ) unless( $params->{type} );
+    $params->{type} = $TWiki::PREFS->getPreferencesValue( 'SEARCHVARDEFAULTTYPE' ) unless( $params->{type} );
 
-    my $s = $this->{search}->searchWeb( %$params );
+    my $s = $TWiki::SEARCH->searchWeb( %$params );
     return $s;
 }
 
@@ -3102,11 +3110,11 @@
     my @webslist = split( /,\s*/, $webs );
     foreach my $aweb ( @webslist ) {
         if( $aweb eq 'public' ) {
-            push( @list, $this->{store}->getListOfWebs( 'user,public,allowed' ) );
+            push( @list, $TWiki::STORE->getListOfWebs( 'user,public,allowed' ) );
         } elsif( $aweb eq 'webtemplate' ) {
-            push( @list, $this->{store}->getListOfWebs( 'template,allowed' ));
+            push( @list, $TWiki::STORE->getListOfWebs( 'template,allowed' ));
         } else{
-            push( @list, $aweb ) if( $this->{store}->webExists( $aweb ) );
+            push( @list, $aweb ) if( $TWiki::STORE->webExists( $aweb ) );
         }
     }
 
@@ -3143,10 +3151,10 @@
 
     return '' if
       $web ne $this->{webName} &&
-      $this->{prefs}->getWebPreferencesValue( 'NOSEARCHALL', $web );
+      $TWiki::PREFS->getWebPreferencesValue( 'NOSEARCHALL', $web );
 
     my @items;
-    foreach my $item ( $this->{store}->getTopicNames( $web ) ) {
+    foreach my $item ( $TWiki::STORE->getTopicNames( $web ) ) {
         my $line = $format;
         $line =~ s/\$web\b/$web/g;
         $line =~ s/\$name\b/$item/g;
@@ -3345,7 +3353,7 @@
 
 sub _LANGUAGE {
     my $this = shift;
-    return $this->{i18n}->language();
+    return $I18N->language();
 }
 
 sub _LANGUAGES {
@@ -3359,7 +3367,7 @@
     my $marker = $params->{marker} || 'selected="selected"';
 
     # $languages is a hash reference:
-    my $languages = $this->{i18n}->enabled_languages();
+    my $languages = $I18N->enabled_languages();
 
     my @tags = sort(keys(%{$languages}));
 
@@ -3409,7 +3417,7 @@
     }
 
     # do the magic:
-    my $result  =  $this->{i18n}->maketext($str, @args);
+    my $result  =  $I18N->maketext($str, @args);
 
     # replace accesskeys:
     $result =~ s#(^|[^&])&([a-zA-Z])#$1<span class='twikiAccessKey'>$2</span>#g;
@@ -3467,7 +3475,7 @@
 }
 
 sub _ALLVARIABLES {
-    return shift->{prefs}->stringify();
+    return $TWiki::PREFS->stringify();
 }
 
 sub _META {
@@ -3481,17 +3489,17 @@
 
     if( $option eq 'form' ) {
         # META:FORM and META:FIELD
-        return TWiki::Form::renderForDisplay( $this->{templates}, $meta );
+        return TWiki::Form::renderForDisplay( $TWiki::TEMPLATES, $meta );
     } elsif ( $option eq 'formfield' ) {
         # a formfield from within topic text
-        return $this->{renderer}->renderFormField( $meta, $params );
+        return $TWiki::RENDER->renderFormField( $meta, $params );
     } elsif( $option eq 'attachments' ) {
         # renders attachment tables
-        return $this->{attach}->renderMetaData( $web, $topic, $meta, $params );
+        return $TWiki::ATTACH->renderMetaData( $web, $topic, $meta, $params );
     } elsif( $option eq 'moved' ) {
-        return $this->{renderer}->renderMoved( $web, $topic, $meta, $params );
+        return $TWiki::RENDER->renderMoved( $web, $topic, $meta, $params );
     } elsif( $option eq 'parent' ) {
-        return $this->{renderer}->renderParent( $web, $topic, $meta, $params );
+        return $TWiki::RENDER->renderParent( $web, $topic, $meta, $params );
     }
 
     return '';
@@ -3511,7 +3519,7 @@
 # Shortcut to %TMPL:P{"sep"}%
 sub _SEP {
     my $this = shift;
-    return $this->{templates}->expandTemplate('sep');
+    return $TWiki::TEMPLATES->expandTemplate('sep');
 }
 
 #deprecated functionality, now implemented using %USERINFO%
@@ -3520,7 +3528,7 @@
     my ( $this, $params ) = @_;
     ASSERT($this->isa( 'TWiki')) if DEBUG;
 
-    $params->{format} = $this->{prefs}->getPreferencesValue( 'WIKINAME' ) ||
+    $params->{format} = $TWiki::PREFS->getPreferencesValue( 'WIKINAME' ) ||
       '$wikiname';
 
     return $this->_USERINFO($params);
@@ -3532,7 +3540,7 @@
     my ( $this, $params ) = @_;
     ASSERT($this->isa( 'TWiki')) if DEBUG;
 
-    $params->{format} = $this->{prefs}->getPreferencesValue( 'USERNAME' ) ||
+    $params->{format} = $TWiki::PREFS->getPreferencesValue( 'USERNAME' ) ||
       '$username';
 
     return $this->_USERINFO($params);
@@ -3545,7 +3553,7 @@
     ASSERT($this->isa( 'TWiki')) if DEBUG;
 
     $params->{format} =
-      $this->{prefs}->getPreferencesValue( 'WIKIUSERNAME' ) ||
+      $TWiki::PREFS->getPreferencesValue( 'WIKIUSERNAME' ) ||
         '$wikiusername';
 
     return $this->_USERINFO($params);
@@ -3557,7 +3565,7 @@
 
     my $user = $this->{user};
     if( $params->{_DEFAULT} ) {
-        $user = $this->{users}->findUser( $params->{_DEFAULT}, undef, 1 );
+        $user = $TWiki::USERS->findUser( $params->{_DEFAULT}, undef, 1 );
         return '' if !$user;
         return '' if( $TWiki::cfg{AntiSpam}{HideUserDetails} &&
                         !$this->{user}->isAdmin() &&
@@ -3595,7 +3603,7 @@
 sub _GROUPS {
     my ( $this, $params ) = @_;
 
-    my $groups = $this->{users}->eachGroup();
+    my $groups = $TWiki::USERS->eachGroup();
     my @table;
     while( $groups->hasNext() ) {
         my $group = $groups->next();
Index: TWiki/Prefs/PrefsCache.pm
===================================================================
--- TWiki/Prefs/PrefsCache.pm	(revision 13172)
+++ TWiki/Prefs/PrefsCache.pm	(working copy)
@@ -132,10 +132,9 @@
 
     $this->{SOURCE} = $web.'.'.$topic;
 
-    my $session = $this->{MANAGER}->{session};
-    if( $session->{store}->topicExists( $web, $topic )) {
+    if( $TWiki::STORE->topicExists( $web, $topic )) {
         my( $meta, $text ) =
-          $session->{store}->readTopic( undef, $web, $topic, undef );
+          $TWiki::STORE->readTopic( undef, $web, $topic, undef );
 
         $parser ||= new TWiki::Prefs::Parser();
         $parser->parseText( $text, $this, $keyPrefix );
@@ -164,10 +163,9 @@
 
     $this->{SOURCE} = $web.'.'.$topic;
 
-    my $session = $this->{MANAGER}->{session};
     unless( $meta ) {
-        $meta = new TWiki::Meta( $session, $web, $topic );
-        $session->{store}->extractMetaData( $meta, \$text );
+        $meta = new TWiki::Meta( $web, $topic );
+        $TWiki::STORE->extractMetaData( $meta, \$text );
     }
 
     my $parser = new TWiki::Prefs::Parser();
Index: TWiki/Attach.pm
===================================================================
--- TWiki/Attach.pm	(revision 13172)
+++ TWiki/Attach.pm	(working copy)
@@ -44,17 +44,15 @@
 
 =pod
 
----++ ClassMethod new( $session )
+---++ ClassMethod new()
 
 Constructor
 
 =cut
 
 sub new {
-    my ( $class, $session ) = @_;
+    my ( $class ) = @_;
     my $this = bless( {}, $class );
-    ASSERT($session->isa( 'TWiki')) if DEBUG;
-    $this->{session} = $session;
     return $this;
 }
 
@@ -84,7 +82,7 @@
 	my @attachments = $meta->find( 'FILEATTACHMENT' );
     return '' unless @attachments;
 
-    my $templates = $this->{session}->{templates};
+    my $templates = $TWiki::TEMPLATES->{templates};
     $templates->readTemplate($tmplname);
 
 	my $rows = '';
@@ -125,11 +123,11 @@
     my( $this, $web, $topic, %attrs ) = @_;
     ASSERT($this->isa( 'TWiki::Attach')) if DEBUG;
 
-    my $store = $this->{session}->{store};
+    my $store = $TWiki::STORE;
     my $latestRev =
       $store->getRevisionNumber( $web, $topic, $attrs{name} );
 
-    my $templates = $this->{session}->{templates};
+    my $templates = $TWiki::TEMPLATES;
     $templates->readTemplate('attachtables');
 
     my $header = $templates->expandTemplate('ATTACH:versions:header');
@@ -183,8 +181,8 @@
         return $info->{version};
     }
     elsif ( $attr eq 'ICON' ) {
-        my $picked = $this->{session}->mapToIconFileName( $file );
-        my $url = $this->{session}->getIconUrl( 0, $picked );
+        my $picked = $TWiki::SESSION->mapToIconFileName( $file );
+        my $url = $TWiki::SESSION->getIconUrl( 0, $picked );
         return CGI::img( { src => $url, width => 16, height=>16,
                            align => 'top',
                            alt => $picked || '',
@@ -197,7 +195,7 @@
         return $1;
     }
     elsif ( $attr eq 'URL' ) {
-        return $this->{session}->getScriptUrl
+        return $TWiki::SESSION->getScriptUrl
           ( 0, 'viewfile', $web, $topic,
             rev => $info->{version} || undef, filename => $file );
     }
@@ -225,7 +223,7 @@
         return TWiki::Time::formatTime( $info->{date} || 0 );
     }
     elsif ( $attr eq 'USER' ) {
-        my $user = $this->{session}->{users}->findUser($info->{user});
+        my $user = $TWiki::USERS->findUser($info->{user});
         if (defined($user)) {
             return $user->webDotWikiName();
         } else {
@@ -261,8 +259,8 @@
 
     my $fileLink = '';
     my $imgSize = '';
-    my $prefs = $this->{session}->{prefs};
-    my $store = $this->{session}->{store};
+    my $prefs = $TWiki::PREFS;
+    my $store = $TWiki::STORE;
 
     if( $attName =~ /\.(gif|jpg|jpeg|png)$/i ) {
         # inline image
@@ -553,7 +551,7 @@
         if( ! $fileUser ) { 
             $fileUser = ''; 
         } else {
-            my $u = $this->{session}->{users}->findUser( $fileUser );
+            my $u = $TWiki::USERS->findUser( $fileUser );
             $fileUser = $u->login() if $u;
         }
         $fileUser =~ s/ //go;
@@ -638,7 +636,7 @@
             $date = TWiki::Time::parseTime( $date );
         }
         $att->{date} = $date;
-        my $u = $this->{session}->{users}->findUser( $att->{user} );
+        my $u = $TWiki::USERS->findUser( $att->{user} );
         $att->{user} = $u->webDotWikiName() if $u;
     }
 }
Index: TWiki/Search.pm
===================================================================
--- TWiki/Search.pm	(revision 13172)
+++ TWiki/Search.pm	(working copy)
@@ -47,19 +47,15 @@
 
 =pod
 
----++ ClassMethod new ($session)
+---++ ClassMethod new()
 
 Constructor for the singleton Search engine object.
 
 =cut
 
 sub new {
-    my ( $class, $session ) = @_;
+    my ( $class ) = @_;
     my $this = bless( {}, $class );
-
-    ASSERT($session->isa( 'TWiki')) if DEBUG;
-    $this->{session} = $session;
-
     return $this;
 }
 
@@ -76,7 +72,7 @@
     # Only well-secured intranet sites, authenticated for all access
     # (view, edit, attach, search, etc), AND forced to use unsafe
     # platforms, should use the $forceUnsafeRegexes flag.
-    my $unsafePlatform = ( not ($this->{session}->{sandbox}->{SAFE} ) );
+    my $unsafePlatform = ( not ($TWiki::SANDBOX->{SAFE} ) );
 
     # FIXME: Use of new global
     my $useFilterIn = ($unsafePlatform and not $TWiki::cfg{ForceUnsafeRegexes});
@@ -195,7 +191,7 @@
         $searchString =~ s/[\+\-]\s+//go;
 
         # Build pattern of stop words
-        my $prefs = $this->{session}->{prefs};
+        my $prefs = $TWiki::PREFS;
         my $stopWords = $prefs->getPreferencesValue( 'SEARCHSTOPWORDS' ) || '';
         $stopWords =~ s/[\s\,]+/\|/go;
         $stopWords =~ s/[\(\)]//go;
@@ -232,7 +228,7 @@
 
     my @topicList = ();
     return @topicList unless( @theTokens );   # bail out if no search string
-    my $store = $this->{session}->{store};
+    my $store = $TWiki::STORE;
 
     if( $topic ) {
         # limit search to topic list
@@ -371,8 +367,8 @@
     my %params = @_;
     my $callback =      $params{_callback};
     my $cbdata =        $params{_cbdata};
-    my $baseTopic =     $params{basetopic} || $this->{session}->{topicName};
-    my $baseWeb =       $params{baseweb}   || $this->{session}->{webName};
+    my $baseTopic =     $params{basetopic} || $TWiki::SESSION->{topicName};
+    my $baseWeb =       $params{baseweb}   || $TWiki::SESSION->{webName};
     my $doBookView =    TWiki::isTrue( $params{bookview} );
     my $caseSensitive = TWiki::isTrue( $params{casesensitive} );
     my $excludeTopic =  $params{excludetopic} || '';
@@ -410,8 +406,7 @@
 
     $baseWeb =~ s/\./\//go;
 
-    my $session = $this->{session};
-    my $renderer = $session->{renderer};
+    my $renderer = $TWiki::RENDER;
 
     # Limit search results
     if ($limit =~ /(^\d+$)/o) {
@@ -440,9 +435,9 @@
     }
 
     my $searchResult = '';
-    my $homeWeb = $session->{webName};
+    my $homeWeb = $TWiki::SESSION->{webName};
     my $homeTopic = $TWiki::cfg{HomeTopicName};
-    my $store = $session->{store};
+    my $store = $TWiki::STORE;
 
     my %excludeWeb;
     my @tmpWebs;
@@ -470,10 +465,10 @@
 
     } else {
         # default to current web
-        push( @tmpWebs, $session->{webName} );
+        push( @tmpWebs, $TWiki::SESSION->{webName} );
         if ( TWiki::isTrue( $recurse )) {
-            push( @tmpWebs, $store->getListOfWebs( 'user,allowed',
-                                                   $session->{webName} ));
+            push( @tmpWebs, $store->getListOfWebs(
+                'user,allowed', $TWiki::SESSION->{webName} ));
         }
     }
 
@@ -504,7 +499,7 @@
     } else {
         $template = 'search';
     }
-    $tmpl = $session->{templates}->readTemplate( $template );
+    $tmpl = $TWiki::TEMPLATES->readTemplate( $template );
 
     # SMELL: the only META tags in a template will be METASEARCH
     # Why the heck are they being filtered????
@@ -528,16 +523,16 @@
     }
 
     # Expand tags in template sections
-    $tmplSearch = $session->handleCommonTags( $tmplSearch,
+    $tmplSearch = $TWiki::SESSION->handleCommonTags( $tmplSearch,
                                               $homeWeb,
                                               $homeTopic );
-    $tmplNumber = $session->handleCommonTags( $tmplNumber,
+    $tmplNumber = $TWiki::SESSION->handleCommonTags( $tmplNumber,
                                               $homeWeb,
                                               $homeTopic );
 
     # If not inline search, also expand tags in head and tail sections
     unless( $inline ) {
-        $tmplHead = $session->handleCommonTags( $tmplHead,
+        $tmplHead = $TWiki::SESSION->handleCommonTags( $tmplHead,
                                                 $homeWeb,
                                                 $homeTopic );
 
@@ -583,11 +578,11 @@
     # FIXME: Move log entry further down to log actual webs searched
     if( ( $TWiki::cfg{Log}{search} ) && ( ! $inline ) ) {
         my $t = join( ' ', @webs );
-        $session->writeLog( 'search', $t, $searchString );
+        $TWiki::SESSION->writeLog( 'search', $t, $searchString );
     }
 
     # Loop through webs
-    my $isAdmin = $session->{user}->isAdmin();
+    my $isAdmin = $TWiki::SESSION->{user}->isAdmin();
     my $ttopics = 0;
     foreach my $web ( @webs ) {
         $web =~ s/$TWiki::cfg{NameFilter}//go;
@@ -595,7 +590,7 @@
 
         next unless $store->webExists( $web );  # can't process what ain't thar
 
-        my $prefs = $session->{prefs};
+        my $prefs = $TWiki::PREFS;
         my $thisWebNoSearchAll = $prefs->getWebPreferencesValue( 'NOSEARCHALL', $web ) || '';
 
         # make sure we can report this web on an 'all' search
@@ -603,7 +598,7 @@
         next if ( $searchAllFlag
                   && ! $isAdmin
                   && ( $thisWebNoSearchAll =~ /on/i || $web =~ /^[\.\_]/ )
-                  && $web ne $session->{webName} );
+                  && $web ne $TWiki::SESSION->{webName} );
 
         # Run the search on topics in this web
         my @topicList = $this->_searchTopicsInWeb(
@@ -713,7 +708,7 @@
             my $isoDate = TWiki::Time::formatTime( $epochSecs, '$iso', 'gmtime');
 
             my $revUser = $topicInfo->{$topic}->{editby} || 'UnknownUser';
-            my $ru = $session->{users}->findUser( $revUser );
+            my $ru = $TWiki::USERS->findUser( $revUser );
             my $revNum  = $topicInfo->{$topic}->{revNum} || 0;
 
             # Check security
@@ -734,7 +729,7 @@
                         # primitive way to prevent recursion
                         $text =~ s/%SEARCH/%<nop>SEARCH/g;
                     }
-                    $text = $session->handleCommonTags(
+                    $text = $TWiki::SESSION->handleCommonTags(
                         $text, $web, $topic, $meta );
                 }
             }
@@ -780,7 +775,7 @@
                     $out =~ s/\$createwikiusername/$this->_getRev1Info( $web, $topic, 'wikiusername', $r1info )/ges;
                     if( $out =~ m/\$text/ ) {
                         ( $meta, $text ) = $this->_getTextAndMeta( $topicInfo, $web, $topic ) unless $text;
-                        if( $topic eq $session->{topicName} ) {
+                        if( $topic eq $TWiki::SESSION->{topicName} ) {
                             # defuse SEARCH in current topic to prevent loop
                             $text =~ s/%SEARCH{.*?}%/SEARCH{...}/go;
                         }
@@ -796,7 +791,7 @@
 
                 my $srev = 'r' . $revNum;
                 if( $revNum eq '0' || $revNum eq '1' ) {
-                    $srev = CGI::span( { class => 'twikiNew' }, ($this->{session}->{i18n}->maketext('NEW')) );
+                    $srev = CGI::span( { class => 'twikiNew' }, ($TWiki::I18N->maketext('NEW')) );
                 }
                 $out =~ s/%REVISION%/$srev/o;
                 $out =~ s/%AUTHOR%/$revUser/o;
@@ -809,9 +804,9 @@
                         # primitive way to prevent recursion
                         $text =~ s/%SEARCH/%<nop>SEARCH/g;
                     }
-                    $text = $session->handleCommonTags(
+                    $text = $TWiki::SESSION->handleCommonTags(
                         $text, $web, $topic, $meta );
-                    $text = $session->{renderer}->getRenderedVersion
+                    $text = $TWiki::RENDER->getRenderedVersion
                       ( $text, $web, $topic );
                     # FIXME: What about meta data rendering?
                     $out =~ s/%TEXTHEAD%/$text/go;
@@ -854,13 +849,13 @@
                 # lazy output of header (only if needed for the first time)
                 unless( $headerDone ) {
                     $headerDone = 1;
-                    my $prefs = $session->{prefs};
+                    my $prefs = $TWiki::PREFS;
                     my $thisWebBGColor =
                       $prefs->getWebPreferencesValue( 'WEBBGCOLOR', $web ) ||
                         '\#FF00FF';
                     $beforeText =~ s/%WEBBGCOLOR%/$thisWebBGColor/go;
                     $beforeText =~ s/%WEB%/$web/go;
-                    $beforeText = $session->handleCommonTags(
+                    $beforeText = $TWiki::SESSION->handleCommonTags(
                         $beforeText, $web, $topic );
                     if ( defined $callback ) {
                         $beforeText =
@@ -901,7 +896,7 @@
         # output footer only if hits in web
         if( $ntopics ) {
             # output footer of $web
-            $afterText  = $session->handleCommonTags(
+            $afterText  = $TWiki::SESSION->handleCommonTags(
                 $afterText, $web, $homeTopic );
             if( $inline || $format ) {
                 $afterText =~ s/\n$//os;  # remove trailing new line
@@ -949,7 +944,7 @@
     }
 
     unless( $inline ) {
-        $tmplTail = $session->handleCommonTags( $tmplTail,
+        $tmplTail = $TWiki::SESSION->handleCommonTags( $tmplTail,
                                                 $homeWeb,
                                                 $homeTopic );
 
@@ -967,7 +962,7 @@
     return undef if ( defined $callback );
     return $searchResult if $inline;
 
-    $searchResult = $session->handleCommonTags( $searchResult,
+    $searchResult = $TWiki::SESSION->handleCommonTags( $searchResult,
                                                 $homeWeb,
                                                 $homeTopic );
     $searchResult = $renderer->getRenderedVersion( $searchResult,
@@ -1017,8 +1012,7 @@
 sub _extractTopicInfo {
     my ( $this, $web, $topic, $sortfield ) = @_;
     my $info = {};
-    my $session = $this->{session};
-    my $store = $session->{store};
+    my $store = $TWiki::STORE;
 
     my ( $meta, $text ) = $this->_getTextAndMeta( undef, $web, $topic );
 
@@ -1031,10 +1025,10 @@
     $info->{revNum}     = $revnum;
 
     $info->{allowView} =
-      $session->{security}->
-        checkAccessPermission( 'VIEW', $session->{user},
-                               $text, $meta,
-                               $topic, $web );
+      $TWiki::ACCESS->checkAccessPermission(
+          'VIEW', $TWiki::SESSION->{user},
+          $text, $meta,
+          $topic, $web );
 
     return $info unless $sortfield;
 
@@ -1051,7 +1045,7 @@
 sub _getTextAndMeta {
     my( $this, $topicInfo, $web, $topic ) = @_;
     my ( $meta, $text );
-    my $store = $this->{session}->{store};
+    my $store = $TWiki::STORE;
 
     # read from cache if it's there
     if ( $topicInfo ) {
@@ -1075,10 +1069,10 @@
 sub _getRev1Info {
     my( $this, $web, $topic, $attr, $info ) = @_;
     my $key = $web.'.'.$topic;
-    my $store = $this->{session}->{store};
+    my $store = $TWiki::STORE;
 
     unless( $info->{webTopic} && $info->{webTopic} eq $key ) {
-        my $meta = new TWiki::Meta( $this->{session}, $web, $topic );
+        my $meta = new TWiki::Meta( $web, $topic );
         my ( $d, $u ) = $meta->getRevisionInfo( 1 );
         $info->{date} = $d;
         $info->{user} = $u;
Index: TWiki/Compatibility.pm
===================================================================
--- TWiki/Compatibility.pm	(revision 13172)
+++ TWiki/Compatibility.pm	(working copy)
@@ -112,7 +112,7 @@
 
 =pod
 
----++ StaticMethod upgradeCategoryTable( $session, $web, $topic, $meta, $text ) -> $text
+---++ StaticMethod upgradeCategoryTable( $web, $topic, $meta, $text ) -> $text
 
 Upgrade old style category table
 
@@ -121,9 +121,9 @@
 =cut
 
 sub upgradeCategoryTable {
-    my( $session, $web, $topic, $meta, $text ) = @_;
+    my( $web, $topic, $meta, $text ) = @_;
 
-    my $icat = $session->{templates}->readTemplate( 'twikicatitems' );
+    my $icat = $TWiki::TEMPLATES->readTemplate( 'twikicatitems' );
 
     if( $icat ) {
         my @items = ();
@@ -141,7 +141,7 @@
                 push @items, ( [$catname, $catmod, $catvalue] );
             }
         }
-        my $prefs = $session->{prefs};
+        my $prefs = $TWiki::PREFS;
         my $listForms = $prefs->getWebPreferencesValue( 'WEBFORMS', $web );
         $listForms =~ s/^\s*//go;
         $listForms =~ s/\s*$//go;
@@ -150,7 +150,7 @@
         $defaultFormTemplate = $formTemplates[0] if ( @formTemplates );
 
         if( ! $defaultFormTemplate ) {
-            $session->writeWarning( "Form: can't get form definition to convert category table " .
+            $TWiki::SESSION->writeWarning( "Form: can't get form definition to convert category table " .
                                   " for topic $web.$topic" );
             foreach my $oldCat ( @items ) {
                 my $name = $oldCat->[0];
@@ -165,7 +165,7 @@
             return;
         }
 
-        my $def = new TWiki::Form($session, $web, $defaultFormTemplate );
+        my $def = new TWiki::Form( $web, $defaultFormTemplate );
         $meta->put( 'FORM', { name => $defaultFormTemplate } );
 
         foreach my $fieldDef ( @{$def->{fields}} ) {
@@ -188,7 +188,7 @@
         }
 
     } else {
-        $session->writeWarning( "Form: get find category template twikicatitems for Web $web" );
+        $TWiki::SESSION->writeWarning( "Form: get find category template twikicatitems for Web $web" );
     }
     return $text;
 }
Index: TWiki/Upgrade/MoveTopics.pm
===================================================================
--- TWiki/Upgrade/MoveTopics.pm	(revision 13172)
+++ TWiki/Upgrade/MoveTopics.pm	(working copy)
@@ -23,7 +23,7 @@
 sub moveTopics {
 my ( $session ) = @_;
 
-	if (! $session->{store}->webExists('TWikiConfiguration') ) {
+	if (! $TWiki::STORE->webExists('TWikiConfiguration') ) {
 		my $opts =
 		{
 			WEBBGCOLOR => '#C0FFFF',
@@ -32,11 +32,11 @@
 			NOSEARCHALL => '',
 		};
 		$opts->{SITEMAPLIST} = "on" if( $opts->{SITEMAPWHAT} );
-	    my $err = $session->{store}->createWeb( $session->{user},
+	    my $err = $TWiki::STORE->createWeb( $session->{user},
                                                 'TWikiConfiguration',
                                                 '_default', $opts);
 	}
-	if (! $session->{store}->webExists('TWikiDocumentation') ) {
+	if (! $TWiki::STORE->webExists('TWikiDocumentation') ) {
 		my $opts =
 		{
 			WEBBGCOLOR => '#C0C0C0',
@@ -45,11 +45,11 @@
 			NOSEARCHALL => '',
 		};
 		$opts->{SITEMAPLIST} = "on" if( $opts->{SITEMAPWHAT} );
-	    my $err = $session->{store}->createWeb( $session->{user},
+	    my $err = $TWiki::STORE->createWeb( $session->{user},
                                                 'TWikiDocumentation',
                                                 '_default', $opts );
 	}
-	if (! $session->{store}->webExists('TWikiUsers') ) {
+	if (! $TWiki::STORE->webExists('TWikiUsers') ) {
 		my $opts =
 		{
 			WEBBGCOLOR => '#C0C0FF',
@@ -58,7 +58,7 @@
 			NOSEARCHALL => '',
 		};
 		$opts->{SITEMAPLIST} = "on" if( $opts->{SITEMAPWHAT} );
-	    my $err = $session->{store}->createWeb( $session->{user},
+	    my $err = $TWiki::STORE->createWeb( $session->{user},
                                                 'TWikiUsers',
                                                 '_default', $opts );
 	}
@@ -310,8 +310,7 @@
                                                      $oldWeb, $oldTopic,
                                                      $newWeb);
     # SMELL: this may throw a TWiki::OopsException if there is an error
-    TWiki::UI::Manage::move( $session,
-                             $oldWeb, $oldTopic,
+    TWiki::UI::Manage::move( $oldWeb, $oldTopic,
                              $newWeb, $newTopic,
                              undef, $refs );
 }
Index: TWiki/UI.pm
===================================================================
--- TWiki/UI.pm	(revision 13172)
+++ TWiki/UI.pm	(working copy)
@@ -151,31 +151,31 @@
         }
     }
 
-    my $session = new TWiki( $user, $query, \%initialContext );
+    local $TWiki::SESSION = new TWiki( $user, $query, \%initialContext );
 
     local $SIG{__DIE__} = \&Carp::confess;
 
     try {
-        $session->{loginManager}->checkAccess();
-        &$method( $session );
+        $TWiki::LOGIN->checkAccess();
+        &$method( );
     } catch TWiki::AccessControlException with {
         my $e = shift;
-        unless( $session->{loginManager}->forceAuthentication() ) {
+        unless( $TWiki::LOGIN->forceAuthentication() ) {
             # Client did not want to authenticate, perhaps because
             # we are already authenticated.
-            my $url = $session->getOopsUrl('accessdenied',
+            my $url = $TWiki::SESSION->getOopsUrl('accessdenied',
                                        def => 'topic_access',
                                        web => $e->{web},
                                        topic => $e->{topic},
                                        params => [ $e->{mode},
                                                    $e->{reason} ]);
-            $session->redirect( $url, 1 );
+            $TWiki::SESSION->redirect( $url, 1 );
         }
 
     } catch TWiki::OopsException with {
         my $e = shift;
-        my $url = $session->getOopsUrl( $e );
-        $session->redirect( $url, $e->{keep} );
+        my $url = $TWiki::SESSION->getOopsUrl( $e );
+        $TWiki::SESSION->redirect( $url, $e->{keep} );
 
     } catch Error::Simple with {
         my $e = shift;
@@ -186,7 +186,7 @@
         } else {
             my $mess = $e->stringify();
             print STDERR $mess;
-            $session->writeWarning( $mess );
+            $TWiki::SESSION->writeWarning( $mess );
             # tell the browser where to look for more help
             print 'TWiki detected an internal error - please check your TWiki logs and webserver logs for more information.'."\n\n";
             $mess =~ s/ at .*$//s;
@@ -199,12 +199,12 @@
         print "Unspecified error";
     };
 
-    $session->finish();
+    $TWiki::SESSION->finish();
 }
 
 =pod twiki
 
----++ StaticMethod checkWebExists( $session, $web, $topic, $op )
+---++ StaticMethod checkWebExists( $web, $topic, $op )
 
 Check if the web exists. If it doesn't, will throw an oops exception.
  $op is the user operation being performed.
@@ -212,10 +212,9 @@
 =cut
 
 sub checkWebExists {
-    my ( $session, $webName, $topic, $op ) = @_;
-    ASSERT($session->isa( 'TWiki')) if DEBUG;
+    my ( $webName, $topic, $op ) = @_;
 
-    unless ( $session->{store}->webExists( $webName ) ) {
+    unless ( $TWiki::STORE->webExists( $webName ) ) {
         throw
           TWiki::OopsException( 'accessdenied',
                                 def => 'no_such_web',
@@ -227,7 +226,7 @@
 
 =pod
 
----++ StaticMethod topicExists( $session, $web, $topic, $op ) => boolean
+---++ StaticMethod checkTopicExists( $web, $topic, $op ) => boolean
 
 Check if the given topic exists, throwing an OopsException
 if it doesn't. $op is the user operation being performed.
@@ -235,10 +234,9 @@
 =cut
 
 sub checkTopicExists {
-    my ( $session, $webName, $topic, $op ) = @_;
-    ASSERT($session->isa( 'TWiki')) if DEBUG;
+    my ( $webName, $topic, $op ) = @_;
 
-    unless( $session->{store}->topicExists( $webName, $topic )) {
+    unless( $TWiki::STORE->topicExists( $webName, $topic )) {
         throw TWiki::OopsException( 'accessdenied',
                                     def => 'no_such_topic',
                                     web => $webName,
@@ -249,31 +247,6 @@
 
 =pod twiki
 
----++ StaticMethod checkMirror( $session, $web, $topic )
-
-Checks if this web is a mirror web, throwing an OopsException
-if it is.
-
-=cut
-
-sub checkMirror {
-    my ( $session, $webName, $topic ) = @_;
-    ASSERT($session->isa( 'TWiki')) if DEBUG;
-
-    my( $mirrorSiteName, $mirrorViewURL ) =
-      $session->readOnlyMirrorWeb( $webName );
-
-    return unless ( $mirrorSiteName );
-
-    throw TWiki::OopsException( 'mirror',
-                                web => $webName,
-                                topic => $topic,
-                                params => [ $mirrorSiteName,
-                                            $mirrorViewURL ] );
-}
-
-=pod twiki
-
 ---++ StaticMethod checkAccess( $web, $topic, $mode, $user )
 
 Check if the given mode of access by the given user to the given
@@ -282,10 +255,9 @@
 =cut
 
 sub checkAccess {
-    my ( $session, $web, $topic, $mode, $user ) = @_;
-    ASSERT($session->isa( 'TWiki')) if DEBUG;
+    my ( $web, $topic, $mode, $user ) = @_;
 
-    unless( $session->{security}->checkAccessPermission(
+    unless( $TWiki::ACCESS->checkAccessPermission(
         $mode, $user, undef, undef, $topic, $web )) {
         throw TWiki::OopsException( 'accessdenied',
                                     def => 'topic_access',
@@ -293,32 +265,31 @@
                                     topic => $topic,
                                     params =>
                                     [ $mode,
-                                      $session->{security}->getReason()]);
+                                      $TWiki::ACCESS->getReason()]);
     }
 }
 
 =pod
 
----++ StaticMethod readTemplateTopic( $session, $theTopicName ) -> ( $meta, $text )
+---++ StaticMethod readTemplateTopic( $theTopicName ) -> ( $meta, $text )
 
-Read a topic from the TWiki web, or if that fails from the current
+!Read a topic from the TWiki web, or if that fails from the current
 web.
 
 =cut
 
 sub readTemplateTopic {
-    my( $session, $theTopicName ) = @_;
-    ASSERT($session->isa( 'TWiki')) if DEBUG;
+    my( $theTopicName ) = @_;
 
     $theTopicName =~ s/$TWiki::cfg{NameFilter}//go;
 
     my $web = $TWiki::cfg{SystemWebName};
-    if( $session->{store}->topicExists( $session->{webName}, $theTopicName )) {
+    if( $TWiki::STORE->topicExists( $TWiki::SESSION->{webName}, $theTopicName )) {
         # try to read from current web, if found
-        $web = $session->{webName};
+        $web = $TWiki::SESSION->{webName};
     }
-    return $session->{store}->readTopic(
-        $session->{user}, $web, $theTopicName, undef );
+    return $TWiki::STORE->readTopic(
+        $TWiki::SESSION->{user}, $web, $theTopicName, undef );
 }
 
 1;
Index: TWiki/User.pm
===================================================================
--- TWiki/User.pm	(revision 13172)
+++ TWiki/User.pm	(working copy)
@@ -53,7 +53,7 @@
 
 =pod
 
----++ ClassMethod new( $session, $loginname, $wikiname )
+---++ ClassMethod new( $loginname, $wikiname )
 
 Construct a new user object for the given login name, wiki name.
 
@@ -65,17 +65,15 @@
 =cut
 
 sub new {
-    my( $class, $session, $name, $wikiname ) = @_;
-    ASSERT($session->isa( 'TWiki')) if DEBUG;
+    my( $class, $name, $wikiname ) = @_;
     ASSERT($name) if DEBUG;
     ASSERT($wikiname) if DEBUG;
 
     my $this = bless( {}, $class );
-    $this->{session} = $session;
 
     $this->{login} = $name;
-    my( $web, $topic ) =
-      $session->normalizeWebTopicName( $TWiki::cfg{UsersWebName}, $wikiname );
+    my( $web, $topic ) = $TWiki::SESSION->normalizeWebTopicName(
+        $TWiki::cfg{UsersWebName}, $wikiname );
     $this->{web} = $web;
     $this->{wikiname} = $topic;
     $this->{groups} = [];
@@ -182,7 +180,7 @@
     my $this  = shift;
     ASSERT($this->isa( 'TWiki::User')) if DEBUG;
 
-    my $passwordHandler = $this->{session}->{users}->{passwords};
+    my $passwordHandler = $TWiki::USERS->{passwords};
     return $passwordHandler->fetchPass($this->{login});
 }
 
@@ -204,7 +202,7 @@
     my ( $this, $password ) = @_;
     ASSERT($this->isa( 'TWiki::User')) if DEBUG;
 
-    my $passwordHandler = $this->{session}->{users}->{passwords};
+    my $passwordHandler = $TWiki::USERS->{passwords};
     return $passwordHandler->checkPassword($this->{login}, $password);
 }
 
@@ -223,7 +221,7 @@
     my $this = shift;
     ASSERT($this->isa( 'TWiki::User')) if DEBUG;
 
-    my $passwordHandler = $this->{session}->{users}->{passwords};
+    my $passwordHandler = $TWiki::USERS->{passwords};
     return $passwordHandler->deleteUser( $this->{login} );
 }
 
@@ -242,7 +240,7 @@
     my ( $this, $oldUserPassword, $newUserPassword ) = @_;
     ASSERT($this->isa( 'TWiki::User')) if DEBUG;
 
-    my $passwordHandler = $this->{session}->{users}->{passwords};
+    my $passwordHandler = $TWiki::USERS->{passwords};
     if( $passwordHandler->passwd($this->{login},
                                  $newUserPassword, $oldUserPassword)) {
         return undef;
@@ -266,7 +264,7 @@
     my ( $this, $newUserPassword ) = @_;
     ASSERT($this->isa( 'TWiki::User')) if DEBUG;
 
-    my $passwordHandler = $this->{session}->{users}->{passwords};
+    my $passwordHandler = $TWiki::USERS->{passwords};
     return $passwordHandler->passwd($this->{login}, $newUserPassword);
 }
 
@@ -324,7 +322,7 @@
                 push( @{$this->{emails}}, $it->next()->emails() );
             }
         } else {
-            my $passwordHandler = $this->{session}->{users}->{passwords};
+            my $passwordHandler = $TWiki::USERS->{passwords};
             push(@{$this->{emails}}, $passwordHandler->getEmails($this->{login}));
         }
     }
@@ -344,7 +342,7 @@
     my $this = shift;
     ASSERT($this->isa( 'TWiki::User')) if DEBUG;
     return if $this->isGroup();
-    my $passwordHandler = $this->{session}->{users}->{passwords};
+    my $passwordHandler = $TWiki::USERS->{passwords};
     return $passwordHandler->setEmails($this->{login}, @_);
 }
 
@@ -364,7 +362,7 @@
         if ($this->{wikiname} eq $TWiki::cfg{SuperAdminGroup}) {
             $this->{isKnownAdmin} = 1;
         } else {
-            my $sag = $this->{session}->{users}->findUser(
+            my $sag = $TWiki::USERS->findUser(
                  $TWiki::cfg{SuperAdminGroup} );
             $this->{isKnownAdmin} = $this->isInGroup( $sag );
         }
@@ -384,8 +382,8 @@
     my $this = shift;
     ASSERT($this->isa( 'TWiki::User')) if DEBUG;
     return $this->{groups} if defined($this->{groups});
-    my $users = $this->{session}->{users};
-    my $it = $this->{session}->{users}->eachGroup();
+    my $users = $TWiki::USERS->{users};
+    my $it = $TWiki::USERS->eachGroup();
     while ($it->hasNext()) {
         my $groupObject = $it->next();
         my $it = $groupObject->eachGroupMember();
@@ -414,7 +412,7 @@
 
     unless( ref( $userlist )) {
         # string parameter
-        $userlist = $this->{session}->{users}->expandUserList( $userlist );
+        $userlist = $TWiki::USERS->expandUserList( $userlist );
     }
     my $user;
     foreach $user ( @$userlist ) {
@@ -443,7 +441,7 @@
 
     return 1 if $this->{wikiname} eq $TWiki::cfg{SuperAdminGroup};
 
-    return $this->{session}->{users}->isGroup($this);
+    return $TWiki::USERS->isGroup($this);
 }
 
 =pod
@@ -458,7 +456,7 @@
 sub eachGroupMember {
     my $this = shift;
     ASSERT($this->isGroup()) if DEBUG;
-    return $this->{session}->{users}->eachGroupMember($this);
+    return $TWiki::USERS->eachGroupMember($this);
 }
 
 =pod
@@ -472,7 +470,7 @@
 sub eachMembership {
     my $this = shift;
 
-    return $this->{session}->{users}->eachMembership($this);
+    return $TWiki::USERS->eachMembership($this);
 }
 
 =pod
@@ -485,7 +483,7 @@
 
 sub isInGroup {
     my( $this, $group ) = @_;
-    return $this->{session}->{users}->isInGroup( $this, $group );
+    return $TWiki::USERS->isInGroup( $this, $group );
 }
 
 1;
Index: TWiki/Client.pm
===================================================================
--- TWiki/Client.pm	(revision 13172)
+++ TWiki/Client.pm	(working copy)
@@ -94,7 +94,7 @@
 
 =pod
 
----++ StaticMethod makeLoginManager( $twiki ) -> $TWiki::Client
+---++ StaticMethod makeLoginManager() -> $TWiki::Client
 
 Factory method, used to generate a new TWiki::Client object
 for the given session.
@@ -102,11 +102,9 @@
 =cut
 
 sub makeLoginManager {
-    my $twiki = shift;
-    ASSERT($twiki->isa( 'TWiki')) if DEBUG;
 
     if( $TWiki::cfg{UseClientSessions} &&
-          !$twiki->inContext( 'command_line' )) {
+          !$TWiki::SESSION->inContext( 'command_line' )) {
 
         my $use = 'use CGI::Session';
         if( $TWiki::cfg{Sessions}{UseIPMatching} ) {
@@ -126,11 +124,11 @@
     my $mgr;
     if( $TWiki::cfg{LoginManager} eq 'none' ) {
         # No login manager; just use default behaviours
-        $mgr = new TWiki::Client( $twiki );
+        $mgr = new TWiki::Client();
     } else {
         eval 'use '. $TWiki::cfg{LoginManager};
         throw Error::Simple( $@ ) if $@;
-        $mgr = $TWiki::cfg{LoginManager}->new( $twiki );
+        $mgr = $TWiki::cfg{LoginManager}->new( $TWiki::SESSION );
     }
     return $mgr;
 }
@@ -138,11 +136,10 @@
 # protected: Construct new client object.
 
 sub new {
-    my ( $class, $twiki ) = @_;
+    my ( $class ) = @_;
     my $this = bless( {}, $class );
-    ASSERT($twiki->isa( 'TWiki')) if DEBUG;
-    $this->{twiki} = $twiki;
-    $twiki->leaveContext( 'can_login' );
+
+    $TWiki::SESSION->leaveContext( 'can_login' );
     $this->{_cookies} = [];
     map{ $this->{_authScripts}{$_} = 1; }
       split( /[\s,]+/, $TWiki::cfg{AuthScripts} );
@@ -216,7 +213,6 @@
 
 sub loadSession {
     my ($this, $defaultUser) = @_;
-    my $twiki = $this->{twiki};
 
     # Try and get the user from the webserver
     my $authUser = $this->getUser( $this ) || $defaultUser;
@@ -226,9 +222,9 @@
         return $authUser;
     }
 
-    return $authUser if $twiki->inContext( 'command_line' );
+    return $authUser if $TWiki::SESSION->inContext( 'command_line' );
 
-    my $query = $twiki->{cgiQuery};
+    my $query = $TWiki::SESSION->{cgiQuery};
 
     $this->{_haveCookie} = $query->raw_cookie();
 
@@ -306,8 +302,8 @@
 
     $this->userLoggedIn( $authUser );
 
-    $twiki->{SESSION_TAGS}{SESSIONID} = $this->{_cgisession}->id();
-    $twiki->{SESSION_TAGS}{SESSIONVAR} = $CGI::Session::NAME;
+    $TWiki::SESSION->{SESSION_TAGS}{SESSIONID} = $this->{_cgisession}->id();
+    $TWiki::SESSION->{SESSION_TAGS}{SESSIONVAR} = $CGI::Session::NAME;
 
     return $authUser;
 }
@@ -326,20 +322,19 @@
     return unless( $TWiki::cfg{UseClientSessions} );
 
     my $this = shift;
-    my $twiki = $this->{twiki};
 
-    return undef if $twiki->inContext( 'command_line' );
+    return undef if $TWiki::SESSION->inContext( 'command_line' );
 
-    unless( $twiki->inContext( 'authenticated' ) ||
+    unless( $TWiki::SESSION->inContext( 'authenticated' ) ||
               $TWiki::cfg{LoginManager} eq 'none' ) {
         my $script = $ENV{'SCRIPT_NAME'} || $ENV{'SCRIPT_FILENAME'};
         $script =~ s@^.*/([^./]+)@$1@g if $script;
 
         if( defined $script && $this->{_authScripts}{$script} ) {
-            my $topic = $this->{twiki}->{topicName};
-            my $web = $this->{twiki}->{webName};
+            my $topic = $TWiki::SESSION->{topicName};
+            my $web = $TWiki::SESSION->{webName};
             throw TWiki::AccessControlException(
-                $script, $this->{twiki}->{user}, $web, $topic,
+                $script, $TWiki::SESSION->{user}, $web, $topic,
                 'authentication required' );
         }
     }
@@ -420,15 +415,14 @@
 sub userLoggedIn {
     my( $this, $authUser, $wikiName ) = @_;
 
-    my $twiki = $this->{twiki};
-    return undef if $twiki->inContext( 'command_line' );
+    return undef if $TWiki::SESSION->inContext( 'command_line' );
 
     if( $TWiki::cfg{UseClientSessions} ) {
         # create new session if necessary
         unless( $this->{_cgisession} ) {
             $this->{_cgisession} =
               CGI::Session->new(
-                  undef, $twiki->{cgiQuery},
+                  undef, $TWiki::SESSION->{cgiQuery},
                   { Directory => $TWiki::cfg{TempfileDir} } );
             die CGI::Session->errstr() unless $this->{_cgisession};
         }
@@ -437,13 +431,13 @@
         _trace($this, "Session is authenticated");
         $this->{_cgisession}->param( 'AUTHUSER', $authUser )
           if( $TWiki::cfg{UseClientSessions} );
-        $twiki->enterContext( 'authenticated' );
+        $TWiki::SESSION->enterContext( 'authenticated' );
     } else {
         _trace($this, "Session is NOT authenticated");
         # if we are not authenticated, expire any existing session
         $this->{_cgisession}->clear( [ 'AUTHUSER' ] )
           if( $TWiki::cfg{UseClientSessions} );
-        $twiki->leaveContext( 'authenticated' );
+        $TWiki::SESSION->leaveContext( 'authenticated' );
     }
     if( $TWiki::cfg{UseClientSessions} ) {
         # flush the session, to try to fix Item1820 and Item2234
@@ -459,7 +453,7 @@
 
     my $s = $this->{_MYSCRIPTURL};
     unless( $s ) {
-        $s = quotemeta($this->{twiki}->getScriptUrl( 1, $M1, $M2, $M3 ));
+        $s = quotemeta($TWiki::SESSION->getScriptUrl( 1, $M1, $M2, $M3 ));
         $s =~ s@\\$M1@[^/]*?@go;
         $s =~ s@\\$M2@[^/]*?@go;
         $s =~ s@\\$M3@[^#\?/]*@go;
@@ -545,7 +539,7 @@
     return unless( $TWiki::cfg{UseClientSessions} );
 
     my $this = shift;
-    return undef if $this->{twiki}->inContext( 'command_line' );
+    return undef if $TWiki::SESSION->inContext( 'command_line' );
 
     # If cookies are not turned on and transparent CGI session IDs are,
     # grab every URL that is an internal link and pass a CGI variable
@@ -609,7 +603,7 @@
     return unless( $TWiki::cfg{UseClientSessions} );
 
     my( $this, $c ) = @_;
-    return undef if $this->{twiki}->inContext( 'command_line' );
+    return undef if $TWiki::SESSION->inContext( 'command_line' );
     ASSERT($c->isa('CGI::Cookie')) if DEBUG;
 
     push( @{$this->{_cookies}}, $c );
@@ -630,7 +624,7 @@
     return unless $this->{_cgisession};
     return if $TWiki::cfg{Sessions}{MapIP2SID};
 
-    my $query = $this->{twiki}->{cgiQuery};
+    my $query = $TWiki::SESSION->{cgiQuery};
     $this->_pushCookie();
     $hopts->{cookie} = $this->{_cookies};
 }
@@ -805,15 +799,12 @@
 
 sub _LOGIN {
     #my( $twiki, $params, $topic, $web ) = @_;
-    my $twiki = shift;
-    my $this = $twiki->{loginManager};
-    ASSERT($this->isa('TWiki::Client')) if DEBUG;
 
-    return '' if $twiki->inContext( 'authenticated' );
+    return '' if $TWiki::SESSION->inContext( 'authenticated' );
 
-    my $url = $this->loginUrl();
+    my $url = $TWiki::LOGIN->loginUrl();
     if( $url ) {
-        my $text = $twiki->{templates}->expandTemplate('LOG_IN');
+        my $text = $TWiki::TEMPLATES->expandTemplate('LOG_IN');
         return CGI::a( { href=>$url }, $text );
     }
     return '';
@@ -821,26 +812,21 @@
 
 sub _LOGOUTURL {
     my( $twiki, $params, $topic, $web ) = @_;
-    my $this = $twiki->{loginManager};
-    ASSERT($this->isa('TWiki::Client')) if DEBUG;
-
-    return $twiki->getScriptUrl(
+    return $TWiki::SESSION->getScriptUrl(
         0, 'view',
-        $twiki->{SESSION_TAGS}{BASEWEB},
-        $twiki->{SESSION_TAGS}{BASETOPIC},
+        $TWiki::SESSION->{SESSION_TAGS}{BASEWEB},
+        $TWiki::SESSION->{SESSION_TAGS}{BASETOPIC},
         'logout' => 1 );
 }
 
 sub _LOGOUT {
     my( $twiki, $params, $topic, $web ) = @_;
-    my $this = $twiki->{loginManager};
-    ASSERT($this->isa('TWiki::Client')) if DEBUG;
 
-    return '' unless $twiki->inContext( 'authenticated' );
+    return '' unless $TWiki::SESSION->inContext( 'authenticated' );
 
     my $url = _LOGOUTURL( @_ );
     if( $url ) {
-        my $text = $twiki->{templates}->expandTemplate('LOG_OUT');
+        my $text = $TWiki::TEMPLATES->expandTemplate('LOG_OUT');
         return CGI::a( {href=>$url }, $text );
     }
     return '';
@@ -848,10 +834,8 @@
 
 sub _AUTHENTICATED {
     my( $twiki, $params ) = @_;
-    my $this = $twiki->{loginManager};
-    ASSERT($this->isa('TWiki::Client')) if DEBUG;
 
-    if( $twiki->inContext( 'authenticated' )) {
+    if( $TWiki::SESSION->inContext( 'authenticated' )) {
         return $params->{then} || 1;
     } else {
         return $params->{else} || 0;
@@ -860,9 +844,8 @@
 
 sub _CANLOGIN {
     my( $twiki, $params ) = @_;
-    my $this = $twiki->{loginManager};
-    ASSERT($this->isa('TWiki::Client')) if DEBUG;
-    if( $twiki->inContext( 'can_login' )) {
+
+    if( $TWiki::SESSION->inContext( 'can_login' )) {
         return $params->{then} || 1;
     } else {
         return $params->{else} || 0;
@@ -871,26 +854,23 @@
 
 sub _SESSION_VARIABLE {
     my( $twiki, $params ) = @_;
-    my $this = $twiki->{loginManager};
-    ASSERT($this->isa('TWiki::Client')) if DEBUG;
+
     my $name = $params->{_DEFAULT};
 
     if( defined( $params->{set} ) ) {
-        $this->setSessionValue( $name, $params->{set} );
+        $TWiki::LOGIN->setSessionValue( $name, $params->{set} );
         return '';
     } elsif( defined( $params->{clear} )) {
-        $this->clearSessionValue( $name );
+        $TWiki::LOGIN->clearSessionValue( $name );
         return '';
     } else {
-        return $this->getSessionValue( $name ) || '';
+        return $TWiki::LOGIN->getSessionValue( $name ) || '';
     }
 }
 
 sub _LOGINURL {
     my( $twiki, $params ) = @_;
-    my $this = $twiki->{loginManager};
-    ASSERT($this->isa('TWiki::Client')) if DEBUG;
-    return $this->loginUrl();
+    return $TWiki::LOGIN->loginUrl();
 }
 
 sub _dispLogon {
@@ -898,9 +878,8 @@
 
     return '' unless $this->{_cgisession};
 
-    my $twiki = $this->{twiki};
-    my $topic = $twiki->{topicName};
-    my $web = $twiki->{webName};
+    my $topic = $TWiki::SESSION->{topicName};
+    my $web = $TWiki::SESSION->{webName};
     my $sessionId = $this->{_cgisession}->id();
 
     my $urlToUse = $this->loginUrl();
@@ -909,15 +888,14 @@
         $urlToUse = $this->_rewriteURL( $urlToUse );
     }
 
-    my $text = $twiki->{templates}->expandTemplate('LOG_IN');
+    my $text = $TWiki::TEMPLATES->expandTemplate('LOG_IN');
     return CGI::a({ class => 'twikiAlert', href => $urlToUse }, $text );
 }
 
 sub _skinSelect {
     my $this = shift;
-    my $twiki = $this->{twiki};
-    my $skins = $twiki->{prefs}->getPreferencesValue('SKINS');
-    my $skin = $twiki->getSkin();
+    my $skins = $TWiki::PREFS->getPreferencesValue('SKINS');
+    my $skin = $TWiki::SESSION->getSkin();
     my @skins = split( /,/, $skins );
     unshift( @skins, 'default' );
     my $options = '';
Index: TWiki/Prefs.pm
===================================================================
--- TWiki/Prefs.pm	(revision 13172)
+++ TWiki/Prefs.pm	(working copy)
@@ -47,7 +47,7 @@
 
 =pod
 
----++ ClassMethod new( $session [, $cache] )
+---++ ClassMethod new( [$cache] )
 
 Creates a new Prefs object. If $cache is defined, it will be
 pushed onto the stack.
@@ -55,15 +55,14 @@
 =cut
 
 sub new {
-    my( $class, $session, $cache ) = @_;
+    my( $class, $cache ) = @_;
     my $this = bless( {}, $class );
-    ASSERT($session->isa( 'TWiki')) if DEBUG;
-    $this->{session} = $session;
+
     push( @{$this->{PREFS}}, $cache ) if defined( $cache );
     # $this->{TOPICS} - hash of TWiki::Prefs objects, for solitary topics
     # $this->{WEBS} - hash of TWiki::Prefs objects, for solitary webs
     # remember what "Local" means
-    $this->{LOCAL} = $session->{webName}.'.'.$this->{session}->{topicName};
+    $this->{LOCAL} = $TWiki::SESSION->{webName}.'.'.$TWiki::SESSION->{topicName};
 
     return $this;
 }
@@ -166,7 +165,7 @@
 
     # Then local site prefs
     if( $TWiki::cfg{LocalSitePreferences} ) {
-        my( $lweb, $ltopic ) = $this->{session}->normalizeWebTopicName(
+        my( $lweb, $ltopic ) = $TWiki::SESSION->normalizeWebTopicName(
             undef, $TWiki::cfg{LocalSitePreferences} );
         $this->pushPreferences( $lweb, $ltopic, 'SITE' );
     }
@@ -336,7 +335,7 @@
     my $wtn = $web.'.'.$TWiki::cfg{WebPrefsTopicName};
 
     unless( $this->{WEBS}{$wtn} ) {
-        my $blank = new TWiki::Prefs( $this->{session} );
+        my $blank = new TWiki::Prefs();
         $blank->pushWebPreferences( $web );
         $this->{WEBS}{$wtn} = $blank;
     }
Index: TWiki/Render.pm
===================================================================
--- TWiki/Render.pm	(revision 13172)
+++ TWiki/Render.pm	(working copy)
@@ -67,7 +67,7 @@
 
 =pod
 
----++ ClassMethod new ($session)
+---++ ClassMethod new ()
 
 Creates a new renderer with initial state from preference values
 (NEWTOPICLINKSYMBOL LINKTOOLTIPINFO)
@@ -75,23 +75,20 @@
 =cut
 
 sub new {
-    my ( $class, $session ) = @_;
+    my ( $class ) = @_;
     my $this = bless( {}, $class );
-    ASSERT($session->isa( 'TWiki')) if DEBUG;
 
-    $this->{session} = $session;
-
     $this->{NEWLINKSYMBOL} =
-      $session->{prefs}->getPreferencesValue('NEWTOPICLINKSYMBOL')
+      $TWiki::PREFS->getPreferencesValue('NEWTOPICLINKSYMBOL')
         || CGI::sup('?');
     $this->{NEWLINKFORMAT} =
-      $session->{prefs}->getPreferencesValue('NEWLINKFORMAT')
+      $TWiki::PREFS->getPreferencesValue('NEWLINKFORMAT')
         || '<span class="twikiNewLink">$text<a href="%SCRIPTURLPATH{"edit"}%/$web/$topic?topicparent=%WEB%.%TOPIC%" '.
 	   'rel="nofollow" title="%MAKETEXT{"Create this topic"}%">'.
            '$linksymbol</a></span>';
     # tooltip init
     $this->{LINKTOOLTIPINFO} =
-      $session->{prefs}->getPreferencesValue('LINKTOOLTIPINFO')
+      $TWiki::PREFS->getPreferencesValue('LINKTOOLTIPINFO')
         || '';
     $this->{LINKTOOLTIPINFO} = '$username - $date - r$rev: $summary'
       if( TWiki::isTrue( $this->{LINKTOOLTIPINFO} ));
@@ -126,7 +123,7 @@
     my $text = '';
     my $parentMeta = $meta->get( 'TOPICPARENT' );
     my $parent;
-    my $store = $this->{session}->{store};
+    my $store = $TWiki::STORE;
 
     $parent = $parentMeta->{name} if $parentMeta;
 
@@ -134,7 +131,7 @@
 
     while( $parent ) {
         ( $pWeb, $pTopic ) =
-          $this->{session}->normalizeWebTopicName( $pWeb, $parent );
+          $TWiki::SESSION->normalizeWebTopicName( $pWeb, $parent );
         $parent = $pWeb.'.'.$pTopic;
         last if( $noWebHome &&
                  ( $pTopic eq $TWiki::cfg{HomeTopicName} ) ||
@@ -173,11 +170,11 @@
 
     if( $moved ) {
         my( $fromWeb, $fromTopic ) =
-          $this->{session}->normalizeWebTopicName( $web, $moved->{from} );
+          $TWiki::SESSION->normalizeWebTopicName( $web, $moved->{from} );
         my( $toWeb, $toTopic ) =
-          $this->{session}->normalizeWebTopicName( $web, $moved->{to} );
+          $TWiki::SESSION->normalizeWebTopicName( $web, $moved->{to} );
         my $by = $moved->{by};
-        my $u = $this->{session}->{users}->findUser( $by );
+        my $u = $TWiki::USERS->findUser( $by );
         $by = $u->webDotWikiName() if $u;
         my $date = TWiki::Time::formatTime( $moved->{date}, '', 'gmtime' );
 
@@ -185,10 +182,10 @@
         my $putBack = '';
         if( $web eq $toWeb && $topic eq $toTopic ) {
             $putBack  = ' - '.
-              CGI::a( { title=>($this->{session}->{i18n}->maketext(
+              CGI::a( { title=>($TWiki::I18N->maketext(
                                   'Click to move topic back to previous location, with option to change references.')
                                ),
-                        href => $this->{session}->getScriptUrl
+                        href => $TWiki::SESSION->getScriptUrl
                         ( 0, 'rename', $web, $topic,
                          newweb => $fromWeb,
                          newtopic => $fromTopic,
@@ -196,10 +193,10 @@
                          nonwikiword => 'checked' ),
                         rel => 'nofollow'
                       },
-                      $this->{session}->{i18n}->maketext('put it back') );
+                      $TWiki::I18N->maketext('put it back') );
         }
         $text = CGI::i(
-          $this->{session}->{i18n}->maketext("[_1] moved from [_2] on [_3] by [_4]",
+          $TWiki::I18N->maketext("[_1] moved from [_2] on [_3] by [_4]",
                                              "<nop>$toWeb.<nop>$toTopic",
                                              "<nop>$fromWeb.<nop>$fromTopic",
                                              $date,
@@ -423,12 +420,12 @@
     my( $this, $theWeb, $theTopic ) = @_;
     return '' unless( $this->{LINKTOOLTIPINFO} );
     return '' if( $this->{LINKTOOLTIPINFO} =~ /^off$/i );
-    return '' unless( $this->{session}->inContext( 'view' ));
+    return '' unless( $TWiki::SESSION->inContext( 'view' ));
 
     # FIXME: This is slow, it can be improved by caching topic rev info and summary
-    my $store = $this->{session}->{store};
+    my $store = $TWiki::STORE;
     # SMELL: we ought not to have to fake this. Topic object model, please!!
-    my $meta = new TWiki::Meta( $this->{session}, $theWeb, $theTopic );
+    my $meta = new TWiki::Meta( $theWeb, $theTopic );
     my( $date, $user, $rev ) = $meta->getRevisionInfo();
     my $text = $this->{LINKTOOLTIPINFO};
     $text =~ s/\$web/<nop>$theWeb/g;
@@ -485,7 +482,7 @@
 
     #WebHome links to tother webs render as the WebName
     if (($theLinkText eq $TWiki::cfg{HomeTopicName}) && 
-        ($theWeb ne $this->{session}->{webName})) {
+        ($theWeb ne $TWiki::SESSION->{webName})) {
             $theLinkText = $theWeb;
     }
 
@@ -508,7 +505,7 @@
 # TODO: this should be overridable by plugins.
 sub _renderWikiWord {
     my ($this, $theWeb, $theTopic, $theLinkText, $theAnchor, $doLinkToMissingPages, $doKeepWeb) = @_;
-    my $store = $this->{session}->{store};
+    my $store = $TWiki::STORE;
     my $topicExists = $store->topicExists( $theWeb, $theTopic );
 
     my $singular = '';
@@ -544,15 +541,15 @@
     my ($this, $web, $topic, $text, $anchor) = @_;
 
     my $currentWebHome = '';
-    $currentWebHome = 'twikiCurrentWebHomeLink ' if (($web eq $this->{session}->{webName}) &&
+    $currentWebHome = 'twikiCurrentWebHomeLink ' if (($web eq $TWiki::SESSION->{webName}) &&
                                       ($topic eq $TWiki::cfg{HomeTopicName} ));
 
     my $currentTopic = '';
-    $currentTopic = 'twikiCurrentTopicLink ' if (($web eq $this->{session}->{webName}) &&
-                                       ($topic eq $this->{session}->{topicName}));
+    $currentTopic = 'twikiCurrentTopicLink ' if (($web eq $TWiki::SESSION->{webName}) &&
+                                       ($topic eq $TWiki::SESSION->{topicName}));
 
     my @attrs;
-    my $href = $this->{session}->getScriptUrl( 0, 'view', $web, $topic );
+    my $href = $TWiki::SESSION->getScriptUrl( 0, 'view', $web, $topic );
     if( $anchor ) {
         $anchor = $this->makeAnchorName( $anchor );
         push( @attrs, class => $currentTopic.$currentWebHome.'twikiAnchorLink', href => $href.'#'.$anchor );
@@ -578,8 +575,8 @@
     $ans =~ s/\$topic/$topic/g;
     $ans =~ s/\$text/$text/g;
     $ans =~ s/\$linksymbol/$this->{NEWLINKSYMBOL}/g;
-    $ans = $this->{session}->handleCommonTags(
-        $ans, $this->{session}{webName}, $this->{session}{topicName});
+    $ans = $TWiki::SESSION->handleCommonTags(
+        $ans, $TWiki::SESSION->{webName}, $TWiki::SESSION->{topicName});
     return $ans;
 }
 
@@ -613,7 +610,7 @@
 
         # 'Web.TopicName' or 'Web.ABBREV' link:
         if ( $topic eq $TWiki::cfg{HomeTopicName} &&
-             $web ne $this->{session}->{webName} ) {
+             $web ne $TWiki::SESSION->{webName} ) {
             $text = $web;
         } else {
             $text = $topic;
@@ -621,11 +618,11 @@
     }
 
     # Allow spacing out, etc
-    $text = $this->{session}->{plugins}->renderWikiWordHandler( $text ) || $text;
+    $text = $TWiki::PLUGINS->renderWikiWordHandler( $text ) || $text;
 
     # =$doKeepWeb= boolean: true to keep web prefix (for non existing Web.TOPIC)
     # (Necessary to leave "web part" of ABR.ABR.ABR intact if topic not found)
-    $keepWeb = ( $topic =~ /^$TWiki::regex{abbrevRegex}$/o && $web ne $this->{session}->{webName} );
+    $keepWeb = ( $topic =~ /^$TWiki::regex{abbrevRegex}$/o && $web ne $TWiki::SESSION->{webName} );
 
     # false means suppress link for non-existing pages
     $linkIfAbsent = ( $topic !~ /^$TWiki::regex{abbrevRegex}$/o );
@@ -694,7 +691,7 @@
     $topic = $link if( $link );
 
     # Topic defaults to the current topic
-    ($web, $topic) = $this->{session}->normalizeWebTopicName( $web, $topic );
+    ($web, $topic) = $TWiki::SESSION->normalizeWebTopicName( $web, $topic );
 
     return $this->internalLink( $web, $topic, $text, $anchor, 1, undef );
 }
@@ -790,11 +787,11 @@
     }
 
     my $meta = $this->{ffCache}{$formWeb.'.'.$formTopic};
-    my $store = $this->{session}->{store};
+    my $store = $TWiki::STORE;
     unless ( $meta ) {
         my $dummyText;
         ( $meta, $dummyText ) =
-          $store->readTopic( $this->{session}->{user}, $formWeb, $formTopic, $rev );
+          $store->readTopic( $TWiki::SESSION->{user}, $formWeb, $formTopic, $rev );
         $this->{ffCache}{$formWeb.'.'.$formTopic} = $meta;
     }
 
@@ -844,12 +841,9 @@
 
     return '' unless $text;  # nothing to do
 
-    $theTopic ||= $this->{session}->{topicName};
-    $theWeb ||= $this->{session}->{webName};
-    my $session = $this->{session};
-    my $plugins = $session->{plugins};
-    my $prefs = $session->{prefs};
-    
+    $theTopic ||= $TWiki::SESSION->{topicName};
+    $theWeb ||= $TWiki::SESSION->{webName};
+
     @{$this->{LIST}} = ();
 
     # Initial cleanup
@@ -884,23 +878,23 @@
     # DEPRECATED startRenderingHandler before PRE removed
     # SMELL: could parse more efficiently if this wasn't
     # here.
-    $plugins->startRenderingHandler( $text, $theWeb, $theTopic );
+    $TWiki::PLUGINS->startRenderingHandler( $text, $theWeb, $theTopic );
 
     $text = $this->takeOutBlocks( $text, 'pre', $removed );
 
     # Join lines ending in '\' (don't need \r?, it was removed already)
     $text =~ s/\\\n//gs;
 
-    $plugins->preRenderingHandler( $text, $removed );
+    $TWiki::PLUGINS->preRenderingHandler( $text, $removed );
 
-    if( $plugins->haveHandlerFor( 'insidePREHandler' )) {
+    if( $TWiki::PLUGINS->haveHandlerFor( 'insidePREHandler' )) {
         foreach my $region ( sort keys %$removed ) {
             next unless ( $region =~ /^pre\d+$/i );
             my @lines = split( /\r?\n/, $removed->{$region}{text} );
             my $rt = '';
             while ( scalar( @lines )) {
                 my $line = shift( @lines );
-                $plugins->insidePREHandler( $line );
+                $TWiki::PLUGINS->insidePREHandler( $line );
                 if ( $line =~ /\n/ ) {
                     unshift( @lines, split( /\r?\n/, $line ));
                     next;
@@ -911,7 +905,7 @@
         }
     }
 
-    if( $plugins->haveHandlerFor( 'outsidePREHandler' )) {
+    if( $TWiki::PLUGINS->haveHandlerFor( 'outsidePREHandler' )) {
         # DEPRECATED - this is the one call preventing
         # effective optimisation of the TWiki ML processing loop,
         # as it exposes the concept of a 'line loop' to plugins,
@@ -922,7 +916,7 @@
         my $rt = '';
         while ( scalar( @lines ) ) {
             my $line = shift( @lines );
-            $plugins->outsidePREHandler( $line );
+            $TWiki::PLUGINS->outsidePREHandler( $line );
             if ( $line =~ /\n/ ) {
                 unshift( @lines, split( /\r?\n/, $line ));
                 next;
@@ -1091,7 +1085,7 @@
     # i.e. [[$1][$3]]
     $text =~ s/\[\[([^\]\[\n]+)\](\[([^\]\n]+)\])?\]/$this->_handleSquareBracketedLink($theWeb,$theTopic,$1,$3)/ge;
     
-    unless( TWiki::isTrue( $prefs->getPreferencesValue('NOAUTOLINK')) ) {
+    unless( TWiki::isTrue( $TWiki::PREFS->getPreferencesValue('NOAUTOLINK')) ) {
         # Handle WikiWords
         $text = $this->takeOutBlocks( $text, 'noautolink', $removed );
         $text =~ s/$STARTWW(?:($TWiki::regex{webNameRegex})\.)?($TWiki::regex{wikiWordRegex}|$TWiki::regex{abbrevRegex})($TWiki::regex{anchorRegex})?/$this->_handleWikiWord($theWeb,$1,$2,$3)/geom;
@@ -1101,7 +1095,7 @@
     $this->putBackBlocks( \$text, $removed, 'pre' );
 
     # DEPRECATED plugins hook after PRE re-inserted
-    $plugins->endRenderingHandler( $text );
+    $TWiki::PLUGINS->endRenderingHandler( $text );
 
     # replace verbatim with pre in the final output
     $this->putBackBlocks( \$text, $removedVerbatim,
@@ -1115,9 +1109,9 @@
     $this->putBackProtected( \$text, $removedHead );
     $this->putBackProtected( \$text, $removedComments );
 
-    $this->{session}->{loginManager}->endRenderingHandler( $text );
+    $TWiki::LOGIN->endRenderingHandler( $text );
 
-    $plugins->postRenderingHandler( $text );
+    $TWiki::PLUGINS->postRenderingHandler( $text );
     return $text;
 }
 
@@ -1189,11 +1183,11 @@
 
     if( $opts =~ /expandvar/ ) {
         $text =~ s/(\%)(SEARCH){/$1<nop>$2/g; # prevent recursion
-        $text = $this->{session}->handleCommonTags( $text, $web, $topic );
+        $text = $TWiki::SESSION->handleCommonTags( $text, $web, $topic );
     } else {
         $text =~ s/%WEB%/$web/g;
         $text =~ s/%TOPIC%/$topic/g;
-        my $wtn = $this->{session}->{prefs}->getPreferencesValue(
+        my $wtn = $TWiki::PREFS->getPreferencesValue(
             'WIKITOOLNAME' ) || '';
         $text =~ s/%WIKITOOLNAME%/$wtn/g;
         if( $opts =~ /showvar/ ) {
@@ -1258,7 +1252,7 @@
     # characters. Only works for ISO-8859-1 sites, since the Unicode
     # encoding (&#nnn;) is identical for first 256 characters. 
     # I18N TODO: Convert to Unicode from any site character set.
-    if( $this->{session}->inContext( 'rss' ) &&
+    if( $TWiki::SESSION->inContext( 'rss' ) &&
           defined( $TWiki::cfg{Site}{CharSet} ) &&
             $TWiki::cfg{Site}{CharSet} =~ /^iso-?8859-?1$/i ) {
         $text =~ s/([\x7f-\xff])/"\&\#" . unpack( 'C', $1 ) .';'/ge;
@@ -1535,7 +1529,7 @@
 sub renderRevisionInfo {
     my( $this, $web, $topic, $meta, $rrev, $format ) = @_;
     ASSERT($this->isa( 'TWiki::Render')) if DEBUG;
-    my $store = $this->{session}->{store};
+    my $store = $TWiki::STORE;
 
     if( $rrev ) {
         $rrev = $store->cleanUpRevID( $rrev );
@@ -1599,7 +1593,7 @@
     ASSERT($this->isa( 'TWiki::Render')) if DEBUG;
     #ASSERT($user->isa( 'TWiki::User')) if DEBUG;
     my $summary = '';
-    my $store = $this->{session}->{store};
+    my $store = $TWiki::STORE;
 
     $orev = $nrev - 1 unless (defined($orev) || !defined($nrev));
 
@@ -1633,7 +1627,7 @@
                 if( $tml ) {
                     $block =~ s/^-(.*)$/CGI::del( $1 )/se;
                     $block =~ s/^\+(.*)$/CGI::ins( $1 )/se;
-                } elsif ( $this->{session}->inContext('rss')) {
+                } elsif ( $TWiki::SESSION->inContext('rss')) {
                     $block =~ s/^-/REMOVED: /;
                     $block =~ s/^\+/INSERTED: /;
                 }
@@ -1819,7 +1813,7 @@
     my( $this, $text, $meta, $oldWeb, $oldTopic, $newWeb, $newTopic ) = @_;
     ASSERT($this->isa( 'TWiki::Render')) if DEBUG;
 
-    my @topics = $this->{session}->{store}->getTopicNames( $oldWeb );
+    my @topics = $TWiki::STORE->getTopicNames( $oldWeb );
     my $options =
       {
        # exclude this topic from the list
@@ -1840,7 +1834,7 @@
                                  \&_replaceInternalRefs, $options );
 
     ## Ok, let's do it again, but look for links to topics in the new web and remove their full paths
-    @topics = $this->{session}->{store}->getTopicNames( $newWeb );
+    @topics = $TWiki::STORE->getTopicNames( $newWeb );
     $options =
       {
        # exclude this topic from the list
Index: TWiki/Plugins.pm
===================================================================
--- TWiki/Plugins.pm	(revision 13172)
+++ TWiki/Plugins.pm	(working copy)
@@ -53,13 +53,13 @@
 =my $pref = $TWiki::Plugins::SESSION->writeWarning($message);=
 
 Methods in other modules such as Store must be accessed through
-the relevant TWiki sub-object, for example
+the relevant TWiki singleton object, for example
 
 =TWiki::Store::saveTopic(...)=
 
 should be replaced with
 
-=$TWiki::Plugins::SESSION->{store}->saveTopic(...)=
+=$TWiki::STORE->saveTopic(...)=
 
 Note that calling TWiki internal methods is very very bad practice,
 and should be avoided wherever practical.
@@ -113,7 +113,7 @@
 
 =pod
 
----++ ClassMethod new( $session )
+---++ ClassMethod new()
 
 Construct new singleton plugins collection object. The object is a
 container for a list of plugins and the handlers registered by the plugins.
@@ -122,13 +122,10 @@
 =cut
 
 sub new {
-    my ( $class, $session ) = @_;
+    my ( $class ) = @_;
 
     my $this = bless( {}, $class );
 
-    ASSERT($session->isa( 'TWiki')) if DEBUG;
-    $this->{session} = $session;
-
     unless( $inited ) {
         TWiki::registerTagHandler( 'PLUGINDESCRIPTIONS',
                                    \&_handlePLUGINDESCRIPTIONS );
@@ -162,8 +159,7 @@
 
     my %lookup;
 
-    my $session = $this->{session};
-    my $query = $session->{cgiQuery};
+    my $query = $TWiki::SESSION->{cgiQuery};
 
     my @pluginList = ();
     my %already;
@@ -199,7 +195,7 @@
     foreach my $pn ( @pluginList ) {
         my $p;
         unless( $p = $lookup{$pn} ) {
-            $p = new TWiki::Plugin( $session, $pn,
+            $p = new TWiki::Plugin( $pn,
                                     $TWiki::cfg{Plugins}{$pn}{Module} )
         }
         push @{$this->{plugins}}, $p;
@@ -216,7 +212,7 @@
         }
         # Report initialisation errors
         if( $p->{errors} ) {
-            $this->{session}->writeWarning( join( "\n", @{$p->{errors}} ));
+            $TWiki::SESSION->writeWarning( join( "\n", @{$p->{errors}} ));
         }
         $lookup{$pn} = $p;
     }
@@ -237,7 +233,7 @@
     ASSERT($this->isa( 'TWiki::Plugins')) if DEBUG;
 
     # Set the session for this call stack
-    local $TWiki::Plugins::SESSION = $this->{session};
+    local $TWiki::Plugins::SESSION = $TWiki::SESSION;
 
     foreach my $plugin ( @{$this->{plugins}} ) {
         $plugin->registerSettings( $this );
@@ -255,12 +251,12 @@
 sub enable {
     my $this = shift;
     ASSERT($this->isa( 'TWiki::Plugins')) if DEBUG;
-    my $prefs = $this->{session}->{prefs};
+    my $prefs = $TWiki::PREFS;
     my $dissed = $prefs->getPreferencesValue('DISABLEDPLUGINS') || '';
     my %disabled = map { $_ => 1 } split(/,\s*/, $dissed);
 
     # Set the session for this call stack
-    local $TWiki::Plugins::SESSION = $this->{session};
+    local $TWiki::Plugins::SESSION = $TWiki::SESSION;
 
     foreach my $plugin ( @{$this->{plugins}} ) {
         if ($disabled{$plugin->{name}}) {
@@ -270,7 +266,7 @@
         $plugin->registerHandlers( $this );
         # Report initialisation errors
         if ( $plugin->{errors} ) {
-            $this->{session}->writeWarning( join( "\n", @{$plugin->{errors}} ));
+            $TWiki::SESSION->writeWarning( join( "\n", @{$plugin->{errors}} ));
         }
     }
 }
@@ -327,7 +323,7 @@
 
     foreach my $plugin ( @{$this->{registeredHandlers}{$handlerName}} ) {
         # Set the value of $SESSION for this call stack
-        local $SESSION = $this->{session};
+        local $SESSION = $TWiki::SESSION;
         # apply handler on the remaining list of args
         no strict 'refs';
         my $status = $plugin->invoke( $handlerName, @_ );
@@ -359,7 +355,7 @@
 # %FAILEDPLUGINS reports reasons why plugins failed to load
 # note this is invoked with the session as the first parameter
 sub _handleFAILEDPLUGINS {
-    my $this = shift->{plugins};
+    my $this = $TWiki::PLUGINS;
 
     my $text = CGI::start_table( { border => 1, class => 'twikiTable' } ).
       CGI::Tr(CGI::th('Plugin').CGI::th('Errors'));
@@ -405,7 +401,7 @@
 
 # note this is invoked with the session as the first parameter
 sub _handlePLUGINDESCRIPTIONS {
-    my $this = shift->{plugins};
+    my $this = $TWiki::PLUGINS;
     my $text = '';
     foreach my $plugin ( @{$this->{plugins}} ) {
         $text .= CGI::li( $plugin->getDescription() . ' ' );
@@ -416,7 +412,7 @@
 
 # note this is invoked with the session as the first parameter
 sub _handleACTIVATEDPLUGINS {
-    my $this = shift->{plugins};
+    my $this = $TWiki::PLUGINS;
     my $text = '';
     foreach my $plugin ( @{$this->{plugins}} ) {
         unless( $plugin->{disabled} ) {
Index: TWiki/Store/RcsLite.pm
===================================================================
--- TWiki/Store/RcsLite.pm	(revision 13172)
+++ TWiki/Store/RcsLite.pm	(working copy)
@@ -230,7 +230,7 @@
     }
     my $fh = new FileHandle();
     if( ! $fh->open( $rcsFile ) ) {
-        $this->{session}->writeWarning( 'Failed to open '.$rcsFile );
+        $TWiki::SESSION->writeWarning( 'Failed to open '.$rcsFile );
         $this->{state} = 'nocommav';
         return;
     }
@@ -331,7 +331,7 @@
 
     unless( $state eq 'parsed' ) {
         my $error = $this->{rcsFile}.' is corrupt; parsed up to '.$state;
-        $this->{session}->writeWarning( $error );
+        $TWiki::SESSION->writeWarning( $error );
         #ASSERT(0) if DEBUG;
         $headNum = 0;
         $state = 'nocommav'; # ignore the RCS file; graceful recovery
Index: TWiki/Store/RcsFile.pm
===================================================================
--- TWiki/Store/RcsFile.pm	(revision 13172)
+++ TWiki/Store/RcsFile.pm	(working copy)
@@ -47,7 +47,7 @@
 
 =pod
 
----++ ClassMethod new($session, $web, $topic, $attachment)
+---++ ClassMethod new($web, $topic, $attachment)
 
 Constructor. There is one object per stored file.
 
@@ -56,10 +56,8 @@
 =cut
 
 sub new {
-    my( $class, $session, $web, $topic, $attachment ) = @_;
-    #ASSERT($session->isa( 'TWiki')) if DEBUG;
+    my( $class, $web, $topic, $attachment ) = @_;
     my $this = bless( {}, $class );
-    $this->{session} = $session;
 
     utf8::downgrade( $web ) if( $web && $] >= 5.008 );
     $this->{web} = $web;
@@ -342,7 +340,7 @@
 
     no strict 'refs';
     return &{$this->{searchFn}}($searchString, $topics, $options,
-               $sDir, $this->{session}->{sandbox});
+               $sDir, $TWiki::SANDBOX);
     use strict 'refs';
 }
 
@@ -473,8 +471,7 @@
     my $oldTopic = $this->{topic};
 
     # Move data file
-    my $new = new TWiki::Store::RcsFile( $this->{session},
-                                         $newWeb, $newTopic, '' );
+    my $new = new TWiki::Store::RcsFile( $newWeb, $newTopic, '' );
     _moveFile( $this->{file}, $new->{file} );
 
     # Move history
@@ -505,8 +502,7 @@
     my $oldWeb = $this->{web};
     my $oldTopic = $this->{topic};
 
-    my $new = new TWiki::Store::RcsFile( $this->{session},
-                                         $newWeb, $newTopic, '' );
+    my $new = new TWiki::Store::RcsFile( $newWeb, $newTopic, '' );
 
     _copyFile( $this->{file}, $new->{file} );
     if( -e $this->{rcsFile} ) {
@@ -518,7 +514,7 @@
         for my $att ( grep { !/^\./ } readdir DIR ) {
             $att = TWiki::Sandbox::untaintUnchecked( $att );
             my $oldAtt = new TWiki::Store::RcsFile(
-                $this->{session}, $this->{web}, $this->{topic}, $att );
+                $this->{web}, $this->{topic}, $att );
             $oldAtt->copyAttachment( $newWeb, $newTopic );
         }
 
@@ -538,7 +534,7 @@
     my( $this, $newWeb, $newTopic, $newAttachment ) = @_;
 
     # FIXME might want to delete old directories if empty
-    my $new = TWiki::Store::RcsFile->new( $this->{session}, $newWeb,
+    my $new = new TWiki::Store::RcsFile( $newWeb,
                                           $newTopic, $newAttachment );
 
     _moveFile( $this->{file}, $new->{file} );
@@ -563,7 +559,7 @@
     my $oldTopic = $this->{topic};
     my $attachment = $this->{attachment};
 
-    my $new = TWiki::Store::RcsFile->new( $this->{session}, $newWeb,
+    my $new = TWiki::Store::RcsFile->new( $newWeb,
                                           $newTopic, $attachment );
 
     _copyFile( $this->{file}, $new->{file} );
@@ -602,7 +598,7 @@
 sub setLock {
     my( $this, $lock, $user ) = @_;
 
-    $user = $this->{session}->{user} unless $user;
+    $user = $TWiki::SESSION->{user} unless $user;
 
     my $filename = $this->_controlFileName('lock');
     if( $lock ) {
Index: TWiki/Store/Subversive.pm
===================================================================
--- TWiki/Store/Subversive.pm	(revision 13172)
+++ TWiki/Store/Subversive.pm	(working copy)
@@ -26,11 +26,8 @@
 use TWiki::Time;
 
 sub new {
-    my( $class, $session, $web, $topic, $attachment ) = @_;
-
-    ASSERT($session->isa( 'TWiki')) if DEBUG;
+    my( $class, $web, $topic, $attachment ) = @_;
     my $this = bless( {}, $class );
-    $this->{session} = $session;
 
     $this->{web} = $web;
 
@@ -82,7 +79,7 @@
         }
         close(F);
 
-        my ($output, $exit) = $this->{session}->{sandbox}->sysCommand(
+        my ($output, $exit) = $TWiki::SANDBOX->sysCommand(
             'svn add %FILENAME|F%',
             FILENAME => $this->{file});
         if( $exit ) {
@@ -104,7 +101,7 @@
             $path .= '/';
         } elsif( $path ) {
             if(  ! -e "$path$dir" && -e "$path/.svn" ) {
-                my($output, $exit) = $this->{session}->{sandbox}->sysCommand(
+                my($output, $exit) = $TWiki::SANDBOX->sysCommand(
                     'svn mkdir %FILENAME|F%',
                     FILENAME => $path.$dir);
                 if( $exit ) {
@@ -294,7 +291,7 @@
     my $maxTopicsInSet = 512; # max number of topics for a grep call
     my @take = @$topics;
     my @set = splice( @take, 0, $maxTopicsInSet );
-    my $sandbox = $this->{session}->{sandbox};
+    my $sandbox = $TWiki::SANDBOX;
     while( @set ) {
         @set = map { "$sDir/$_.txt" } @set;
         my ($matches, $exit ) = $sandbox->sysCommand(
@@ -433,8 +430,7 @@
     my $oldTopic = $this->{topic};
 
     # Move data file
-    my $new = new TWiki::Store::Subversive( $this->{session},
-                                            $newWeb, $newTopic, '' );
+    my $new = new TWiki::Store::Subversive( $newWeb, $newTopic, '' );
     $this->_moveFile( $this->{file}, $new->{file} );
 
     # Move attachments
@@ -459,8 +455,7 @@
     my $oldWeb = $this->{web};
     my $oldTopic = $this->{topic};
 
-    my $new = new TWiki::Store::Subversive( $this->{session},
-                                         $newWeb, $newTopic, '' );
+    my $new = new TWiki::Store::Subversive( $newWeb, $newTopic, '' );
 
     $this->_copyFile( $this->{file}, $new->{file} );
 
@@ -469,7 +464,7 @@
         for my $att ( grep { !/^\./ } readdir DIR ) {
             $att = TWiki::Sandbox::untaintUnchecked( $att );
             my $oldAtt = new TWiki::Store::Subversive(
-                $this->{session}, $this->{web}, $this->{topic}, $att );
+                $this->{web}, $this->{topic}, $att );
             $oldAtt->copyAttachment( $newWeb, $newTopic );
         }
 
@@ -481,7 +476,7 @@
     my( $this, $newWeb, $newTopic, $newAttachment ) = @_;
 
     # FIXME might want to delete old directories if empty
-    my $new = TWiki::Store::Subversive->new( $this->{session}, $newWeb,
+    my $new = TWiki::Store::Subversive->new( $newWeb,
                                           $newTopic, $newAttachment );
 
     $this->_moveFile( $this->{file}, $new->{file} );
@@ -494,7 +489,7 @@
     my $oldTopic = $this->{topic};
     my $attachment = $this->{attachment};
 
-    my $new = TWiki::Store::Subversive->new( $this->{session}, $newWeb,
+    my $new = TWiki::Store::Subversive->new( $newWeb,
                                           $newTopic, $attachment );
 
     $this->_copyFile( $this->{file}, $new->{file} );
@@ -556,7 +551,7 @@
 
     $this->_mkPathTo( $to );
 
-    my($output, $exit) = $this->{session}->{sandbox}->sysCommand(
+    my($output, $exit) = $TWiki::SANDBOX->sysCommand(
         'svn cp %FROM|F% %TO|F%',
         FROM => $from, TO => $to);
     if( $exit ) {
@@ -569,7 +564,7 @@
     my( $this, $from, $to ) = @_;
 
     $this->_mkPathTo( $to );
-    my($output, $exit) = $this->{session}->{sandbox}->sysCommand(
+    my($output, $exit) = $TWiki::SANDBOX->sysCommand(
         'svn mv %FROM|F% %TO|F%',
         FROM => $from, TO => $to);
     if( $exit ) {
@@ -661,7 +656,7 @@
 sub _rmtree {
     my ($this, $root) = @_;
 
-    my ($output, $exit) = $this->{session}->{sandbox}->sysCommand(
+    my ($output, $exit) = $TWiki::SANDBOX->sysCommand(
         'svn rm %FILENAME|F%',
         FILENAME => $root);
     if( $exit ) {
@@ -705,7 +700,7 @@
 sub numRevisions {
     my $this = shift;
 
-    my($output, $exit) = $this->{session}->{sandbox}->sysCommand(
+    my($output, $exit) = $TWiki::SANDBOX->sysCommand(
         'svn info %FILE|F%',
         FILE => $this->{file} );
     if( $exit ) {
@@ -731,7 +726,7 @@
         return [];
     }
 
-    my($output, $exit) = $this->{session}->{sandbox}->sysCommand(
+    my($output, $exit) = $TWiki::SANDBOX->sysCommand(
         'svn diff -r%FT|U% --non-interactive %FILE|F%',
         FT => $ft,
         FILE => $this->{file} );
Index: TWiki/Store/RcsWrap.pm
===================================================================
--- TWiki/Store/RcsWrap.pm	(revision 13172)
+++ TWiki/Store/RcsWrap.pm	(working copy)
@@ -68,7 +68,7 @@
     return if -e $this->{rcsFile};
 
     my ( $rcsOutput, $exit ) =
-      $this->{session}->{sandbox}->sysCommand(
+      $TWiki::SANDBOX->sysCommand(
           $TWiki::cfg{RCS}{initBinaryCmd}, FILENAME => $this->{file} );
     if( $exit ) {
         throw Error::Simple( $TWiki::cfg{RCS}{initBinaryCmd}.
@@ -93,7 +93,7 @@
     return if -e $this->{rcsFile};
 
     my ( $rcsOutput, $exit ) =
-      $this->{session}->{sandbox}->sysCommand
+      $TWiki::SANDBOX->sysCommand
         ( $TWiki::cfg{RCS}{initTextCmd},
           FILENAME => $this->{file} );
     if( $exit ) {
@@ -153,7 +153,7 @@
 
     $this->_lock();
     my ($rcsOut, $exit) =
-      $this->{session}->{sandbox}->sysCommand(
+      $TWiki::SANDBOX->sysCommand(
           $TWiki::cfg{RCS}{ciDateCmd},
           DATE => $date,
           USERNAME => $user,
@@ -179,13 +179,13 @@
 
     # delete latest revision (unlock (may not be needed), delete revision)
     my ($rcsOut, $exit) =
-      $this->{session}->{sandbox}->sysCommand(
+      $TWiki::SANDBOX->sysCommand(
           $TWiki::cfg{RCS}{unlockCmd},
           FILENAME => $this->{file} );
 
     chmod( $TWiki::cfg{RCS}{filePermission}, $this->{file} );
 
-    ($rcsOut, $exit) = $this->{session}->{sandbox}->sysCommand(
+    ($rcsOut, $exit) = $TWiki::SANDBOX->sysCommand(
         $TWiki::cfg{RCS}{delRevCmd},
         REVISION => '1.'.$rev,
         FILENAME => $this->{file} );
@@ -198,7 +198,7 @@
 
     # Update the checkout
     $rev--;
-    ($rcsOut, $exit) = $this->{session}->{sandbox}->sysCommand(
+    ($rcsOut, $exit) = $TWiki::SANDBOX->sysCommand(
         $TWiki::cfg{RCS}{coCmd},
         REVISION => '1.'.$rev,
         FILENAME => $this->{file} );
@@ -233,13 +233,13 @@
         $tmpfile = $this->_mkTmpFilename();
         $tmpRevFile = $tmpfile.',v';
         copy( $this->{rcsFile}, $tmpRevFile );
-        my ($tmp, $status) = $this->{session}->{sandbox}->sysCommand(
+        my ($tmp, $status) = $TWiki::SANDBOX->sysCommand(
             $TWiki::cfg{RCS}{tmpBinaryCmd},
             FILENAME => $tmpRevFile );
         $file = $tmpfile;
         $coCmd =~ s/-p%REVISION/-r%REVISION/;
     }
-    my ($text, $status) = $this->{session}->{sandbox}->sysCommand(
+    my ($text, $status) = $TWiki::SANDBOX->sysCommand(
         $coCmd,
         REVISION => '1.'.$version,
         FILENAME => $file );
@@ -264,7 +264,7 @@
     }
 
     my ($rcsOutput, $exit) =
-      $this->{session}->{sandbox}->sysCommand
+      $TWiki::SANDBOX->sysCommand
         ( $TWiki::cfg{RCS}{histCmd},
           FILENAME => $this->{rcsFile} );
     if( $exit ) {
@@ -289,7 +289,7 @@
         if( !$version || $version > $this->numRevisions()) {
             $version = $this->numRevisions();
         }
-        my( $rcsOut, $exit ) = $this->{session}->{sandbox}->sysCommand
+        my( $rcsOut, $exit ) = $TWiki::SANDBOX->sysCommand
           ( $TWiki::cfg{RCS}{infoCmd},
             REVISION => '1.'.$version,
             FILENAME => $this->{rcsFile} );
@@ -323,7 +323,7 @@
         }
     } else {
         $contextLines = 3 unless defined($contextLines);
-        ( $tmp, $exit ) = $this->{session}->{sandbox}->sysCommand(
+        ( $tmp, $exit ) = $TWiki::SANDBOX->sysCommand(
             $TWiki::cfg{RCS}{diffCmd},
             REVISION1 => '1.'.$rev1,
             REVISION2 => '1.'.$rev2,
@@ -406,7 +406,7 @@
     if( defined( $date )) {
         $date = TWiki::Time::formatTime( $date , '$rcs', 'gmtime');
         $cmd = $TWiki::cfg{RCS}{ciDateCmd};
-        ($rcsOutput, $exit)= $this->{session}->{sandbox}->sysCommand(
+        ($rcsOutput, $exit)= $TWiki::SANDBOX->sysCommand(
             $cmd,
             USERNAME => $user,
             FILENAME => $this->{file},
@@ -414,7 +414,7 @@
             DATE => $date );
     } else {
         $cmd = $TWiki::cfg{RCS}{ciCmd};
-        ($rcsOutput, $exit)= $this->{session}->{sandbox}->sysCommand(
+        ($rcsOutput, $exit)= $TWiki::SANDBOX->sysCommand(
             $cmd,
             USERNAME => $user,
             FILENAME => $this->{file},
@@ -436,7 +436,7 @@
     return unless -e $this->{rcsFile};
 
     # Try and get a lock on the file
-    my ($rcsOutput, $exit) = $this->{session}->{sandbox}->sysCommand(
+    my ($rcsOutput, $exit) = $TWiki::SANDBOX->sysCommand(
         $TWiki::cfg{RCS}{lockCmd}, FILENAME => $this->{file} );
 
     if( $exit ) {
@@ -445,9 +445,9 @@
         # scenarios - see Item2102
         if ((time - (stat($this->{rcsFile}))[9]) > 3600) {
             warn 'Automatic recovery: breaking lock for ' . $this->{file} ;
-            $this->{session}->{sandbox}->sysCommand(
+            $TWiki::SANDBOX->sysCommand(
                 $TWiki::cfg{RCS}{breaklockCmd}, FILENAME => $this->{file} );
-        ($rcsOutput, $exit) = $this->{session}->{sandbox}->sysCommand(
+        ($rcsOutput, $exit) = $TWiki::SANDBOX->sysCommand(
                 $TWiki::cfg{RCS}{lockCmd}, FILENAME => $this->{file} );
         }
        if ( $exit ) {
@@ -468,7 +468,7 @@
         return undef;
     }
 	$date = TWiki::Time::formatTime( $date , '$rcs', 'gmtime');
-    my ($rcsOutput, $exit) = $this->{session}->{sandbox}->sysCommand(
+    my ($rcsOutput, $exit) = $TWiki::SANDBOX->sysCommand(
         $TWiki::cfg{RCS}{rlogDateCmd},
         DATE => $date,
         FILENAME => $this->{file} );
Index: TWiki/Meta.pm
===================================================================
--- TWiki/Meta.pm	(revision 13172)
+++ TWiki/Meta.pm	(working copy)
@@ -54,20 +54,18 @@
 
 =pod
 
----++ ClassMethod new($session, $web, $topic)
+---++ ClassMethod new($web, $topic)
 
 Construct a new, empty Meta collection.
 
 =cut
 
 sub new {
-    my ( $class, $session, $web, $topic ) = @_;
-    ASSERT($session->isa( 'TWiki')) if DEBUG;
+    my ( $class, $web, $topic ) = @_;
     my $this = bless( {}, $class );
 
     # Note: internal fields must be prepended with _. All other
     # fields will be assumed to be meta-data.
-    $this->{_session} = $session;
 
     ASSERT($web) if DEBUG;
     ASSERT($topic) if DEBUG;
@@ -388,14 +386,14 @@
 sub getRevisionInfo {
     my( $this, $fromrev ) = @_;
     ASSERT($this->isa( 'TWiki::Meta')) if DEBUG;
-    my $store = $this->{_session}->{store};
+    my $store = $TWiki::STORE;
 
     my $topicinfo = $this->get( 'TOPICINFO' );
 
     my( $date, $author, $rev, $comment );
     if( $topicinfo ) {
         $date = $topicinfo->{date} ;
-        $author = $this->{_session}->{users}->findUser($topicinfo->{author});
+        $author = $TWiki::USERS->findUser($topicinfo->{author});
         $rev = $topicinfo->{version};
         $rev =~ s/^\$Rev(:\s*\d+)?\s*\$$/0/; # parse out SVN keywords in doc
         $rev =~ s/^\d+\.//;
@@ -439,7 +437,7 @@
                     my $merged = TWiki::Merge::merge2(
                         'A', $otherD->{value}, 'B', $thisD->{value},
                         '.*?\s+',
-                        $this->{_session},
+                        $TWiki::SESSION,
                         $formDef->getField( $thisD->{name} ) );
                     # SMELL: we don't merge attributes or title
                     $thisD->{value} = $merged;
Index: TWiki/Func.pm
===================================================================
--- TWiki/Func.pm	(revision 13172)
+++ TWiki/Func.pm	(working copy)
@@ -277,7 +277,7 @@
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
     ASSERT(defined $url) if DEBUG;
 
-    return $TWiki::Plugins::SESSION->{net}->getExternalResource( $url );
+    return $TWiki::NET->getExternalResource( $url );
 }
 
 =pod
@@ -311,7 +311,7 @@
 
 sub getSessionKeys {
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
-    my $hash = $TWiki::Plugins::SESSION->{loginManager}->getSessionValues();
+    my $hash = $TWiki::LOGIN->getSessionValues();
     return keys %{$hash};
 }
 
@@ -331,7 +331,7 @@
 #   my( $key ) = @_;
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
 
-    return $TWiki::Plugins::SESSION->{loginManager}->getSessionValue( @_ );
+    return $TWiki::LOGIN->getSessionValue( @_ );
 }
 
 
@@ -352,7 +352,7 @@
 #   my( $key, $value ) = @_;
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
 
-    $TWiki::Plugins::SESSION->{loginManager}->setSessionValue( @_ );
+    $TWiki::LOGIN->setSessionValue( @_ );
 }
 
 =pod
@@ -371,7 +371,7 @@
 sub clearSessionValue {
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
 
-    return $TWiki::Plugins::SESSION->{loginManager}->clearSessionValue( @_ );
+    return $TWiki::LOGIN->clearSessionValue( @_ );
 }
 
 =pod
@@ -457,15 +457,15 @@
     my $old = {
         web => $twiki->{webName},
         topic => $twiki->{topicName},
-        mark => $twiki->{prefs}->mark() };
+        mark => $TWiki::PREFS->mark() };
 
     push( @{$twiki->{_FUNC_PREFS_STACK}}, $old );
     $twiki->{webName} = $web;
     $twiki->{topicName} = $topic;
-    $twiki->{prefs}->pushWebPreferences( $web );
-    $twiki->{prefs}->pushPreferences( $web, $topic, 'TOPIC' );
-    $twiki->{prefs}->pushPreferenceValues(
-        'SESSION', $twiki->{loginManager}->getSessionValues() );
+    $TWiki::PREFS->pushWebPreferences( $web );
+    $TWiki::PREFS->pushPreferences( $web, $topic, 'TOPIC' );
+    $TWiki::PREFS->pushPreferenceValues(
+        'SESSION', $TWiki::LOGIN->getSessionValues() );
 }
 
 =pod
@@ -484,7 +484,7 @@
     my $twiki = $TWiki::Plugins::SESSION;
     ASSERT(scalar(@{$twiki->{_FUNC_PREFS_STACK}})) if DEBUG;
     my $old = pop( @{$twiki->{_FUNC_PREFS_STACK}} );
-    $twiki->{prefs}->restore( $old->{mark});
+    $TWiki::PREFS->restore( $old->{mark});
     $twiki->{webName} = $old->{web};
     $twiki->{topicName} = $old->{topic};
 }
@@ -522,12 +522,11 @@
 
 sub getPreferencesValue {
     my( $key, $web ) = @_;
-    ASSERT($TWiki::Plugins::SESSION) if DEBUG;
     if( $web ) {
-        return $TWiki::Plugins::SESSION->{prefs}->getWebPreferencesValue(
+        return $TWiki::PREFS->getWebPreferencesValue(
             $key, $web );
     } else {
-        return $TWiki::Plugins::SESSION->{prefs}->getPreferencesValue( $key );
+        return $TWiki::PREFS->getPreferencesValue( $key );
     }
 }
 
@@ -553,7 +552,7 @@
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
     my $package = caller;
     $package =~ s/.*:://; # strip off TWiki::Plugins:: prefix
-    return $TWiki::Plugins::SESSION->{prefs}->getPreferencesValue( "\U$package\E_$key" );
+    return $TWiki::PREFS->getPreferencesValue( "\U$package\E_$key" );
 }
 
 =pod
@@ -723,7 +722,7 @@
     my( $wiki ) = @_;
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
     return '' unless $wiki;
-    my $user = $TWiki::Plugins::SESSION->{users}->findUser( $wiki, undef, 1 );
+    my $user = $TWiki::USERS->findUser( $wiki, undef, 1 );
     return $wiki unless $user;
     return $user->login();
 }
@@ -745,7 +744,7 @@
     my( $login, $dontAddWeb ) = @_;
     return '' unless $login;
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
-    my $user = $TWiki::Plugins::SESSION->{users}->findUser( $login, undef, 1 );
+    my $user = $TWiki::USERS->findUser( $login, undef, 1 );
     return '' unless $user;
     return $user->wikiName() if $dontAddWeb;
     return $user->webDotWikiName();
@@ -769,7 +768,7 @@
     ASSERT($email) if DEBUG;
 
     my %matches;
-    my $ua = $TWiki::Plugins::SESSION->{users}->findUserByEmail( $email );
+    my $ua = $TWiki::USERS->findUserByEmail( $email );
     if ($ua) {
         foreach my $user (@$ua) {
             if( $dontAddWeb ) {
@@ -798,7 +797,7 @@
     my( $user ) = @_;
 
     if( $user ) {
-        $user = $TWiki::Plugins::SESSION->{users}->findUser($user, undef, 1);
+        $user = $TWiki::USERS->findUser($user, undef, 1);
     } else {
         $user = $TWiki::Plugins::SESSION->{user};
     }
@@ -836,7 +835,7 @@
     my ($user) = @_;
 
     if ($user) {
-        $user = $TWiki::Plugins::SESSION->{users}->findUser($user, undef, 1);
+        $user = $TWiki::USERS->findUser($user, undef, 1);
     } else {
         $user = $TWiki::Plugins::SESSION->{user};
     }
@@ -863,11 +862,11 @@
     my ($group, $user) = @_;
 
     if ($user) {
-        $user = $TWiki::Plugins::SESSION->{users}->findUser($user, $user, 1);
+        $user = $TWiki::USERS->findUser($user, $user, 1);
     } else {
         $user = $TWiki::Plugins::SESSION->{user};
     }
-    $group = $TWiki::Plugins::SESSION->{users}->findUser($group, $group, 1);
+    $group = $TWiki::USERS->findUser($group, $group, 1);
     return () unless $group->isGroup();
     return $user->isInGroup( $group );
 }
@@ -895,8 +894,7 @@
 =cut
 
 sub eachUser {
-    my $session = $TWiki::Plugins::SESSION;
-    my $it = $session->{users}->eachUser();
+    my $it = $TWiki::USERS->eachUser();
     # Get the name from the user object
     $it->{process} = sub { return $_[0]->wikiName() };
     return $it;
@@ -916,7 +914,7 @@
     my ($user) = @_;
 
     if ($user) {
-        $user = $TWiki::Plugins::SESSION->{users}->findUser($user, $user, 1);
+        $user = $TWiki::USERS->findUser($user, $user, 1);
     } else {
         $user = $TWiki::Plugins::SESSION->{user};
     }
@@ -948,8 +946,7 @@
 =cut
 
 sub eachGroup {
-    my $session = $TWiki::Plugins::SESSION;
-    my $it = $session->{users}->eachGroup();
+    my $it = $TWiki::USERS->eachGroup();
     # Get the name from the user object
     $it->{process} = sub { return $_[0]->wikiName() };
     return $it;
@@ -966,9 +963,8 @@
 sub isGroup {
     my( $group ) = @_;
 
-    my $users = $TWiki::Plugins::SESSION->{users};
-    my $uo = $users->findUser( $group );
-    return $users->isGroup( $uo );
+    my $uo = $TWiki::USERS->findUser( $group );
+    return $TWiki::USERS->isGroup( $uo );
 }
 
 =pod
@@ -994,8 +990,7 @@
 
 sub eachGroupMember {
     my $group = shift;
-    my $session = $TWiki::Plugins::SESSION;
-    my $user = $session->{users}->findUser($group);
+    my $user = $TWiki::USERS->findUser($group);
     return undef unless $user->isGroup();
     my $it = $user->eachGroupMember();
     # Get the name from the user object
@@ -1085,8 +1080,8 @@
     return 1 unless ( $user );
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
     $text = undef unless $text;
-    $user = $TWiki::Plugins::SESSION->{users}->findUser( $user );
-    return $TWiki::Plugins::SESSION->{security}->checkAccessPermission(
+    $user = $TWiki::USERS->findUser( $user );
+    return $TWiki::ACCESS->checkAccessPermission(
         $type, $user, $text, $meta, $topic, $web );
 }
 
@@ -1122,7 +1117,7 @@
 sub getListOfWebs {
     my $filter = shift;
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
-    return $TWiki::Plugins::SESSION->{store}->getListOfWebs($filter);
+    return $TWiki::STORE->getListOfWebs($filter);
 }
 
 =pod
@@ -1139,7 +1134,7 @@
 sub webExists {
 #   my( $web ) = @_;
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
-    return $TWiki::Plugins::SESSION->{store}->webExists( @_ );
+    return $TWiki::STORE->{store}->webExists( @_ );
 }
 
 =pod
@@ -1174,7 +1169,7 @@
 
 sub createWeb {
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
-    $TWiki::Plugins::SESSION->{store}->createWeb(
+    $TWiki::STORE->createWeb(
         $TWiki::Plugins::SESSION->{user}, @_ );
 }
 
@@ -1212,7 +1207,7 @@
 
 sub moveWeb {
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
-    return $TWiki::Plugins::SESSION->{store}->moveWeb(
+    return $TWiki::STORE->moveWeb(
         @_, $TWiki::Plugins::SESSION->{user});
 
 }
@@ -1232,7 +1227,7 @@
 sub getTopicList {
 #   my( $web ) = @_;
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
-    return $TWiki::Plugins::SESSION->{store}->getTopicNames ( @_ );
+    return $TWiki::STORE->getTopicNames ( @_ );
 }
 
 =pod
@@ -1251,7 +1246,7 @@
 sub topicExists {
     my( $web, $topic ) = $TWiki::Plugins::SESSION->normalizeWebTopicName( @_ );
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
-    return $TWiki::Plugins::SESSION->{store}->topicExists( $web, $topic );
+    return $TWiki::STORE->topicExists( $web, $topic );
 }
 
 =pod
@@ -1275,21 +1270,20 @@
     ( $web, $topic ) = normalizeWebTopicName( $web, $topic );
     $script ||= 'edit';
 
-    my $lease = $TWiki::Plugins::SESSION->{store}->getLease( $web, $topic );
+    my $lease = $TWiki::STORE->getLease( $web, $topic );
     if( $lease ) {
         my $remain = $lease->{expires} - time();
-        my $session = $TWiki::Plugins::SESSION;
 
         if( $remain > 0 ) {
             my $who = $lease->{user}->login();
             my $wn = $lease->{user}->webDotWikiName();
             my $past = TWiki::Time::formatDelta(time()-$lease->{taken},
-                                                $TWiki::Plugins::SESSION->{i18n}
+                                                $TWiki::I18N
                                                );
             my $future = TWiki::Time::formatDelta($lease->{expires}-time(),
-                                                  $TWiki::Plugins::SESSION->{i18n}
+                                                  $TWiki::I18N
                                                  );
-            return( $session->getOopsUrl( 'leaseconflict',
+            return( $TWiki::SESSION->getOopsUrl( 'leaseconflict',
                                           def => 'lease_active',
 					  keep => 1,   # Need to keep parameters across redirect
                                           web => $web,
@@ -1323,14 +1317,12 @@
 
 sub setTopicEditLock {
     my( $web, $topic, $lock ) = @_;
-    ASSERT($TWiki::Plugins::SESSION) if DEBUG;
-    my $session = $TWiki::Plugins::SESSION;
-    my $store = $session->{store};
+
     if( $lock ) {
-        $store->setLease( $web, $topic, $session->{user},
+        $TWiki::STORE->setLease( $web, $topic, $TWiki::SESSION->{user},
                           $TWiki::cfg{LeaseLength} );
     } else {
-        $store->clearLease( $web, $topic );
+        $TWiki::STORE->clearLease( $web, $topic );
     }
     return '';
 }
@@ -1369,7 +1361,7 @@
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
     ASSERT($meta) if DEBUG;
 
-    return $TWiki::Plugins::SESSION->{store}->saveTopic
+    return $TWiki::STORE->saveTopic
       ( $TWiki::Plugins::SESSION->{user}, $web, $topic, $text, $meta,
         $options );
 
@@ -1412,46 +1404,40 @@
     my( $web, $topic, $text, $ignorePermissions, $dontNotify ) = @_;
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
 
-    my $session = $TWiki::Plugins::SESSION;
-    my( $mirrorSite, $mirrorViewURL ) = $session->readOnlyMirrorWeb( $web );
-    return $session->getOopsUrl
-      ( 'mirror', web => $web, topic => $topic,
-        params => [ $mirrorSite, $mirrorViewURL ] ) if( $mirrorSite );
-
     # check access permission
     unless( $ignorePermissions ||
-            $session->{security}->checkAccessPermission(
-                'CHANGE', $session->{user}, undef, undef,
+            $TWiki::ACCESS->checkAccessPermission(
+                'CHANGE', $TWiki::SESSION->{user}, undef, undef,
                 $topic, $web )
           ) {
         my @plugin = caller();
-        return $session->getOopsUrl( 'accessdenied',
+        return $TWiki::SESSION->getOopsUrl( 'accessdenied',
                                      def => 'topic_access',
                                      web => $web,
                                      topic => $topic,
                                      params => [ 'in', $plugin[0] ] );
     }
 
-    return $session->getOopsUrl( 'attention',
+    return $TWiki::SESSION->getOopsUrl( 'attention',
                                  def => 'save_error',
                                  web => $web,
                                  topic => $topic )
       unless( defined $text );
 
     # extract meta data and merge old attachment meta data
-    my $meta = new TWiki::Meta( $session, $web, $topic );
-    $session->{store}->extractMetaData( $meta, \$text );
+    my $meta = new TWiki::Meta( $web, $topic );
+    $TWiki::STORE->extractMetaData( $meta, \$text );
     $meta->remove( 'FILEATTACHMENT' );
 
     my( $oldMeta, $oldText ) =
-      $session->{store}->readTopic( undef, $web, $topic, undef );
+      $TWiki::STORE->readTopic( undef, $web, $topic, undef );
     $meta->copyFrom( $oldMeta, 'FILEATTACHMENT' );
     # save topic
     my $error =
-      $session->{store}->saveTopic
-        ( $session->{user}, $web, $topic, $text, $meta,
+      $TWiki::STORE->saveTopic
+        ( $TWiki::SESSION->{user}, $web, $topic, $text, $meta,
           { notify => $dontNotify } );
-    return $session->getOopsUrl
+    return $TWiki::SESSION->getOopsUrl
       ( 'attention', def => 'save_error',
         web => $web, topic => $topic, params => $error ) if( $error );
     return '';
@@ -1500,7 +1486,7 @@
 
     return if( $newWeb eq $web && $newTopic eq $topic );
 
-    $TWiki::Plugins::SESSION->{store}->moveTopic(
+    $TWiki::STORE->moveTopic(
         $web, $topic,
         $newWeb, $newTopic,
         $TWiki::Plugins::SESSION->{user} );
@@ -1538,7 +1524,7 @@
 sub getRevisionInfo {
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
     my( $date, $user, $rev, $comment ) =
-      $TWiki::Plugins::SESSION->{store}->getRevisionInfo( @_ );
+      $TWiki::STORE->getRevisionInfo( @_ );
     $user = $user->wikiName();
     return ( $date, $user, $rev, $comment );
 }
@@ -1560,7 +1546,7 @@
 
 sub getRevisionAtTime {
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
-    return $TWiki::Plugins::SESSION->{store}->getRevisionAtTime( @_ );
+    return $TWiki::STORE->getRevisionAtTime( @_ );
 }
 
 =pod
@@ -1587,7 +1573,7 @@
     #my( $web, $topic, $rev ) = @_;
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
 
-    return $TWiki::Plugins::SESSION->{store}->readTopic( undef, @_ );
+    return $TWiki::STORE->readTopic( undef, @_ );
 }
 
 =pod
@@ -1617,9 +1603,7 @@
 
     my $text;
     try {
-        $text =
-          $TWiki::Plugins::SESSION->{store}->readTopicRaw
-            ( $user, $web, $topic, $rev );
+        $text = $TWiki::STORE->readTopicRaw( $user, $web, $topic, $rev );
     } catch TWiki::AccessControlException with {
         my $e = shift;
         $text = $TWiki::Plugins::SESSION->getOopsUrl
@@ -1650,8 +1634,7 @@
 
     ( $web, $topic ) =
       $TWiki::Plugins::SESSION->normalizeWebTopicName( $web, $topic );
-    return $TWiki::Plugins::SESSION->{store}->attachmentExists(
-        $web, $topic, $attachment );
+    return $TWiki::STORE->attachmentExists( $web, $topic, $attachment );
 }
 
 =pod
@@ -1694,7 +1677,7 @@
     my $result;
 
 #    try {
-        $result = $TWiki::Plugins::SESSION->{store}->readAttachment(
+        $result = $TWiki::STORE->readAttachment(
             $TWiki::Plugins::SESSION->{user}, @_ );
 #    } catch Error::Simple with {
 #    };
@@ -1744,7 +1727,7 @@
     my $result = undef;
 
     try {
-        $TWiki::Plugins::SESSION->{store}->saveAttachment(
+        $TWiki::STORE->saveAttachment(
             $web, $topic, $name,
             $TWiki::Plugins::SESSION->{user},
             $data );
@@ -1806,7 +1789,7 @@
                  $newTopic eq $topic &&
                    $newAttachment eq $attachment );
 
-    $TWiki::Plugins::SESSION->{store}->moveAttachment(
+    $TWiki::STORE->moveAttachment(
         $web, $topic, $attachment,
         $newWeb, $newTopic, $newAttachment,
         $TWiki::Plugins::SESSION->{user} );
@@ -1834,7 +1817,7 @@
 sub readTemplate {
 #   my( $name, $skin ) = @_;
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
-    return $TWiki::Plugins::SESSION->{templates}->readTemplate( @_ );
+    return $TWiki::TEMPLATES->readTemplate( @_ );
 }
 
 =pod
@@ -1859,7 +1842,7 @@
 
 sub loadTemplate {
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
-    return $TWiki::Plugins::SESSION->{templates}->readTemplate( @_ );
+    return $TWiki::TEMPLATES->readTemplate( @_ );
 }
 
 =pod
@@ -1879,7 +1862,7 @@
 
 sub expandTemplate {
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
-    return $TWiki::Plugins::SESSION->{templates}->expandTemplate( @_ );
+    return $TWiki::TEMPLATES->expandTemplate( @_ );
 }
 
 =pod
@@ -2015,7 +1998,7 @@
 sub renderText {
 #   my( $text, $web ) = @_;
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
-    return $TWiki::Plugins::SESSION->{renderer}->getRenderedVersion( @_ );
+    return $TWiki::RENDER->getRenderedVersion( @_ );
 }
 
 =pod
@@ -2039,7 +2022,7 @@
     my $pre = shift;
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
 #   my( $web, $topic, $label, $anchor, $anchor, $createLink ) = @_;
-    return $pre . $TWiki::Plugins::SESSION->{renderer}->internalLink( @_ );
+    return $pre . $TWiki::RENDER->internalLink( @_ );
 }
 
 =pod
@@ -2076,7 +2059,7 @@
 sub sendEmail {
     #my( $text, $retries ) = @_;
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
-    return $TWiki::Plugins::SESSION->{net}->sendEmail( @_ );
+    return $TWiki::NET->sendEmail( @_ );
 }
 
 =pod
@@ -2096,7 +2079,7 @@
     my( $wiki ) = @_;
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
     return '' unless $wiki;
-    my $user = $TWiki::Plugins::SESSION->{users}->findUser( $wiki, undef, 1 );
+    my $user = $TWiki::USERS->findUser( $wiki, undef, 1 );
     return '' unless $user;
     return join( ',', $user->emails() );
 }
@@ -2318,7 +2301,7 @@
 sub searchInWebContent {
     #my( $searchString, $web, $topics, $options ) = @_;
 
-    return $TWiki::Plugins::SESSION->{store}->searchInWebContent( @_ );
+    return $TWiki::STORE->searchInWebContent( @_ );
 }
 
 =pod
@@ -2347,7 +2330,7 @@
 sub getWorkArea {
     my( $plugin ) = @_;
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
-    return $TWiki::Plugins::SESSION->{store}->getWorkArea( $plugin );
+    return $TWiki::STORE->getWorkArea( $plugin );
 }
 
 =pod
@@ -2699,7 +2682,7 @@
 
 sub getPublicWebList {
     ASSERT($TWiki::Plugins::SESSION) if DEBUG;
-    return $TWiki::Plugins::SESSION->{store}->getListOfWebs("user,public");
+    return $TWiki::STORE->getListOfWebs("user,public");
 }
 
 =pod
Index: TWiki/Plugin.pm
===================================================================
--- TWiki/Plugin.pm	(revision 13172)
+++ TWiki/Plugin.pm	(working copy)
@@ -72,22 +72,19 @@
 
 =pod
 
----++ ClassMethod new( $session, $name, $module )
+---++ ClassMethod new( $name, $module )
 
-   * =$session= - TWiki object
    * =$name= - name of the plugin e.g. MyPlugin
    * =$module= - (options) name of the plugin class. Default is TWiki::Plugins::$name
 
 =cut
 
 sub new {
-    my ( $class, $session, $name, $module ) = @_;
-    ASSERT($session->isa( 'TWiki')) if DEBUG;
+    my ( $class, $name, $module ) = @_;
 
     my $this = bless( {}, $class );
     $name = TWiki::Sandbox::untaintUnchecked( $name );
     $this->{name} = $name || '';
-    $this->{session} = $session;
     $this->{module} = $module || 'TWiki::Plugins::'.$name;
 
     return $this;
@@ -124,17 +121,17 @@
     $this->{no_topic} = $noTopic;
 
     unless ($noTopic) {
-        my $store = $this->{session}->{store};
+        my $store = $TWiki::STORE;
         if ( $store->topicExists(
             $TWiki::cfg{SystemWebName}, $this->{name} ) ) {
             # found plugin in TWiki web
         } elsif ( $store->topicExists( 'Plugins', $this->{name} ) ) {
             # found plugin in Plugins web (compatibility, deprecated)
             $this->{installWeb} = 'Plugins';
-        } elsif ( $store->topicExists( $this->{session}->{webName},
+        } elsif ( $store->topicExists( $TWiki::SESSION->{webName},
                                        $this->{name} ) ) {
             # found plugin in current web
-            $this->{installWeb} = $this->{session}->{webName};
+            $this->{installWeb} = $TWiki::SESSION->{webName};
         } else {
             # not found
             push( @{$this->{errors}}, 'Plugins: could not fully register '.
@@ -148,7 +145,7 @@
     $this->{description} = eval '$'.$p.'::SHORTDESCRIPTION';
 
     # Set the session for this call stack
-    local $TWiki::Plugins::SESSION = $this->{session};
+    local $TWiki::Plugins::SESSION = $TWiki::SESSION;
 
     my $sub = $p . '::earlyInitPlugin';
     if( defined( &$sub ) ) {
@@ -166,9 +163,9 @@
     $sub = $p. '::initializeUserHandler';
     if( defined( &$sub ) ) {
         no strict 'refs';
-        $user = &$sub( $this->{session}->{remoteUser},
-                       $this->{session}->{cgiQuery}->url(),
-                       $this->{session}->{pathInfo} );
+        $user = &$sub( $TWiki::SESSION->{remoteUser},
+                       $TWiki::SESSION->{cgiQuery}->url(),
+                       $TWiki::SESSION->{pathInfo} );
         use strict 'refs';
     }
     #print STDERR "Compile $p: ".timestr(timediff(new Benchmark, $begin))."\n";
@@ -191,7 +188,7 @@
         return;
     }
 
-    my $prefs = $this->{session}->{prefs};
+    my $prefs = $TWiki::PREFS;
     if( !$this->{no_topic} ) {
         $prefs->pushPreferences( $this->{installWeb}, $this->{name}, 'PLUGIN',
                                  uc( $this->{name} ) . '_');
@@ -233,7 +230,7 @@
             $plugins->addListener( $h, $this );
         }
     }
-    $this->{session}->enterContext( $this->{name}.'Enabled' );
+    $TWiki::SESSION->enterContext( $this->{name}.'Enabled' );
 }
 
 # Invoke a handler
@@ -242,7 +239,7 @@
     my $handlerName = shift;
     my $handler = $this->{module}.'::'.$handlerName;
     no strict 'refs';
-    return &$handler( @_ );;
+    return &$handler( @_ );
     use strict 'refs';
 }
 
@@ -275,7 +272,7 @@
 
     unless( defined $this->{description} ) {
         my $pref = uc( $this->{name} ) . '_SHORTDESCRIPTION';
-        my $prefs = $this->{session}->{prefs};
+        my $prefs = $TWiki::PREFS;
         $this->{description} = $prefs->getPreferencesValue( $pref ) || '';
     }
     if( $this->{disabled} ) {
Index: TWiki/OopsException.pm
===================================================================
--- TWiki/OopsException.pm	(revision 13172)
+++ TWiki/OopsException.pm	(working copy)
@@ -66,23 +66,23 @@
 
 =pod
 
----++ ObjectMethod stringify( [$session] ) -> $string
+---++ ObjectMethod stringify() -> $string
 
-Generates a string representation for the object. if a session is passed in, and
+Generates a string representation for the object. if a session is available, and
 the excpetion specifies a def, then that def is expanded. This is to allow
 internal expansion of oops exceptions for example when performing bulk operations.
 
 =cut
 
 sub stringify {
-    my( $this, $session ) = @_;
+    my( $this ) = @_;
 
-    if ($this->{template} && $this->{def} && $session) {
+    if ($this->{template} && $this->{def} && $TWiki::SESSION) {
         # load the defs
-        $session->{templates}->readTemplate( 'oops'.$this->{template},
-                                             $session->getSkin() );
-        my $message = $session->{templates}->expandTemplate( $this->{def} );
-        $message = $session->handleCommonTags(
+        $TWiki::TEMPLATES->readTemplate( 'oops'.$this->{template},
+                                             $TWiki::SESSION->getSkin() );
+        my $message = $TWiki::TEMPLATES->expandTemplate( $this->{def} );
+        $message = $TWiki::SESSION->handleCommonTags(
             $message, $this->{web}, $this->{topic} );
         my $n = 1;
         foreach my $param ( @{$this->{params}} ) {
Index: TWiki/Form.pm
===================================================================
--- TWiki/Form.pm	(revision 13172)
+++ TWiki/Form.pm	(working copy)
@@ -62,7 +62,7 @@
 
 =pod
 
----++ ClassMethod new ( $session, $web, $form, $def )
+---++ ClassMethod new ( $web, $form, $def )
 
    * $web - default web to recover form from, if $form doesn't specify a web
    * =$form= - topic name to read form definition from
@@ -74,26 +74,23 @@
 =cut
 
 sub new {
-    my( $class, $session, $web, $form, $def ) = @_;
+    my( $class, $web, $form, $def ) = @_;
     my $this = bless( {}, $class );
 
     ( $web, $form ) =
-      $session->normalizeWebTopicName( $web, $form );
+      $TWiki::SESSION->normalizeWebTopicName( $web, $form );
 
-    my $store = $session->{store};
-
-    $this->{session} = $session;
     $this->{web} = $web;
     $this->{topic} = $form;
 
     unless ( $def ) {
 
         # Read topic that defines the form
-        unless( $store->topicExists( $web, $form ) ) {
+        unless( $TWiki::STORE->topicExists( $web, $form ) ) {
             return undef;
         }
         my( $meta, $text ) =
-          $store->readTopic( $session->{user}, $web, $form, undef );
+          $TWiki::STORE->readTopic( $TWiki::SESSION->{user}, $web, $form, undef );
 
         $this->{fields} = $this->_parseFormDefinition( $meta, $text );
 
@@ -112,14 +109,14 @@
             @posValues = split( /,/, $fieldDef->{value} );
             my $topic = $fieldDef->{definingTopic} || $fieldDef->{name};
             my( $fieldWeb, $fieldTopic ) =
-              $session->normalizeWebTopicName($web, $topic);
+              $TWiki::SESSION->normalizeWebTopicName($web, $topic);
             if (!scalar(@posValues)) {
-                if ( $store->topicExists( $fieldWeb, $fieldTopic ) ) {
+                if ( $TWiki::STORE->topicExists( $fieldWeb, $fieldTopic ) ) {
                     my( $meta, $text ) =
-                      $store->readTopic( $session->{user},
+                      $TWiki::STORE->readTopic( $TWiki::SESSION->{user},
                                          $fieldWeb, $fieldTopic, undef );
                     # Add processing of SEARCHES for Lists
-                    $text = $this->{session}->handleCommonTags(
+                    $text = $TWiki::SESSION->handleCommonTags(
                         $text, $this->{web}, $this->{topic}, $meta);
                     @posValues = _getPossibleFieldValues( $text );
                     $fieldDef->{type} ||= 'select';  #FIXME keep?
@@ -146,7 +143,6 @@
 sub _parseFormDefinition {
     my( $this, $meta, $text ) = @_;
 
-    my $store = $this->{session}->{store};
     my @fields = ();
     my $inBlock = 0;
     $text =~ s/\\\r?\n//go; # remove trailing '\' and join continuation lines
@@ -188,7 +184,7 @@
             }
 
             $vals ||= '';
-            $vals = $this->{session}->handleCommonTags(
+            $vals = $TWiki::SESSION->handleCommonTags(
                 $vals, $this->{web}, $this->{topic}, $meta);
             $vals =~ s/<\/?(nop|noautolink)\/?>//go;
             $vals =~ s/^\s*//go;
@@ -198,7 +194,7 @@
             if( $vals eq '$users' ) {
                 $vals = $TWiki::cfg{UsersWebName} . '.' .
                   join( ", ${TWiki::cfg{UsersWebName}}.",
-                        ( $store->getTopicNames( $TWiki::cfg{UsersWebName} ) ) );
+                        ( $TWiki::STORE->getTopicNames( $TWiki::cfg{UsersWebName} ) ) );
             }
 
             $tooltip ||= '';
@@ -237,12 +233,6 @@
     return \@fields;
 }
 
-sub _searchVals {
-    my ( $session, $arg ) = @_;
-    $arg =~ s/%WEB%/$session->{webName}/go;
-    return $session->_SEARCH(new TWiki::Attrs($arg), $session->{topicName}, $session->{webName});
-}
-
 # Chop out all except A-Za-z0-9_.
 # I'm sure there must have been a good reason for this once.
 sub _cleanField {
@@ -292,27 +282,26 @@
     $string =~ s/[\[\]]//go;
 
     $topic ||= $string;
-    $tooltip ||= $this->{session}->{i18n}->maketext('Click to see details in separate window');
+    $tooltip ||= $TWiki::I18N->maketext('Click to see details in separate window');
 
     my $web;
     ( $web, $topic ) =
-      $this->{session}->normalizeWebTopicName( $this->{web}, $topic );
+      $TWiki::SESSION->normalizeWebTopicName( $this->{web}, $topic );
 
     my $link;
 
-    my $store = $this->{session}->{store};
-    if( $store->topicExists( $web, $topic ) ) {
+    if( $TWiki::STORE->topicExists( $web, $topic ) ) {
         $link =
           CGI::a(
               { target => $topic,
                 onclick => 'return launchWindow("'.$web.'","'.$topic.'")',
                 title => $tooltip,
-                href =>$this->{session}->getScriptUrl( 0, 'view',
+                href =>$TWiki::SESSION->getScriptUrl( 0, 'view',
                                                        $web, $topic ),
                 rel => 'nofollow'
                }, $string );
     } else {
-        my $expanded = $this->{session}->handleCommonTags(
+        my $expanded = $TWiki::SESSION->handleCommonTags(
             $string, $web, $topic, $meta );
         if ( $tooltip ) {
             $link = CGI::span ( { title => $tooltip }, $expanded );
@@ -341,14 +330,12 @@
     my( $this, $web, $topic, $meta ) = @_;
     ASSERT($this->isa( 'TWiki::Form')) if DEBUG;
     ASSERT($meta->isa( 'TWiki::Meta')) if DEBUG;
-    my $session = $this->{session};
 
-
     if( $this->{mandatoryFieldsPresent} ) {
-        $session->enterContext( 'mandatoryfields' );
+        $TWiki::SESSION->enterContext( 'mandatoryfields' );
     }
-    my $tmpl = $session->{templates}->readTemplate( "form" );
-    $tmpl = $session->handleCommonTags( $tmpl, $web, $topic, $meta );
+    my $tmpl = $TWiki::TEMPLATES->readTemplate( "form" );
+    $tmpl = $TWiki::SESSION->handleCommonTags( $tmpl, $web, $topic, $meta );
 
     # Note: if WEBFORMS preference is not set, can only delete form.
     $tmpl =~ s/%FORMTITLE%/$this->_link($meta, $this->{web}.'.'.$this->{topic})/geo;
@@ -364,8 +351,8 @@
             # Special handling for untitled labels
             my $tmp = $repeatUntitledText;
             my $value =
-              $session->{renderer}->getRenderedVersion(
-                  $session->handleCommonTags(
+              $TWiki::RENDER->getRenderedVersion(
+                  $TWiki::SESSION->handleCommonTags(
                       $fieldDef->{value}, $web, $topic, $meta ));
             $tmp =~ s/%ROWVALUE%/$value/go;
             $text .= $tmp;
@@ -383,7 +370,7 @@
                 # definition. Doesn't make sense for checkboxes.
                 $value = $fieldDef->{value};
                 if( defined( $value )) {
-                    $value = $session->handleCommonTags(
+                    $value = $TWiki::SESSION->handleCommonTags(
                         $value, $web, $topic, $meta );
                     $value = TWiki::expandStandardEscapes( $value ); # Item2837
                 }
@@ -429,7 +416,6 @@
     my $size = $fieldDef->{size};
     my $attributes = $fieldDef->{attributes} || '';
     my $extra = '';
-    my $session = $this->{session};
 
     if( $attributes =~ /M/ ) {
         $extra = CGI::span( { class => 'twikiAlert' }, ' *' );
@@ -443,7 +429,7 @@
     $name = $this->cgiName( $name );
 
     # Give plugin field types a chance first
-    my $output = $session->{plugins}->renderFormFieldForEditHandler
+    my $output = $TWiki::PLUGINS->renderFormFieldForEditHandler
       ( $name, $type, $size, $value, $attributes, $fieldDef->{value} );
 
     if( $output ) {
@@ -470,8 +456,8 @@
 				     -alt => 'Calendar',
 				     -class => 'twikiButton twikiEditFormCalendarButton' );
 	$value .= '%ENDTWISTY%';
-	$value = $session->{renderer}->getRenderedVersion(
-        $session->handleCommonTags( $value, $web, $topic ));
+	$value = $TWiki::RENDER->getRenderedVersion(
+        $TWiki::SESSION->handleCommonTags( $value, $web, $topic ));
       }
     } elsif( $type eq 'text' ) {
         $value = CGI::textfield( -class => 'twikiInputField twikiEditFormTextField',
@@ -486,8 +472,8 @@
         # take it from the text, we must be sure it cannot be
         # changed through the URL?
         # Pth: Changed labels through the URL is a feature for TWiki applications
-        my $renderedValue = $session->{renderer}->getRenderedVersion
-          ( $session->handleCommonTags( $value, $web, $topic ));
+        my $renderedValue = $TWiki::RENDER->getRenderedVersion
+          ( $TWiki::SESSION->handleCommonTags( $value, $web, $topic ));
         $value = CGI::hidden( -name => $name,
                               -value => $value );
         $value .= CGI::div( { class => 'twikiEditFormLabelField' },
@@ -576,12 +562,12 @@
             $extra = CGI::br();
             $extra .= CGI::button
               ( -class => 'twikiCheckBox twikiEditFormCheckboxButton',
-                -value => $session->{i18n}->maketext('Set all'),
+                -value => $TWiki::I18N->maketext('Set all'),
                 -onClick => 'checkAll(this,2,'.$boxes.',true)' );
             $extra .= '&nbsp;';
             $extra .= CGI::button
               ( -class => 'twikiCheckBox twikiEditFormCheckboxButton',
-                -value => $session->{i18n}->maketext('Clear all'),
+                -value => $TWiki::I18N->maketext('Clear all'),
                 -onClick => 'checkAll(this,1,'.$boxes.',false)');
         }
         my %isSelected = map { $_ => 1 } split(/\s*,\s*/, $value);
@@ -589,7 +575,7 @@
             #NOTE: Does not expand $item in label
             $attrs{$item} =
               { class => 'twikiEditFormCheckboxField',
-                label => $session->handleCommonTags(
+                label => $TWiki::SESSION->handleCommonTags(
                     $item, $web, $topic )
                };
 
@@ -617,7 +603,7 @@
         foreach $item ( @$options ) {
             $attrs{$item} =
               { class=>'twikiRadioButton twikiEditFormRadioField',
-                label=>$session->handleCommonTags(
+                label=>$TWiki::SESSION->handleCommonTags(
                     $item, $web, $topic ) };
 
             $selected = $item if( $item eq $value );
@@ -655,7 +641,6 @@
     my( $this, $meta ) = @_;
     ASSERT($this->isa( 'TWiki::Form')) if DEBUG;
     ASSERT($meta->isa( 'TWiki::Meta')) if DEBUG;
-    my $session = $this->{session};
 
     my $text = "";
 
@@ -737,8 +722,8 @@
 
         if (defined $value) {
             $seen++;
-            if ($this->{session}->inContext('edit')) {
-                $value  =  TWiki::expandStandardEscapes( $value );
+            if ($TWiki::SESSION->inContext('edit')) {
+                $value = TWiki::expandStandardEscapes( $value );
             }
         }
 
Index: TWiki/Client/TemplateLogin.pm
===================================================================
--- TWiki/Client/TemplateLogin.pm	(revision 13172)
+++ TWiki/Client/TemplateLogin.pm	(working copy)
@@ -36,20 +36,18 @@
 =cut
 
 package TWiki::Client::TemplateLogin;
+use base 'TWiki::Client';
 
 use strict;
 use Assert;
-use TWiki::Client;
 
-@TWiki::Client::TemplateLogin::ISA = ( 'TWiki::Client' );
-
 sub new {
-    my( $class, $session ) = @_;
+    my( $class ) = @_;
 
-    my $this = bless( $class->SUPER::new($session), $class );
-    $session->enterContext( 'can_login' );
+    my $this = bless( $class->SUPER::new(), $class );
+    $TWiki::SESSION->enterContext( 'can_login' );
     if ($TWiki::cfg{Sessions}{ExpireCookiesAfter}) {
-        $session->enterContext( 'can_remember_login' );
+        $TWiki::SESSION->enterContext( 'can_remember_login' );
     }
     return $this;
 }
@@ -57,17 +55,15 @@
 # Triggered on auth fail
 sub forceAuthentication {
     my $this = shift;
-    my $twiki = $this->{twiki};
 
-    unless( $twiki->inContext( 'authenticated' )) {
-        my $query = $twiki->{cgiQuery};
+    unless( $TWiki::SESSION->inContext( 'authenticated' )) {
+        my $query = $TWiki::SESSION->{cgiQuery};
         # Redirect with passthrough so we don't lose the original query params
-        my $twiki = $this->{twiki};
-        my $topic = $twiki->{topicName};
-        my $web = $twiki->{webName};
-        my $url = $twiki->getScriptUrl( 0, 'login', $web, $topic);
+        my $topic = $TWiki::SESSION->{topicName};
+        my $web = $TWiki::SESSION->{webName};
+        my $url = $TWiki::SESSION->getScriptUrl( 0, 'login', $web, $topic);
         $query->param( -name=>'origurl', -value=>$ENV{REQUEST_URI} );
-        $twiki->redirect( $url, 1 );
+        $TWiki::SESSION->redirect( $url, 1 );
         return 1;
     }
     return undef;
@@ -76,11 +72,10 @@
 # Content of a login link
 sub loginUrl {
     my $this = shift;
-    my $twiki = $this->{twiki};
-    my $topic = $twiki->{topicName};
-    my $web = $twiki->{webName};
-    my $query = $twiki->{cgiQuery};
-    return $twiki->getScriptUrl( 0, 'login', $web, $topic,
+    my $topic = $TWiki::SESSION->{topicName};
+    my $web = $TWiki::SESSION->{webName};
+    my $query = $TWiki::SESSION->{cgiQuery};
+    return $TWiki::SESSION->getScriptUrl( 0, 'login', $web, $topic,
                                  origurl => $ENV{REQUEST_URI} );
 }
 
@@ -107,8 +102,7 @@
 =cut
 
 sub login {
-    my( $this, $query, $twikiSession ) = @_;
-    my $twiki = $this->{twiki};
+    my( $this, $query ) = @_;
 
     my $origurl = $query->param( 'origurl' );
     my $loginName = $query->param( 'username' );
@@ -118,38 +112,39 @@
     # Eat these so there's no risk of accidental passthrough
     $query->delete('origurl', 'username', 'password');
 
-    my $tmpl = $twiki->{templates}->readTemplate(
-        'login', $twiki->getSkin() );
+    my $tmpl = $TWiki::TEMPLATES->readTemplate(
+        'login', $TWiki::SESSION->getSkin() );
 
-    my $banner = $twiki->{templates}->expandTemplate( 'LOG_IN_BANNER' );
+    my $banner = $TWiki::TEMPLATES->expandTemplate( 'LOG_IN_BANNER' );
     my $note = '';
-    my $topic = $twiki->{topicName};
-    my $web = $twiki->{webName};
+    my $topic = $TWiki::SESSION->{topicName};
+    my $web = $TWiki::SESSION->{webName};
 
     my $cgisession = $this->{_cgisession};
 
     $cgisession->param( 'REMEMBER', $remember ) if $cgisession;
     if( $cgisession && $cgisession->param( 'AUTHUSER' ) &&
           $loginName ne $cgisession->param( 'AUTHUSER' )) {
-        $banner = $twiki->{templates}->expandTemplate( 'LOGGED_IN_BANNER' );
-        $note = $twiki->{templates}->expandTemplate( 'NEW_USER_NOTE' );
+        $banner = $TWiki::TEMPLATES->expandTemplate( 'LOGGED_IN_BANNER' );
+        $note = $TWiki::TEMPLATES->expandTemplate( 'NEW_USER_NOTE' );
     }
 
     if( $loginName ) {
-        my $passwordHandler = $twiki->{users}->{passwords};
+        my $passwordHandler = $TWiki::USERS->{passwords};
         my $validation = $passwordHandler->checkPassword( $loginName, $loginPass );
 
         if( $validation ) {
             $this->userLoggedIn( $loginName );
             $cgisession->param( 'VALIDATION', $validation ) if $cgisession;
             if( !$origurl || $origurl eq $query->url() ) {
-                $origurl = $twiki->getScriptUrl( 0, 'view', $web, $topic );
+                $origurl = $TWiki::SESSION->getScriptUrl(
+                    0, 'view', $web, $topic );
             }
             # Redirect with passthrough
-            $twikiSession->redirect($origurl, 1 );
+            $TWiki::SESSION->redirect($origurl, 1 );
             return;
         } else {
-            $banner = $twiki->{templates}->expandTemplate('UNRECOGNISED_USER');
+            $banner = $TWiki::TEMPLATES->expandTemplate('UNRECOGNISED_USER');
         }
     }
 
@@ -160,10 +155,10 @@
     $tmpl =~ s/%BANNER%/$banner/g;
     $tmpl =~ s/%NOTE%/$note/g;
 
-    $tmpl = $twiki->handleCommonTags( $tmpl, $web, $topic );
-    $tmpl = $twiki->{renderer}->getRenderedVersion( $tmpl, '' );
+    $tmpl = $TWiki::SESSION->handleCommonTags( $tmpl, $web, $topic );
+    $tmpl = $TWiki::SESSION::RENDER->getRenderedVersion( $tmpl, '' );
     $tmpl =~ s/<nop>//g;
-    $twiki->writePageHeader( $query );
+    $TWiki::SESSION->writePageHeader( $query );
     print $tmpl;
 }
 
Index: TWiki/Client/ApacheLogin.pm
===================================================================
--- TWiki/Client/ApacheLogin.pm	(revision 13172)
+++ TWiki/Client/ApacheLogin.pm	(working copy)
@@ -41,16 +41,15 @@
 =cut
 
 package TWiki::Client::ApacheLogin;
+use base 'TWiki::Client';
 
 use strict;
 use Assert;
 
-@TWiki::Client::ApacheLogin::ISA = qw( TWiki::Client );
-
 sub new {
-    my( $class, $twiki ) = @_;
-    my $this = bless( $class->SUPER::new($twiki), $class );
-    $twiki->enterContext( 'can_login', 1 );
+    my( $class ) = @_;
+    my $this = bless( $class->SUPER::new(), $class );
+    $TWiki::SESSION->enterContext( 'can_login', 1 );
     # Can't logout, though
     TWiki::registerTagHandler('LOGOUT', sub { return '' });
     return $this;
@@ -59,8 +58,7 @@
 sub forceAuthentication {
     my $this = shift;
 
-    my $twiki = $this->{twiki};
-    my $query = $twiki->{cgiQuery};
+    my $query = $TWiki::SESSION->{cgiQuery};
 
     # See if there is an 'auth' version
     # of this script, may be a result of not being logged in.
@@ -79,22 +77,22 @@
         if( $url && $url =~ m!(.*/$scriptName)([^?]*)! ) {
             # $url should not contain query string as it gets appended
             # in TWiki::redirect. Script gets 'auth' appended.
-            $url = "$twiki->{urlHost}${1}auth$2";
+            $url = "$TWiki::SESSION->{urlHost}${1}auth$2";
         } else {
             if( $ENV{SCRIPT_NAME} &&
                    $ENV{SCRIPT_NAME} =~ s/\/$scriptName/\/${scriptName}auth/ ) {
-                $url = $twiki->{urlHost}.$ENV{SCRIPT_NAME};
+                $url = $TWiki::SESSION->{urlHost}.$ENV{SCRIPT_NAME};
             } else {
                 # If SCRIPT_NAME does not contain the script name
                 # the last hope is to try building up the URL using
                 # the SCRIPT_FILENAME.
-                $url = $twiki->{urlHost}.$twiki->{scriptUrlPath}.'/'.
+                $url = $TWiki::SESSION->{urlHost}.$TWiki::SESSION->{scriptUrlPath}.'/'.
                        $scriptName.'auth'.$TWiki::cfg{ScriptSuffix};
             }
             $url .= '/' . $ENV{PATH_INFO} if $ENV{PATH_INFO};
         }
         # Redirect with passthrough so we don't lose the original query params
-        $twiki->redirect( $url, 1 );
+        $TWiki::SESSION->redirect( $url, 1 );
         return 1;
     }
 
@@ -103,15 +101,14 @@
 
 sub loginUrl {
     my $this = shift;
-    my $twiki = $this->{twiki};
-    my $topic = $twiki->{topicName};
-    my $web = $twiki->{webName};
-    return $twiki->getScriptUrl( 0, 'logon', $web, $topic, @_ );
+    my $topic = $TWiki::SESSION->{topicName};
+    my $web = $TWiki::SESSION->{webName};
+    return $TWiki::SESSION->getScriptUrl( 0, 'logon', $web, $topic, @_ );
 }
 
 sub getUser {
     my $this = shift;
-    my $query = $this->{twiki}->{cgiQuery};
+    my $query = $TWiki::SESSION->{cgiQuery};
     my $authUser;
     # Ignore remote user if we got here via an error
     unless (($ENV{REDIRECT_STATUS} || 0) >= 400 ) {
Index: TWiki/I18N/Extract.pm
===================================================================
--- TWiki/I18N/Extract.pm	(revision 13172)
+++ TWiki/I18N/Extract.pm	(working copy)
@@ -42,25 +42,20 @@
 
 =pod
 
----++ ClassMethod new ( $session ) -> $extract
+---++ ClassMethod new() -> $extract
 
-Constructor. Creates a fresh new Extract object. A $session object, instance of
-the TWiki class, is optional: if it's available, it'll be used for printing
-warnings.
-
+Constructor. Creates a fresh new Extract object.
 =cut
 
 sub new {
     my $class = shift;
-    my $session = shift;
 
     unless ( $initialised ) {
-        $session->writeWarning ( $initError ) if $session;
+        $TWiki::SESSION->writeWarning ( $initError );
         return undef;
     }
 
     my $self = new Locale::Maketext::Extract;
-    $self->{session} = $session;
     return bless($self, $class);
 }
 
Index: TWiki/I18N.pm
===================================================================
--- TWiki/I18N.pm	(revision 13172)
+++ TWiki/I18N.pm	(working copy)
@@ -109,19 +109,16 @@
 
 =pod
 
----++ ClassMethod get ( $session )
+---++ ClassMethod get ()
 
 Constructor. Gets the language object corresponding to the current user's language.
 
 =cut
 
 sub get {
-    my $session  = shift;
-    ASSERT($session->isa( 'TWiki')) if DEBUG;
-
     unless ($initialised) {
         foreach my $error (@initErrors) {
-            $session->writeWarning($error);
+            $TWiki::SESSION->writeWarning($error);
         }
     }
 
@@ -131,8 +128,8 @@
     #   browser.
     my $this;
     if ($initialised) {
-        $session->enterContext( 'i18n_enabled' );
-        my $userLanguage = _normalize_language_tag($session->{prefs}->getPreferencesValue('LANGUAGE'));
+        $TWiki::SESSION->enterContext( 'i18n_enabled' );
+        my $userLanguage = _normalize_language_tag($TWiki::PREFS->getPreferencesValue('LANGUAGE'));
         if ($userLanguage) {
             $this = TWiki::I18N->get_handle($userLanguage);
         } else {
@@ -145,13 +142,10 @@
 
         # we couldn't initialise 'optional' I18N infrastructure, warn that we
         # can only use English if I18N has been requested with configure
-        $session->writeWarning('Could not load I18N infrastructure; falling back to English')
+        $TWiki::SESSION->writeWarning('Could not load I18N infrastructure; falling back to English')
           if $TWiki::cfg{UserInterfaceInternationalisation};
     }
 
-    # keep a reference to the session object
-    $this->{session} = $session;
-
     # languages we know about
     $this->{enabled_languages} = { en => 'English' };
     $this->{checked_enabled}   = undef;
@@ -204,7 +198,7 @@
     }
 
     my $result = $this->SUPER::maketext($text, @args);
-    if ($result && $this->{session}) {
+    if ($result) {
         # external calls get the resultant text in the right charset:
         $result = $this->toSiteCharSet($result);
     }
@@ -311,7 +305,7 @@
                                              -charset => $encoding
                                             });
         } else {
-          $this->{session}->writeWarning
+          $TWiki::SESSION->writeWarning
             ( 'Conversion from $encoding no supported, '.
               'or name not recognised - check perldoc Unicode::MapUTF8' );
           return $text;
@@ -322,7 +316,7 @@
         import Encode;
         my $encoding = Encode::resolve_alias ( $TWiki::cfg{Site}{CharSet} );
         if ( not $encoding ) {
-            $this->{session}->writeWarning
+            $TWiki::SESSION->writeWarning
               ( 'Conversion to "'.$TWiki::cfg{Site}{CharSet}.
                 '" not supported, or name not recognised - check '.
                 '"perldoc Encode::Supported"' );
@@ -367,7 +361,7 @@
                                              -charset => $encoding
                                             });
         } else {
-          $this->{session}->writeWarning
+          $TWiki::SESSION->writeWarning
             ( 'Conversion to $encoding no supported, '.
               'or name not recognised - check perldoc Unicode::MapUTF8' );
           return $encoded;
@@ -377,7 +371,7 @@
         import Encode;
         my $encoding = Encode::resolve_alias ( $TWiki::cfg{Site}{CharSet} );
         if ( not $encoding ) {
-            $this->{session}->writeWarning
+            $TWiki::SESSION->writeWarning
               ( 'Conversion from "'.$TWiki::cfg{Site}{CharSet}.
                 '" not supported, or name not recognised - check '.
                 '"perldoc Encode::Supported"' );
Index: TWiki/Users/HtPasswdUser.pm
===================================================================
--- TWiki/Users/HtPasswdUser.pm	(revision 13172)
+++ TWiki/Users/HtPasswdUser.pm	(working copy)
@@ -53,8 +53,8 @@
 }
 
 sub new {
-    my( $class, $session) = @_;
-    my $this = bless( $class->SUPER::new($session), $class );
+    my( $class ) = @_;
+    my $this = bless( $class->SUPER::new(), $class );
     $this->{error} = undef;
     if( $TWiki::cfg{Htpasswd}{Encoding} eq 'md5' ) {
         require Digest::MD5;
Index: TWiki/Users/ApacheHtpasswdUser.pm
===================================================================
--- TWiki/Users/ApacheHtpasswdUser.pm	(revision 13172)
+++ TWiki/Users/ApacheHtpasswdUser.pm	(working copy)
@@ -42,9 +42,9 @@
 =cut
 
 sub new {
-    my( $class, $session ) = @_;
+    my( $class ) = @_;
 
-    my $this = bless( $class->SUPER::new( $session ), $class );
+    my $this = bless( $class->SUPER::new( ), $class );
     $this->{apache} = new Apache::Htpasswd
       ( { passwdFile => $TWiki::cfg{Htpasswd}{FileName} } );
     $this->{error} = undef;
Index: TWiki/Users/Password.pm
===================================================================
--- TWiki/Users/Password.pm	(revision 13172)
+++ TWiki/Users/Password.pm	(working copy)
@@ -36,18 +36,16 @@
 
 =pod
 
----++ ClassMethod new( $session ) -> $object
+---++ ClassMethod new() -> $object
 
-Constructs a new password handler of this type, referring to $session
-for any required TWiki services.
+Constructs a new password handler of this type.
 
 =cut
 
 sub new {
-    my( $class, $session ) = @_;
+    my( $class ) = @_;
 
     my $this = bless( {}, $class );
-    $this->{session} = $session;
     return $this;
 }
 
@@ -180,11 +178,11 @@
 sub getEmails {
     my( $this, $login ) = @_;
 
-    my $user = $this->{session}->{users}->findUser( $login, undef, 1 );
+    my $user = $TWiki::USERS->findUser( $login, undef, 1 );
     return () unless $user;
 
     my ($meta, $text) =
-      $this->{session}->{store}->readTopic(
+      $TWiki::STORE->readTopic(
           undef, $TWiki::cfg{UsersWebName}, $user->wikiName() );
 
     my @addresses;
@@ -218,11 +216,11 @@
     my $login = shift;
     my $mails = join( ';', @_ );
 
-    my $user = $this->{session}->{users}->findUser( $login, undef, 1 );
+    my $user = $TWiki::USERS->findUser( $login, undef, 1 );
     return () unless $user;
 
     my ($meta, $text) =
-      $this->{session}->{store}->readTopic(
+      $TWiki::STORE->readTopic(
           undef, $TWiki::cfg{UsersWebName}, $user->wikiName() );
 
     if ($meta->get('FORM')) {
@@ -239,7 +237,7 @@
         }
     }
 
-    $this->{session}->{store}->saveTopic( $user, $TWiki::cfg{UsersWebName},
+    $TWiki::STORE->saveTopic( $user, $TWiki::cfg{UsersWebName},
                                   $user->wikiName(), $text, $meta );
 }
 
@@ -251,7 +249,7 @@
     # we have to cheat. We do this as follows:
     unless( $this->{_MAP_OF_EMAILS} ) {
         $this->{_MAP_OF_EMAILS} = ();
-        my $it = $this->{session}->{users}->eachUser();
+        my $it = $TWiki::USERS->eachUser();
         while( $it->hasNext() ) {
             my $uo = $it->next();
 ASSERT($uo->isa('TWiki::User'));
Index: TWiki/Users/TWikiUserMapping.pm
===================================================================
--- TWiki/Users/TWikiUserMapping.pm	(revision 13172)
+++ TWiki/Users/TWikiUserMapping.pm	(working copy)
@@ -51,18 +51,16 @@
 
 =pod
 
----++ ClassMethod new( $session ) -> $object
+---++ ClassMethod new( ) -> $object
 
-Constructs a new user mapping handler of this type, referring to $session
-for any required TWiki services.
+Constructs a new user mapping handler of this type
 
 =cut
 
 sub new {
-    my( $class, $session ) = @_;
+    my( $class ) = @_;
 
     my $this = bless( {}, $class );
-    $this->{session} = $session;
 
     %{$this->{U2W}} = ();
     %{$this->{W2U}} = ();
@@ -90,7 +88,7 @@
     my $ref = shift;
     my $group = shift;
     return unless $group;
-    my $groupObject = $ref->{users}->findUser( $group );
+    my $groupObject = $TWiki::USERS->findUser( $group );
     push (@{$ref->{list}}, $groupObject) if $groupObject;
 }
 
@@ -100,10 +98,10 @@
     ASSERT(ref($this) eq 'TWiki::Users::TWikiUserMapping') if DEBUG;
 
     unless( $this->{groupsList} ) {
-        my $users = $this->{session}->{users};
+        my $users = $TWiki::USERS;
         $this->{groupsList} = [];
 
-        $this->{session}->{search}->searchWeb
+        $TWiki::SEARCH->searchWeb
           (
               _callback     => \&_collateGroups,
               _cbdata       =>  { list => $this->{groupsList},
@@ -147,7 +145,7 @@
     ASSERT($user->isa( 'TWiki::User')) if DEBUG;
     ASSERT($me->isa( 'TWiki::User')) if DEBUG;
 
-    my $store = $this->{session}->{store};
+    my $store = $TWiki::STORE;
     my( $meta, $text ) =
       $store->readTopic( undef, $TWiki::cfg{UsersWebName},
                          $TWiki::cfg{UsersTopicName}, undef );
@@ -259,8 +257,8 @@
     ASSERT($this->isa( 'TWiki::Users::TWikiUserMapping')) if DEBUG;
 
     $this->_loadMapping();
-    my $users = $this->{session}->{users};
-    my @list = map { $users->findUser($_) } keys(%{$this->{W2U}});
+
+    my @list = map { $TWiki::USERS->findUser($_) } keys(%{$this->{W2U}});
     return new TWiki::ListIterator( \@list );
 }
 
@@ -287,7 +285,7 @@
     return if $this->{CACHED};
     $this->{CACHED} = 1;
 
-    my $store = $this->{session}->{store};
+    my $store = $TWiki::STORE;
     if( $store->topicExists($TWiki::cfg{UsersWebName},
                             $TWiki::cfg{UsersTopicName} )) {
         my $text = $store->readTopicRaw( undef,
@@ -337,7 +335,7 @@
     my $this = shift;
     my $group = shift;
     ASSERT($this->isa( 'TWiki::Users::TWikiUserMapping')) if DEBUG;
-    my $store = $this->{session}->{store};
+    my $store = $TWiki::STORE;
 
     if( !defined $group->{members} &&
           $store->topicExists( $group->{web}, $group->{wikiname} )) {
@@ -351,7 +349,7 @@
                 # Note: if there are multiple GROUP assignments in the
                 # topic, only the last will be taken.
                 $group->{members} = 
-                  $this->{session}->{users}->expandUserList( $2 );
+                  $TWiki::USERS->expandUserList( $2 );
             }
         }
         # backlink the user to the group
Index: TWiki/Net.pm
===================================================================
--- TWiki/Net.pm	(revision 13172)
+++ TWiki/Net.pm	(working copy)
@@ -37,11 +37,9 @@
 use vars qw( $LWPavailable );
 
 sub new {
-    my ( $class, $session ) = @_;
-    ASSERT($session->isa( 'TWiki')) if DEBUG;
+    my $class = shift;
     my $this = bless( {}, $class );
 
-    $this->{session} = $session;
     $this->{mailHandler} = undef;
 
     return $this;
@@ -147,7 +145,7 @@
             $req .= "Authorization: Basic $base64";
         }
 
-        my $prefs = $this->{session}->{prefs};
+        my $prefs = $TWiki::PREFS;
         my $proxyHost = $prefs->getPreferencesValue('PROXYHOST') ||
           $TWiki::cfg{PROXY}{HOST};
         my $proxyPort = $prefs->getPreferencesValue('PROXYPORT') ||
@@ -225,7 +223,7 @@
 sub _installMailHandler {
     my $this = shift;
     my $handler = 0; # Not undef
-    my $prefs = $this->{session}->{prefs};
+    my $prefs = $TWiki::PREFS;
 
     $this->{MAIL_HOST}  = $prefs->getPreferencesValue( 'SMTPMAILHOST' ) ||
       $TWiki::cfg{SMTP}{MAILHOST};
@@ -242,7 +240,7 @@
             require Net::SMTP;
         };
         if( $@ ) {
-            $this->{session}->writeWarning( "SMTP not available: $@" );
+            $TWiki::SESSION->writeWarning( "SMTP not available: $@" );
         } else {
             $handler = \&_sendEmailByNetSMTP;
         }
@@ -312,7 +310,7 @@
             # caused by SMTP or perl, and give away info about the
             # install that we don't want to share.
             unless( $e =~ /^ERROR/ ) {
-                $this->{session}->writeWarning( $e );
+                $TWiki::SESSION->writeWarning( $e );
                 $e = "Mail could not be sent - see TWiki warning log.";
             }
             $errors .= $e."\n";
Index: TWiki/Store.pm
===================================================================
--- TWiki/Store.pm	(revision 13172)
+++ TWiki/Store.pm	(working copy)
@@ -69,13 +69,9 @@
 =cut
 
 sub new {
-    my ( $class, $session ) = @_;
-    ASSERT($session->isa('TWiki')) if DEBUG;
-
+    my ( $class ) = @_;
     my $this = bless( {}, $class );
 
-    $this->{session} = $session;
-
     $this->{IMPL} = 'TWiki::Store::'.$TWiki::cfg{StoreImpl};
     eval 'use '.$this->{IMPL};
     if( $@ ) {
@@ -107,7 +103,7 @@
 sub _getHandler {
     my( $this, $web, $topic, $attachment ) = @_;
 
-    return $this->{IMPL}->new( $this->{session}, $web, $topic, $attachment );
+    return $this->{IMPL}->new( $web, $topic, $attachment );
 }
 
 =pod
@@ -141,16 +137,17 @@
     }
 
     my $text = $this->readTopicRaw( $user, $web, $topic, $version );
-    my $meta = new TWiki::Meta( $this->{session}, $web, $topic);
+    my $meta = new TWiki::Meta( $web, $topic);
     $this->extractMetaData( $meta, \$text );
 
     # Override meta with that blended from pub.
     if ($TWiki::cfg{AutoAttachPubFiles} &&
-        $web eq $this->{session}{webName} && # only check the currently requested topic
-        $topic eq $this->{session}{topicName}) {
+        $web eq $TWiki::SESSION->{webName} && # only check the currently requested topic
+        $topic eq $TWiki::SESSION->{topicName}) {
 
       my @knownAttachments = $meta->find('FILEATTACHMENT');
-      my @attachmentsFoundInPub = _findAttachments($this, $web, $topic, \@knownAttachments);
+      my @attachmentsFoundInPub = $this->_findAttachments(
+          $web, $topic, \@knownAttachments);
       $meta->putAll('FILEATTACHMENT', @attachmentsFoundInPub) if @attachmentsFoundInPub;
     }
 
@@ -159,7 +156,7 @@
 
 =pod 
 
----++ ObjectMethod _findAttachments($session, $web, $topic, $knownAttachments) -> @attachmentsFoundInPub
+---++ ObjectMethod _findAttachments($web, $topic, $knownAttachments) -> @attachmentsFoundInPub
 
 Synchronise the attachment list with what's actually on disk Returns an ARRAY
 of FILEATTACHMENTs. These can be put in the new meta using
@@ -176,12 +173,8 @@
 
 sub _findAttachments {
     my ($this, $web, $topic, $attachmentsKnownInMeta) = @_;
-    my $session = $this->{session};
-    ASSERT($session->isa( 'TWiki' )) if DEBUG;
 
-    my $store = $this;
-
-    my %filesListedInPub = $store->getAttachmentList($web, $topic);
+    my %filesListedInPub = $this->getAttachmentList($web, $topic);
     my %filesListedInMeta = ();
 
     # You need the following lines if you want metadata to supplement
@@ -253,7 +246,7 @@
 
     # test if topic contains a webName to override $web
     ( $web, $topic ) =
-      $this->{session}->normalizeWebTopicName( $web, $topic );
+      $TWiki::SESSION->normalizeWebTopicName( $web, $topic );
 
     my $text;
 
@@ -267,11 +260,11 @@
     # Note: passing undef as meta will cause extraction of the meta
     # from the (raw) text passed
     if( $user &&
-          !$this->{session}->{security}->checkAccessPermission
+          !$TWiki::ACCESS->checkAccessPermission
             ( 'VIEW', $user, $text, undef, $topic, $web )) {
         throw TWiki::AccessControlException(
             'VIEW', $user, $web, $topic,
-            $this->{session}->{security}->getReason());
+            $TWiki::ACCESS->getReason());
     }
 
     return $text;
@@ -299,20 +292,20 @@
     try {
         my( $ometa, $otext ) = $this->readTopic( undef, $oldWeb, $oldTopic );
         if( $user &&
-              !$this->{session}->{security}->checkAccessPermission
+              !$TWiki::ACCESS->checkAccessPermission
                 ( 'CHANGE', $user, $otext, $ometa, $oldTopic, $oldWeb )) {
             throw TWiki::AccessControlException(
                 'CHANGE', $user, $oldWeb, $oldTopic,
-                $this->{session}->{security}->getReason());
+                $TWiki::ACCESS->getReason());
         }
 
         my ( $nmeta, $ntext ) = $this->readTopic( undef, $newWeb, $newTopic );
         if( $user &&
-              !$this->{session}->{security}->checkAccessPermission
+              !$TWiki::ACCESS->checkAccessPermission
                 ( 'CHANGE', $user, $ntext, $nmeta, $newTopic, $newWeb )) {
             throw TWiki::AccessControlException(
                 'CHANGE', $user, $newWeb, $newTopic,
-                $this->{session}->{security}->getReason());
+                $TWiki::ACCESS->getReason());
         }
 
         # Remove file attachment from old topic
@@ -339,7 +332,7 @@
                                 $nmeta, { dontlog => 1,
                                           notify => 0,
                                           comment => 'moved' } );
-        $this->{session}->writeLog(
+        $TWiki::SESSION->writeLog(
             'move',
             $fileAttachment->{movefrom}.' moved to '.
               $fileAttachment->{movedto}, $user->webDotWikiName() );
@@ -349,7 +342,7 @@
     };
 
     # alert plugins of attachment move
-    $this->{session}->{plugins}->afterRenameHandler( $oldWeb, $oldTopic, $oldAttachment,
+    $TWiki::PLUGINS->afterRenameHandler( $oldWeb, $oldTopic, $oldAttachment,
                                                      $newWeb, $newTopic, $newAttachment );
 }
 
@@ -377,10 +370,10 @@
     ASSERT($this->isa('TWiki::Store')) if DEBUG;
 
     if( $user &&
-          !$this->{session}->{security}->checkAccessPermission
+          !$TWiki::ACCESS->checkAccessPermission
             ( 'VIEW', $user, undef, undef, $topic, $web )) {
         throw TWiki::AccessControlException( 'VIEW', $user, $web, $topic,
-                                             $this->{session}->{security}->getReason());
+                                             $TWiki::ACCESS->getReason());
     }
 
     my $handler = $this->_getHandler( $web, $topic, $att );
@@ -456,12 +449,12 @@
         my $otext = $this->readTopicRaw( undef, $oldWeb, $oldTopic );
         # Note: undef $meta param will cause $otext to be parsed for meta
         if( $user &&
-              !$this->{session}->{security}->checkAccessPermission
+              !$TWiki::ACCESS->checkAccessPermission
                 ( 'CHANGE', $user, $otext, undef, $oldTopic, $oldWeb )) {
             throw TWiki::AccessControlException(
                 'CHANGE', $user,
                 $oldWeb, $oldTopic,
-                $this->{session}->{security}->getReason());
+                $TWiki::ACCESS->getReason());
         }
 
         my ( $nmeta, $ntext );
@@ -469,11 +462,11 @@
             ( $nmeta, $ntext ) = $this->readTopic( undef, $newWeb, $newTopic );
         }
         if( $user &&
-              !$this->{session}->{security}->checkAccessPermission
+              !$TWiki::ACCESS->checkAccessPermission
                 ( 'CHANGE', $user, $ntext, $nmeta, $newTopic, $newWeb )) {
             throw TWiki::AccessControlException(
                 'CHANGE', $user, $newWeb, $newTopic,
-                $this->{session}->{security}->getReason());
+                $TWiki::ACCESS->getReason());
         }
 
         $handler->moveTopic( $newWeb, $newTopic );
@@ -492,11 +485,11 @@
     if( $TWiki::cfg{Log}{rename} ) {
         my $old = $oldWeb.'.'.$oldTopic;
         my $new = $newWeb.'.'.$newTopic;
-        $this->{session}->writeLog( 'rename', $old, "moved to $new", $user );
+        $TWiki::SESSION->writeLog( 'rename', $old, "moved to $new", $user );
     }
 
     # alert plugins of topic move
-    $this->{session}->{plugins}->afterRenameHandler( $oldWeb, $oldTopic, '',
+    $TWiki::PLUGINS->afterRenameHandler( $oldWeb, $oldTopic, '',
                                                      $newWeb, $newTopic, '' );
 }
 
@@ -564,11 +557,11 @@
 
     # Log rename
     if( $TWiki::cfg{Log}{rename} ) {
-        $this->{session}->writeLog( 'renameweb', $oldWeb, 'moved to '.$newWeb, $user );
+        $TWiki::SESSION->writeLog( 'renameweb', $oldWeb, 'moved to '.$newWeb, $user );
     }
 
     # alert plugins of web move
-    $this->{session}->{plugins}->afterRenameHandler( $oldWeb, '', '', $newWeb, '', '' );
+    $TWiki::PLUGINS->afterRenameHandler( $oldWeb, '', '', $newWeb, '', '' );
 }
 
 =pod
@@ -592,11 +585,11 @@
     ASSERT($this->isa('TWiki::Store')) if DEBUG;
 
     if( $user &&
-          !$this->{session}->{security}->checkAccessPermission
+          !$TWiki::ACCESS->checkAccessPermission
             ( 'VIEW', $user, undef, undef, $topic, $web )) {
         throw TWiki::AccessControlException(
             'VIEW', $user, $web, $topic,
-            $this->{session}->{security}->getReason());
+            $TWiki::ACCESS->getReason());
     }
 
     my $handler = $this->_getHandler( $web, $topic, $attachment );
@@ -733,7 +726,7 @@
       $handler->getRevisionInfo( $rev );
     $rev = $rrev;
 
-    $user = $this->{session}->{users}->findUser( $user ) if $user;
+    $user = $TWiki::USERS->findUser( $user ) if $user;
 
     return ( $date, $user, $rev, $comment );
 }
@@ -849,16 +842,16 @@
     $options = {} unless defined( $options );
 
     if( $user &&
-          !$this->{session}->{security}->checkAccessPermission
+          !$TWiki::ACCESS->checkAccessPermission
             ( 'CHANGE', $user, undef, undef, $topic, $web )) {
         throw TWiki::AccessControlException(
             'CHANGE', $user, $web, $topic,
-            $this->{session}->{security}->getReason());
+            $TWiki::ACCESS->getReason());
     }
-    my $plugins = $this->{session}->{plugins};
+
     # Semantics inherited from Cairo. See
     # TWiki:Codev.BugBeforeSaveHandlerBroken
-    if( $plugins->haveHandlerFor( 'beforeSaveHandler' )) {
+    if( $TWiki::PLUGINS->haveHandlerFor( 'beforeSaveHandler' )) {
         my $before = '';
         if( $meta ) {
             # write the meta into the topic text. Nasty compatibility
@@ -866,9 +859,9 @@
             $text = _writeMeta( $meta, $text );
             $before = $meta->stringify();
         }
-        $plugins->beforeSaveHandler( $text, $topic, $web, $meta );
+        $TWiki::PLUGINS->beforeSaveHandler( $text, $topic, $web, $meta );
         # remove meta again
-        my $after = new TWiki::Meta( $this->{session}, $web, $topic);
+        my $after = new TWiki::Meta( $web, $topic);
         $this->extractMetaData( $after, \$text );
         # If there are no changes in the $meta object, take the meta
         # from the text. Nasty compatibility requirement.
@@ -885,11 +878,11 @@
 
     # Semantics inherited from Cairo. See
     # TWiki:Codev.BugBeforeSaveHandlerBroken
-    if( $plugins->haveHandlerFor( 'afterSaveHandler' )) {
+    if( $TWiki::PLUGINS->haveHandlerFor( 'afterSaveHandler' )) {
         if( $meta ) {
             $text = _writeMeta( $meta, $text );
         }
-        $plugins->afterSaveHandler( $text, $topic, $web,
+        $TWiki::PLUGINS->afterSaveHandler( $text, $topic, $web,
                                     $error?$error->{-text}:'', $meta );
     }
 
@@ -928,7 +921,6 @@
     ASSERT($user->isa('TWiki::User')) if DEBUG;
     ASSERT(defined($opts)) if DEBUG;
     my $action;
-    my $plugins = $this->{session}->{plugins};
     my $attrs;
 
     $this->lockTopic( $user, $web, $topic );
@@ -938,12 +930,12 @@
         my( $meta, $text ) = $this->readTopic( undef, $web, $topic, undef );
 
         if( $user &&
-              !$this->{session}->{security}->checkAccessPermission
+              !$TWiki::ACCESS->checkAccessPermission
                 ( 'CHANGE', $user, $text, $meta, $topic, $web )) {
 
             throw TWiki::AccessControlException(
                 'CHANGE', $user, $web, $topic,
-                $this->{session}->{security}->getReason());
+                $TWiki::ACCESS->getReason());
         }
 
         if( $opts->{file} && !$opts->{stream} ) {
@@ -967,7 +959,7 @@
 
             my $tmpFile;
 
-            if( $plugins->haveHandlerFor( 'beforeAttachmentSaveHandler' )) {
+            if( $TWiki::PLUGINS->haveHandlerFor( 'beforeAttachmentSaveHandler' )) {
                 # SMELL: legacy spec of beforeAttachmentSaveHandler requires
                 # a local copy of the stream. This could be a problem for
                 # very big data files.
@@ -987,7 +979,7 @@
                 }
                 close( $fh );
                 $attrs->{tmpFilename} = $tmpFile;
-                $plugins->beforeAttachmentSaveHandler( $attrs, $topic, $web );
+                $TWiki::PLUGINS->beforeAttachmentSaveHandler( $attrs, $topic, $web );
                 open( $opts->{stream}, "<$tmpFile" );
                 binmode( $opts->{stream} );
             }
@@ -1002,8 +994,8 @@
 
             unlink( $tmpFile ) if( $tmpFile && -e $tmpFile );
 
-            if( $plugins->haveHandlerFor( 'afterAttachmentSaveHandler' )) {
-                $plugins->afterAttachmentSaveHandler( $attrs, $topic, $web,
+            if( $TWiki::PLUGINS->haveHandlerFor( 'afterAttachmentSaveHandler' )) {
+                $TWiki::PLUGINS->afterAttachmentSaveHandler( $attrs, $topic, $web,
                                                       $error ? 
                                                         $error->{-text} : '' );
             }
@@ -1029,7 +1021,7 @@
         }
 
         if( $opts->{createlink} ) {
-            $text .= $this->{session}->{attach}->getAttachmentLink(
+            $text .= $TWiki::ATTACH->getAttachmentLink(
                 $user, $web, $topic, $attachment, $meta );
         }
 
@@ -1040,7 +1032,7 @@
     };
 
     if ( ( ! $opts->{dontlog} ) && ( $TWiki::cfg{Log}{$action} ) ) {
-        $this->{session}->writeLog( $action, $web.'.'.$topic, $attachment, $user );
+        $TWiki::SESSION->writeLog( $action, $web.'.'.$topic, $attachment, $user );
     }
 }
 
@@ -1051,7 +1043,7 @@
 
     ASSERT($user->isa('TWiki::User')) if DEBUG;
 
-    $meta ||= new TWiki::Meta( $this->{session}, $web, $topic );
+    $meta ||= new TWiki::Meta( $web, $topic );
 
     my $handler = $this->_getHandler( $web, $topic );
     my $currentRev = $handler->numRevisions() || 0;
@@ -1095,7 +1087,7 @@
         $this->_recordChange( $web, $topic, $user, $nextRev, $extra );
 
         if( ( $TWiki::cfg{Log}{save} ) && ! ( $options->{dontlog} ) ) {
-            $this->{session}->writeLog( 'save', $web.'.'.$topic,
+            $TWiki::SESSION->writeLog( 'save', $web.'.'.$topic,
                                         $extra, $user );
         }
     } finally {
@@ -1165,7 +1157,7 @@
         my $extra = "repRev $rev by " . $revuser->login() .
             ' '. TWiki::Time::formatTime( $revdate, '$rcs', 'gmtime' );
         $extra   .= ' minor' if( $options->{minor} );
-        $this->{session}->writeLog( $options->{operation} || 'save',
+        $TWiki::SESSION->writeLog( $options->{operation} || 'save',
                                     $web.'.'.$topic, $extra, $user );
     }
 }
@@ -1210,7 +1202,7 @@
     # TODO: delete entry in .changes
 
     # write log entry
-    $this->{session}->writeLog( 'cmd', $web.'.'.$topic, 'delRev by '.
+    $TWiki::SESSION->writeLog( 'cmd', $web.'.'.$topic, 'delRev by '.
                                   $user->login().": $rev", $user );
 }
 
@@ -1243,14 +1235,14 @@
     while ( 1 ) {
         my ( $user, $time ) = $handler->isLocked();
         last if ( !$user || $locker->wikiName() eq $user );
-        $this->{session}->writeWarning( "Lock on $web.$topic for ".
+        $TWiki::SESSION->writeWarning( "Lock on $web.$topic for ".
                                           $locker->wikiName().
                                             " denied by $user" );
         # see how old the lock is. If it's older than 2 minutes,
         # break it anyway. Locks are atomic, and should never be
         # held that long, by _any_ process.
         if ( time() - $time > 2 * 60 ) {
-            $this->{session}->writeWarning
+            $TWiki::SESSION->writeWarning
               ( $locker->wikiName()." broke ${user}s lock on $web.$topic" );
             $handler->setLock( 0 );
             last;
@@ -1368,27 +1360,27 @@
     # If there is no meta data then convert from old format
     if( ! $meta->count( 'TOPICINFO' ) ) {
         if ( $$rtext =~ /<!--TWikiAttachment-->/ ) {
-            $$rtext = $this->{session}->{attach}->migrateToFileAttachmentMacro( $meta,
+            $$rtext = $TWiki::ATTACH->migrateToFileAttachmentMacro( $meta,
                                                                                 $$rtext );
         }
 
         if ( $$rtext =~ /<!--TWikiCat-->/ ) {
             require TWiki::Compatibility;
-            $$rtext = TWiki::Compatibility::upgradeCategoryTable( $this->{session}, $meta->web(), $meta->topic(),
+            $$rtext = TWiki::Compatibility::upgradeCategoryTable( $TWiki::SESSION, $meta->web(), $meta->topic(),
                                                                   $meta, $$rtext );
         }
     } elsif( $format eq '1.0beta' ) {
         # This format used live at DrKW for a few months
         if( $$rtext =~ /<!--TWikiCat-->/ ) {
             require TWiki::Compatibility;
-            $$rtext = TWiki::Compatibility::upgradeCategoryTable( $this->{session}, $meta->web(), $meta->topic(),
+            $$rtext = TWiki::Compatibility::upgradeCategoryTable( $TWiki::SESSION, $meta->web(), $meta->topic(),
                                                                   $meta,
                                                                   $$rtext );
         }
-        $this->{session}->{attach}->upgradeFrom1v0beta( $meta );
+        $TWiki::ATTACH->upgradeFrom1v0beta( $meta );
         if( $meta->count( 'TOPICMOVED' ) ) {
             my $moved = $meta->get( 'TOPICMOVED' );
-            my $u = $this->{session}->{users}->findUser( $moved->{by} );
+            my $u = $TWiki::USERS->findUser( $moved->{by} );
             $moved->{by} = $u->wikiName() if $u;
             $meta->put( 'TOPICMOVED', $moved );
         }
@@ -1436,7 +1428,7 @@
     }
     close( $strm );
 
-    my $meta = new TWiki::Meta( $this->{session}, $web, $topic );
+    my $meta = new TWiki::Meta( $web, $topic );
     $this->extractMetaData( $meta, \$data );
     my $parentMeta = $meta->get( 'TOPICPARENT' );
     return $parentMeta->{name} if $parentMeta;
@@ -1576,10 +1568,10 @@
         @webList = grep { /(?:^_|\/_)/, } @webList;
     }
 
-    my $user = $this->{session}->{user};
+    my $user = $TWiki::SESSION->{user};
     if( $filter =~ /\bpublic\b/ && !$user->isAdmin()) {
-        my $prefs = $this->{session}->{prefs};
-        my $wn = $this->{session}->{webName};
+        my $prefs = $TWiki::PREFS;
+        my $wn = $TWiki::SESSION->{webName};
         @webList =
           grep {
               $_ eq $wn ||
@@ -1588,10 +1580,9 @@
     }
 
     if( $filter =~ /\ballowed\b/ ) {
-        my $security = $this->{session}->{security};
         @webList =
           grep {
-              $security->checkAccessPermission(
+              $TWiki::ACCESS->checkAccessPermission(
                   'VIEW', $user, undef, undef, undef, $_ )
           } @webList;
     }
@@ -1658,7 +1649,7 @@
 
     unless( $baseWeb ) {
         # For a web to be a web, it has to have at least one topic
-        my $meta = new TWiki::Meta( $this->{session}, $newWeb,
+        my $meta = new TWiki::Meta( $newWeb,
                                     $TWiki::cfg{WebPrefsTopicName} );
         $this->saveTopic( $user, $newWeb, $TWiki::cfg{WebPrefsTopicName},
                           "Preferences", $meta );
@@ -1908,8 +1899,8 @@
     my ( $this, $params ) = @_;
 
     my $attrType = $params->{type} || 'FIELD';
-    my $attrWeb = $params->{web} || $this->{session}->{webName};
-    my $attrTopic = $params->{topic} || $this->{session}->{topicName};
+    my $attrWeb = $params->{web} || $TWiki::SESSION->{webName};
+    my $attrTopic = $params->{topic} || $TWiki::SESSION->{topicName};
 
     my $searchVal = 'XXX';
 
@@ -1928,7 +1919,7 @@
 
     my $text = '';
     if ($params->{format}) {
-        $text = $this->{session}->{search}->searchWeb
+        $text = $TWiki::SEARCH->searchWeb
         (
          format	       => $params->{format},
          search        => $searchVal,
@@ -1943,7 +1934,7 @@
          inline        => 1,
         );
     } else {
-    $this->{session}->{search}->searchWeb
+    $TWiki::SEARCH->searchWeb
       (
        _callback     => \&_collate,
        _cbdata       => \$text,,
@@ -2054,7 +2045,7 @@
     my $handler = $this->_getHandler( $web, $topic );
     my $lease = $handler->getLease();
     if( $lease ) {
-        my $user = $this->{session}->{users}->findUser( $lease->{user} );
+        my $user = $TWiki::USERS->findUser( $lease->{user} );
         ASSERT( $user->isa('TWiki::User')) if DEBUG;
         $lease->{user} = $user;
     }
Index: TWiki/Templates.pm
===================================================================
--- TWiki/Templates.pm	(revision 13172)
+++ TWiki/Templates.pm	(working copy)
@@ -53,18 +53,15 @@
 
 =pod
 
----++ ClassMethod new ( $session )
+---++ ClassMethod new()
 
 Constructor. Creates a new template database object.
-   * $session - session (TWiki) object
 
 =cut
 
 sub new {
-    my ( $class, $session ) = @_;
-    ASSERT($session->isa( 'TWiki')) if DEBUG;
+    my ( $class ) = @_;
     my $this = bless( {}, $class );
-    $this->{session} = $session;
 
     $this->{VARS} = { sep => ' | ' };
 
@@ -149,7 +146,7 @@
     if( $context ) {
         $template = $then if defined( $then );
         foreach my $id ( split( /\,\s*/, $context )) {
-            unless( $this->{session}->{context}->{$id} ) {
+            unless( $TWiki::SESSION->{context}->{$id} ) {
                 $template = ( $else || '' );
                 last;
             }
@@ -269,12 +266,11 @@
 # STATIC: Return value: raw template text, or '' if read fails
 sub _readTemplateFile {
     my( $this, $name, $skins, $web ) = @_;
-    my $session = $this->{session};
-    my $store = $session->{store};
+    my $store = $TWiki::STORE;
 
-    $skins = $session->getSkin() unless defined( $skins );
+    $skins = $TWiki::SESSION->getSkin() unless defined( $skins );
     #print STDERR "SKIN path is $skins\n";
-    $web ||= $session->{webName};
+    $web ||= $TWiki::SESSION->{webName};
     $name ||= '';
 
     # SMELL: not i18n-friendly (can't have accented characters in skin name)
@@ -291,14 +287,14 @@
     my $userdirweb = $web;
     my $userdirname = $name;
     if( $name =~ /^(.+)\.(.+?)$/ ) {
-       $userdirweb = ucfirst($1);
-       $userdirname = ucfirst($2);
+        $userdirweb = ucfirst($1);
+        $userdirname = ucfirst($2);
 
-       # if the name can be parsed into $web.$name, then this is an attempt
-       # to explicit include that topic. No further searching required.
-       if( validateTopic($session,$store,$session->{user},$userdirname,$userdirweb )) {
-	   return retrieveTopic( $store, $userdirweb, $userdirname );
-       }
+        # if the name can be parsed into $web.$name, then this is an attempt
+        # to explicit include that topic. No further searching required.
+        if( _validateTopic( $userdirname, $userdirweb )) {
+            return _retrieveTopic( $userdirweb, $userdirname );
+        }
     }
     else {
         $userdirweb = ucfirst($userdirweb);
@@ -338,16 +334,16 @@
 
 	  if ( $userdir ) {
 	    # candidate in user directory
-	    my ($web1, $name1) = $session->normalizeWebTopicName($web, $file);
+	    my ($web1, $name1) = $TWiki::SESSION->normalizeWebTopicName($web, $file);
 
-	    if( validateTopic($session,$store,$session->{user},$name1,$web1) ) {
-	      next if (defined($this->{files}->{'topic'.$session->{user},$name1,$web1}));
+	    if( _validateTopic( $name1, $web1 )) {
+	      next if (defined($this->{files}->{'topic'.$TWiki::SESSION->{user},$name1,$web1}));
 	      #recursion prevention.
-	      $this->{files}->{'topic'.$session->{user},$name1,$web1} = 1;
-	      return retrieveTopic( $store, $web1, $name1 );
+	      $this->{files}->{'topic'.$TWiki::SESSION->{user},$name1,$web1} = 1;
+	      return _retrieveTopic( $web1, $name1 );
 	    }
 	  } else {
-	    if( validateFile( $file )) {
+	    if( _validateFile( $file )) {
 	      next if (defined($this->{files}->{$file}));
 	      #recursion prevention.
 	      $this->{files}->{$file} = 1;
@@ -365,21 +361,22 @@
     return '';
 }
 
-sub validateFile {
+sub _validateFile {
    my $file = shift;
    return -e $file;
 }
 
-sub validateTopic {
-   my( $session, $store, $user, $topic, $web ) = @_;
-   return $store->topicExists( $web, $topic ) && 
-   $session->{security}->checkAccessPermission(
-       'VIEW', $user, undef, undef, $topic, $web );
+sub _validateTopic {
+   my( $topic, $web ) = @_;
+   return $TWiki::STORE->topicExists( $web, $topic ) && 
+   $TWiki::ACCESS->checkAccessPermission(
+       'VIEW', $TWiki::SESSION->{user}, undef, undef, $topic, $web );
 }
 
-sub retrieveTopic {
-   my( $store, $web, $topic ) = @_;
-   my ( $meta, $text ) = $store->readTopic( undef, $web, $topic, undef );
+sub _retrieveTopic {
+   my( $web, $topic ) = @_;
+   my ( $meta, $text ) = $TWiki::STORE->readTopic(
+       undef, $web, $topic, undef );
    return $text;
 }
 
Index: TWiki/Sandbox.pm
===================================================================
--- TWiki/Sandbox.pm	(revision 13172)
+++ TWiki/Sandbox.pm	(working copy)
@@ -41,7 +41,7 @@
 
 =pod
 
----++ ClassMethod new( $os, $realOS )
+---++ ClassMethod new()
 
 Construct a new sandbox suitable for $os, setting
 flags for platform features that help.  $realOS distinguishes
@@ -50,16 +50,13 @@
 =cut
 
 sub new {
-    my ( $class, $os, $realOS ) = @_;
+    my ( $class ) = @_;
     my $this = bless( {}, $class );
+    my ($os, $realOS) = ($TWiki::cfg{OS}, $TWiki::cfg{DetailedOS});
 
-    ASSERT( defined $os ) if DEBUG;
-    ASSERT( defined $realOS ) if DEBUG;
-
     $this->{REAL_SAFE_PIPE_OPEN} = 1;     # supports open(FH, '-|")
     $this->{EMULATED_SAFE_PIPE_OPEN} = 1; # supports pipe() and fork()
 
-
     # filter the support based on what platforms are proven
     # not to work.
     #from the Activestate Docco this is _only_ defined on ActiveState Perl
Index: TWiki/If.pm
===================================================================
--- TWiki/If.pm	(revision 13172)
+++ TWiki/If.pm	(working copy)
@@ -58,12 +58,12 @@
 =cut
 
 sub evaluate {
-    my( $this, $session ) = @_;
+    my( $this ) = @_;
 
     return $this->{op} unless ref( $this->{op} );
 
     my $fn = $this->{op}->{exec};
-    return &$fn( $session, $this->{left}, $this->{right} );
+    return &$fn( $TWiki::SESSION, $this->{left}, $this->{right} );
 }
 
 sub stringify {
@@ -129,7 +129,7 @@
         my $eval =  $b->evaluate($twiki);
         return 0 unless $eval;
         return 1 if( defined( $twiki->{cgiQuery}->param( $eval )));
-        return 1 if( defined( $twiki->{prefs}->getPreferencesValue( $eval )));
+        return 1 if( defined( $TWiki::PREFS->getPreferencesValue( $eval )));
         return 1 if( defined( $twiki->{SESSION_TAGS}{$eval} ));
         return 0;
     }
Index: TWiki/Merge.pm
===================================================================
--- TWiki/Merge.pm	(revision 13172)
+++ TWiki/Merge.pm	(working copy)
@@ -35,14 +35,13 @@
 
 =pod
 
----++ StaticMethod merge2( $arev, $a, $brev, $b, $sep, $session, $info )
+---++ StaticMethod merge2( $arev, $a, $brev, $b, $sep, $info )
 
    * =$arev= - rev for $a (string)
    * =$a= - first ('original') string
    * =$brev= - rev for $b (string)
    * =$b= - second ('new') string
    * =$sep= = separator, string RE e.g. '.*?\n' for lines
-   * =$session= - TWiki object
    * =$info= - data block passed to plugins merge handler. Conventionally this will identify the source of the text being merged (the source form field, or undef for the body text)
 
 Perform a merge of two versions of the same text, using
@@ -63,19 +62,17 @@
 Call it like this:
 <verbatim>
 $newText = TWiki::Merge::merge2(
-   $oldrev, $old, $newrev, $new, '.*?\n', $session, $info );
+   $oldrev, $old, $newrev, $new, '.*?\n', $info );
 </verbatim>
 
 =cut
 
 sub merge2 {
-    my ( $va, $ia, $vb, $ib, $sep, $session, $info ) = @_;
+    my ( $va, $ia, $vb, $ib, $sep, $info ) = @_;
 
     my @a = split( /($sep)/, $ia );
     my @b = split( /($sep)/, $ib );
 
-    ASSERT($session && $session->isa('TWiki')) if DEBUG;
-
     my @out;
     Algorithm::Diff::traverse_balanced( \@a, \@b,
                                         {
@@ -88,19 +85,16 @@
                                         \@out,
                                         \@a,
                                         \@b,
-                                        $session,
                                         $info );
     return join( '', @out );
 }
 
 sub _acceptA {
-    my ( $a, $b, $out, $ai, $bi, $session, $info ) = @_;
+    my ( $a, $b, $out, $ai, $bi, $info ) = @_;
 
-    ASSERT($session->isa('TWiki')) if DEBUG;
-
     #print STDERR "From A: '$ai->[$a]'\n";
     # accept text from the old version without asking for resolution
-    my $merged = $session->{plugins}->mergeHandler(
+    my $merged = $TWiki::PLUGINS->mergeHandler(
         ' ',  $ai->[$a], undef, $info );
     if( defined $merged ) {
         push( @$out, $merged );
@@ -110,12 +104,10 @@
 }
 
 sub _acceptB {
-    my ( $a, $b, $out, $ai, $bi, $session, $info ) = @_;
+    my ( $a, $b, $out, $ai, $bi, $info ) = @_;
 
-    ASSERT($session->isa('TWiki')) if DEBUG;
-
     #print STDERR "From B: '$bi->[$b]'\n";
-    my $merged = $session->{plugins}->mergeHandler(
+    my $merged = $TWiki::PLUGINS->mergeHandler(
         ' ',  $bi->[$b], undef, $info );
     if( defined $merged ) {
         push( @$out, $merged );
@@ -125,9 +117,8 @@
 }
 
 sub _change {
-    my ( $a, $b, $out, $ai, $bi, $session, $info ) = @_;
+    my ( $a, $b, $out, $ai, $bi, $info ) = @_;
     my $merged;
-    ASSERT($session->isa('TWiki')) if DEBUG;
 
     # Diff isn't terribly smart sometimes; it will generate changes
     # with a or b empty, which I would have thought should have
@@ -136,7 +127,7 @@
         # there is some non-white text to delete
         if( $bi->[$b] =~ /\S/ ) {
             # this insert is replacing something with something
-            $merged = $session->{plugins}->mergeHandler(
+            $merged = $TWiki::PLUGINS->mergeHandler(
                 'c', $ai->[$a], $bi->[$b], $info );
             if( defined $merged ) {
                 push( @$out, $merged );
@@ -145,7 +136,7 @@
                 push( @$out, CGI::ins( $bi->[$b] ) );
             }
         } else {
-            $merged = $session->{plugins}->mergeHandler(
+            $merged = $TWiki::PLUGINS->mergeHandler(
                 '-',  $ai->[$a], $bi->[$b], $info );
             if( defined $merged ) {
                 push( @$out, $merged );
@@ -155,7 +146,7 @@
         }
     } elsif ( $bi->[$b] =~ /\S/ ) {
         # inserting new
-        $merged = $session->{plugins}->mergeHandler(
+        $merged = $TWiki::PLUGINS->mergeHandler(
             '+',  $ai->[$a], $bi->[$b], $info );
         #print STDERR "From B: '$bi->[$b]'\n";
         if( defined $merged ) {
@@ -166,7 +157,7 @@
     } else {
         # otherwise this insert is not replacing anything
         #print STDERR "From B: '$bi->[$b]'\n";
-        $merged = $session->{plugins}->mergeHandler(
+        $merged = $TWiki::PLUGINS->mergeHandler(
             ' ',  $ai->[$a], $bi->[$b], $info );
         if( defined $merged ) {
             push( @$out, $merged );
@@ -257,8 +248,7 @@
 
 =pod
 
----++ StaticMethod merge3( $arev, $a, $brev, $b, $crev, $c, $sep,
-                          $session, $info )
+---++ StaticMethod merge3( $arev, $a, $brev, $b, $crev, $c, $sep, $info )
 
    * =$arev= - rev for common ancestor (id e.g. ver no)
    * =$a= - common ancestor
@@ -267,7 +257,6 @@
    * =$crev= - rev no for second derivative string (id)
    * =$c= - second derivative string
    * =$sep= = separator, string RE e.g. '.*?\n' for lines
-   * =$session= - TWiki object
    * =$info= - data block passed to plugins merge handler. Conventionally this will identify the source of the text being merged (the source form field, or undef for the body text)
 
 Perform a merge of two versions (b and c) of the same text, using
@@ -302,7 +291,7 @@
 =cut
 
 sub merge3 {
-    my ( $arev, $ia, $brev, $ib, $crev, $ic, $sep, $session, $info ) = @_;
+    my ( $arev, $ia, $brev, $ib, $crev, $ic, $sep, $info ) = @_;
 
     $sep = "\r?\n" if (!defined($sep));
 
@@ -422,14 +411,14 @@
                     _handleConflict(\@out,
                                     \@aconf, \@bconf, \@cconf,
                                    $arev, $brev, $crev, $sep,
-                                   $session, $info);
+                                   $info);
                     $conflict = 0;
                     push @out, @merged;
                     @merged = ();
                 }
             } else {
                 # the line is non-conflicting
-                my $merged = $session->{plugins}->mergeHandler(
+                my $merged = $TWiki::PLUGINS->mergeHandler(
                     ' ',  $dline, $dline, $info );
                 if( defined $merged ) {
                     push( @out, $merged );
@@ -450,7 +439,7 @@
         }
 
         _handleConflict(\@out, \@aconf, \@bconf, \@cconf,
-                       $arev, $brev, $crev, $sep, $session, $info);
+                       $arev, $brev, $crev, $sep, $info);
     }
     push @out, @merged;
     @merged = ();
@@ -465,14 +454,13 @@
 my $conflictB = CGI::b('CONFLICT');
 
 sub _handleConflict {
-    my( $out, $aconf, $bconf, $cconf, $arev, $brev, $crev,
-        $sep, $session, $info ) = @_;
+    my( $out, $aconf, $bconf, $cconf, $arev, $brev, $crev, $sep, $info ) = @_;
     my( @a, @b, @c );
 
     @a = grep( $_, @$aconf );
     @b = grep( $_, @$bconf );
     @c = grep( $_, @$cconf );
-    my $merged = $session->{plugins}->mergeHandler(
+    my $merged = $TWiki::PLUGINS->mergeHandler(
         'c',  join( '', @b ), join( '', @c ), $info);
     if( defined $merged ) {
         push( @$out, $merged );
Index: TWiki/Access.pm
===================================================================
--- TWiki/Access.pm	(revision 13172)
+++ TWiki/Access.pm	(working copy)
@@ -40,10 +40,8 @@
 =cut
 
 sub new {
-    my ( $class, $session ) = @_;
+    my ( $class ) = @_;
     my $this = bless( {}, $class );
-    ASSERT($session->isa( 'TWiki')) if DEBUG;
-    $this->{session} = $session;
 
     %{$this->{GROUPS}} = ();
 
@@ -97,7 +95,7 @@
 
     $mode = uc( $mode );  # upper case
 
-    my $prefs = $this->{session}->{prefs};
+    my $prefs = $TWiki::PREFS;
 
     my $allowText;
     my $denyText;
@@ -120,7 +118,7 @@
     if( defined( $denyText )) {
         if( $denyText =~ /\S$/ ) {
             if( $user->isInList( $denyText )) {
-                $this->{failure} = $this->{session}->{i18n}->maketext('access denied on topic');
+                $this->{failure} = $TWiki::I18N->maketext('access denied on topic');
                 #print STDERR $this->{failure},"\n";
                 return 0;
             }
@@ -137,7 +135,7 @@
             #print STDERR "in ALLOWTOPIC\n";
             return 1;
         }
-        $this->{failure} = $this->{session}->{i18n}->maketext('access not allowed on topic');
+        $this->{failure} = $TWiki::I18N->maketext('access not allowed on topic');
         #print STDERR $this->{failure},"\n";
         return 0;
     }
@@ -148,7 +146,7 @@
         $denyText =
           $prefs->getWebPreferencesValue( 'DENYWEB'.$mode, $web );
         if( defined( $denyText ) && $user->isInList( $denyText )) {
-            $this->{failure} = $this->{session}->{i18n}->maketext('access denied on web');
+            $this->{failure} = $TWiki::I18N->maketext('access denied on web');
             #print STDERR $this->{failure},"\n";
             return 0;
         }
@@ -160,7 +158,7 @@
 
     if( defined( $allowText ) && $allowText =~ /\S/ ) {
         unless( $user->isInList( $allowText )) {
-            $this->{failure} = $this->{session}->{i18n}->maketext('access not allowed on web');
+            $this->{failure} = $TWiki::I18N->maketext('access not allowed on web');
             #print STDERR $this->{failure},"\n";
             return 0;
         }
@@ -171,7 +169,7 @@
         $denyText =
           $prefs->getPreferencesValue( 'DENYROOT'.$mode, $web );
         if( defined( $denyText ) && $user->isInList( $denyText )) {
-            $this->{failure} = $this->{session}->{i18n}->maketext('access denied on root');
+            $this->{failure} = $TWiki::I18N->maketext('access denied on root');
             #print STDERR $this->{failure},"\n";
             return 0;
         }
@@ -180,7 +178,7 @@
 
         if( defined( $allowText ) && $allowText =~ /\S/ ) {
             unless( $user->isInList( $allowText )) {
-                $this->{failure} = $this->{session}->{i18n}->maketext('access not allowed on root');
+                $this->{failure} = $TWiki::I18N->maketext('access not allowed on root');
                 #print STDERR $this->{failure},"\n";
                 return 0;
             }
Index: TWiki/Users.pm
===================================================================
--- TWiki/Users.pm	(revision 13172)
+++ TWiki/Users.pm	(working copy)
@@ -43,30 +43,27 @@
 
 =pod
 
----++ ClassMethod new ($session, $impl)
+---++ ClassMethod new ($impl)
 
 Construct the user management object
 
 =cut
 
 sub new {
-    my ( $class, $session ) = @_;
-    ASSERT($session->isa( 'TWiki')) if DEBUG;
+    my ( $class ) = @_;
     my $this = bless( {}, $class );
 
-    $this->{session} = $session;
-
     my $implPasswordManager = $TWiki::cfg{PasswordManager};
     $implPasswordManager = 'TWiki::Users::Password' if( $implPasswordManager eq 'none' );
     eval "use $implPasswordManager";
     die "Password Manager: $@" if $@;
-    $this->{passwords} = $implPasswordManager->new( $session );
+    $this->{passwords} = $implPasswordManager->new();
 
     my $implUserMappingManager = $TWiki::cfg{UserMappingManager};
     $implUserMappingManager = 'TWiki::Users::TWikiUserMapping' if( $implUserMappingManager eq 'none' );
     eval "use $implUserMappingManager";
     die "User Mapping Manager: $@" if $@;
-    $this->{usermappingmanager} = $implUserMappingManager->new( $session );
+    $this->{usermappingmanager} = $implUserMappingManager->new();
 
     $this->{login} = {};
     $this->{wikiname} = {};
@@ -155,7 +152,7 @@
     $name ||= $TWiki::cfg{DefaultUserLogin};
     my $object;
 
-    #$this->{session}->writeDebug("Looking for $name / $wikiname / $dontCreate");
+    #$TWiki::SESSION->writeDebug("Looking for $name / $wikiname / $dontCreate");
 
     # is it a cached login name?
     $object = $this->{login}{$name};
@@ -206,7 +203,7 @@
         # default to wikiname being the same as name.
         # Commented out because this warning is too common, and tends to
         # flood the logs.
-        # $this->{session}->writeWarning("$name does not exist in TWikiUsers - is this a bogus user?") unless( $name =~ /Group$/ );
+        # $TWiki::SESSION->writeWarning("$name does not exist in TWikiUsers - is this a bogus user?") unless( $name =~ /Group$/ );
         $wikiname = $name;
     }
 
@@ -241,7 +238,7 @@
 sub createUser {
     my( $this, $name, $wikiname ) = @_;
 
-    my $object = new TWiki::User( $this->{session}, $name, $wikiname );
+    my $object = new TWiki::User( $name, $wikiname );
     if ( defined ($object) ) {
         $this->{login}{$object->login()} = $object;
         $this->{wikiname}{$object->webDotWikiName()} = $object;
Index: TWiki/UI/Register.pm
===================================================================
--- TWiki/UI/Register.pm	(revision 13172)
+++ TWiki/UI/Register.pm	(working copy)
@@ -64,7 +64,7 @@
 
 =pod
 
----++ StaticMethod register_cgi( $session )
+---++ StaticMethod register_cgi( )
 
 =register= command handler.
 This method is designed to be
@@ -73,10 +73,9 @@
 =cut
 
 sub register_cgi {
-    my $session = shift;
 
     # absolute URL context for email generation
-    $session->enterContext('absolute_urls');
+    $TWiki::SESSION->enterContext('absolute_urls');
 
     my $tempUserDir = $TWiki::cfg{RegistrationApprovals};
     my $needApproval = 0;
@@ -85,30 +84,30 @@
 
     # NB. bulkRegister invoked from ManageCgiScript.
 
-    my $action = $session->{cgiQuery}->param('action') || '';
+    my $action = $TWiki::SESSION->{cgiQuery}->param('action') || '';
 
     if ($action eq 'register') {
-      registerAndNext($session, $tempUserDir);
+        _registerAndNext($tempUserDir);
     }
     elsif ($action eq 'verify') {
-        verifyEmailAddress( $session, $tempUserDir );
+        verifyEmailAddress( $tempUserDir );
         if ($needApproval) {
             throw Error::Simple('Approval code has not been written!');
         }
-        finish( $session, $tempUserDir);
+        _finish( $tempUserDir);
     }
     elsif ($action eq 'resetPassword') {
         #SMELL - is this still called here, or only by passwd? 
-        resetPassword( $session );
+        _resetPassword( );
     }
     elsif ($action eq 'approve') {
-        finish($session, $tempUserDir );
+        _finish($tempUserDir );
     }
     else {
-      registerAndNext($session, $tempUserDir);
+        _registerAndNext($TWiki::SESSION, $tempUserDir);
     }
 
-    $session->leaveContext('absolute_urls');
+    $TWiki::SESSION->leaveContext('absolute_urls');
 
     # Output of register:
     #    UnsavedUser, accessible by username.$verificationCode
@@ -125,7 +124,7 @@
 
 =pod
 
----++ StaticMethod passwd_cgi( $session )
+---++ StaticMethod passwd_cgi()
 
 =passwd= command handler.
 This method is designed to be
@@ -134,26 +133,24 @@
 =cut
 
 sub passwd_cgi {
-    my $session = shift;
+    my $action = $TWiki::SESSION->{cgiQuery}->param('action');
 
-    my $action = $session->{cgiQuery}->param('action');
-
     # absolute URL context for email generation
-    $session->enterContext('absolute_urls');
+    $TWiki::SESSION->enterContext('absolute_urls');
 
     if( $action eq 'changePassword' ) {
-        changePassword( $session );
+        changePassword( $TWiki::SESSION );
     }
     elsif ( $action eq 'resetPassword' ) {
-        resetPassword( $session );
+        _resetPassword( );
     }
     else {
         throw TWiki::OopsException( 'attention',
-                                    web => $session->{webName},
-                                    topic => $session->{topicName},
+                                    web => $TWiki::SESSION->{webName},
+                                    topic => $TWiki::SESSION->{topicName},
                                     def => 'missing_action' );
     }
-    $session->leaveContext('absolute_urls');
+    $TWiki::SESSION->leaveContext('absolute_urls');
 }
 
 # TODO: S&R {form} with {ordered}
@@ -179,7 +176,7 @@
 
 =pod
 
----++ StaticMethod bulkRegister($session)
+---++ StaticMethod bulkRegister()
 
   Called by ManageCgiScript::bulkRegister (requires authentication) with topic = the page with the entries on it.
    1 Makes sure you are an admin user ;)
@@ -193,16 +190,14 @@
 =cut
 
 sub bulkRegister {
-    my $session = shift;
-
-    my $user = $session->{user};
-    my $topic = $session->{topicName};
-    my $web = $session->{webName};
+    my $user = $TWiki::SESSION->{user};
+    my $topic = $TWiki::SESSION->{topicName};
+    my $web = $TWiki::SESSION->{webName};
     my $userweb = $TWiki::cfg{UsersWebName};
-    my $query = $session->{cgiQuery};
+    my $query = $TWiki::SESSION->{cgiQuery};
 
     # absolute URL context for email generation
-    $session->enterContext('absolute_urls');
+    $TWiki::SESSION->enterContext('absolute_urls');
 
     my $settings = {};
     $settings->{doOverwriteTopics} =
@@ -219,7 +214,7 @@
 
     #-- Read the topic containing a table of people to be registered
 
-    my ($meta, $text) = $session->{store}->readTopic( undef,
+    my ($meta, $text) = $TWiki::STORE->readTopic( undef,
                                                       $web, $topic, undef );
     my %data;
     ( $settings->{fieldNames}, %data ) =
@@ -239,9 +234,9 @@
         next ROW if (length($row->{WikiName}) == 0);
 
         try {
-            _validateRegistration( $session, $row, $query, $topic, 0 );
+            _validateRegistration( $row, $query, $topic, 0 );
             my ($userTopic, $uLog) =
-              _registerSingleBulkUser($session, $row, $settings );
+              _registerSingleBulkUser($row, $settings );
             if( $userTopic ) {
                 $log .= "\n---+++ ". $row->{WikiName}."\n";
                 $log .= $b.' Added to users topic '.$userTopic.":\n".
@@ -250,7 +245,7 @@
             }
         } catch TWiki::OopsException with {
             my $e = shift;
-            $log .= $e->stringify( $session )."\n";
+            $log .= $e->stringify( $TWiki::SESSION )."\n";
         };
     }
 
@@ -259,15 +254,15 @@
 
     my $logWeb;
     my $logTopic =  $query->param('LogTopic') || $topic.'Result';
-    ( $logWeb, $logTopic ) = $session->normalizeWebTopicName( '', $logTopic );
+    ( $logWeb, $logTopic ) = $TWiki::SESSION->normalizeWebTopicName( '', $logTopic );
 
     #-- Save the LogFile as designated, link back to the source topic 
     $meta->put( 'TOPICPARENT', { name => $web.'.'.$topic } );
-    my $err = $session->{store}->saveTopic($user, $logWeb, $logTopic, $log, $meta );
+    my $err = $TWiki::STORE->saveTopic($user, $logWeb, $logTopic, $log, $meta );
 
-    $session->leaveContext('absolute_urls');
+    $TWiki::SESSION->leaveContext('absolute_urls');
 
-    $session->redirect($session->getScriptUrl( 1, 'view', $web, $logTopic ));
+    $TWiki::SESSION->redirect($TWiki::SESSION->getScriptUrl( 1, 'view', $web, $logTopic ));
 }
 
 #    Process a single user, parameters passed as a hash
@@ -281,7 +276,7 @@
 # SMELL could be made much more efficient if needed, as calls to addUserToMapping()
 # are quite expensive when doing 300 in succession!
 sub _registerSingleBulkUser {
-    my ($session, $row, $settings) = @_;
+    my ($row, $settings) = @_;
     ASSERT( $row ) if DEBUG;
     ASSERT( $settings->{fieldNames} ) if DEBUG;
     my $fieldNames = $settings->{fieldNames};
@@ -318,21 +313,21 @@
     #-- Generation of the page is done from the {form} subhash, so align the two
     $row->{form} = _makeFormFieldOrderMatch( $fieldNames, $row);
 
-    my $passResult = _addUserToPasswordSystem( $session, $row );
+    my $passResult = _addUserToPasswordSystem( $row );
     $log .= $b.' Password set '.($passResult?'OK':'FAILED')."\n";
     #TODO: need a path for if it doesn't succeed.
 
-    $session->writeLog('bulkregister', $row->{webName}.'.'.$row->{WikiName},
+    $TWiki::SESSION->writeLog('bulkregister', $row->{webName}.'.'.$row->{WikiName},
                        $row->{Email}, $row->{WikiName} );
 
-    my $user = $session->{users}->findUser( $row->{LoginName},
-                                            $row->{WikiName} );
+    my $user = $TWiki::USERS->findUser( $row->{LoginName},
+                                        $row->{WikiName} );
 
     my $userTopic =
-      $session->{users}->addUserToMapping( $user, $session->{user} );
+      $TWiki::USERS->addUserToMapping( $user, $TWiki::SESSION->{user} );
 
-    if( $doOverwriteTopics or !$session->{store}->topicExists( $row->{webName}, $row->{WikiName} ) ) {
-        $log .= _createUserTopic($session, 'NewUserTemplate', $row);
+    if( $doOverwriteTopics or !$TWiki::STORE->topicExists( $row->{webName}, $row->{WikiName} ) ) {
+        $log .= _createUserTopic('NewUserTemplate', $row);
     } else {
         $log .= $b.' Not writing topic '.$row->{WikiName}."\n";
 	}
@@ -340,7 +335,7 @@
 
     #if ($TWiki::cfg{EmailUserDetails}) {
         # If you want it, write it.
-        # _sendEmail($session, 'registernotifybulk', $data );
+        # _sendEmail('registernotifybulk', $data );
     #    $log .= $b.' Password email disabled\n';
     #}
     return ($userTopic, $log);
@@ -373,31 +368,23 @@
     return \@form;
 }
 
-=pod
-
----++ StaticMethod registerAndNext($session, $tempUserDir) 
-
-This is called when action = register or action = ""
-
-It calls register and either Verify or Finish.
-
-Hopefully we will get workflow integrated and rewrite this to be table driven
-
-=cut
-
-sub registerAndNext {
-  my ($session, $tempUserDir) = @_;
-  register( $session );
+# _registerAndNext($tempUserDir)
+# This is called when action = register or action = ""
+# It calls register and either Verify or Finish.
+# Hopefully we will get workflow integrated and rewrite this to be table driven
+sub _registerAndNext {
+  my ($tempUserDir) = @_;
+  register();
   if ($TWiki::cfg{Register}{NeedVerification}) {
-     _requireVerification($session, $tempUserDir);
+     _requireVerification($tempUserDir);
   } else {
-     finish($session);
+     _finish( $tempUserDir );
   }
 }
 
 =pod
 
----++ StaticMethod register($session)
+---++ StaticMethod register()
 
 This is called through: TWikiRegistration -> RegisterCgiScript -> here
 
@@ -407,18 +394,16 @@
 =cut
 
 sub register {
-    my( $session ) = @_;
+    my $query = $TWiki::SESSION->{cgiQuery};
+    my $topic = $TWiki::SESSION->{topicName};
+    my $web = $TWiki::SESSION->{webName};
 
-    my $query = $session->{cgiQuery};
-    my $topic = $session->{topicName};
-    my $web = $session->{webName};
-
     my $data = _getDataFromQuery( $query, $query->param() );
 
     $data->{webName} = $web;
     $data->{debug} = 1;
 
-    _validateRegistration( $session, $data, $query, $topic, 1 );
+    _validateRegistration( $data, $query, $topic, 1 );
 }
 
 #   1 generates a activation password
@@ -426,11 +411,11 @@
 #   3 sends them a 'registerconfirm' email.
 #   4 redirects browser to 'regconfirm'
 sub _requireVerification {
-    my ($session, $tmpDir) = @_;
+    my ($tmpDir) = @_;
 
-    my $query = $session->{cgiQuery};
-    my $topic = $session->{topicName};
-    my $web = $session->{webName};
+    my $query = $TWiki::SESSION->{cgiQuery};
+    my $topic = $TWiki::SESSION->{topicName};
+    my $web = $TWiki::SESSION->{webName};
 
     my $data = _getDataFromQuery( $query, $query->param() );
     $data->{webName} = $web;
@@ -439,11 +424,11 @@
       $data->{WikiName}.'.'.TWiki::User::randomPassword();
     _putRegDetailsByCode( $data, $tmpDir );
 
-    $session->writeLog(
+    $TWiki::SESSION->writeLog(
         'regstart', $TWiki::cfg{UsersWebName}.'.'.$data->{WikiName},
         $data->{Email}, $data->{WikiName} );
 
-    my $err = _sendEmail( $session, 'registerconfirm', $data );
+    my $err = _sendEmail( 'registerconfirm', $data );
     my $em = TWiki::entityEncode( $data->{Email} );
 
     if($err) {
@@ -462,22 +447,18 @@
                                 params => [ $em ] );
 }
 
-=pod
+# _resetPassword()
+#
+# Generates a password. Mails it to them and asks them to change it. Entry
+# point intended to be called from TWiki::UI::run
+#
 
----++ StaticMethod resetPassword($session)
+sub _resetPassword {
+    my $query = $TWiki::SESSION->{cgiQuery};
+    my $topic = $TWiki::SESSION->{topicName};
+    my $web = $TWiki::SESSION->{webName};
+    my $user = $TWiki::SESSION->{user};
 
-Generates a password. Mails it to them and asks them to change it. Entry
-point intended to be called from TWiki::UI::run
-
-=cut
-
-sub resetPassword {
-    my $session = shift;
-    my $query = $session->{cgiQuery};
-    my $topic = $session->{topicName};
-    my $web = $session->{webName};
-    my $user = $session->{user};
-
     my @userNames = $query->param( 'LoginName' ) ;
     unless( @userNames ) {
         throw TWiki::OopsException( 'attention',
@@ -508,7 +489,7 @@
     my $good = 1;
     foreach my $userName (@userNames) {
         $good = $good &&
-          _resetUsersPassword( $session, $userName, $introduction, \$message );
+          _resetUsersPassword( $userName, $introduction, \$message );
     }
 
     my $action = '';
@@ -534,20 +515,20 @@
 
 # return status
 sub _resetUsersPassword {
-    my( $session, $userName, $introduction, $pMess ) = @_;
+    my( $userName, $introduction, $pMess ) = @_;
 
-    my $user = $session->{users}->findUser( $userName, undef, 1);
+    my $user = $TWiki::USERS->findUser( $userName, undef, 1);
     unless( $user ) {
         # couldn't work out who they are, its neither loginName nor
         # wikiName.
-        $$pMess .= $session->inlineAlert( 'alerts', 'bad_user', $userName );
+        $$pMess .= $TWiki::SESSION->inlineAlert( 'alerts', 'bad_user', $userName );
         return 0;
     }
 
     my $message = '';
     unless( $user->passwordExists() ) {
         # Not an error.
-        $$pMess .= $session->inlineAlert( 'alerts', 'missing_user',
+        $$pMess .= $TWiki::SESSION->inlineAlert( 'alerts', 'missing_user',
                                           $user->wikiName());
     }
 
@@ -555,12 +536,11 @@
 
     my @em = $user->emails();
     if (!scalar(@em)) {
-        $$pMess .= $session->inlineAlert( 'alerts', 'no_email_for',
+        $$pMess .= $TWiki::SESSION->inlineAlert( 'alerts', 'no_email_for',
                                           $user->wikiName());
     } else {
         foreach my $email ( @em ) {
             my $err = _sendEmail(
-                $session,
                 'mailresetpassword',
                 {
                     webName => $TWiki::cfg{UsersWebName},
@@ -573,12 +553,12 @@
                 } );
 
             if( $err ) {
-                $$pMess .= $session->inlineAlert( 'alerts', 'generic', $err );
+                $$pMess .= $TWiki::SESSION->inlineAlert( 'alerts', 'generic', $err );
             }
         }
     }
 
-    $$pMess .= $session->inlineAlert( 'alerts',
+    $$pMess .= $TWiki::SESSION->inlineAlert( 'alerts',
                                       'new_sys_pass',
                                       $user->login(),
                                       $user->wikiName() );
@@ -588,7 +568,7 @@
 
 =pod
 
----++ StaticMethod changePassword( $session )
+---++ StaticMethod changePassword()
 
 Change the user's password and/or email. Details of the user and password
 are passed in CGI parameters.
@@ -606,13 +586,11 @@
 =cut
 
 sub changePassword {
-    my $session = shift;
+    my $topic = $TWiki::SESSION->{topicName};
+    my $webName = $TWiki::SESSION->{webName};
+    my $query = $TWiki::SESSION->{cgiQuery};
+    my $requestUser = $TWiki::SESSION->{user};
 
-    my $topic = $session->{topicName};
-    my $webName = $session->{webName};
-    my $query = $session->{cgiQuery};
-    my $requestUser = $session->{user};
-
     my $oldpassword = $query->param( 'oldpassword' );
     my $username = $query->param( 'username' );
     my $passwordA = $query->param( 'password' );
@@ -630,7 +608,7 @@
                                     params => [ 'username' ] );
     }
 
-    my $user = $session->{users}->findUser( $username );
+    my $user = $TWiki::USERS->findUser( $username );
 
     unless ($user) {
         throw TWiki::OopsException( 'attention',
@@ -692,13 +670,13 @@
         }
         my $e = $user->changePassword( $oldpassword, $passwordA );
         if( $e ) {
-            $session->writeWarning('password could not be changed: '.$e);
+            $TWiki::SESSION->writeWarning('password could not be changed: '.$e);
             throw TWiki::OopsException( 'attention',
                                         web => $webName,
                                         topic => $topic,
                                         def => 'password_not_changed');
         } else {
-            $session->writeLog('changepasswd', $user->wikiName());
+            $TWiki::SESSION->writeLog('changepasswd', $user->wikiName());
         }
         # OK - password changed
         throw TWiki::OopsException( 'attention',
@@ -716,7 +694,7 @@
 
 =pod
 
----++ StaticMethod verifyEmailAddress($session, $tempUserDir)
+---++ StaticMethod verifyEmailAddress($tempUserDir)
 
 This is called: on receipt of the activation password -> RegisterCgiScript -> here
    1 calls _reloadUserContext(activation password)
@@ -727,9 +705,9 @@
 =cut
 
 sub verifyEmailAddress {
-    my( $session, $tempUserDir ) = @_;
+    my( $tempUserDir ) = @_;
 
-    my $code = $session->{cgiQuery}->param('code');
+    my $code = $TWiki::SESSION->{cgiQuery}->param('code');
     unless( $code ) {
         throw Error::Simple( 'verifyEmailAddress: no verification code!');
     }
@@ -739,16 +717,16 @@
         throw Error::Simple( 'verifyEmailAddress: no email address!');
     }
 
-    my $topic = $session->{topicName};
-    my $web = $session->{webName};
+    my $topic = $TWiki::SESSION->{topicName};
+    my $web = $TWiki::SESSION->{webName};
 
-    #    $this->{session}->writeLog('verifyuser', $loginName, $userName);
+    #    $TWiki::SESSION->writeLog('verifyuser', $loginName, $userName);
 
 }
 
 =pod
 
----++ StaticMethod finish
+---++ StaticMethod _finish
 
 Presently this is called in RegisterCgiScript directly after a call to verify. The separation is intended for the RegistrationApprovals functionality
    1 calls _reloadUserContext (throws oops if appropriate)
@@ -764,12 +742,12 @@
 
 =cut
 
-sub finish {
-    my( $session, $tempUserDir) = @_;
+sub _finish {
+    my( $tempUserDir) = @_;
 
-    my $topic = $session->{topicName};
-    my $web = $session->{webName};
-    my $query = $session->{cgiQuery};
+    my $topic = $TWiki::SESSION->{topicName};
+    my $web = $TWiki::SESSION->{webName};
+    my $query = $TWiki::SESSION->{cgiQuery};
 	my $code = $query->param('code');
 
 	my $data;
@@ -785,7 +763,7 @@
         throw Error::Simple( 'no WikiName after reload');
     }
 
-    my $success = _addUserToPasswordSystem( $session, $data );
+    my $success = _addUserToPasswordSystem( $data );
     # SMELL - error condition? surely need a way to flag an error?
     unless ( $success ) {
         throw TWiki::OopsException( 'attention',
@@ -796,43 +774,43 @@
     }
 
     # Plugin callback to set cookies.
-    $session->{plugins}->registrationHandler( $data->{WebName},
+    $TWiki::PLUGINS->registrationHandler( $data->{WebName},
                                               $data->{WikiName},
                                               $data->{LoginName} );
 
     # let the client session know that we're logged in. (This probably
     # eliminates the need for the registrationHandler call above,
     # but we'll leave them both in here for now.)
-    $session->{loginManager}->userLoggedIn( $data->{LoginName}, $data->{WikiName} );
+    $TWiki::LOGIN->userLoggedIn( $data->{LoginName}, $data->{WikiName} );
 
     # add user to TWikiUsers topic
-    my $user = $session->{users}->createUser( $data->{LoginName},
+    my $user = $TWiki::USERS->createUser( $data->{LoginName},
                                               $data->{WikiName} );
 
-    my $agent = $session->{users}->findUser( $twikiRegistrationAgent,
+    my $agent = $TWiki::USERS->findUser( $twikiRegistrationAgent,
                                              $twikiRegistrationAgent);
 
-    my $userTopic = $session->{users}->addUserToMapping( $user, $agent);
+    my $userTopic = $TWiki::USERS->addUserToMapping( $user, $agent);
 
     # inform user and admin about the registration.
-    my $status = _emailRegistrationConfirmations( $session, $data );
+    my $status = _emailRegistrationConfirmations( $data );
 
-    my $log = _createUserTopic($session, 'NewUserTemplate', $data);
+    my $log = _createUserTopic('NewUserTemplate', $data);
 
     $user->setEmails( $data->{Email} );
 
     # write log entry
     if ($TWiki::cfg{Log}{register}) {
-        $session->writeLog(
+        $TWiki::SESSION->writeLog(
             'register', $TWiki::cfg{UsersWebName}.'.'.$data->{WikiName},
             $data->{Email}, $data->{WikiName} );
     }
 
     if( $status ) {
-        $status = $session->{i18n}->maketext(
+        $status = $TWiki::I18N->maketext(
             'Warning: Could not send confirmation email')."\n\n$status";
     } else {
-        $status = $session->{i18n}->maketext(
+        $status = $TWiki::I18N->maketext(
             'A confirmation e-mail has been sent to [_1]',
             TWiki::entityEncode( $data->{Email} ));
     }
@@ -852,8 +830,8 @@
 #I use RegistrationHandler::register to prevent certain fields (like password) 
 #appearing in the homepage and to fetch photos into the topic
 sub _createUserTopic {
-    my ($session, $template, $row) = @_;
-    my ( $meta, $text ) = TWiki::UI::readTemplateTopic($session, $template);
+    my ($template, $row) = @_;
+    my ( $meta, $text ) = TWiki::UI::readTemplateTopic($template);
     my $log = $b.' Writing topic '.$TWiki::cfg{UsersWebName}.'.'.$row->{WikiName}."\n".
       $b2.' RegistrationHandler: ';
     my $regLog = $text;
@@ -861,7 +839,7 @@
     $log .= $b2.' '.
       join( "\n".$b2.' ',
             split( /\r?\n/,
-                   _writeRegistrationDetailsToTopic( $session, $row,
+                   _writeRegistrationDetailsToTopic( $row,
                                                      $meta, $text )))."\n";
     return $log;
 }
@@ -872,7 +850,7 @@
 #Returns 'BulletFields' or 'FormFields' depending on what it chose.
 #
 sub _writeRegistrationDetailsToTopic {
-    my ($session, $data, $meta, $text) = @_;
+    my ($data, $meta, $text) = @_;
 
     ASSERT($data->{WikiName}) if DEBUG;
 
@@ -888,7 +866,7 @@
     my $form = $meta->get( 'FORM' );
     if( $form ) {
         ( $meta, $addText ) =
-          _populateUserTopicForm( $session, $form->{name}, $meta, $data );
+          _populateUserTopicForm( $form->{name}, $meta, $data );
         $log = 'Using Form Fields';
     } else {
         $addText = _getRegFormAsTopicContent( $data );
@@ -897,26 +875,26 @@
     $text = $before . $addText . $after;
 
     my $userName = $data->{remoteUser} || $data->{WikiName};
-    my $user = $session->{users}->findUser( $userName );
-    $text = $session->expandVariablesOnTopicCreation( $text, $user );
+    my $user = $TWiki::USERS->findUser( $userName );
+    $text = $TWiki::SESSION->expandVariablesOnTopicCreation( $text, $user );
 
     $meta->put( 'TOPICPARENT', { 'name' => $TWiki::cfg{UsersTopicName}} );
 
-    my $agent = $session->{users}->findUser( $twikiRegistrationAgent,
+    my $agent = $TWiki::USERS->findUser( $twikiRegistrationAgent,
                                              $twikiRegistrationAgent);
 
-    $session->{store}->saveTopic($agent, $TWiki::cfg{UsersWebName},
+    $TWiki::STORE->saveTopic($agent, $TWiki::cfg{UsersWebName},
                                  $data->{WikiName}, $text, $meta );
     return $log;
 }
 
 # Puts form fields into the topic form
 sub _populateUserTopicForm {
-    my ( $session, $formName, $meta, $data ) = @_;
+    my ( $formName, $meta, $data ) = @_;
 
     my %inform;
     my $form =
-      new TWiki::Form( $session, $TWiki::cfg{UsersWebName}, $formName );
+      new TWiki::Form( $TWiki::SESSION, $TWiki::cfg{UsersWebName}, $formName );
     foreach my $field ( @{$form->{fields}} ) {
         foreach my $fd (@{$data->{form}}) {
             next unless $fd->{name} eq $field->{name};
@@ -956,32 +934,30 @@
 #emails both the admin 'registernotifyadmin' and the user 'registernotify', 
 #in separate emails so they both get targeted information (and no password to the admin).
 sub _emailRegistrationConfirmations {
-    my ( $session, $data ) = @_;
+    my ( $data ) = @_;
 
-    my $skin = $session->getSkin();
+    my $skin = $TWiki::SESSION->getSkin();
     my $template =
-      $session->{templates}->readTemplate( 'registernotify', $skin );
+      $TWiki::TEMPLATES->readTemplate( 'registernotify', $skin );
     my $email =
-      _buildConfirmationEmail( $session,
-                               $data,
+      _buildConfirmationEmail( $data,
                                $template,
                                $TWiki::cfg{Register}{HidePasswd}
                              );
 
-    my $warnings = $session->{net}->sendEmail( $email);
+    my $warnings = $TWiki::NET->sendEmail( $email);
 
     $template =
-      $session->{templates}->readTemplate( 'registernotifyadmin', $skin );
+      $TWiki::TEMPLATES->readTemplate( 'registernotifyadmin', $skin );
     $email =
-      _buildConfirmationEmail( $session,
-                               $data,
+      _buildConfirmationEmail( $data,
                                $template,
                                1 );
 
-    my $err = $session->{net}->sendEmail( $email );
+    my $err = $TWiki::NET->sendEmail( $email );
     if( $err ) {
         # don't tell the user about this one
-        $session->writeWarning('Could not confirm registration: '.$err);
+        $TWiki::SESSION->writeWarning('Could not confirm registration: '.$err);
     }
 
     return $warnings;
@@ -989,7 +965,7 @@
 
 #The template dictates the to: field
 sub _buildConfirmationEmail {
-    my ( $session, $data, $templateText, $hidePassword ) = @_;
+    my ( $data, $templateText, $hidePassword ) = @_;
 
     $data->{Name} ||= $data->{WikiName};
     $templateText =~ s/%FIRSTLASTNAME%/$data->{Name}/go;
@@ -1008,7 +984,7 @@
         }
     }
     $templateText = $before.($after||'');
-    $templateText = $session->handleCommonTags(
+    $templateText = $TWiki::SESSION->handleCommonTags(
         $templateText, $TWiki::cfg{UsersWebName}, $data->{WikiName} );
     $templateText =~ s/( ?) *<\/?(nop|noautolink)\/?>\n?/$1/gois;
     # remove <nop> and <noautolink> tags
@@ -1018,11 +994,11 @@
 
 # Throws an Oops exception if there is a problem.
 sub _validateRegistration {
-    my ( $session, $data, $query, $topic, $requireForm ) = @_;
+    my ( $data, $query, $topic, $requireForm ) = @_;
 
     # DELETED CHECK: check for wikiName field.
 
-    if($session->{store}->topicExists( $TWiki::cfg{UsersWebName}, $data->{WikiName} )) {
+    if($TWiki::STORE->topicExists( $TWiki::cfg{UsersWebName}, $data->{WikiName} )) {
         throw TWiki::OopsException( 'attention',
                                     web => $data->{webName},
                                     topic => $topic,
@@ -1039,7 +1015,7 @@
                                     params => [ $data->{LoginName} ] );
     }
 
-    if ($session->{users}->lookupLoginName($data->{LoginName})) {
+    if ($TWiki::USERS->lookupLoginName($data->{LoginName})) {
         throw TWiki::OopsException( 'attention',
                                     web => $data->{webName},
                                     topic => $topic,
@@ -1047,7 +1023,7 @@
                                     params => [ $data->{LoginName},  ] );
     }
 
-    my $user = $session->{users}->findUser( $data->{LoginName}, undef, 1 );
+    my $user = $TWiki::USERS->findUser( $data->{LoginName}, undef, 1 );
     if ( $user && $user->passwordExists() ) {
         throw TWiki::OopsException( 'attention',
                                     web => $data->{webName},
@@ -1133,9 +1109,9 @@
 
 #SMELL - when should they get notified of the password?
 sub _addUserToPasswordSystem {
-    my( $session, $userRow ) = @_;
+    my( $userRow ) = @_;
 
-    my $user = $session->{users}->findUser($userRow->{LoginName}, $userRow->{WikiName});
+    my $user = $TWiki::USERS->findUser($userRow->{LoginName}, $userRow->{WikiName});
     if ($user && $user->passwordExists()) {
         unless( $user->checkPassword( $userRow->{Password} )) {
             throw Error::Simple("New password did not match existing password for this user");
@@ -1147,13 +1123,13 @@
     my $success;
     if ($userRow->{CryptPassword})  {
         throw Error::Simple( 'No API to install crypted password' );
-        #	$success = $session->{users}->installCryptedPassword($userRow->{LoginName},
+        #	$success = $TWiki::USERS->installCryptedPassword($userRow->{LoginName},
         #						   $userRow->{CryptPassword});
     }
     my $password = $userRow->{Password};
     unless ($password) {
         $password = TWiki::User::randomPassword();
-        $session->writeWarning('No password specified for '.$userRow->{LoginName}.' - using random='.$password);
+        $TWiki::SESSION->writeWarning('No password specified for '.$userRow->{LoginName}.' - using random='.$password);
     }
     $user->addPassword( $password );
     return 1;
@@ -1161,9 +1137,9 @@
 
 # sends $p->{template} to $p->{Email} with a bunch of substitutions.
 sub _sendEmail {
-    my( $session, $template, $p ) = @_;
+    my( $template, $p ) = @_;
 
-    my $text = $session->{templates}->readTemplate( $template );
+    my $text = $TWiki::TEMPLATES->readTemplate( $template );
     $p->{Introduction} ||= '';
     $p->{Name} ||= $p->{WikiName};
     $text =~ s/%LOGINNAME%/$p->{LoginName}/geo;
@@ -1173,10 +1149,10 @@
     $text =~ s/%INTRODUCTION%/$p->{Introduction}/go;
     $text =~ s/%VERIFICATIONCODE%/$p->{VerificationCode}/go;
     $text =~ s/%PASSWORD%/$p->{PasswordA}/go;
-    $text = $session->handleCommonTags(
+    $text = $TWiki::SESSION->handleCommonTags(
         $text, $TWiki::cfg{UsersWebName}, $p->{WikiName} );
 
-    return $session->{net}->sendEmail($text);
+    return $TWiki::NET->sendEmail($text);
 }
 
 # | In | reference to the users data structure |
Index: TWiki/UI/Upload.pm
===================================================================
--- TWiki/UI/Upload.pm	(revision 13172)
+++ TWiki/UI/Upload.pm	(working copy)
@@ -39,7 +39,7 @@
 
 =pod
 
----++ StaticMethod attach( $session )
+---++ StaticMethod attach()
 
 =upload= command handler.
 This method is designed to be
@@ -51,16 +51,14 @@
 =cut
 
 sub attach {
-    my $session = shift;
+    my $query = $TWiki::SESSION->{cgiQuery};
+    my $webName = $TWiki::SESSION->{webName};
+    my $topic = $TWiki::SESSION->{topicName};
 
-    my $query = $session->{cgiQuery};
-    my $webName = $session->{webName};
-    my $topic = $session->{topicName};
-
     my $fileName = $query->param( 'filename' ) || '';
-    my $skin = $session->getSkin();
+    my $skin = $TWiki::SESSION->getSkin();
 
-    TWiki::UI::checkWebExists( $session, $webName, $topic, 'attach' );
+    TWiki::UI::checkWebExists( $webName, $topic, 'attach' );
 
     my $tmpl = '';
     my $text = '';
@@ -69,15 +67,13 @@
     my $fileUser = '';
     my $isHideChecked = '';
 
-    TWiki::UI::checkMirror( $session, $webName, $topic );
-
-    TWiki::UI::checkAccess( $session, $webName, $topic,
-                            'CHANGE', $session->{user} );
-    TWiki::UI::checkTopicExists( $session, $webName, $topic,
+    TWiki::UI::checkAccess( $webName, $topic,
+                            'CHANGE', $TWiki::SESSION->{user} );
+    TWiki::UI::checkTopicExists( $webName, $topic,
                                  'upload files to' );
 
     ( $meta, $text ) =
-      $session->{store}->readTopic( $session->{user}, $webName, $topic, undef );
+      $TWiki::STORE->readTopic( $TWiki::SESSION->{user}, $webName, $topic, undef );
     my $args = $meta->get( 'FILEATTACHMENT', $fileName );
     $args = {
              name => $fileName,
@@ -95,38 +91,38 @@
     # Attach is a read function, only has potential for a change
     if( $TWiki::cfg{Log}{attach} ) {
         # write log entry
-        $session->writeLog( 'attach', $webName.'.'.$topic, $fileName );
+        $TWiki::SESSION->writeLog( 'attach', $webName.'.'.$topic, $fileName );
     }
 
     my $fileWikiUser = '';
     if( $fileName ) {
-        $tmpl = $session->{templates}->readTemplate( 'attachagain', $skin );
-        my $u = $session->{users}->findUser( $args->{user} );
+        $tmpl = $TWiki::TEMPLATES->readTemplate( 'attachagain', $skin );
+        my $u = $TWiki::USERS->findUser( $args->{user} );
         $fileWikiUser = $u->webDotWikiName() if $u;
     } else {
-        $tmpl = $session->{templates}->readTemplate( 'attachnew', $skin );
+        $tmpl = $TWiki::TEMPLATES->readTemplate( 'attachnew', $skin );
     }
     if ( $fileName ) {
         # must come after templates have been read
-        $atext .= $session->{attach}->formatVersions( $webName, $topic, %$args );
+        $atext .= $TWiki::ATTACH->formatVersions( $webName, $topic, %$args );
     }
     $tmpl =~ s/%ATTACHTABLE%/$atext/go;
     $tmpl =~ s/%FILEUSER%/$fileWikiUser/go;
-    $session->enterContext( 'can_render_meta', $meta );
-    $tmpl = $session->handleCommonTags( $tmpl, $webName, $topic );
-    $tmpl = $session->{renderer}->getRenderedVersion( $tmpl, $webName, $topic );
+    $TWiki::SESSION->enterContext( 'can_render_meta', $meta );
+    $tmpl = $TWiki::SESSION->handleCommonTags( $tmpl, $webName, $topic );
+    $tmpl = $TWiki::RENDER->getRenderedVersion( $tmpl, $webName, $topic );
     $tmpl =~ s/%HIDEFILE%/$isHideChecked/go;
     $tmpl =~ s/%FILENAME%/$fileName/go;
     $tmpl =~ s/%FILEPATH%/$args->{path}/go;
     $args->{comment} = TWiki::entityEncode( $args->{comment} );
     $tmpl =~ s/%FILECOMMENT%/$args->{comment}/go;
 
-    $session->writeCompletePage( $tmpl );
+    $TWiki::SESSION->writeCompletePage( $tmpl );
 }
 
 =pod
 
----++ StaticMethod upload( $session )
+---++ StaticMethod upload( $TWiki::SESSION )
 
 =upload= command handler.
 This method is designed to be
@@ -149,13 +145,11 @@
 =cut
 
 sub upload {
-    my $session = shift;
+    my $query = $TWiki::SESSION->{cgiQuery};
+    my $webName = $TWiki::SESSION->{webName};
+    my $topic = $TWiki::SESSION->{topicName};
+    my $user = $TWiki::SESSION->{user};
 
-    my $query = $session->{cgiQuery};
-    my $webName = $session->{webName};
-    my $topic = $session->{topicName};
-    my $user = $session->{user};
-
     my $hideFile = $query->param( 'hidefile' ) || '';
     my $fileComment = $query->param( 'filecomment' ) || '';
     my $createLink = $query->param( 'createlink' ) || '';
@@ -173,10 +167,9 @@
     $fileName =~ s/\s*$//o;
     $filePath =~ s/\s*$//o;
 
-    TWiki::UI::checkWebExists( $session, $webName, $topic, 'attach files to' );
-    TWiki::UI::checkTopicExists( $session, $webName, $topic, 'attach files to' );
-    TWiki::UI::checkMirror( $session, $webName, $topic );
-    TWiki::UI::checkAccess( $session, $webName, $topic,
+    TWiki::UI::checkWebExists( $webName, $topic, 'attach files to' );
+    TWiki::UI::checkTopicExists( $webName, $topic, 'attach files to' );
+    TWiki::UI::checkAccess( $webName, $topic,
                             'CHANGE', $user );
 
     my ( $fileSize, $fileDate, $tmpFileName );
@@ -205,7 +198,7 @@
                                         params => ($filePath || '""') );
         }
 
-        my $maxSize = $session->{prefs}->getPreferencesValue( 'ATTACHFILESIZELIMIT' );
+        my $maxSize = $TWiki::PREFS->getPreferencesValue( 'ATTACHFILESIZELIMIT' );
         $maxSize = 0 unless ( $maxSize =~ /([0-9]+)/o );
 
         if( $maxSize && $fileSize > $maxSize * 1024 ) {
@@ -218,7 +211,7 @@
     }
 
     try {
-        $session->{store}->saveAttachment(
+        $TWiki::STORE->saveAttachment(
             $webName, $topic, $fileName, $user,
             { dontlog => !$TWiki::cfg{Log}{upload},
               comment => $fileComment,
@@ -240,8 +233,8 @@
     close( $stream ) if $stream;
 
     if( $fileName eq $origName ) {
-	    my $redirecturl = _getRedirectUrl( $session ) || $session->getScriptUrl( 1, 'view', $webName, $topic );
-        $session->redirect( $redirecturl );
+	    my $redirecturl = _getRedirectUrl() || $TWiki::SESSION->getScriptUrl( 1, 'view', $webName, $topic );
+        $TWiki::SESSION->redirect( $redirecturl );
     } else {
         throw TWiki::OopsException( 'attention',
                                     def => 'upload_name_changed',
@@ -267,9 +260,7 @@
 =cut
 
 sub _getRedirectUrl {
-    my $session = shift;
-
-    my $query = $session->{cgiQuery};
+    my $query = $TWiki::SESSION->{cgiQuery};
     my $redirecturl = $query->param( 'redirectto' );
     return '' unless $redirecturl;
     if( $redirecturl =~ /^$TWiki::regex{linkProtocolPattern}\:\/\//o ) {
@@ -281,8 +272,8 @@
         }
     }
     # assuming 'web.topic' or 'topic'
-    my ( $w, $t ) = $session->normalizeWebTopicName( $session->{webName}, $redirecturl );
-    $redirecturl = $session->getScriptUrl( 1, 'view', $w, $t );
+    my ( $w, $t ) = $TWiki::SESSION->normalizeWebTopicName( $TWiki::SESSION->{webName}, $redirecturl );
+    $redirecturl = $TWiki::SESSION->getScriptUrl( 1, 'view', $w, $t );
 }
 
 1;
Index: TWiki/UI/Edit.pm
===================================================================
--- TWiki/UI/Edit.pm	(revision 13172)
+++ TWiki/UI/Edit.pm	(working copy)
@@ -46,7 +46,7 @@
 
 =pod
 
----++ StaticMethod edit( $session )
+---++ StaticMethod edit( )
 
 Edit command handler.
 This method is designed to be
@@ -67,19 +67,18 @@
 =cut
 
 sub edit {
-    my $session = shift;
-    my ( $text, $tmpl ) = init_edit( $session, 'edit' );
-    finalize_edit ( $session, $text, $tmpl );
+    my ( $text, $tmpl ) = _init_edit( 'edit' );
+    _finalize_edit( $text, $tmpl );
 }
 
 
-sub init_edit {
-    my ( $session, $templateName )  = @_;
+sub _init_edit {
+    my ( $templateName )  = @_;
 
-    my $query = $session->{cgiQuery};
-    my $webName = $session->{webName};
-    my $topic = $session->{topicName};
-    my $user = $session->{user};
+    my $query = $TWiki::SESSION->{cgiQuery};
+    my $webName = $TWiki::SESSION->{webName};
+    my $topic = $TWiki::SESSION->{topicName};
+    my $user = $TWiki::SESSION->{user};
 
     # empty means edit both form and text, "form" means edit form only,
     # "text" means edit text only
@@ -94,13 +93,12 @@
     # apptype is undocumented legacy
     my $cgiAppType = $query->param( 'contenttype' ) ||
       $query->param( 'apptype' ) || 'text/html';
-    my $skin = $session->getSkin();
+    my $skin = $TWiki::SESSION->getSkin();
     my $theParent = $query->param( 'topicparent' ) || '';
     my $ptext = $query->param( 'text' );
-    my $store = $session->{store};
+    my $store = $TWiki::STORE;
 
-    TWiki::UI::checkWebExists( $session, $webName, $topic, 'edit' );
-    TWiki::UI::checkMirror( $session, $webName, $topic );
+    TWiki::UI::checkWebExists( $webName, $topic, 'edit' );
 
     my $tmpl = '';
     my $text = '';
@@ -109,8 +107,8 @@
     my $topicExists  = $store->topicExists( $webName, $topic );
 
     # If you want to edit, you have to be able to view and change.
-    TWiki::UI::checkAccess( $session, $webName, $topic, 'VIEW', $user );
-    TWiki::UI::checkAccess( $session, $webName, $topic, 'CHANGE', $user );
+    TWiki::UI::checkAccess( $webName, $topic, 'VIEW', $user );
+    TWiki::UI::checkAccess( $webName, $topic, 'CHANGE', $user );
 
     # Check lease, unless we have been instructed to ignore it
     # or if we are using the 10X's or AUTOINC topic name for
@@ -135,7 +133,7 @@
                             $TWiki::cfg{LeaseLengthLessForceful} ) {
                         $def = 'lease_old';
                         $past = TWiki::Time::formatDelta(
-                            $t - $lease->{expires}, $session->{i18n} );
+                            $t - $lease->{expires}, $TWiki::I18N );
                         $future = '';
                     }
                 }
@@ -143,9 +141,9 @@
                     # The lease is active
                     $def = 'lease_active';
                     $past = TWiki::Time::formatDelta(
-                        $t - $lease->{taken}, $session->{i18n} );
+                        $t - $lease->{taken}, $I18N );
                     $future = TWiki::Time::formatDelta(
-                        $lease->{expires} - $t, $session->{i18n} );
+                        $lease->{expires} - $t, $I18N );
                 }
                 if( $def ) {
                     # use a 'keep' redirect to ensure we pass parameter
@@ -188,7 +186,7 @@
           $store->readTopic( undef, $webName, $topic, undef );
     }
 
-    if( $saveCmd && ! $session->{user}->isAdmin()) {
+    if( $saveCmd && ! $TWiki::SESSION->{user}->isAdmin()) {
         throw TWiki::OopsException( 'accessdenied', def=>'only_group',
                                     web => $webName, topic => $topic,
                                     params => $TWiki::cfg{UsersWebName}.
@@ -198,13 +196,13 @@
 
     # Get edit template, standard or a different skin
     my $template = $query->param( 'template' ) ||
-	$session->{prefs}->getPreferencesValue('EDIT_TEMPLATE') ||
+	$TWiki::PREFS->getPreferencesValue('EDIT_TEMPLATE') ||
         $templateName;
     $tmpl =
-      $session->{templates}->readTemplate( $template.$editaction, $skin );
+      $TWiki::TEMPLATES->readTemplate( $template.$editaction, $skin );
 
     if( !$tmpl && $template ne $templateName ) {
-        $tmpl = $session->{templates}->readTemplate( $templateName, $skin );
+        $tmpl = $TWiki::TEMPLATES->readTemplate( $templateName, $skin );
     }
 
     if( !$tmpl ) {
@@ -220,7 +218,7 @@
     unless( $topicExists ) {
         if( $templateTopic ) {
             ( $templateWeb, $templateTopic ) =
-              $session->normalizeWebTopicName( $templateWeb, $templateTopic );
+              $TWiki::SESSION->normalizeWebTopicName( $templateWeb, $templateTopic );
 
             unless( $store->topicExists( $templateWeb, $templateTopic )) {
                 throw TWiki::OopsException( 'accessdenied',
@@ -231,11 +229,11 @@
             }
 
             ( $meta, $text ) =
-              $store->readTopic( $session->{user}, $templateWeb,
+              $store->readTopic( $TWiki::SESSION->{user}, $templateWeb,
                                         $templateTopic, undef );
             $templateTopic = $templateWeb.'.'.$templateTopic;
         } else {
-            ( $meta, $text ) = TWiki::UI::readTemplateTopic( $session, 'WebTopicEditTemplate' );
+            ( $meta, $text ) = TWiki::UI::readTemplateTopic('WebTopicEditTemplate' );
         }
 
         $extra = "(not exist)";
@@ -246,7 +244,7 @@
             $formTemplate = $form->{name} if $form;
         }
 
-        $text = $session->expandVariablesOnTopicCreation( $text, $user );
+        $text = $TWiki::SESSION->expandVariablesOnTopicCreation( $text, $user );
         $tmpl =~ s/%NEWTOPIC%/1/;
     } else {
         $tmpl =~ s/%NEWTOPIC%//;
@@ -272,7 +270,7 @@
     } elsif( $theParent ) {
         my $parentWeb;
         ($parentWeb, $theParent) =
-          $session->normalizeWebTopicName( $webName, $theParent );
+          $TWiki::SESSION->normalizeWebTopicName( $webName, $theParent );
         if( $parentWeb ne $webName ) {
             $theParent = $parentWeb.'.'.$theParent;
         }
@@ -299,40 +297,40 @@
     }
 
     if( $saveCmd ) {
-        $text = $store->readTopicRaw( $session->{user}, $webName,
+        $text = $store->readTopicRaw( $TWiki::SESSION->{user}, $webName,
                                                  $topic, undef );
     }
 
-    $session->{plugins}->beforeEditHandler(
+    $TWiki::PLUGINS->beforeEditHandler(
         $text, $topic, $webName, $meta ) unless( $saveCmd );
 
     if( $TWiki::cfg{Log}{edit} ) {
         # write log entry
-        $session->writeLog( 'edit', $webName.'.'.$topic, $extra );
+        $TWiki::SESSION->writeLog( 'edit', $webName.'.'.$topic, $extra );
     }
 
     $tmpl =~ s/\(edit\)/\(edit cmd=$saveCmd\)/go if $saveCmd;
 
     $tmpl =~ s/%CMD%/$saveCmd/go;
-    $session->enterContext( 'can_render_meta', $meta );
+    $TWiki::SESSION->enterContext( 'can_render_meta', $meta );
 
-    $tmpl = $session->handleCommonTags( $tmpl, $webName, $topic, $meta );
-    $tmpl = $session->{renderer}->getRenderedVersion( $tmpl, $webName, $topic );
+    $tmpl = $TWiki::SESSION->handleCommonTags( $tmpl, $webName, $topic, $meta );
+    $tmpl = $TWiki::RENDER->getRenderedVersion( $tmpl, $webName, $topic );
     # Don't want to render form fields, so this after getRenderedVersion
     my $formMeta = $meta->get( 'FORM' );
     my $form = '';
     my $formText = '';
     $form = $formMeta->{name} if( $formMeta );
     if( $form && !$saveCmd ) {
-        my $formDef = new TWiki::Form( $session, $templateWeb, $form );
+        my $formDef = new TWiki::Form( $TWiki::SESSION, $templateWeb, $form );
         unless( $formDef ) {
             throw TWiki::OopsException( 'attention',
                                         def => 'no_form_def',
-                                        web => $session->{webName},
-                                        topic => $session->{topicName},
+                                        web => $TWiki::SESSION->{webName},
+                                        topic => $TWiki::SESSION->{topicName},
                                         params => [ $templateWeb, $form ] );
         }
-        $formDef->getFieldValuesFromQuery( $session->{cgiQuery}, $meta );
+        $formDef->getFieldValuesFromQuery( $TWiki::SESSION->{cgiQuery}, $meta );
         # And render them for editing
         # SMELL: these are both side-effecting functions, that will set
         # default values for fields if they are not set in the meta.
@@ -342,9 +340,9 @@
         } else {
             $formText = $formDef->renderForEdit( $webName, $topic, $meta );
         }
-    } elsif( !$saveCmd && $session->{prefs}->getWebPreferencesValue( 'WEBFORMS', $webName )) {
-        $formText = $session->{templates}->readTemplate( "addform", $skin );
-        $formText = $session->handleCommonTags(
+    } elsif( !$saveCmd && $TWiki::PREFS->getWebPreferencesValue( 'WEBFORMS', $webName )) {
+        $formText = $TWiki::TEMPLATES->readTemplate( "addform", $skin );
+        $formText = $TWiki::SESSION->handleCommonTags(
             $formText, $webName, $topic, $meta );
     }
     $tmpl =~ s/%FORMFIELDS%/$formText/g;
@@ -354,14 +352,14 @@
     return ( $text, $tmpl );
 }
 
-sub finalize_edit {
+sub _finalize_edit {
 
-    my ( $session, $text, $tmpl ) = @_;
+    my ( $text, $tmpl ) = @_;
 
-    my $query = $session->{cgiQuery};
-    my $webName = $session->{webName};
-    my $topic = $session->{topicName};
-    my $user = $session->{user};
+    my $query = $TWiki::SESSION->{cgiQuery};
+    my $webName = $TWiki::SESSION->{webName};
+    my $topic = $TWiki::SESSION->{topicName};
+    my $user = $TWiki::SESSION->{user};
     # apptype is undocumented legacy
     my $cgiAppType = $query->param( 'contenttype' ) ||
       $query->param( 'apptype' ) || 'text/html';
@@ -371,9 +369,9 @@
     $text = TWiki::entityEncode( $text );
     $tmpl =~ s/%TEXT%/$text/g;
 
-    $session->{store}->setLease( $webName, $topic, $user, $TWiki::cfg{LeaseLength} );
+    $TWiki::STORE->setLease( $webName, $topic, $user, $TWiki::cfg{LeaseLength} );
 
-    $session->writeCompletePage( $tmpl, 'edit', $cgiAppType );
+    $TWiki::SESSION->writeCompletePage( $tmpl, 'edit', $cgiAppType );
 }
 
 1;
Index: TWiki/UI/Search.pm
===================================================================
--- TWiki/UI/Search.pm	(revision 13172)
+++ TWiki/UI/Search.pm	(working copy)
@@ -33,7 +33,7 @@
 
 =pod
 
----++ StaticMethod search( $session )
+---++ StaticMethod search( )
 
 Perform a search as dictated by CGI parameters:
 
@@ -67,14 +67,12 @@
 =cut
 
 sub search {
-    my $session = shift;
+    my $query = $TWiki::SESSION->{cgiQuery};
+    my $webName = $TWiki::SESSION->{webName};
+    my $topic = $TWiki::SESSION->{topicName};
 
-    my $query = $session->{cgiQuery};
-    my $webName = $session->{webName};
-    my $topic = $session->{topicName};
+    TWiki::UI::checkWebExists( $webName, $topic, 'search' );
 
-    TWiki::UI::checkWebExists( $session, $webName, $topic, 'search' );
-
     # The CGI.pm docs claim that it returns all of the values in a
     # multiple select if called in a list context, but that may not
     # work (didn't on the dev box -- perl 5.004_4 and CGI.pm 2.36 on
@@ -105,10 +103,10 @@
     $attrWeb =~ tr/+/ /;       # pluses become spaces
     $attrWeb =~ s/%([0-9a-fA-F]{2})/pack('c',hex($1))/ge;  # %20 becomes space
 
-#    $session->writePageHeader();
+#    $TWiki::SESSION->writePageHeader();
 
     # SMELL: what's all the 'scalar' crud, below?
-    my $text = $session->{search}->searchWeb(
+    my $text = $TWiki::SEARCH->searchWeb(
 #        _callback       => \&_contentCallback,	#FIXME - can't process format=| $topic | line by line...
         _callback       => undef,
         _cbdata         => undef,
@@ -120,7 +118,7 @@
         'scope'         => scalar $query->param( 'scope' ),
         'order'         => scalar $query->param( 'order' ),
         'type'          => scalar $query->param( 'type' ) ||
-          $session->{prefs}->getPreferencesValue( 'SEARCHDEFAULTTTYPE' ),
+          $TWiki::PREFS->getPreferencesValue( 'SEARCHDEFAULTTTYPE' ),
         'regex'         => scalar $query->param( 'regex' ),
         'limit'         => scalar $query->param( 'limit' ),
         'reverse'       => scalar $query->param( 'reverse' ),
@@ -141,7 +139,7 @@
         'subweb'     => scalar $query->param( 'subweb' )
     );
  
-    $session->writeCompletePage($text);
+    $TWiki::SESSION->writeCompletePage($text);
     
 }
 
Index: TWiki/UI/Changes.pm
===================================================================
--- TWiki/UI/Changes.pm	(revision 13172)
+++ TWiki/UI/Changes.pm	(working copy)
@@ -38,21 +38,19 @@
 
 # Command handler for changes command
 sub changes {
-    my $session = shift;
+    my $query = $TWiki::SESSION->{cgiQuery};
+    my $webName = $TWiki::SESSION->{webName};
+    my $topic = $TWiki::SESSION->{topicName};
 
-    my $query = $session->{cgiQuery};
-    my $webName = $session->{webName};
-    my $topic = $session->{topicName};
+    TWiki::UI::checkWebExists( $webName, $topic, 'find changes in' );
 
-    TWiki::UI::checkWebExists( $session, $webName, $topic, 'find changes in' );
+    my $skin = $TWiki::SESSION->getSkin();
 
-    my $skin = $session->getSkin();
+    my $text = $TWiki::TEMPLATES->readTemplate( 'changes', $skin );
 
-    my $text = $session->{templates}->readTemplate( 'changes', $skin );
-
     my( $page, $eachChange, $after) = split( /%REPEAT%/, $text );
 
-    my $changeData = $session->{store}->readMetaData( $webName, 'changes' );
+    my $changeData = $TWiki::STORE->readMetaData( $webName, 'changes' );
     my @changes = split( /\r?\n/, $changeData );
     unless( $query->param( 'minor' )) {
         @changes = grep { !/\tminor$/ } @changes;
@@ -67,14 +65,14 @@
     foreach my $change ( reverse @changes ) {
         my( $changedTopic, $login, $time, $rev ) = split( /\t/, $change );
         unless( $done{$changedTopic} ) {
-            next unless $session->{store}->topicExists( $webName, $changedTopic );
+            next unless $TWiki::STORE->topicExists( $webName, $changedTopic );
 
             try {
-                my $summary = $session->{renderer}->summariseChanges(
-                    $session->{user}, $webName, $changedTopic, $rev );
+                my $summary = $TWiki::RENDER->summariseChanges(
+                    $TWiki::SESSION->{user}, $webName, $changedTopic, $rev );
                 my $thisChange = $eachChange;
                 $thisChange =~ s/%TOPICNAME%/$changedTopic/go;
-                my $u = $session->{users}->findUser( $login );
+                my $u = $TWiki::USERS->findUser( $login );
                 my $wikiuser = $u ? $u->webDotWikiName() : '';
                 $thisChange =~ s/%AUTHOR%/$wikiuser/go;
                 $time = TWiki::Time::formatTime( $time );
@@ -85,7 +83,7 @@
                 }
                 $thisChange =~ s/%TIME%/$time/g;
                 $thisChange =~ s/%REVISION%/$srev/go;
-                $thisChange = $session->{renderer}->getRenderedVersion
+                $thisChange = $TWiki::RENDER->getRenderedVersion
                   ( $thisChange, $webName, $changedTopic );
                 $thisChange =~ s/%TEXTHEAD%/$summary/go;
                 $page .= $thisChange;
@@ -97,14 +95,14 @@
     }
     if( $TWiki::cfg{Log}{changes} ) {
         # write log entry
-        $session->writeLog( 'changes', $webName, '' );
+        $TWiki::SESSION->writeLog( 'changes', $webName, '' );
     }
     $page .= $after;
 
-    $page = $session->handleCommonTags( $page, $webName, $topic );
-    $page = $session->{renderer}->getRenderedVersion($page, $webName, $topic );
+    $page = $TWiki::SESSION->handleCommonTags( $page, $webName, $topic );
+    $page = $TWiki::RENDER->getRenderedVersion($page, $webName, $topic );
 
-    $session->writeCompletePage( $page );
+    $TWiki::SESSION->writeCompletePage( $page );
 }
 
 1;
Index: TWiki/UI/Manage.pm
===================================================================
--- TWiki/UI/Manage.pm	(revision 13172)
+++ TWiki/UI/Manage.pm	(working copy)
@@ -39,7 +39,7 @@
 
 =pod
 
----++ StaticMethod manage( $session )
+---++ StaticMethod manage()
 
 =manage= command handler.
 This method is designed to be
@@ -48,22 +48,20 @@
 =cut
 
 sub manage {
-    my $session = shift;
+    my $action = $TWiki::SESSION->{cgiQuery}->param( 'action' );
 
-    my $action = $session->{cgiQuery}->param( 'action' );
-
     if( $action eq 'createweb' ) {
-        _createWeb( $session );
+        _createWeb( );
     } elsif( $action eq 'changePassword' ) {
-        TWiki::UI::Register::changePassword( $session );
+        TWiki::UI::Register::changePassword( );
     } elsif ($action eq 'bulkRegister') {
-        TWiki::UI::Register::bulkRegister( $session );
+        TWiki::UI::Register::bulkRegister( );
     } elsif( $action eq 'deleteUserAccount' ) {
-        _removeUser( $session );
+        _removeUser( );
     } elsif( $action eq 'editSettings' ) {
-        _editSettings( $session );
+        _editSettings( );
     } elsif( $action eq 'saveSettings' ) {
-        _saveSettings( $session );
+        _saveSettings( );
     } elsif( $action ) {
         throw TWiki::OopsException( 'attention',
                                     def => 'unrecognized_action',
@@ -76,13 +74,11 @@
 # Renames the user's topic (with renaming all links) and
 # removes user entry from passwords. CGI parameters:
 sub _removeUser {
-    my $session = shift;
+    my $webName = $TWiki::SESSION->{webName};
+    my $topic = $TWiki::SESSION->{topicName};
+    my $query = $TWiki::SESSION->{cgiQuery};
+    my $user = $TWiki::SESSION->{user};
 
-    my $webName = $session->{webName};
-    my $topic = $session->{topicName};
-    my $query = $session->{cgiQuery};
-    my $user = $session->{user};
-
     my $password = $query->param( 'password' );
 
     # check if user entry exists
@@ -134,13 +130,11 @@
 }
 
 sub _createWeb {
-    my $session = shift;
+    my $topicName = $TWiki::SESSION->{topicName};
+    my $webName = $TWiki::SESSION->{webName};
+    my $query = $TWiki::SESSION->{cgiQuery};
+    my $user = $TWiki::SESSION->{user};
 
-    my $topicName = $session->{topicName};
-    my $webName = $session->{webName};
-    my $query = $session->{cgiQuery};
-    my $user = $session->{user};
-
     my $webBGColor = $query->param( 'webbgcolor' ) || '';
     my $siteMapWhat = $query->param( 'sitemapwhat' ) || '';
     my $siteMapUseTo = $query->param( 'sitemapuseto' ) || '';
@@ -151,8 +145,8 @@
     if( $webName =~ m|^(.*)[./](.*?)$| ) {
         $parent = $1;
     }
-    TWiki::UI::checkAccess( $session, $parent, undef,
-                            'CHANGE', $session->{user} );
+    TWiki::UI::checkAccess( $parent, undef,
+                            'CHANGE', $TWiki::SESSION->{user} );
 
     my $newWeb = $query->param( 'newweb' ) || '';
     unless( $newWeb ) {
@@ -165,7 +159,7 @@
     $newWeb = TWiki::Sandbox::untaintUnchecked( $newWeb );
 
     my $baseWeb = $query->param( 'baseweb' ) || '';
-    unless( $session->{store}->webExists( $baseWeb )) {
+    unless( $TWiki::STORE->webExists( $baseWeb )) {
         throw TWiki::OopsException
           ( 'attention', def => 'base_web_missing', params => $baseWeb );
     }
@@ -175,7 +169,7 @@
     # SMELL: check that it is a valid topic name?
     $newTopic = TWiki::Sandbox::untaintUnchecked( $newTopic );
 
-    if( $session->{store}->webExists( $newWeb )) {
+    if( $TWiki::STORE->webExists( $newWeb )) {
         throw TWiki::OopsException
           ( 'attention', def => 'web_exists', params => $newWeb );
     }
@@ -196,7 +190,7 @@
       };
     $opts->{SITEMAPLIST} = 'on' if( $siteMapWhat );
 
-    my $err = $session->{store}->createWeb( $user, $newWeb, $baseWeb, $opts );
+    my $err = $TWiki::STORE->createWeb( $user, $newWeb, $baseWeb, $opts );
     if( $err ) {
         throw TWiki::OopsException
           ( 'attention', def => 'web_creation_error',
@@ -213,7 +207,7 @@
 
 =pod
 
----++ StaticMethod rename( $session )
+---++ StaticMethod rename( )
 
 =rename= command handler.
 This method is designed to be
@@ -233,15 +227,13 @@
 =cut
 
 sub rename {
-    my $session = shift;
-
-    my $oldTopic = $session->{topicName};
-    my $oldWeb = $session->{webName};
-    my $query = $session->{cgiQuery};
+    my $oldTopic = $TWiki::SESSION->{topicName};
+    my $oldWeb = $TWiki::SESSION->{webName};
+    my $query = $TWiki::SESSION->{cgiQuery};
     my $action = $query->param( 'action' ) || '';
 
     if( $action eq 'renameweb' ) {
-        _renameweb( $session );
+        _renameweb( $TWiki::SESSION );
         return;
     }
 
@@ -264,7 +256,6 @@
 
     my $confirm = $query->param( 'confirm' );
     my $doAllowNonWikiWord = $query->param( 'nonwikiword' ) || '';
-    my $store = $session->{store};
 
     $newTopic =~ s/\s//go;
     $newTopic =~ s/$TWiki::cfg{NameFilter}//go;
@@ -272,14 +263,14 @@
 
     $attachment ||= '';
 
-    TWiki::UI::checkWebExists( $session, $oldWeb, $oldTopic, 'rename' );
+    TWiki::UI::checkWebExists( $oldWeb, $oldTopic, 'rename' );
     # Item3270: Wrap topic existence into extra try/catch block to
     #           check for the same name starting with a lower case letter.
     try {
-        TWiki::UI::checkTopicExists( $session, $oldWeb, $oldTopic, 'rename');
+        TWiki::UI::checkTopicExists( $oldWeb, $oldTopic, 'rename');
     } catch TWiki::OopsException with {
         $oldTopic = lcfirst $oldTopic;
-        TWiki::UI::checkTopicExists( $session, $oldWeb, $oldTopic, 'rename');
+        TWiki::UI::checkTopicExists( $oldWeb, $oldTopic, 'rename');
     };
 
     if( $newTopic && !TWiki::isValidWikiWord( $newTopic ) ) {
@@ -298,7 +289,7 @@
 
     if ( $attachment) {
         # Does old attachment exist?
-        unless( $store->attachmentExists( $oldWeb, $oldTopic,
+        unless( $TWiki::STORE->attachmentExists( $oldWeb, $oldTopic,
                                           $attachment )) {
 			my $tmplname = $query->param( 'template' ) || '';
             throw TWiki::OopsException(
@@ -309,16 +300,15 @@
                 params => [
                     $newWeb, $newTopic,
                     $attachment,
-                    $session->{i18n}->maketext('Attachment does not exist')
+                    $TWiki::I18N->maketext('Attachment does not exist')
                    ] );
         }
 
         if( $newWeb && $newTopic ) {
-            TWiki::UI::checkTopicExists( $session, $newWeb,
-                                         $newTopic, 'rename');
+            TWiki::UI::checkTopicExists( $newWeb, $newTopic, 'rename');
 
             # does new attachment already exist?
-            if( $store->attachmentExists( $newWeb, $newTopic,
+            if( $TWiki::STORE->attachmentExists( $newWeb, $newTopic,
                                           $attachment )) {
                 throw TWiki::OopsException(
                     'attention',
@@ -328,17 +318,17 @@
                     params => [
                         $newWeb, $newTopic,
                         $attachment,
-                        $session->{i18n}->maketext(
+                        $TWiki::I18N->maketext(
                             'Attachment already exists in new topic')
                        ] );
             }
         } # else fall through to new topic screen
     } elsif( $newTopic ) {
         ( $newWeb, $newTopic ) =
-          $session->normalizeWebTopicName( $newWeb, $newTopic );
+          $TWiki::SESSION->normalizeWebTopicName( $newWeb, $newTopic );
 
-        TWiki::UI::checkWebExists( $session, $newWeb, $newTopic, 'rename' );
-        if( $store->topicExists( $newWeb, $newTopic)) {
+        TWiki::UI::checkWebExists( $newWeb, $newTopic, 'rename' );
+        if( $TWiki::STORE->topicExists( $newWeb, $newTopic)) {
             throw TWiki::OopsException( 'attention',
                                         def => 'rename_topic_exists',
                                         web => $oldWeb,
@@ -347,15 +337,15 @@
         }
     }
 
-    TWiki::UI::checkAccess( $session, $oldWeb, $oldTopic,
-                            'RENAME', $session->{user} );
+    TWiki::UI::checkAccess( $oldWeb, $oldTopic,
+                            'RENAME', $TWiki::SESSION->{user} );
 
     # Has user selected new name yet?
     if( ! $newTopic || $confirm ) {
         # Must be able to view the source to rename it
-        TWiki::UI::checkAccess( $session, $oldWeb, $oldTopic,
-                                'VIEW', $session->{user} );
-        _newTopicScreen( $session,
+        TWiki::UI::checkAccess( $oldWeb, $oldTopic,
+                                'VIEW', $TWiki::SESSION->{user} );
+        _newTopicScreen( $TWiki::SESSION,
                          $oldWeb, $oldTopic,
                          $newWeb, $newTopic,
                          $attachment,
@@ -367,9 +357,9 @@
     my $refs;
     unless( $attachment ) {
         $refs = _getReferringTopicsListFromURL
-          ( $session, $oldWeb, $oldTopic, $newWeb, $newTopic );
+          ( $TWiki::SESSION, $oldWeb, $oldTopic, $newWeb, $newTopic );
     }
-    move( $session, $oldWeb, $oldTopic, $newWeb, $newTopic,
+    move( $oldWeb, $oldTopic, $newWeb, $newTopic,
           $attachment, $refs );
 
     my $new_url;
@@ -380,34 +370,34 @@
 
         if( $attachment ) {
             # go back to old topic after deleting an attachment
-            $new_url = $session->getScriptUrl( 0, 'view', $oldWeb, $oldTopic );
+            $new_url = $TWiki::SESSION->getScriptUrl( 0, 'view', $oldWeb, $oldTopic );
 
         } else {
             # redirect to parent topic, if set
             my ( $meta, $text ) =
-              $store->readTopic( undef, $newWeb, $newTopic, undef );
+              $TWiki::STORE->readTopic( undef, $newWeb, $newTopic, undef );
             my $parent = $meta->get( 'TOPICPARENT' );
             my( $parentWeb, $parentTopic );
             if( $parent && defined $parent->{name} ) {
                 ( $parentWeb, $parentTopic ) =
-                  $session->normalizeWebTopicName( '', $parent->{name} );
+                  $TWiki::SESSION->normalizeWebTopicName( '', $parent->{name} );
             }
             if( $parentTopic &&
                 !( $parentWeb eq $oldTopic && $parentTopic eq $oldTopic ) &&
-                  $store->topicExists( $parentWeb, $parentTopic ) ) {
-                $new_url = $session->getScriptUrl(
+                  $TWiki::STORE->topicExists( $parentWeb, $parentTopic ) ) {
+                $new_url = $TWiki::SESSION->getScriptUrl(
                     0, 'view', $parentWeb, $parentTopic );
             } else {
-                $new_url = $session->getScriptUrl( 0, 'view', $oldWeb,
+                $new_url = $TWiki::SESSION->getScriptUrl( 0, 'view', $oldWeb,
                                                    $TWiki::cfg{HomeTopicName});
             }
         }
     } else {
         #redirect to new topic
-        $new_url = $session->getScriptUrl( 0, 'view', $newWeb, $newTopic );
+        $new_url = $TWiki::SESSION->getScriptUrl( 0, 'view', $newWeb, $newTopic );
     }
 
-    $session->redirect( $new_url );
+    $TWiki::SESSION->redirect( $new_url );
 }
 
 #| =skin= | skin(s) to use |
@@ -415,12 +405,10 @@
 #| =newparentweb= | new parent web name |
 #| =confirm= | if defined, requires a second level of confirmation.  Currently accepted values are "getlock", "continue", and "cancel" |
 sub _renameweb {
-    my $session = shift;
+    my $oldWeb = $TWiki::SESSION->{webName};
+    my $query = $TWiki::SESSION->{cgiQuery};
+    my $user = $TWiki::SESSION->{user};
 
-    my $oldWeb = $session->{webName};
-    my $query = $session->{cgiQuery};
-    my $user = $session->{user};
-
     my $newParentWeb = $query->param( 'newparentweb' ) || '';
     unless ( !$newParentWeb || TWiki::isValidWebName( $newParentWeb, 1 )) {
         throw TWiki::OopsException
@@ -451,21 +439,19 @@
     my $breakLock = $query->param( 'breaklock' );
     my $confirm = $query->param( 'confirm' ) || '';
     my $doAllowNonWikiWord = $query->param( 'nonwikiword' ) || '';
-    my $store = $session->{store};
-    my $security = $session->{security};
+    my $security = $TWiki::ACCESS;
 
     TWiki::UI::checkWebExists(
-        $session, $oldWeb, $TWiki::cfg{WebPrefsTopicName}, 'rename' );
+        $oldWeb, $TWiki::cfg{WebPrefsTopicName}, 'rename' );
 
     if( $newWeb ) {
         if( $newParentWeb ) {
             # SMELL: need to check change permissions of new parent web
             TWiki::UI::checkWebExists(
-                $session, $newParentWeb,
-                $TWiki::cfg{WebPrefsTopicName}, 'rename' );
+                $newParentWeb, $TWiki::cfg{WebPrefsTopicName}, 'rename' );
         }
 
-        if( $store->webExists( $newWeb )) {
+        if( $TWiki::STORE->webExists( $newWeb )) {
             throw TWiki::OopsException(
                 'attention',
                 def => 'rename_web_exists',
@@ -489,8 +475,8 @@
 
         # get a topic list for all the topics referring to this web,
         # and build up a hash containing permissions and lock info.
-        $refs0 = getReferringTopics( $session, $oldWeb, undef, 0 );
-        $refs1 = getReferringTopics( $session, $oldWeb, undef, 1 );
+        $refs0 = getReferringTopics( $TWiki::SESSION, $oldWeb, undef, 0 );
+        $refs1 = getReferringTopics( $TWiki::SESSION, $oldWeb, undef, 1 );
         foreach my $ref (sort keys %$refs0) {
             $refs{$ref} = $refs0->{$ref};
         }
@@ -511,13 +497,13 @@
                 $webIter = TWiki::Sandbox::untaintUnchecked( $webIter );
                 $webTopic = TWiki::Sandbox::untaintUnchecked( $webTopic );
                 if($confirm eq 'getlock') {
-                    $store->setLease( $webIter, $webTopic, $user,
+                    $TWiki::STORE->setLease( $webIter, $webTopic, $user,
                                       $TWiki::cfg{LeaseLength});
-                    $lease_ref=$store->getLease($webIter,$webTopic);
+                    $lease_ref=$TWiki::STORE->getLease($webIter,$webTopic);
                 } elsif ($confirm eq 'cancel') {
-                    $lease_ref=$store->getLease($webIter,$webTopic);
+                    $lease_ref=$TWiki::STORE->getLease($webIter,$webTopic);
                     if($lease_ref->{user} eq $user) {
-                        $store->clearLease( $webIter, $webTopic );
+                        $TWiki::STORE->clearLease( $webIter, $webTopic );
                     }
                 }
                 my $wit = $webIter.'/'.$webTopic;
@@ -543,21 +529,21 @@
 
         # get a topic list for this web and all its subwebs, and build
         # up a hash containing permissions and lock info.
-        (@webList) = $store->getListOfWebs('public',$oldWeb);
+        (@webList) = $TWiki::STORE->getListOfWebs('public',$oldWeb);
         unshift(@webList,$oldWeb);
         foreach my $webIter (@webList) {
             $webIter = TWiki::Sandbox::untaintUnchecked( $webIter );
-            my @webTopicList=$store->getTopicNames($webIter);
+            my @webTopicList=$TWiki::STORE->getTopicNames($webIter);
             foreach my $webTopic (@webTopicList) {
                 $webTopic = TWiki::Sandbox::untaintUnchecked( $webTopic );
                 if( $confirm eq 'getlock' ) {
-                    $store->setLease( $webIter, $webTopic, $user,
+                    $TWiki::STORE->setLease( $webIter, $webTopic, $user,
                                       $TWiki::cfg{LeaseLength});
-                    $lease_ref = $store->getLease($webIter,$webTopic);
+                    $lease_ref = $TWiki::STORE->getLease($webIter,$webTopic);
                 } elsif ($confirm eq 'cancel') {
-                    $lease_ref = $store->getLease($webIter,$webTopic);
+                    $lease_ref = $TWiki::STORE->getLease($webIter,$webTopic);
                     if( $lease_ref->{user} eq $user ) {
-                        $store->clearLease( $webIter, $webTopic );
+                        $TWiki::STORE->clearLease( $webIter, $webTopic );
                     }
                 }
                 my $wit = $webIter.'/'.$webTopic;
@@ -612,16 +598,16 @@
                       @{$webTopicInfo{movelocked}} ) {
                     $nocontinue = 'style="display:none;"';
                 }
-                my $mvd = join(' ', @{$webTopicInfo{movedenied}} ) || ($session->{i18n}->maketext('(none)'));
+                my $mvd = join(' ', @{$webTopicInfo{movedenied}} ) || ($TWiki::I18N->maketext('(none)'));
                 $mvd = substr($mvd, 0, 300).'... (more)'
                   if( length($mvd) > 300);
-                my $mvl = join(' ', @{$webTopicInfo{movelocked}} ) || ($session->{i18n}->maketext('(none)'));
+                my $mvl = join(' ', @{$webTopicInfo{movelocked}} ) || ($TWiki::I18N->maketext('(none)'));
                 $mvl = substr($mvl, 0, 300).'... (more)'
                   if( length($mvl) > 300);
-                my $mdd = join(' ', @{$webTopicInfo{modifydenied}} ) || ($session->{i18n}->maketext('(none)'));
+                my $mdd = join(' ', @{$webTopicInfo{modifydenied}} ) || ($TWiki::I18N->maketext('(none)'));
                 $mdd = substr($mdd, 0, 300).'... (more)'
                   if( length($mdd) > 300);
-                my $mdl = join(' ', @{$webTopicInfo{modifylocked}} ) || ($session->{i18n}->maketext('(none)'));
+                my $mdl = join(' ', @{$webTopicInfo{modifylocked}} ) || ($TWiki::I18N->maketext('(none)'));
                 $mdl = substr($mdl, 0, 300).'... (more)'
                   if( length($mdl) > 300);
                 throw TWiki::OopsException(
@@ -638,14 +624,14 @@
 
         if ($confirm eq 'cancel') {
             # redirect to original web
-            my $viewURL = $session->getScriptUrl( 0, 'view',
+            my $viewURL = $TWiki::SESSION->getScriptUrl( 0, 'view',
                 $oldWeb, $TWiki::cfg{HomeTopicName});
-            $session->redirect( $viewURL );
+            $TWiki::SESSION->redirect( $viewURL );
         } elsif( $confirm ne 'getlock' ||
                    ($confirm eq 'getlock' &&
                       $modifyingLockedTopics && $movingLockedTopics )) {
             # Has user selected new name yet?
-            _newWebScreen( $session, $oldWeb, $newWeb,
+            _newWebScreen( $TWiki::SESSION, $oldWeb, $newWeb,
                            $confirm, \%webTopicInfo);
             return;
         }
@@ -653,21 +639,21 @@
 
     # Update references in referring pages 
     my $refs = _getReferringTopicsListFromURL(
-        $session, $oldWeb, $TWiki::cfg{HomeTopicName},
+        $TWiki::SESSION, $oldWeb, $TWiki::cfg{HomeTopicName},
         $newWeb, $TWiki::cfg{HomeTopicName} );
 
     # Now, we can move the web.
-    _moveWeb( $session, $oldWeb, $newWeb, $refs );
+    _moveWeb( $TWiki::SESSION, $oldWeb, $newWeb, $refs );
 
     # now remove lease on all topics inside $newWeb.
-    my (@webList) = $store->getListOfWebs('public',$newWeb);
+    my (@webList) = $TWiki::STORE->getListOfWebs('public',$newWeb);
     unshift(@webList,$newWeb);
     foreach my $webIter (@webList) {
         $webIter = TWiki::Sandbox::untaintUnchecked( $webIter );
-        my @webTopicList=$store->getTopicNames($webIter);
+        my @webTopicList=$TWiki::STORE->getTopicNames($webIter);
         foreach my $webTopic (@webTopicList) {
             $webTopic = TWiki::Sandbox::untaintUnchecked( $webTopic );
-            $store->clearLease( $webIter, $webTopic );
+            $TWiki::STORE->clearLease( $webIter, $webTopic );
         }
     }
 
@@ -679,7 +665,7 @@
         $webTopic = TWiki::Sandbox::untaintUnchecked( $webTopic );
         my $webIter=join("/",@path);
         $webIter = TWiki::Sandbox::untaintUnchecked( $webIter );
-        $store->clearLease( $webIter, $webTopic );
+        $TWiki::STORE->clearLease( $webIter, $webTopic );
     }
 
     my $new_url = '';
@@ -688,29 +674,28 @@
 
         # redirect to parent
         if( $oldParentWeb ) {
-            $new_url = $session->getScriptUrl( 0, 'view',
+            $new_url = $TWiki::SESSION->getScriptUrl( 0, 'view',
                 $oldParentWeb, $TWiki::cfg{HomeTopicName} );
         } else {
-            $new_url = $session->getScriptUrl( 0, 'view',
+            $new_url = $TWiki::SESSION->getScriptUrl( 0, 'view',
                 $TWiki::cfg{UsersWebName}, $TWiki::cfg{HomeTopicName} );
         }
     } else {
         # redirect to new web
-        $new_url = $session->getScriptUrl( 0, 'view',
+        $new_url = $TWiki::SESSION->getScriptUrl( 0, 'view',
             $newWeb, $TWiki::cfg{HomeTopicName} );
     }
 
-    $session->redirect( $new_url );
+    $TWiki::SESSION->redirect( $new_url );
 }
 
 =pod
 
----++ StaticMethod move($session, $oldWeb, $oldTopic, $newWeb, $newTopic, $attachment, \@refs )
+---++ StaticMethod move($oldWeb, $oldTopic, $newWeb, $newTopic, $attachment, \@refs )
 
 Move the given topic, or an attachment in the topic, correcting refs to the topic in the topic itself, and
 in the list of topics (specified as web.topic pairs) in the \@refs array.
 
-   * =$session= - reference to session object
    * =$oldWeb= - name of old web - must be untained
    * =$oldTopic= - name of old topic - must be untained
    * =$newWeb= - name of new web - must be untained
@@ -722,15 +707,14 @@
 =cut
 
 sub move {
-    my( $session, $oldWeb, $oldTopic,
+    my( $oldWeb, $oldTopic,
         $newWeb, $newTopic, $attachment, $refs ) = @_;
-    my $store = $session->{store};
 
     if( $attachment ) {
         try {
-            $store->moveAttachment( $oldWeb, $oldTopic, $attachment,
+            $TWiki::STORE->moveAttachment( $oldWeb, $oldTopic, $attachment,
                                     $newWeb, $newTopic, $attachment,
-                                    $session->{user} );
+                                    $TWiki::SESSION->{user} );
         } catch Error::Simple with {
             throw TWiki::OopsException(
                 'attention',
@@ -744,8 +728,8 @@
     }
 
     try {
-        $store->moveTopic( $oldWeb, $oldTopic, $newWeb, $newTopic,
-                           $session->{user} );
+        $TWiki::STORE->moveTopic( $oldWeb, $oldTopic, $newWeb, $newTopic,
+                           $TWiki::SESSION->{user} );
     } catch Error::Simple with {
         throw TWiki::OopsException( 'attention',
                                     web => $oldWeb,
@@ -756,14 +740,13 @@
                                                 $newTopic ] );
     };
 
-    my( $meta, $text ) = $store->readTopic( undef, $newWeb, $newTopic );
+    my( $meta, $text ) = $TWiki::STORE->readTopic( undef, $newWeb, $newTopic );
 
     if( $oldWeb ne $newWeb ) {
         # If the web changed, replace local refs to the topics
         # in $oldWeb with full $oldWeb.topic references so that
         # they still work.
-        my $renderer = $session->{renderer};
-        $renderer->replaceWebInternalReferences(
+        $TWiki::RENDER->replaceWebInternalReferences(
             \$text, $meta,
             $oldWeb, $oldTopic, $newWeb, $newTopic );
     }
@@ -779,7 +762,7 @@
        spacedTopic => TWiki::spaceOutWikiWord( $oldTopic )
       };
     $options->{spacedTopic} =~ s/ / */g;
-    $text = $session->{renderer}->forEachLine(
+    $text = $TWiki::RENDER->forEachLine(
         $text, \&TWiki::Render::replaceTopicReferences, $options );
 
     $meta->put( 'TOPICMOVED',
@@ -788,26 +771,26 @@
                  to   => $newWeb.'.'.$newTopic,
                  date => time(),
                  # SMELL: surely this should be webDotWikiname?
-                 by   => $session->{user}->wikiName(),
+                 by   => $TWiki::SESSION->{user}->wikiName(),
                 } );
 
-    $store->saveTopic( $session->{user}, $newWeb, $newTopic, $text, $meta,
+    $TWiki::STORE->saveTopic( $TWiki::SESSION->{user}, $newWeb, $newTopic, $text, $meta,
                        { minor => 1, comment => 'rename' } );
 
     # update referrers - but _not_ including the moved topic
-    _updateReferringTopics( $session, $oldWeb, $oldTopic,
+    _updateReferringTopics( $TWiki::SESSION, $oldWeb, $oldTopic,
                             $newWeb, $newTopic, $refs );
 }
 
 # Display screen so user can decide on new web and topic.
 sub _newTopicScreen {
-    my( $session, $oldWeb, $oldTopic, $newWeb, $newTopic, $attachment,
+    my( $TWiki::SESSION, $oldWeb, $oldTopic, $newWeb, $newTopic, $attachment,
         $confirm, $doAllowNonWikiWord ) = @_;
 
-    my $query = $session->{cgiQuery};
+    my $query = $TWiki::SESSION->{cgiQuery};
     my $tmplname = $query->param( 'template' ) || '';
     my $tmpl = '';
-    my $skin = $session->getSkin();
+    my $skin = $TWiki::SESSION->getSkin();
     my $currentWebOnly = $query->param( 'currentwebonly' ) || '';
 
     $newTopic = $oldTopic unless ( $newTopic );
@@ -816,16 +799,16 @@
     $nonWikiWordFlag = 'checked="checked"' if( $doAllowNonWikiWord );
 
     if( $attachment ) {
-        $tmpl = $session->{templates}->readTemplate(
+        $tmpl = $TWiki::TEMPLATES->readTemplate(
             $tmplname || 'moveattachment', $skin );
         $tmpl =~ s/%FILENAME%/$attachment/go;
     } elsif( $confirm ) {
-        $tmpl = $session->{templates}->readTemplate( 'renameconfirm', $skin );
+        $tmpl = $TWiki::TEMPLATES->readTemplate( 'renameconfirm', $skin );
     } elsif( $newWeb eq $TWiki::cfg{TrashWebName} &&
                $oldWeb ne $TWiki::cfg{TrashWebName}) {
-        $tmpl = $session->{templates}->readTemplate( 'renamedelete', $skin );
+        $tmpl = $TWiki::TEMPLATES->readTemplate( 'renamedelete', $skin );
     } else {
-        $tmpl = $session->{templates}->readTemplate( 'rename', $skin );
+        $tmpl = $TWiki::TEMPLATES->readTemplate( 'rename', $skin );
     }
 
     if( !$attachment && $newWeb eq $TWiki::cfg{TrashWebName} ) {
@@ -833,7 +816,7 @@
         $newTopic = $oldWeb.$newTopic;
         my $n = 1;
         my $base = $newTopic;
-        while( $session->{store}->topicExists( $newWeb, $newTopic)) {
+        while( $TWiki::STORE->topicExists( $newWeb, $newTopic)) {
             $newTopic = $base.$n;
             $n++;
         }
@@ -847,9 +830,9 @@
         my $refs;
         my $search = '';
         if( $currentWebOnly ) {
-            $search = $session->{i18n}->maketext('(skipped)');
+            $search = $TWiki::I18N->maketext('(skipped)');
         } else {
-            $refs = getReferringTopics( $session, $oldWeb, $oldTopic, 1 );
+            $refs = getReferringTopics( $TWiki::SESSION, $oldWeb, $oldTopic, 1 );
             foreach my $entry ( sort keys %$refs ) {
                 $search .= CGI::Tr
                   (CGI::td(
@@ -865,14 +848,14 @@
                                   $refs->{$entry} ));
             }
             unless( $search ) {
-                $search = ($session->{i18n}->maketext('(none)'));
+                $search = ($TWiki::I18N->maketext('(none)'));
             } else {
                 $search = CGI::start_table().$search.CGI::end_table();
             }
         }
         $tmpl =~ s/%GLOBAL_SEARCH%/$search/o;
 
-        $refs = getReferringTopics( $session, $oldWeb, $oldTopic, 0 );
+        $refs = getReferringTopics( $TWiki::SESSION, $oldWeb, $oldTopic, 0 );
 
         $search = '';;
         foreach my $entry ( sort keys %$refs ) {
@@ -890,19 +873,19 @@
                               $refs->{$entry} ));
         }
         unless( $search ) {
-            $search = ($session->{i18n}->maketext('(none)'));
+            $search = ($TWiki::I18N->maketext('(none)'));
         } else {
             $search = CGI::start_table().$search.CGI::end_table();
         }
         $tmpl =~ s/%LOCAL_SEARCH%/$search/go;
     }
 
-    $tmpl = $session->handleCommonTags( $tmpl, $oldWeb, $oldTopic );
-    $tmpl = $session->{renderer}->getRenderedVersion( $tmpl, $oldWeb, $oldTopic );
-    $session->writeCompletePage( $tmpl );
+    $tmpl = $TWiki::SESSION->handleCommonTags( $tmpl, $oldWeb, $oldTopic );
+    $tmpl = $TWiki::RENDER->getRenderedVersion( $tmpl, $oldWeb, $oldTopic );
+    $TWiki::SESSION->writeCompletePage( $tmpl );
 }
 
-# _moveWeb($session, $oldWeb,  $newWeb, \@refs )
+# _moveWeb($TWiki::SESSION, $oldWeb,  $newWeb, \@refs )
 #
 # Move the given web, correcting refs to the web in the web itself, and
 # in the list of topics (specified as web.topic pairs) in the \@refs array.
@@ -910,22 +893,21 @@
 #
 # All permissions and lease conflicts should be resolved before calling this method.
 #
-#    * =$session= - reference to session object
+#    * =$TWiki::SESSION= - reference to session object
 #    * =$oldWeb= - name of old web
 #    * =$newWeb= - name of new web
 #    * =\@refs= - array of webg.topics that must have refs to this topic converted
 # Will throw TWiki::OopsException on an error.
 
 sub _moveWeb {
-    my( $session, $oldWeb, $newWeb, $refs ) = @_;
-    my $store = $session->{store};
+    my( $TWiki::SESSION, $oldWeb, $newWeb, $refs ) = @_;
 
     $oldWeb =~ s/\./\//go;
     $newWeb =~ s/\./\//go;
 
-    my $user = $session->{user};
+    my $user = $TWiki::SESSION->{user};
 
-    if( $store->webExists( $newWeb )) {
+    if( $TWiki::STORE->webExists( $newWeb )) {
         throw TWiki::OopsException( 'attention',
                                     web => $oldWeb,
                                     topic => '',
@@ -935,10 +917,10 @@
 
     # update referrers.  We need to do this before moving,
     # because there might be topics inside the newWeb which need updating.
-    _updateWebReferringTopics( $session, $oldWeb, $newWeb, $refs );
+    _updateWebReferringTopics( $TWiki::SESSION, $oldWeb, $newWeb, $refs );
 
     try {
-        $store->moveWeb( $oldWeb, $newWeb, $user );
+        $TWiki::STORE->moveWeb( $oldWeb, $newWeb, $user );
     } catch Error::Simple  with {
         my $e = shift;
         throw TWiki::OopsException( 'attention',
@@ -955,10 +937,10 @@
 # are resolved.
 
 sub _newWebScreen {
-    my( $session, $oldWeb, $newWeb,
+    my( $TWiki::SESSION, $oldWeb, $newWeb,
         $confirm, $webTopicInfoRef ) = @_;
 
-    my $query = $session->{cgiQuery};
+    my $query = $TWiki::SESSION->{cgiQuery};
     my $tmpl = '';
 
     $newWeb = $oldWeb unless ( $newWeb );
@@ -968,7 +950,7 @@
     my $newParent = join( '/', @newParentPath );
     my $accessCheckWeb = $newParent;
     my $accessCheckTopic = $TWiki::cfg{WebPrefsTopicName};
-    my $templates = $session->{templates};
+    my $templates = $TWiki::TEMPLATES;
 
     if( $confirm eq 'getlock' ) {
         $tmpl = $templates->readTemplate( 'renamewebconfirm' );
@@ -983,7 +965,7 @@
         $newWeb = "$TWiki::cfg{TrashWebName}/$oldWeb";
         my $n = 1;
         my $base = $newWeb;
-        while( $session->{store}->webExists( $newWeb )) {
+        while( $TWiki::STORE->webExists( $newWeb )) {
             $newWeb = $base.$n;
             $n++;
         }
@@ -1000,13 +982,13 @@
     my( $movelocked, $refdenied, $reflocked ) = ( '', '', '' );
     $movelocked = join(', ', @{$webTopicInfoRef->{movelocked}} )
       if $webTopicInfoRef->{movelocked};
-    $movelocked = ($session->{i18n}->maketext('(none)')) unless $movelocked;
+    $movelocked = ($TWiki::I18N->maketext('(none)')) unless $movelocked;
     $refdenied = join(', ', @{$webTopicInfoRef->{modifydenied}} )
       if $webTopicInfoRef->{modifydenied};
-    $refdenied = ($session->{i18n}->maketext('(none)')) unless $refdenied;
+    $refdenied = ($TWiki::I18N->maketext('(none)')) unless $refdenied;
     $reflocked = join(', ', @{$webTopicInfoRef->{modifylocked}} )
       if $webTopicInfoRef->{modifylocked};
-    $reflocked = ($session->{i18n}->maketext('(none)')) unless $reflocked;
+    $reflocked = ($TWiki::I18N->maketext('(none)')) unless $reflocked;
 
     $tmpl =~ s/%MOVE_LOCKED%/$movelocked/;
     $tmpl =~ s/%REF_DENIED%/$refdenied/;
@@ -1037,7 +1019,7 @@
                          );
     }
     unless( $search ) {
-        $search = ($session->{i18n}->maketext('(none)'));
+        $search = ($TWiki::I18N->maketext('(none)'));
     } else {
         $search = CGI::start_table().$search.CGI::end_table();
     }
@@ -1060,25 +1042,25 @@
                             $refs->{$entry} ));
     }
     unless( $search ) {
-        $search = ($session->{i18n}->maketext('(none)'));
+        $search = ($TWiki::I18N->maketext('(none)'));
     } else {
         $search = CGI::start_table().$search.CGI::end_table();
     }
     $tmpl =~ s/%LOCAL_SEARCH%/$search/go;
 
-    $tmpl = $session->handleCommonTags(
+    $tmpl = $TWiki::SESSION->handleCommonTags(
         $tmpl, $oldWeb, $TWiki::cfg{HomeTopicName} );
-    $tmpl = $session->{renderer}->getRenderedVersion(
+    $tmpl = $TWiki::RENDER->getRenderedVersion(
         $tmpl, $oldWeb, $TWiki::cfg{HomeTopicName} );
-    $session->writeCompletePage( $tmpl );
+    $TWiki::SESSION->writeCompletePage( $tmpl );
 }
 
 # Returns the list of topics that have been found that refer
 # to the renamed topic. Returns a list of topics.
 sub _getReferringTopicsListFromURL {
-    my( $session, $oldWeb, $oldTopic, $newWeb, $newTopic ) = @_;
+    my( $TWiki::SESSION, $oldWeb, $oldTopic, $newWeb, $newTopic ) = @_;
 
-    my $query = $session->{cgiQuery};
+    my $query = $TWiki::SESSION->{cgiQuery};
     my @result;
     foreach my $topic ( $query->param( 'referring_topics' ) ) {
         push @result, $topic;
@@ -1088,9 +1070,9 @@
 
 =pod
 
----++ StaticMethod getReferringTopics($session, $web, $topic, $allWebs) -> \%matches
+---++ StaticMethod getReferringTopics($TWiki::SESSION, $web, $topic, $allWebs) -> \%matches
 
-   * =$session= - the session
+   * =$TWiki::SESSION= - the session
    * =$web= - web to search for
    * =$topic= - topic to search for
    * =$allWebs= - 0 to search $web only. 1 to search all webs _except_ $web.
@@ -1099,20 +1081,20 @@
 =cut
 
 sub getReferringTopics {
-    my( $session, $web, $topic, $allWebs ) = @_;
-    my $store = $session->{store};
-    my $renderer = $session->{renderer};
+    my( $TWiki::SESSION, $web, $topic, $allWebs ) = @_;
+
+    my $renderer = $TWiki::RENDER;
     $web =~ s#\.#/#go;
     my @webs = ( $web );
 
     if( $allWebs ) {
-        @webs = $store->getListOfWebs();
+        @webs = $TWiki::STORE->getListOfWebs();
     }
 
     my %results;
     foreach my $searchWeb ( @webs ) {
         next if( $allWebs && $searchWeb eq $web );
-        my @topicList = $store->getTopicNames( $searchWeb );
+        my @topicList = $TWiki::STORE->getTopicNames( $searchWeb );
         my $searchString;
         my $webString = $web;
         $webString =~ s#[\./]#[\\.\\/]#go;
@@ -1133,7 +1115,7 @@
         # Note use of \< and \> to match the empty string at the
         # edges of a word.
 
-        my $matches = $store->searchInWebContent
+        my $matches = $TWiki::STORE->searchInWebContent
           ( $searchString,
             $searchWeb, \@topicList,
             { casesensitive => 1, type => 'regex' } );
@@ -1158,10 +1140,10 @@
 # SMELL: this might be done more efficiently if it was behind the
 # store interface
 sub _updateReferringTopics {
-    my ( $session, $oldWeb, $oldTopic, $newWeb, $newTopic, $refs ) = @_;
-    my $store = $session->{store};
-    my $renderer = $session->{renderer};
-    my $user = $session->{user};
+    my ( $TWiki::SESSION, $oldWeb, $oldTopic, $newWeb, $newTopic, $refs ) = @_;
+
+    my $renderer = $TWiki::RENDER;
+    my $user = $TWiki::SESSION->{user};
     my $options =
       {
        pre => 1, # process lines in PRE blocks
@@ -1175,13 +1157,13 @@
 
     foreach my $item ( @$refs ) {
         my( $itemWeb, $itemTopic ) =
-          $session->normalizeWebTopicName( '', $item );
+          $TWiki::SESSION->normalizeWebTopicName( '', $item );
 
-        if ( $store->topicExists($itemWeb, $itemTopic) ) {
-            $store->lockTopic( $user, $itemWeb, $itemTopic );
+        if ( $TWiki::STORE->topicExists($itemWeb, $itemTopic) ) {
+            $TWiki::STORE->lockTopic( $user, $itemWeb, $itemTopic );
             try {
                 my( $meta, $text ) =
-                  $store->readTopic( undef, $itemWeb, $itemTopic, undef );
+                  $TWiki::STORE->readTopic( undef, $itemWeb, $itemTopic, undef );
                 $options->{inWeb} = $itemWeb;
 
                 $text = $renderer->forEachLine
@@ -1190,14 +1172,14 @@
                   ( qw/^(FIELD|FORM|TOPICPARENT)$/, undef,
                     \&TWiki::Render::replaceTopicReferences, $options );
 
-                $store->saveTopic( $user, $itemWeb, $itemTopic,
+                $TWiki::STORE->saveTopic( $user, $itemWeb, $itemTopic,
                                    $text, $meta,
                                    { minor => 1 } );
             } catch TWiki::AccessControlException with {
                 my $e = shift;
-                $session->writeWarning( $e->stringify() );
+                $TWiki::SESSION->writeWarning( $e->stringify() );
             } finally {
-                $store->unlockTopic( $user, $itemWeb, $itemTopic );
+                $TWiki::STORE->unlockTopic( $user, $itemWeb, $itemTopic );
             };
         }
     }
@@ -1205,10 +1187,10 @@
 
 # Update pages that refer to a web that is being renamed/moved.
 sub _updateWebReferringTopics {
-    my ( $session, $oldWeb, $newWeb, $refs ) = @_;
-    my $store = $session->{store};
-    my $renderer = $session->{renderer};
-    my $user = $session->{user};
+    my ( $TWiki::SESSION, $oldWeb, $newWeb, $refs ) = @_;
+
+    my $renderer = $TWiki::RENDER;
+    my $user = $TWiki::SESSION->{user};
     my $options =
       {
        oldWeb => $oldWeb,
@@ -1217,13 +1199,13 @@
 
     foreach my $item ( @$refs ) {
         my( $itemWeb, $itemTopic ) =
-          $session->normalizeWebTopicName( '', $item );
+          $TWiki::SESSION->normalizeWebTopicName( '', $item );
 
-        if ( $store->topicExists($itemWeb, $itemTopic) ) {
-            $store->lockTopic( $user, $itemWeb, $itemTopic );
+        if ( $TWiki::STORE->topicExists($itemWeb, $itemTopic) ) {
+            $TWiki::STORE->lockTopic( $user, $itemWeb, $itemTopic );
             try {
                 my( $meta, $text ) =
-                  $store->readTopic( undef, $itemWeb, $itemTopic, undef );
+                  $TWiki::STORE->readTopic( undef, $itemWeb, $itemTopic, undef );
                 $options->{inWeb} = $itemWeb;
 
                 $text = $renderer->forEachLine
@@ -1232,26 +1214,25 @@
                   ( qw/^(FIELD|FORM|TOPICPARENT)$/, undef,
                     \&TWiki::Render::replaceWebReferences, $options );
 
-                $store->saveTopic( $user, $itemWeb, $itemTopic,
+                $TWiki::STORE->saveTopic( $user, $itemWeb, $itemTopic,
                                    $text, $meta,
                                    { minor => 1 } );
             } catch TWiki::AccessControlException with {
                 my $e = shift;
-                $session->writeWarning( $e->stringify() );
+                $TWiki::SESSION->writeWarning( $e->stringify() );
             } finally {
-                $store->unlockTopic( $user, $itemWeb, $itemTopic );
+                $TWiki::STORE->unlockTopic( $user, $itemWeb, $itemTopic );
             };
         }
     }
 }
 
 sub _editSettings {
-    my $session = shift;
-    my $topic = $session->{topicName};
-    my $web = $session->{webName};
+    my $topic = $TWiki::SESSION->{topicName};
+    my $web = $TWiki::SESSION->{webName};
 
     my( $meta, $text ) =
-      $session->{store}->readTopic( $session->{user}, $web, $topic, undef );
+      $TWiki::STORE->readTopic( $TWiki::SESSION->{user}, $web, $topic, undef );
     my ( $orgDate, $orgAuth, $orgRev ) = $meta->getRevisionInfo();
 
     my $settings = "";
@@ -1264,31 +1245,29 @@
          ' '.$name.' = '.$value."\n";
     }
 
-    my $skin = $session->getSkin();
-    my $tmpl = $session->{templates}->readTemplate( 'settings', $skin );
-    $tmpl = $session->handleCommonTags( $tmpl, $web, $topic, $meta );
-    $tmpl = $session->{renderer}->getRenderedVersion( $tmpl, $web, $topic );
+    my $skin = $TWiki::SESSION->getSkin();
+    my $tmpl = $TWiki::TEMPLATES->readTemplate( 'settings', $skin );
+    $tmpl = $TWiki::SESSION->handleCommonTags( $tmpl, $web, $topic, $meta );
+    $tmpl = $TWiki::RENDER->getRenderedVersion( $tmpl, $web, $topic );
 
     $tmpl =~ s/%TEXT%/$settings/o;
     $tmpl =~ s/%ORIGINALREV%/$orgRev/g;
 
-    $session->writeCompletePage( $tmpl );
-
+    $TWiki::SESSION->writeCompletePage( $tmpl );
 }
 
 sub _saveSettings {
-    my $session = shift;
-    my $topic = $session->{topicName};
-    my $web = $session->{webName};
-    my $user = $session->{user};
+    my $topic = $TWiki::SESSION->{topicName};
+    my $web = $TWiki::SESSION->{webName};
+    my $user = $TWiki::SESSION->{user};
 
     # set up editing session
     my ( $currMeta, $currText ) =
-      $session->{store}->readTopic( undef, $web, $topic, undef );
-    my $newMeta = new TWiki::Meta( $session, $web, $topic );
+      $TWiki::STORE->readTopic( undef, $web, $topic, undef );
+    my $newMeta = new TWiki::Meta( $web, $topic );
     $newMeta->copyFrom( $currMeta );
 
-    my $query = $session->{cgiQuery};
+    my $query = $TWiki::SESSION->{cgiQuery};
     my $settings = $query->param( 'text' );
     my $originalrev = $query->param( 'originalrev' );
 
@@ -1310,7 +1289,7 @@
     }
 
     try {
-        $session->{store}->saveTopic( $user, $web, $topic,
+        $TWiki::STORE->saveTopic( $user, $web, $topic,
                                     $currText, $newMeta, $saveOpts );
     } catch Error::Simple with {
         throw TWiki::OopsException( 'attention',
@@ -1319,8 +1298,8 @@
                                     topic => $topic,
                                     params => shift->{-text} );
     };
-    my $viewURL = $session->getScriptUrl( 0, 'view', $web, $topic );
-    $session->redirect( $viewURL );
+    my $viewURL = $TWiki::SESSION->getScriptUrl( 0, 'view', $web, $topic );
+    $TWiki::SESSION->redirect( $viewURL );
     return;
 
 }
Index: TWiki/UI/ChangeForm.pm
===================================================================
--- TWiki/UI/ChangeForm.pm	(revision 13172)
+++ TWiki/UI/ChangeForm.pm	(working copy)
@@ -35,20 +35,19 @@
 
 =pod
 
----+ ClassMethod generate( $session, $theWeb, $theTopic, $editaction )
+---+ ClassMethod generate( $theWeb, $theTopic, $editaction )
 
 Generate the page that supports selection of the form.
 
 =cut
 
 sub generate {
-    my( $session, $web, $topic, $editaction ) = @_;
-    ASSERT($session->isa( 'TWiki')) if DEBUG;
+    my( $web, $topic, $editaction ) = @_;
 
-    my $page = $session->{templates}->readTemplate( 'changeform' );
-    my $q = $session->{cgiQuery};
+    my $page = $TWiki::TEMPLATES->readTemplate( 'changeform' );
+    my $q = $TWiki::SESSION->{cgiQuery};
 
-    my $store = $session->{store};
+    my $store = $TWiki::STORE;
     my $formName = $q->param( 'formtemplate' ) || '';
     unless( $formName ) {
         my( $meta, $tmp ) = $store->readTopic( undef, $web, $topic, undef );
@@ -57,7 +56,7 @@
     }
     $formName = 'none' if( !$formName );
 
-    my $prefs = $session->{prefs};
+    my $prefs = $TWiki::PREFS;
     my $legalForms = $prefs->getWebPreferencesValue( 'WEBFORMS', $web );
     $legalForms =~ s/^\s*//;
     $legalForms =~ s/\s*$//;
@@ -78,7 +77,7 @@
            };
         $props->{checked} = 'checked' if $form eq $formName;
         $formList .= CGI::input( $props );
-	my ($formWeb, $formTopic) = $session->normalizeWebTopicName($web, $form);
+	my ($formWeb, $formTopic) = $TWiki::SESSION->normalizeWebTopicName($web, $form);
         my $formLabelContent = '&nbsp;' . ( $store->topicExists( $formWeb, $formTopic ) ? 
 	  '[['.$formWeb.'.'.$formTopic.']['.$form.']]' : $form );
         $formList .= CGI::label( { for => $formElemId}, $formLabelContent );
@@ -91,8 +90,8 @@
     my $redirectTo = $q->param( 'redirectto' ) || '';
     $page =~ s/%REDIRECTTO%/$redirectTo/go;
 
-    $page = $session->handleCommonTags( $page, $web, $topic );
-    $page = $session->{renderer}->getRenderedVersion( $page, $web, $topic );
+    $page = $TWiki::SESSION->handleCommonTags( $page, $web, $topic );
+    $page = $TWiki::RENDER->getRenderedVersion( $page, $web, $topic );
 
     my $text = CGI::hidden( -name => 'text', -value => $q->param( 'text' ) );
     $page =~ s/%TEXT%/$text/go;
Index: TWiki/UI/RDiff.pm
===================================================================
--- TWiki/UI/RDiff.pm	(revision 13172)
+++ TWiki/UI/RDiff.pm	(working copy)
@@ -68,15 +68,15 @@
 #| Return: =$text= | Formatted html text |
 #| TODO: | this should move to Render.pm |
 sub _renderCellData {
-    my( $session, $meta, $data, $web, $topic ) = @_;
+    my( $meta, $data, $web, $topic ) = @_;
     if ( $data ){
         $data =~ s(^%META:FIELD{(.*)}%.*$)
           (_renderAttrs($1,'|*FORM FIELD $title*|$name|$value|'))gem;
         $data =~ s(^%META:([A-Z]+){(.*)}%$)
           ('|*META '.$1.'*|'._renderAttrs($2).'|')gem;
 
-        $data = $session->handleCommonTags( $data, $web, $topic );
-        $data = $session->{renderer}->getRenderedVersion( $data, $web, $topic );
+        $data = $TWiki::SESSION->handleCommonTags( $data, $web, $topic );
+        $data = $TWiki::RENDER->getRenderedVersion( $data, $web, $topic );
         # Match up table tags, remove comments
         if( $data =~ m/<\/?(th|td|table)\b/i ) {
             # data has <th> or <td>, need to fix ables
@@ -135,11 +135,11 @@
 #| TODO: | this should move to Render.pm |
 sub _renderSideBySide
 {
-    my ( $session, $web, $topic, $diffType, $left, $right ) = @_;
+    my ( $web, $topic, $diffType, $left, $right ) = @_;
     my $result = '';
 
-    $left = _renderCellData( $session, $left, $web, $topic );
-    $right = _renderCellData( $session, $right, $web, $topic );
+    $left = _renderCellData( $left, $web, $topic );
+    $right = _renderCellData( $right, $web, $topic );
 
     if ( $diffType eq '-') {
         $result .= _sideBySideRow( $left, $right, '-', 'u' )
@@ -155,9 +155,9 @@
                             class=>$format{l}[1],
                            },
                            CGI::th({align=>'center'},
-                                   ($session->{i18n}->maketext('Line: [_1]',$left))).
+                                   ($TWiki::I18N->maketext('Line: [_1]',$left))).
                            CGI::th({align=>'center'},
-                                   ($session->{i18n}->maketext('Line: [_1]',$right)))
+                                   ($TWiki::I18N->maketext('Line: [_1]',$right)))
                           );
     }
     # unhide html comments (<!-- --> type tags)
@@ -247,50 +247,50 @@
 #| TODO: | this should move to Render.pm |
 sub _renderSequential
 {
-    my ( $session, $web, $topic, $diffType, $left, $right ) = @_;
+    my ( $web, $topic, $diffType, $left, $right ) = @_;
     my $result = '';
 
     #note: I have made the colspan 9 to make sure that it spans all columns (thought there are only 2 now)
     if ( $diffType eq '-') {
         $result .=
           _sequentialRow( '#FFD7D7',
-                          ($session->{i18n}->maketext('Deleted')),
+                          ($TWiki::I18N->maketext('Deleted')),
                           'Deleted',
-                          _renderCellData( $session, $left, $web, $topic ),
+                          _renderCellData( $left, $web, $topic ),
                           '-', '&lt;');
     } elsif ( $diffType eq '+') {
         $result .=
           _sequentialRow( '#D0FFD0',
-                          ($session->{i18n}->maketext('Added')),
+                          ($TWiki::I18N->maketext('Added')),
                           'Added',
-                          _renderCellData( $session, $right, $web, $topic ),
+                          _renderCellData( $right, $web, $topic ),
                           '+', '&gt;' );
     } elsif ( $diffType eq 'u') {
         $result .=
           _sequentialRow( undef,
-                          ($session->{i18n}->maketext('Unchanged')),
+                          ($TWiki::I18N->maketext('Unchanged')),
                           'Unchanged',
-                          _renderCellData( $session, $right, $web, $topic ),
+                          _renderCellData( $right, $web, $topic ),
                           'u', '' );
     } elsif ( $diffType eq 'c') {
         $result .=
           _sequentialRow( '#D0FFD0',
-                          ($session->{i18n}->maketext('Changed')),
+                          ($TWiki::I18N->maketext('Changed')),
                           'Deleted',
-                          _renderCellData( $session, $left, $web, $topic ),
+                          _renderCellData( $left, $web, $topic ),
                           '-', '&lt;' );
         $result .=
           _sequentialRow( undef,
-                          ($session->{i18n}->maketext('Changed')),
+                          ($TWiki::I18N->maketext('Changed')),
                           'Added',
-                          _renderCellData( $session, $right, $web, $topic ),
+                          _renderCellData( $right, $web, $topic ),
                           '+', '&gt;' );
     } elsif ( $diffType eq 'l' && $left ne '' && $right ne '' ) {
         $result .= CGI::Tr({bgcolor=>$format{l}[0],
                             class=>'twikiDiffLineNumberHeader'},
                            CGI::th({align=>'left',
                                     colspan=>9},
-                                    ($session->{i18n}->maketext('Line: [_1] to [_2]',$left,$right))
+                                    ($TWiki::I18N->maketext('Line: [_1] to [_2]',$left,$right))
                                   )
                            );
     }
@@ -308,7 +308,7 @@
 #| TODO: | move into Render.pm |
 sub _renderRevisionDiff
 {
-    my( $session, $web, $topic, $sdiffArray_ref, $renderStyle ) = @_;
+    my( $web, $topic, $sdiffArray_ref, $renderStyle ) = @_;
 
 #combine sequential array elements that are the same diffType
     my @diffArray = ();
@@ -345,11 +345,11 @@
             $next_ref = undef;
 		}
 		if ( $renderStyle eq 'sequential' ) {
-		    $result .= _renderSequential( $session, $web, $topic, @$diff_ref );
+		    $result .= _renderSequential( $web, $topic, @$diff_ref );
 		} elsif ( $renderStyle eq 'sidebyside' ) {
             $result .= CGI::Tr(CGI::td({ width=>'50%'}, ''),
                                CGI::td({ width=>'50%'}, ''));
-		    $result .= _renderSideBySide( $session, $web, $topic, @$diff_ref );
+		    $result .= _renderSideBySide( $web, $topic, @$diff_ref );
 		} elsif ( $renderStyle eq 'debug' ) {
 		    $result .= _renderDebug( @$diff_ref );
 		}
@@ -358,11 +358,11 @@
     #don't forget the last one ;)
     if ( $diff_ref ) {
         if ( $renderStyle eq 'sequential' ) {
-            $result .= _renderSequential ( $session, $web, $topic, @$diff_ref );
+            $result .= _renderSequential ( $web, $topic, @$diff_ref );
         } elsif ( $renderStyle eq 'sidebyside' ) {
             $result .= CGI::Tr(CGI::td({ width=>'50%'}, ''),
                                CGI::td({ width=>'50%'}, ''));
-            $result .= _renderSideBySide( $session, $web, $topic, @$diff_ref );
+            $result .= _renderSideBySide( $web, $topic, @$diff_ref );
         } elsif ( $renderStyle eq 'debug' ) {
             $result .= _renderDebug( @$diff_ref );
         }
@@ -375,7 +375,7 @@
 
 =pod
 
----++ StaticMethod diff( $session, $web, $topic, $query )
+---++ StaticMethod diff( )
 
 =diff= command handler.
 This method is designed to be
@@ -397,29 +397,27 @@
 =cut
 
 sub diff {
-    my $session = shift;
+    my $query = $TWiki::SESSION->{cgiQuery};
+    my $webName = $TWiki::SESSION->{webName};
+    my $topic = $TWiki::SESSION->{topicName};
 
-    my $query = $session->{cgiQuery};
-    my $webName = $session->{webName};
-    my $topic = $session->{topicName};
+    TWiki::UI::checkWebExists( $webName, $topic, 'diff' );
+    TWiki::UI::checkTopicExists( $webName, $topic, 'diff' );
 
-    TWiki::UI::checkWebExists( $session, $webName, $topic, 'diff' );
-    TWiki::UI::checkTopicExists( $session, $webName, $topic, 'diff' );
-
     my $renderStyle = $query->param('render') ||
-      $session->{prefs}->getPreferencesValue( 'DIFFRENDERSTYLE' ) ||
+      $TWiki::PREFS->getPreferencesValue( 'DIFFRENDERSTYLE' ) ||
         'sequential';
     my $diffType = $query->param('type') || 'history';
     my $contextLines = $query->param('context');
     unless( defined $contextLines ) {
-        $session->{prefs}->getPreferencesValue( 'DIFFCONTEXTLINES' );
+        $TWiki::PREFS->getPreferencesValue( 'DIFFCONTEXTLINES' );
         $contextLines = 3 unless defined $contextLines;
     }
     my $rev1 = $query->param( 'rev1' );
     my $rev2 = $query->param( 'rev2' );
 
-    my $skin = $session->getSkin();
-    my $tmpl = $session->{templates}->readTemplate( 'rdiff', $skin );
+    my $skin = $TWiki::SESSION->getSkin();
+    my $tmpl = $TWiki::TEMPLATES->readTemplate( 'rdiff', $skin );
     $tmpl =~ s/\%META{.*?}\%//go;  # remove %META{'parent'}%
 
     my( $before, $difftmpl, $after, $tail) = split( /%REPEAT%/, $tmpl);
@@ -428,14 +426,14 @@
     $after ||= '';
     $tail ||= '';
 
-    my $maxrev = $session->{store}->getRevisionNumber( $webName, $topic );
+    my $maxrev = $TWiki::STORE->getRevisionNumber( $webName, $topic );
     $maxrev =~ s/r?1\.//go;  # cut 'r' and major
 
-    $rev1 = $session->{store}->cleanUpRevID( $rev1 );
+    $rev1 = $TWiki::STORE->cleanUpRevID( $rev1 );
     $rev1 = $maxrev if( $rev1 < 1 );
     $rev1 = $maxrev if( $rev1 > $maxrev );
 
-    $rev2 = $session->{store}->cleanUpRevID( $rev2 );
+    $rev2 = $TWiki::STORE->cleanUpRevID( $rev2 );
     $rev2 = 1 if( $rev2 < 1 );
     $rev2 = $maxrev if( $rev2 > $maxrev );
 
@@ -449,13 +447,13 @@
 
     $before =~ s/%REVTITLE1%/$revTitle1/go;
     $before =~ s/%REVTITLE2%/$revTitle2/go;
-    $before = $session->handleCommonTags( $before, $webName, $topic );
-    $before = $session->{renderer}->getRenderedVersion( $before, $webName, $topic );
+    $before = $TWiki::SESSION->handleCommonTags( $before, $webName, $topic );
+    $before = $TWiki::RENDER->getRenderedVersion( $before, $webName, $topic );
 
     my $page = $before;
 
     # do one or more diffs
-    $difftmpl = $session->handleCommonTags( $difftmpl, $webName, $topic );
+    $difftmpl = $TWiki::SESSION->handleCommonTags( $difftmpl, $webName, $topic );
     my $r1 = $rev1;
     my $r2 = $rev2;
     my $isMultipleDiff = 0;
@@ -472,17 +470,17 @@
         my $rInfo = '';
         my $text;
         if ( $r1 > $r2 + 1) {
-            $rInfo = $session->{i18n}->maketext(
+            $rInfo = $TWiki::I18N->maketext(
                 "Changes from r[_1] to r[_2]", $r2, $r1);
         } else {
-            $rInfo = $session->{renderer}->renderRevisionInfo(
+            $rInfo = $TWiki::RENDER->renderRevisionInfo(
                 $webName, $topic, undef, $r1, '$date - $wikiusername' );
         }
         # eliminate white space to prevent wrap around in HR table:
         $rInfo =~ s/\s+/&nbsp;/g;
-        my $diffArrayRef = $session->{store}->getRevisionDiff(
-            $session->{user}, $webName, $topic, $r2, $r1, $contextLines );
-        $text = _renderRevisionDiff( $session, $webName, $topic,
+        my $diffArrayRef = $TWiki::STORE->getRevisionDiff(
+            $TWiki::SESSION->{user}, $webName, $topic, $r2, $r1, $contextLines );
+        $text = _renderRevisionDiff( $webName, $topic,
                                      $diffArrayRef, $renderStyle );
         $diff =~ s/%REVINFO1%/$rInfo/go;
         $diff =~ s/%TEXT%/$text/go;
@@ -493,7 +491,7 @@
     } while( $diffType eq 'history' && ( $r1 > $rev2 || $r1 == 1 ));
 
     if( $TWiki::cfg{Log}{rdiff} ) {
-        $session->writeLog( 'rdiff', $webName.'.'.$topic, "$rev1 $rev2" );
+        $TWiki::SESSION->writeLog( 'rdiff', $webName.'.'.$topic, "$rev1 $rev2" );
     }
 
     my $i = $maxrev;
@@ -510,7 +508,7 @@
 
     while( $i > 0 ) {
         $revisions .= ' '.
-          CGI::a( { href=>$session->getScriptUrl( 0, 'view', $webName, $topic,
+          CGI::a( { href=>$TWiki::SESSION->getScriptUrl( 0, 'view', $webName, $topic,
                                                   rev => $i ),
                     rel => 'nofollow' }, 'r'.$i);
         if( $i != 1 ) {
@@ -522,7 +520,7 @@
                 } else {
                     $j = $i - 1;
                     $revisions .= ' '.
-                      CGI::a( { href=>$session->getScriptUrl(
+                      CGI::a( { href=>$TWiki::SESSION->getScriptUrl(
                           0, 'rdiff', $webName, $topic,
                           rev1 => $i, rev2 => $j ),
                                 rel => 'nofollow' },
@@ -537,11 +535,11 @@
     my $tailResult = '';
     my $revTitle   = '';
     while( $i >= $rev2) {
-        $revTitle = CGI::a( { href=>$session->getScriptUrl(
+        $revTitle = CGI::a( { href=>$TWiki::SESSION->getScriptUrl(
             0, 'view', $webName, $topic, rev => $i ),
                               rel => 'nofollow' },
                             $i);
-        my $revInfo = $session->{renderer}->renderRevisionInfo( $webName, $topic, undef, $i );
+        my $revInfo = $TWiki::RENDER->renderRevisionInfo( $webName, $topic, undef, $i );
         $tailResult .= $tail;
         $tailResult =~ s/%REVTITLE%/$revTitle/go;
         $tailResult =~ s/%REVINFO%/$revInfo/go;
@@ -552,11 +550,11 @@
     $after =~ s/%CURRREV%/$rev1/go;
     $after =~ s/%MAXREV%/$maxrev/go;
 
-    $after = $session->handleCommonTags( $after, $webName, $topic );
-    $after = $session->{renderer}->getRenderedVersion( $after, $webName, $topic );
+    $after = $TWiki::SESSION->handleCommonTags( $after, $webName, $topic );
+    $after = $TWiki::RENDER->getRenderedVersion( $after, $webName, $topic );
     $page .= $after;
 
-    $session->writeCompletePage( $page );
+    $TWiki::SESSION->writeCompletePage( $page );
 }
 
 1;
Index: TWiki/UI/Statistics.pm
===================================================================
--- TWiki/UI/Statistics.pm	(revision 13172)
+++ TWiki/UI/Statistics.pm	(working copy)
@@ -49,7 +49,7 @@
 
 =pod
 
----++ StaticMethod statistics( $session )
+---++ StaticMethod statistics( )
 
 =statistics= command handler.
 This method is designed to be
@@ -62,26 +62,24 @@
 =cut
 
 sub statistics {
-    my $session = shift;
+    my $webName = $TWiki::SESSION->{webName};
 
-    my $webName = $session->{webName};
-
     my $tmp = '';
     # web to redirect to after finishing
     my $destWeb = $TWiki::cfg{UsersWebName};
-    my $logDate = $session->{cgiQuery}->param( 'logdate' ) || '';
+    my $logDate = $TWiki::SESSION->{cgiQuery}->param( 'logdate' ) || '';
     $logDate =~ s/[^0-9]//g;  # remove all non numerals
-    $debug = $session->{cgiQuery}->param( 'debug' );
+    $debug = $TWiki::SESSION->{cgiQuery}->param( 'debug' );
 
-    unless( $session->inContext( 'command_line' )) {
+    unless( $TWiki::SESSION->inContext( 'command_line' )) {
         # running from CGI
-        $session->writePageHeader();
+        $TWiki::SESSION->writePageHeader();
         print CGI::start_html(-title=>'TWiki: Create Usage Statistics');
     }
     # Initial messages
-    _printMsg( $session, 'TWiki: Create Usage Statistics' );
-    _printMsg( $session, '!Do not interrupt this script!' );
-    _printMsg( $session, '(Please wait until page download has finished)' );
+    _printMsg( 'TWiki: Create Usage Statistics' );
+    _printMsg( '!Do not interrupt this script!' );
+    _printMsg( '(Please wait until page download has finished)' );
 
     unless( $logDate ) {
         $logDate =
@@ -94,18 +92,18 @@
         $logYear = $1;
         $logMonth = $TWiki::Time::ISOMONTH[ ( $2 % 12 ) - 1 ];
     } else {
-        _printMsg( $session, "!Error in date $logDate - must be YYYYMM" );
+        _printMsg( "!Error in date $logDate - must be YYYYMM" );
         return;
     }
 
     my $logMonthYear = "$logMonth $logYear";
-    _printMsg( $session, "* Statistics for $logMonthYear" );
+    _printMsg( "* Statistics for $logMonthYear" );
 
     my $logFile = $TWiki::cfg{LogFileName};
     $logFile =~ s/%DATE%/$logDate/g;
 
     unless( -e $logFile ) {
-        _printMsg( $session, "!Log file $logFile does not exist; aborting" );
+        _printMsg(  "!Log file $logFile does not exist; aborting" );
         return;
     }
 
@@ -134,21 +132,21 @@
     # Do a single data collection pass on the temporary copy of logfile,
     # then process each web once.
     my ($viewRef, $contribRef, $statViewsRef, $statSavesRef, $statUploadsRef) =
-      _collectLogData( $session, $TMPFILE, $logMonthYear );
+      _collectLogData( $TMPFILE, $logMonthYear );
 
     my @weblist;
-    my $webSet = TWiki::Sandbox::untaintUnchecked($session->{cgiQuery}->param( 'webs' )) || $session->{requestedWebName};
+    my $webSet = TWiki::Sandbox::untaintUnchecked($TWiki::SESSION->{cgiQuery}->param( 'webs' )) || $TWiki::SESSION->{requestedWebName};
     if( $webSet) {
         # do specific webs
         push( @weblist, split( /,\s*/, $webSet ));
     } else {
         # otherwise do all user webs:
-        @weblist = $session->{store}->getListOfWebs( 'user' );
+        @weblist = $TWiki::STORE->getListOfWebs( 'user' );
     }
     my $firstTime = 1;
     foreach my $web ( @weblist ) {
         try {
-            $destWeb = _processWeb( $session,
+            $destWeb = _processWeb(
                                 $web,
                                 $logMonthYear,
                                 $viewRef,
@@ -158,7 +156,7 @@
                                 $statUploadsRef,
                                 $firstTime );
         } catch TWiki::AccessControlException with  {
-            _printMsg( $session, '  - ERROR: no permission to CHANGE statistics topic in '.$web);
+            _printMsg( '  - ERROR: no permission to CHANGE statistics topic in '.$web);
         }
         $firstTime = 0;
     }
@@ -167,15 +165,15 @@
     unlink $tmpFilename;# FIXME: works on Windows???  Unlink before
     # usage to ensure deleted on crash?
 
-    if( !$session->inContext( 'command_line' ) ) {
+    if( !$TWiki::SESSION->inContext( 'command_line' ) ) {
         $tmp = $TWiki::cfg{Stats}{TopicName};
-        my $url = $session->getScriptUrl( 0, 'view', $destWeb, $tmp );
-        _printMsg( $session, '* Go back to '
+        my $url = $TWiki::SESSION->getScriptUrl( 0, 'view', $destWeb, $tmp );
+        _printMsg( '* Go back to '
                    . CGI::a( { href => $url,
                                rel => 'nofollow' }, $tmp) );
     }
-    _printMsg( $session, 'End creating usage statistics' );
-    print CGI::end_html() unless( $session->inContext( 'command_line' ) );
+    _printMsg( 'End creating usage statistics' );
+    print CGI::end_html() unless( $TWiki::SESSION->inContext( 'command_line' ) );
 }
 
 # Debug only
@@ -210,7 +208,7 @@
 #   $contrib{$web}{"Main.".$WikiName} == number of saves/uploads, by user
 
 sub _collectLogData {
-    my( $session, $TMPFILE, $theLogMonthYear ) = @_;
+    my( $TMPFILE, $theLogMonthYear ) = @_;
 
     # Log file format:
     # | date | user | op | web.topic | notes | ip |
@@ -243,7 +241,7 @@
             $logFileUserName = shift @fields;
         }
         
-        my $userObj = $session->{users}->findUser($logFileUserName);
+        my $userObj = $TWiki::USERS->findUser($logFileUserName);
         
         my( $opName, $webTopic, $notes, $ip ) = @fields;
 
@@ -300,7 +298,7 @@
                 }
             }
         } else {
-            $session->writeDebug('WebStatistics: Bad logfile line '.$line);
+            $TWiki::SESSION->writeDebug('WebStatistics: Bad logfile line '.$line);
         }
     }
 
@@ -308,16 +306,16 @@
 }
 
 sub _processWeb {
-    my( $session, $web, $theLogMonthYear, $viewRef, $contribRef,
+    my( $web, $theLogMonthYear, $viewRef, $contribRef,
         $statViewsRef, $statSavesRef, $statUploadsRef, $isFirstTime ) = @_;
 
-    my( $topic, $user ) = ( $session->{topicName}, $session->{user} );
+    my( $topic, $user ) = ( $TWiki::SESSION->{topicName}, $TWiki::SESSION->{user} );
 
     if( $isFirstTime ) {
-        _printMsg( $session, '* Executed by '.$user->wikiName() );
+        _printMsg( '* Executed by '.$user->wikiName() );
     }
 
-    _printMsg( $session, "* Reporting on TWiki.$web web" );
+    _printMsg( "* Reporting on TWiki.$web web" );
 
     # Handle null values, print summary message to browser/stdout
     my $statViews = $statViewsRef->{$web};
@@ -326,7 +324,7 @@
     $statViews ||= 0;
     $statSaves ||= 0;
     $statUploads ||= 0;
-    _printMsg( $session, "  - view: $statViews, save: $statSaves, upload: $statUploads" );
+    _printMsg( "  - view: $statViews, save: $statSaves, upload: $statUploads" );
 
     
     # Get the top N views and contribs in this web
@@ -339,11 +337,11 @@
     if( @topViews ) {
         $statTopViews = join( CGI::br(), @topViews );
         $topViews[0] =~ s/[\[\]]*//g;
-        _printMsg( $session, '  - top view: '.$topViews[0] );
+        _printMsg( '  - top view: '.$topViews[0] );
     }
     if( @topContribs ) {
         $statTopContributors = join( CGI::br(), @topContribs );
-        _printMsg( $session, '  - top contributor: '.$topContribs[0] );
+        _printMsg( '  - top contributor: '.$topContribs[0] );
     }
 
     # Update the WebStatistics topic
@@ -352,9 +350,9 @@
     my $statsTopic = $TWiki::cfg{Stats}{TopicName};
     # DEBUG
     # $statsTopic = 'TestStatistics';		# Create this by hand
-    if( $session->{store}->topicExists( $web, $statsTopic ) ) {
+    if( $TWiki::STORE->topicExists( $web, $statsTopic ) ) {
         my( $meta, $text ) =
-          $session->{store}->readTopic( undef, $web, $statsTopic, undef );
+          $TWiki::STORE->readTopic( undef, $web, $statsTopic, undef );
         my @lines = split( /\r?\n/, $text );
         my $statLine;
         my $idxStat = -1;
@@ -393,15 +391,15 @@
         }
         $text = join( "\n", @lines );
         $text .= "\n";
-        $session->{store}->saveTopic( $user, $web, $statsTopic,
+        $TWiki::STORE->saveTopic( $user, $web, $statsTopic,
                                       $text, $meta,
                                       { minor => 1,
                                         dontlog => 1 } );
 
-        _printMsg( $session, "  - Topic $statsTopic updated" );
+        _printMsg( "  - Topic $statsTopic updated" );
 
     } else {
-        _printMsg( $session, "! Warning: No updates done, topic $web.$statsTopic does not exist" );
+        _printMsg( "! Warning: No updates done, topic $web.$statsTopic does not exist" );
     }
 
     return $web;
@@ -460,9 +458,9 @@
 }
 
 sub _printMsg {
-    my( $session, $msg ) = @_;
+    my( $msg ) = @_;
 
-    if( $session->inContext('command_line') ) {
+    if( $TWiki::SESSION->inContext('command_line') ) {
         $msg =~ s/&nbsp;/ /go;
     } else {
         if( $msg =~ s/^\!// ) {
Index: TWiki/UI/View.pm
===================================================================
--- TWiki/UI/View.pm	(revision 13172)
+++ TWiki/UI/View.pm	(working copy)
@@ -43,7 +43,7 @@
 
 =pod
 
----++ StaticMethod view( $session )
+---++ StaticMethod view()
 
 =view= command handler.
 This method is designed to be
@@ -61,12 +61,10 @@
 =cut
 
 sub view {
-    my $session = shift;
+    my $query = $TWiki::SESSION->{cgiQuery};
+    my $webName = $TWiki::SESSION->{webName};
+    my $topicName = $TWiki::SESSION->{topicName};
 
-    my $query = $session->{cgiQuery};
-    my $webName = $session->{webName};
-    my $topicName = $session->{topicName};
-
     my $raw = $query->param( 'raw' ) || '';
     my $contentType = $query->param( 'contenttype' );
 
@@ -74,13 +72,13 @@
     my $logEntry = '';
     my $revdate = '';
     my $revuser = '';
-    my $store = $session->{store};
+    my $store = $TWiki::STORE;
     # is this view indexable by search engines? Default yes.
     my $indexableView = 1;
 
-    TWiki::UI::checkWebExists( $session, $webName, $topicName, 'view' );
+    TWiki::UI::checkWebExists( $webName, $topicName, 'view' );
 
-    my $skin = $session->getSkin();
+    my $skin = $TWiki::SESSION->getSkin();
 
     my $rev = $store->cleanUpRevID( $query->param( 'rev' ));
 
@@ -93,9 +91,9 @@
     my( $meta, $text );
     if( $topicExists ) {
         ( $currMeta, $currText ) = $store->readTopic
-          ( $session->{user}, $webName, $topicName, undef );
-        TWiki::UI::checkAccess( $session, $webName, $topicName,
-                                'VIEW', $session->{user}, $currText );
+          ( $TWiki::SESSION->{user}, $webName, $topicName, undef );
+        TWiki::UI::checkAccess( $webName, $topicName,
+                                'VIEW', $TWiki::SESSION->{user}, $currText );
         ( $revdate, $revuser, $showRev ) = $currMeta->getRevisionInfo();
         $revdate = TWiki::Time::formatTime( $revdate );
 
@@ -105,7 +103,7 @@
 
         if( $rev < $showRev ) {
             ( $meta, $text ) = $store->readTopic
-              ( $session->{user}, $webName, $topicName, $rev );
+              ( $TWiki::SESSION->{user}, $webName, $topicName, $rev );
 
             ( $revdate, $revuser ) = $meta->getRevisionInfo();
             $revdate = TWiki::Time::formatTime( $revdate );
@@ -133,14 +131,14 @@
 
     } else { # Topic does not exist yet
         $indexableView = 0;
-        $session->enterContext( 'new_topic' );
+        $TWiki::SESSION->enterContext( 'new_topic' );
         $rev = 1;
         if( TWiki::isValidTopicName( $topicName )) {
             ( $currMeta, $currText ) =
-              TWiki::UI::readTemplateTopic( $session, 'WebTopicViewTemplate' );
+              TWiki::UI::readTemplateTopic( 'WebTopicViewTemplate' );
         } else {
             ( $currMeta, $currText ) =
-              TWiki::UI::readTemplateTopic( $session, 'WebTopicNonWikiTemplate' );
+              TWiki::UI::readTemplateTopic( 'WebTopicNonWikiTemplate' );
         }
         ( $text, $meta ) = ( $currText, $currMeta );
         $logEntry .= ' (not exist)';
@@ -155,34 +153,34 @@
     }
 
     if( $TWiki::cfg{Log}{view} ) {
-        $session->writeLog( 'view', $webName.'.'.$topicName, $logEntry );
+        $TWiki::SESSION->writeLog( 'view', $webName.'.'.$topicName, $logEntry );
     }
 
     my( $mirrorSiteName, $mirrorViewURL, $mirrorLink, $mirrorNote ) =
-      $session->readOnlyMirrorWeb( $webName );
+      $TWiki::SESSION->readOnlyMirrorWeb( $webName );
 
     # Note; must enter all contexts before the template is read, as
     # TMPL:P is expanded on the fly in the template reader. :-(
     my( $revTitle, $revArg ) = ( '', '' );
     if( $mirrorSiteName ) {
-        $session->enterContext( 'inactive' );
+        $TWiki::SESSION->enterContext( 'inactive' );
         unless( $topicExists ) {
             $text = '';
         }
     } elsif( $rev < $showRev ) {
-        $session->enterContext( 'inactive' );
+        $TWiki::SESSION->enterContext( 'inactive' );
         # disable edit of previous revisions
         $revTitle = '(r'.$rev.')';
         $revArg = '&rev='.$rev;
     }
 
     my $template = $query->param( 'template' ) ||
-      $session->{prefs}->getPreferencesValue( 'VIEW_TEMPLATE' ) ||
+      $TWiki::PREFS->getPreferencesValue( 'VIEW_TEMPLATE' ) ||
         'view';
 
-    my $tmpl = $session->{templates}->readTemplate( $template, $skin );
+    my $tmpl = $TWiki::TEMPLATES->readTemplate( $template, $skin );
     if( !$tmpl && $template ne 'view' ) {
-        $tmpl = $session->{templates}->readTemplate( 'view', $skin );
+        $tmpl = $TWiki::TEMPLATES->readTemplate( 'view', $skin );
     }
 
     if( !$tmpl ) {
@@ -216,15 +214,17 @@
         if( $doingRev == $rev) {
             $revs .= 'r'.$rev;
         } else {
-            $revs .= CGI::a({
-                             href=>$session->getScriptUrl( 0,
-                                                           'view',
-                                                           $webName,
-                                                           $topicName,
-                                                           rev => $doingRev ),
-                             rel => 'nofollow'
-                            },
-                            "r$doingRev" );
+            $revs .= CGI::a(
+                {
+                    href=>$TWiki::SESSION->getScriptUrl(
+                        0,
+                        'view',
+                        $webName,
+                        $topicName,
+                        rev => $doingRev ),
+                    rel => 'nofollow'
+                   },
+                "r$doingRev" );
         }
         if ( $doingRev - $rev >= $TWiki::cfg{NumberOfRevisions} ) {
             # we started too far away, need to jump closer to $rev
@@ -236,7 +236,7 @@
         }
         if( $revsToShow ) {
             $revs .= '&nbsp;' . CGI::a
-              ( { href=>$session->getScriptUrl(
+              ( { href=>$TWiki::SESSION->getScriptUrl(
                   0, 'rdiff', $webName, $topicName,
                   rev1 => $doingRev,
                   rev2 => $doingRev-1 ),
@@ -246,9 +246,9 @@
         $doingRev--;
     }
 
-    my $ri = $session->{renderer}->renderRevisionInfo( $webName,
-                                                       $topicName,
-                                                       $meta );
+    my $ri = $TWiki::RENDER->renderRevisionInfo( $webName,
+                                                 $topicName,
+                                                 $meta );
     $tmpl =~ s/%REVINFO%/$ri/go;
     $tmpl =~ s/%REVISIONS%/$revs/go;
 
@@ -316,15 +316,15 @@
     } else {
         $contentType = 'text/html'
     }
-    $session->{SESSION_TAGS}{MAXREV} = $showRev;
-    $session->{SESSION_TAGS}{CURRREV} = $rev;
+    $TWiki::SESSION->{SESSION_TAGS}{MAXREV} = $showRev;
+    $TWiki::SESSION->{SESSION_TAGS}{CURRREV} = $rev;
 
     # Set page generation mode to RSS if using an RSS skin
-    $session->enterContext( 'rss' ) if $skin =~ /\brss/;
+    $TWiki::SESSION->enterContext( 'rss' ) if $skin =~ /\brss/;
 
     # Set the meta-object that contains the rendering info
     # SMELL: hack to get around not having a proper topic object model
-    $session->enterContext( 'can_render_meta', $meta );
+    $TWiki::SESSION->enterContext( 'can_render_meta', $meta );
 
     my $page;
     # Legacy: If the _only_ skin is 'text' it is used like this:
@@ -337,43 +337,44 @@
         # use raw text
         $page = $text;
     } else {
-        my @args = ( $session, $webName, $topicName, $meta, $minimalist );
+        my @args = ( $webName, $topicName, $meta, $minimalist );
 
-        $session->enterContext( 'header_text' );
+        $TWiki::SESSION->enterContext( 'header_text' );
         $page = _prepare($start, @args);
-        $session->leaveContext( 'header_text' );
+        $TWiki::SESSION->leaveContext( 'header_text' );
 
         if( $raw ) {
-	    if ($text) {
-	      my $p = $session->{prefs};
-	      $page .=
-		CGI::textarea( -readonly => 'readonly',
-			       -rows => $p->getPreferencesValue('EDITBOXHEIGHT'),
-			       -cols => $p->getPreferencesValue('EDITBOXWIDTH'),
-			       -style => $p->getPreferencesValue('EDITBOXSTYLE'),
-			       -default => $text
-			     );
-	    }
+            if ($text) {
+                my $p = $TWiki::PREFS;
+                $page .=
+                  CGI::textarea(
+                      -readonly => 'readonly',
+                      -rows => $p->getPreferencesValue('EDITBOXHEIGHT'),
+                      -cols => $p->getPreferencesValue('EDITBOXWIDTH'),
+                      -style => $p->getPreferencesValue('EDITBOXSTYLE'),
+                      -default => $text
+                     );
+            }
         } else {
-            $session->enterContext( 'body_text' );
+            $TWiki::SESSION->enterContext( 'body_text' );
             $page .= _prepare($text, @args);
-            $session->leaveContext( 'body_text' );
+            $TWiki::SESSION->leaveContext( 'body_text' );
         }
 
-        $session->enterContext( 'footer_text' );
+        $TWiki::SESSION->enterContext( 'footer_text' );
         $page .= _prepare($end, @args);
-        $session->leaveContext( 'footer_text' );
+        $TWiki::SESSION->leaveContext( 'footer_text' );
     }
     # Output has to be done in one go, because if we generate the header and
     # then redirect because of some later constraint, some browsers fall over
-    $session->writeCompletePage( $page, 'view', $contentType )
+    $TWiki::SESSION->writeCompletePage( $page, 'view', $contentType )
 }
 
 sub _prepare {
-    my( $text, $session, $webName, $topicName, $meta, $minimalist) = @_;
+    my( $text, $webName, $topicName, $meta, $minimalist) = @_;
 
-    $text = $session->handleCommonTags( $text, $webName, $topicName, $meta );
-    $text = $session->{renderer}->getRenderedVersion( $text, $webName, $topicName );
+    $text = $TWiki::SESSION->handleCommonTags( $text, $webName, $topicName, $meta );
+    $text = $TWiki::RENDER->getRenderedVersion( $text, $webName, $topicName );
     $text =~ s/( ?) *<\/?(nop|noautolink)\/?>\n?/$1/gois;
 
     if( $minimalist ) {
@@ -387,7 +388,7 @@
 
 =pod
 
----++ StaticMethod viewfile( $session, $web, $topic, $query )
+---++ StaticMethod viewfile( $web, $topic, $query )
 
 =viewfile= command handler.
 This method is designed to be
@@ -400,17 +401,15 @@
 =cut
 
 sub viewfile {
-    my $session = shift;
+    my $query = $TWiki::SESSION->{cgiQuery};
+    my $webName = $TWiki::SESSION->{webName};
+    my $topic = $TWiki::SESSION->{topicName};
 
-    my $query = $session->{cgiQuery};
-    my $webName = $session->{webName};
-    my $topic = $session->{topicName};
-
     my $fileName = $query->param( 'filename' );
     $fileName = TWiki::Sandbox::sanitizeAttachmentName( $fileName );
 
-    my $rev = $session->{store}->cleanUpRevID( $query->param( 'rev' ) );
-    unless( $fileName && $session->{store}->attachmentExists(
+    my $rev = $TWiki::STORE->cleanUpRevID( $query->param( 'rev' ) );
+    unless( $fileName && $TWiki::STORE->attachmentExists(
         $webName, $topic, $fileName )) {
         throw TWiki::OopsException( 'attention',
                                     def => 'no_such_attachment',
@@ -418,10 +417,10 @@
                                     topic => $topic,
                                     params => [ 'viewfile', $fileName||'?' ] );
     }
-    my $fileContent = $session->{store}->readAttachment(
-        $session->{user}, $webName, $topic, $fileName, $rev );
+    my $fileContent = $TWiki::STORE->readAttachment(
+        $TWiki::SESSION->{user}, $webName, $topic, $fileName, $rev );
 
-    my $type = _suffixToMimeType( $session, $fileName );
+    my $type = _suffixToMimeType( $fileName );
     my $length =  length( $fileContent );
     my $dispo = 'inline;filename='.$fileName;
 
@@ -435,7 +434,7 @@
 }
 
 sub _suffixToMimeType {
-    my( $session, $theFilename ) = @_;
+    my( $theFilename ) = @_;
 
     my $mimeType = 'text/plain';
     if( $theFilename =~ /\.([^.]+)$/ ) {
Index: TWiki/UI/Save.pm
===================================================================
--- TWiki/UI/Save.pm	(revision 13172)
+++ TWiki/UI/Save.pm	(working copy)
@@ -43,24 +43,23 @@
 
 # Used by save and preview
 sub buildNewTopic {
-    my( $session, $script ) = @_;
+    my( $script ) = @_;
 
-    my $query = $session->{cgiQuery};
-    my $webName = $session->{webName};
-    my $topic = $session->{topicName};
-    my $store = $session->{store};
+    my $query = $TWiki::SESSION->{cgiQuery};
+    my $webName = $TWiki::SESSION->{webName};
+    my $topic = $TWiki::SESSION->{topicName};
+    my $store = $TWiki::STORE;
 
     unless( scalar($query->param()) ) {
         # insufficient parameters to save
         throw TWiki::OopsException( 'attention',
                                     def => 'bad_script_parameters',
-                                    web => $session->{webName},
-                                    topic => $session->{topicName},
+                                    web => $TWiki::SESSION->{webName},
+                                    topic => $TWiki::SESSION->{topicName},
                                     params => [ $script ]);
     }
 
-    TWiki::UI::checkMirror( $session, $webName, $topic );
-    TWiki::UI::checkWebExists( $session, $webName, $topic, 'save' );
+    TWiki::UI::checkWebExists( $webName, $topic, 'save' );
 
     my $topicExists  = $store->topicExists( $webName, $topic );
 
@@ -87,8 +86,8 @@
                                     params => [ $topic ] );
     }
 
-    my $user = $session->{user};
-    TWiki::UI::checkAccess( $session, $webName, $topic,
+    my $user = $TWiki::SESSION->{user};
+    TWiki::UI::checkAccess( $webName, $topic,
                             'CHANGE', $user );
 
     my $saveOpts = {};
@@ -96,7 +95,7 @@
     my $originalrev = $query->param( 'originalrev' ); # rev edit started on
 
     # Populate the new meta data
-    my $newMeta = new TWiki::Meta( $session, $webName, $topic );
+    my $newMeta = new TWiki::Meta( $webName, $topic );
 
     my ( $prevMeta, $prevText );
     my ( $templateText, $templateMeta );
@@ -116,14 +115,14 @@
         }
     } elsif ($templatetopic) {
         ( $templateweb, $templatetopic ) =
-          $session->normalizeWebTopicName( $templateweb, $templatetopic );
+          $TWiki::SESSION->normalizeWebTopicName( $templateweb, $templatetopic );
 
         ( $templateMeta, $templateText ) =
           $store->readTopic( $user, $templateweb,
                              $templatetopic, undef );
         $templateText = '' if $query->param( 'newtopic' ); # created by edit
         $templateText =
-          $session->expandVariablesOnTopicCreation( $templateText );
+          $TWiki::SESSION->expandVariablesOnTopicCreation( $templateText );
         foreach my $k ( keys %$templateMeta ) {
             unless( $k =~ /^_/ || $k eq 'FORM' || $k eq 'TOPICPARENT' ||
                       $k eq 'FIELD' || $k eq 'TOPICMOVED' ) {
@@ -191,12 +190,12 @@
     }
 
     if( $formName ) {
-        $formDef = new TWiki::Form( $session, $webName, $formName );
+        $formDef = new TWiki::Form( $TWiki::SESSION, $webName, $formName );
         unless( $formDef ) {
             throw TWiki::OopsException( 'attention',
                                         def => 'no_form_def',
-                                        web => $session->{webName},
-                                        topic => $session->{topicName},
+                                        web => $TWiki::SESSION->{webName},
+                                        topic => $TWiki::SESSION->{topicName},
                                         params => [ $webName, $formName ] );
         }
         $newMeta->put( 'FORM', { name => $formName });
@@ -222,8 +221,8 @@
             throw TWiki::OopsException(
                 'attention',
                 def=>'mandatory_field',
-                web => $session->{webName},
-                topic => $session->{topicName},
+                web => $TWiki::SESSION->{webName},
+                topic => $TWiki::SESSION->{topicName},
                 params => [ join( ' ', @$missing ) ] );
         }
     }
@@ -253,7 +252,7 @@
                     $pti->{version}, $prevText,
                     $rev, $newText,
                     '.*?\n',
-                    $session );
+                    $TWiki::SESSION );
             } else {
                 # common ancestor; we can 3-way merge
                 my( $ancestorMeta, $ancestorText ) =
@@ -262,7 +261,7 @@
                     $orev, $ancestorText,
                     $rev, $prevText,
                     'new', $newText,
-                    '.*?\n', $session );
+                    '.*?\n', $TWiki::SESSION );
             }
             if( $formDef && $prevMeta ) {
                 $newMeta->merge( $prevMeta, $formDef );
@@ -275,9 +274,7 @@
 }
 
 sub _getRedirectUrl {
-    my $session = shift;
-
-    my $query = $session->{cgiQuery};
+    my $query = $TWiki::SESSION->{cgiQuery};
     my $redirecturl = $query->param( 'redirectto' );
     return '' unless $redirecturl;
     if( $redirecturl =~ /^$TWiki::regex{linkProtocolPattern}\:\/\//o ) {
@@ -289,13 +286,13 @@
         }
     }
     # assuming 'web.topic' or 'topic'
-    my ( $w, $t ) = $session->normalizeWebTopicName( $session->{webName}, $redirecturl );
-    $redirecturl = $session->getScriptUrl( 1, 'view', $w, $t );
+    my ( $w, $t ) = $TWiki::SESSION->normalizeWebTopicName( $TWiki::SESSION->{webName}, $redirecturl );
+    $redirecturl = $TWiki::SESSION->getScriptUrl( 1, 'view', $w, $t );
 }
 
 =pod
 
----++ StaticMethod save($session)
+---++ StaticMethod save()
 
 Command handler for =save= command.
 This method is designed to be
@@ -309,14 +306,12 @@
 =cut
 
 sub save {
-    my $session = shift;
+    my $query = $TWiki::SESSION->{cgiQuery};
+    my $web = $TWiki::SESSION->{webName};
+    my $topic = $TWiki::SESSION->{topicName};
+    my $store = $TWiki::STORE;
+    my $user = $TWiki::SESSION->{user};
 
-    my $query = $session->{cgiQuery};
-    my $web = $session->{webName};
-    my $topic = $session->{topicName};
-    my $store = $session->{store};
-    my $user = $session->{user};
-
     # Do not remove, keep as undocumented feature for compatibility with
     # TWiki 4.0.x: Allow for dynamic topic creation by replacing strings
     # of at least 10 x's XXXXXX with a next-in-sequence number.
@@ -330,7 +325,7 @@
 			$topic =~ s/X{10}X*/$n/e;
 			$n++;
 		} while( $store->topicExists( $web, $topic ));
-        $session->{topicName} = $topic;
+        $TWiki::SESSION->{topicName} = $topic;
     }
 
     # Allow for more flexible topic creation with sortable names and
@@ -361,10 +356,10 @@
             # first auto-inc topic
             $topic =~ s/AUTOINC[0-9]+/$start/;
         }
-        $session->{topicName} = $topic;
+        $TWiki::SESSION->{topicName} = $topic;
     }
 
-    my $redirecturl = _getRedirectUrl( $session );
+    my $redirecturl = _getRedirectUrl();
     my $saveaction = '';
     foreach my $action qw( save checkpoint quietsave cancel preview
                            addform replaceform delRev repRev ) {
@@ -378,7 +373,7 @@
     # for compatibility with old templates.
     if( !$saveaction && $query->param( 'action' )) {
         $saveaction = lc($query->param( 'action' ));
-        $session->writeWarning(<<WARN);
+        $TWiki::SESSION->writeWarning(<<WARN);
 Use of deprecated "action" parameter to "save". Correct your templates!
 WARN
 
@@ -401,19 +396,19 @@
                                $query->param( 'topicparent' ),
                                $TWiki::cfg{HomeTopicName} ) {
                 ( $w, $t ) =
-                  $session->normalizeWebTopicName( $web, $test );
+                  $TWiki::SESSION->normalizeWebTopicName( $web, $test );
                 last if( $store->topicExists( $w, $t ));
             }
-            $viewURL = $session->getScriptUrl( 1, 'view', $w, $t );
+            $viewURL = $TWiki::SESSION->getScriptUrl( 1, 'view', $w, $t );
         }
-        $session->redirect( $viewURL );
+        $TWiki::SESSION->redirect( $viewURL );
 
         return;
     }
 
     if( $saveaction eq 'preview' ) {
         require TWiki::UI::Preview;
-        TWiki::UI::Preview::preview( $session );
+        TWiki::UI::Preview::preview( $TWiki::SESSION );
         return;
     }
 
@@ -426,15 +421,14 @@
           $saveaction eq 'replaceform' ||
             $saveaction eq 'preview' && $query->param( 'submitChangeForm' )) {
         require TWiki::UI::ChangeForm;
-        $session->writeCompletePage
-          ( TWiki::UI::ChangeForm::generate( $session, $web,
-                                             $topic, $editaction ) );
+        $TWiki::SESSION->writeCompletePage
+          ( TWiki::UI::ChangeForm::generate( $web, $topic, $editaction ) );
         return;
     }
 
     if( $saveaction eq 'checkpoint' ) {
         $query->param( -name=>'dontnotify', -value=>'checked' );
-        my $editURL = $session->getScriptUrl( 1, $edit, $web, $topic );
+        my $editURL = $TWiki::SESSION->getScriptUrl( 1, $edit, $web, $topic );
         $redirecturl = $editURL.'?t='.time();
         $redirecturl .= '&redirectto='.$query->param( 'redirectto' )
           if $query->param( 'redirectto' );
@@ -468,14 +462,14 @@
     }
 
     my $saveCmd = $query->param( 'cmd' ) || 0;
-    if ( $saveCmd && ! $session->{user}->isAdmin()) {
+    if ( $saveCmd && ! $TWiki::SESSION->{user}->isAdmin()) {
         throw TWiki::OopsException( 'accessdenied', def => 'only_group',
                                     web => $web, topic => $topic,
                                     params => $TWiki::cfg{UsersWebName}.
                                       '.'.$TWiki::cfg{SuperAdminGroup} );
     }
 
-    $redirecturl ||= $session->getScriptUrl( 1, 'view', $web, $topic );
+    $redirecturl ||= $TWiki::SESSION->getScriptUrl( 1, 'view', $web, $topic );
 
     if( $saveCmd eq 'delRev' ) {
         # delete top revision
@@ -489,7 +483,7 @@
                                         params => shift->{-text} );
         };
 
-        $session->redirect( $redirecturl );
+        $TWiki::SESSION->redirect( $redirecturl );
         return;
     }
 
@@ -498,7 +492,7 @@
         # make it look as much like the original as possible. The query
         # text is expected to contain %META as well as text.
         my $textQueryParam = $query->param( 'text' );
-        my $meta = new TWiki::Meta( $session, $web, $topic );
+        my $meta = new TWiki::Meta( $web, $topic );
         $store->extractMetaData( $meta, \$textQueryParam );
         my $saveOpts = {
             timetravel => 1,
@@ -515,15 +509,15 @@
                                         params => shift->{-text} );
         };
 
-        $session->redirect( $redirecturl );
+        $TWiki::SESSION->redirect( $redirecturl );
         return;
     }
 
     my( $newMeta, $newText, $saveOpts, $merged ) =
-      TWiki::UI::Save::buildNewTopic($session, 'save');
+      TWiki::UI::Save::buildNewTopic($TWiki::SESSION, 'save');
 
     if( $saveaction =~ /^(save|checkpoint)$/ ) {
-        $session->{plugins}->afterEditHandler( $newText, $topic, $web, $newMeta );
+        $TWiki::PLUGINS->afterEditHandler( $newText, $topic, $web, $newMeta );
     }
 
     try {
@@ -550,7 +544,7 @@
                                     params => $merged );
     }
 
-    $session->redirect( $redirecturl );
+    $TWiki::SESSION->redirect( $redirecturl );
 }
 
 1;
Index: TWiki/UI/Oops.pm
===================================================================
--- TWiki/UI/Oops.pm	(revision 13172)
+++ TWiki/UI/Oops.pm	(working copy)
@@ -33,7 +33,7 @@
 
 =pod
 
----++ StaticMethod oops_cgi($session)
+---++ StaticMethod oops_cgi()
 
 =oops= command handler.
 This method is designed to be invoked via the =TWiki::UI::run= method.
@@ -46,17 +46,16 @@
 =cut
 
 sub oops_cgi {
-    my $session = shift;
-    my $topic = $session->{topicName};
-    my $web = $session->{webName};
-    my $query = $session->{cgiQuery};
+    my $topic = $TWiki::SESSION->{topicName};
+    my $web = $TWiki::SESSION->{webName};
+    my $query = $TWiki::SESSION->{cgiQuery};
 
-    oops( $session, $web, $topic, $query, 0 );
+    oops( $web, $topic, $query, 0 );
 }
 
 =pod
 
----++ StaticMethod oops($session, $web, $topic, $query, $keep)
+---++ StaticMethod oops( $web, $topic, $query, $keep)
 
 The body of an oops script call, abstracted out so it can be called for
 the case where an oops is required, but all the parameters in the query
@@ -69,7 +68,7 @@
 =cut
 
 sub oops {
-    my( $session, $web, $topic, $query, $keep ) = @_;
+    my( $web, $topic, $query, $keep ) = @_;
 
     my $tmplName;
     my $def;
@@ -101,9 +100,9 @@
     # Do not pass on the template parameter otherwise continuation won't work
     $query->delete( 'template' );
 
-    my $skin = $session->getSkin();
+    my $skin = $TWiki::SESSION->getSkin();
 
-    my $tmplData = $session->{templates}->readTemplate( $tmplName, $skin );
+    my $tmplData = $TWiki::TEMPLATES->readTemplate( $tmplName, $skin );
 
     if( ! $tmplData ) {
         $tmplData = CGI::start_html()
@@ -114,22 +113,22 @@
     } else {
         if( defined $def ) {
             # if a def is specified, instantiate that def
-            my $blah = $session->{templates}->expandTemplate( $def );
+            my $blah = $TWiki::TEMPLATES->expandTemplate( $def );
             $tmplData =~ s/%INSTANTIATE%/$blah/;
         }
-        $tmplData = $session->handleCommonTags( $tmplData, $web, $topic );
+        $tmplData = $TWiki::SESSION->handleCommonTags( $tmplData, $web, $topic );
         $n = 1;
         foreach my $param ( @params ) {
             $tmplData =~ s/%PARAM$n%/$param/g;
             $n++;
         }
         ASSERT( $tmplData !~ /%PARAM\d+%/ ) if DEBUG;
-        $tmplData = $session->handleCommonTags( $tmplData, $web, $topic );
-        $tmplData = $session->{renderer}->getRenderedVersion( $tmplData, $web,
+        $tmplData = $TWiki::SESSION->handleCommonTags( $tmplData, $web, $topic );
+        $tmplData = $TWiki::RENDER->getRenderedVersion( $tmplData, $web,
                                                               $topic );
     }
 
-    $session->writeCompletePage( $tmplData );
+    $TWiki::SESSION->writeCompletePage( $tmplData );
 }
 
 1;
Index: TWiki/UI/Preview.pm
===================================================================
--- TWiki/UI/Preview.pm	(revision 13172)
+++ TWiki/UI/Preview.pm	(working copy)
@@ -28,15 +28,13 @@
 use TWiki::OopsException;
 
 sub preview {
-    my $session = shift;
+    my $query = $TWiki::SESSION->{cgiQuery};
+    my $web = $TWiki::SESSION->{webName};
+    my $topic = $TWiki::SESSION->{topicName};
+    my $user = $TWiki::SESSION->{user};
 
-    my $query = $session->{cgiQuery};
-    my $web = $session->{webName};
-    my $topic = $session->{topicName};
-    my $user = $session->{user};
-
     my( $meta, $text, $saveOpts, $merged ) =
-      TWiki::UI::Save::buildNewTopic($session, 'preview');
+      TWiki::UI::Save::buildNewTopic('preview');
 
     # Note: param(formtemplate) has already been decoded by buildNewTopic
     # so the $meta entry reflects if it was used.
@@ -44,21 +42,21 @@
     my $form = $meta->get('FORM') || '';
     if( $form ) {
         $form = $form->{name}; # used later on as well
-        my $formDef = new TWiki::Form( $session, $web, $form );
+        my $formDef = new TWiki::Form( $web, $form );
         unless( $formDef ) {
             throw TWiki::OopsException( 'attention',
                                         def => 'no_form_def',
-                                        web => $session->{webName},
-                                        topic => $session->{topicName},
+                                        web => $TWiki::SESSION->{webName},
+                                        topic => $TWiki::SESSION->{topicName},
                                         params => [ $web, $form ] );
         }
         $formFields = $formDef->renderHidden( $meta, 0 );
     }
 
-    $session->{plugins}->afterEditHandler( $text, $topic, $web );
+    $TWiki::PLUGINS->afterEditHandler( $text, $topic, $web );
 
-    my $skin = $session->getSkin();
-    my $tmpl = $session->{templates}->readTemplate( 'preview', $skin );
+    my $skin = $TWiki::SESSION->getSkin();
+    my $tmpl = $TWiki::TEMPLATES->readTemplate( 'preview', $skin );
     if( $saveOpts->{minor} ) {
         $tmpl =~ s/%DONTNOTIFYCHECKBOX%/checked="checked"/go;
     } else {
@@ -82,11 +80,11 @@
     $parent ||= '';
     $tmpl =~ s/%TOPICPARENT%/$parent/g;
 
-    $session->enterContext( 'can_render_meta', $meta );
+    $TWiki::SESSION->enterContext( 'can_render_meta', $meta );
 
     my $dispText = $text;
-    $dispText = $session->handleCommonTags( $dispText, $web, $topic, $meta );
-    $dispText = $session->{renderer}->getRenderedVersion( $dispText, $web, $topic );
+    $dispText = $TWiki::SESSION->handleCommonTags( $dispText, $web, $topic, $meta );
+    $dispText = $TWiki::RENDER->getRenderedVersion( $dispText, $web, $topic );
 
     # Disable links and inputs in the text
     $dispText =~ s#<a\s[^>]*>(.*?)</a>#<span class="twikiEmulatedLink">$1</span>#gis;
@@ -94,8 +92,8 @@
     $dispText =~ s(</?form(|\s.*?)>)()gis;
     $dispText =~ s/(<[^>]*\bon[A-Za-z]+=)('[^']*'|"[^"]*")/$1''/gis;
 
-    $tmpl = $session->handleCommonTags( $tmpl, $web, $topic, $meta );
-    $tmpl = $session->{renderer}->getRenderedVersion( $tmpl, $web, $topic );
+    $tmpl = $TWiki::SESSION->handleCommonTags( $tmpl, $web, $topic, $meta );
+    $tmpl = $TWiki::RENDER->getRenderedVersion( $tmpl, $web, $topic );
     $tmpl =~ s/%TEXT%/$dispText/go;
     $tmpl =~ s/%FORMFIELDS%/$formFields/go;
 
@@ -106,7 +104,7 @@
 
     $tmpl =~ s/<\/?(nop|noautolink)\/?>//gis;
 
-    $session->writeCompletePage( $tmpl );
+    $TWiki::SESSION->writeCompletePage( $tmpl );
 }
 
 1;
