You are here: Foswiki>Tasks Web>Item604 (24 May 2011, GeorgeClark)Edit Attach

Item604: TWikiCompatibilityPlugin doesn't publish variables in the $TWiki namespace

pencil
Priority: Urgent
Current State: Closed
Released In: 1.0.0
Target Release: patch
Applies To: Extension
Component: TWikiCompatibilityPlugin
Branches:
Reported By: Foswiki:Main.WillNorris
Waiting For: WillNorris
Last Change By: GeorgeClark
ImageGalleryPlugin uses the following code snippet to determine which version of TWiki (before 4.0.0 or 4.0.0 or later) to decide where to read certain variables from.

$this->{isDakar} = defined $TWiki::RELEASE;

i have modified this (as a TEMPORARY measure) because i could not find the proper place to declare $TWiki::RELEASE and have ImageGalleryPlugin recognize it. my stopgap "fix" is

$this->{isDakar} = defined $TWiki::RELEASE || defined $Foswiki::RELEASE;

in Item175, IsaacLin writes:

Regarding problems with reading configuration from legacy LocalSite.cfg files: Perhaps namespace aliasing is happening too late? It may not be feasible to load in a plugin to do the aliasing; there may need to be a special hook so this can be done during the compile-time phase. I know the aliasing approach seems to have been abandoned, but I think assigning one symbol table to another is a very concise way to do precisely what is needed.

i didn't realize the aliasing approach had been abandonded; furthermore, i second his assessment that "assigning one symbol table to another is a very concise way to do precisely what is needed"

-- WillNorris - 30 Dec 2008

The aliasing approach has not been abandoned. The mechanism used is different, however.

The problem is that blanket aliasing is not the appropriate solution in most cases. Aliasing a package works if there is a 1:1 correspondance between the TWiki and Foswiki methods. However this is already not the case. So we have used aliasing where that 1:1 mapping exists, but had to kick down to aliasing individual symbols, or using interface functions in many cases.

Note that we started by respecting the APIs, and aliasing only those that were published. We have stretched the point by aliasing some other symbols - and publishing them in Foswiki to avoid future problems - but we can never be 100% proof against extension authors who use unpublished symbols - such as $TWiki::RELEASE. Unfortunately this symbol cannot be aliased; $Foswiki::RELEASE does not correspond to $TWiki::RELEASE. The best we can do is to declare

our $RELEASE = 'TWiki-4.2.3';
in TWiki.pm in the compatibility plugin. However there may still be an issue if the plugin is using this variable to decide what other unpublished core functions to call frown, sad smile

Isaac's remarks predated much of the work on the plugin. I'm not aware of any outstanding issues regarding late binding of TWiki-type LocalSite.cfgs.

-- CrawfordCurrie - 30 Dec 2008

first, a clarification: the places where i have seen $TWiki::RELEASE used have been to retain compatibility with pre-TWiki 4. that is, if running under TWiki 4, it uses the documented methods as compared to going directly into the data structures.

i have tried to fix this by adding the following code to the bottom of TWiki.pm:

package TWiki;
our $RELEASE = 'TWiki-4.2.3';

(i also tried)
our $TWiki::RELEASE = 'TWiki-4.2.3';

but no go and i'm not sure why. also, i thought that it was strange that TWiki.pm has a commented out package TWiki; declaration.

-- WillNorris - 02 Jan 2009

If you are convinced that this has to be supported I would recommend adding a unit test to the compatibility plugin.

I don't recall exactly why the package declaration is commented out, but you can be fairly comfident that something breaks if it is declared. I have a vague recollection of it causing problems when loading a TWiki LocalSite.cfg.

You could also try: $TWiki::RELEASE =  'TWiki-4.2.3'; (i.e. without the our)

Index: lib/Foswiki/Plugins/TWikiCompatibilityPlugin.pm
===================================================================
--- lib/Foswiki/Plugins/TWikiCompatibilityPlugin.pm     (revision 1705)
+++ lib/Foswiki/Plugins/TWikiCompatibilityPlugin.pm     (working copy)
@@ -29,6 +29,7 @@
 use vars qw( $VERSION $RELEASE $SHORTDESCRIPTION $debug $pluginName $NO_PREFS_IN_TOPIC );
 $VERSION = '$Rev$';
 $RELEASE = 'Foswiki-1.0';
+$TWiki::RELEASE = 'TWiki 4.2.3';
 $SHORTDESCRIPTION = 'add TWiki personality to Foswiki';
 $NO_PREFS_IN_TOPIC = 1;
 $pluginName = 'TWikiCompatibilityPlugin';

(with special thanks to OlivierRaginel on IRC)


How about dropping support for TWiki/Dakar in ImageGalleryPlugin? The above check in IGP isn't of any use anymore.

-- MichaelDaum - 07 Jan 2009
Topic revision: r17 - 24 May 2011, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy