Changeset 806


Ignore:
Timestamp:
11/19/08 12:04:24 (3 years ago)
Author:
SvenDowideit
Message:

Item175: untested topicmapping

Location:
trunk/TWikiCompatibilityPlugin
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/TWikiCompatibilityPlugin/data/TWiki/TWikiCompatibilityPlugin.txt

    r805 r806  
    99 
    1010---++ Usage 
     11Automaticalle maps requests for legacy TWiki web topics to Foswiki free topics as per 
     12[[http://foswiki.org/Development/TopicNameMappingTable][TopicNameMappingTable]]. 
    1113 
    12 ---++ Examples 
    1314 
    1415---++ Installation Instructions 
  • trunk/TWikiCompatibilityPlugin/lib/TWiki/Plugins/TWikiCompatibilityPlugin.pm

    r805 r806  
    33# This program is free software; you can redistribute it and/or 
    44# modify it under the terms of the GNU General Public License 
    5 # as published by the Free Software Foundation; either version 2 
     5# as published by the Free Software Foundation; either version 3 
    66# of the License, or (at your option) any later version. 
    77# 
     
    1616---+ package TWiki::Plugins::TWikiCompatibilityPlugin 
    1717 
    18 To interact with TWiki use ONLY the official API functions 
    19 in the TWiki::Func module. Do not reference any functions or 
    20 variables elsewhere in TWiki, as these are subject to change 
    21 without prior warning, and your plugin may suddenly stop 
    22 working. 
    23  
    24 For increased performance, all handlers except initPlugin are 
    25 disabled below. *To enable a handler* remove the leading DISABLE_ from 
    26 the function name. For efficiency and clarity, you should comment out or 
    27 delete the whole of handlers you don't use before you release your 
    28 plugin. 
    29  
    30 __NOTE:__ When developing a plugin it is important to remember that 
    31 TWiki is tolerant of plugins that do not compile. In this case, 
    32 the failure will be silent but the plugin will not be available. 
    33 See [[%SYSTEMWEB%.Plugins#FAILEDPLUGINS]] for error messages. 
    34  
    35 __NOTE:__ Defining deprecated handlers will cause the handlers to be  
    36 listed in [[%SYSTEMWEB%.Plugins#FAILEDPLUGINS]]. See 
    37 [[%SYSTEMWEB%.Plugins#Handlig_deprecated_functions]] 
    38 for information on regarding deprecated handlers that are defined for 
    39 compatibility with older TWiki versions. 
    40  
    41 __NOTE:__ When writing handlers, keep in mind that these may be invoked 
    42 on included topics. For example, if a plugin generates links to the current 
    43 topic, these need to be generated before the afterCommonTagsHandler is run, 
    44 as at that point in the rendering loop we have lost the information that we 
    45 the text had been included from another topic. 
    4618 
    4719=cut 
     
    5527require TWiki::Func;    # The plugins API 
    5628require TWiki::Plugins; # For the API version 
    57  
    58 # $VERSION is referred to by TWiki, and is the only global variable that 
    59 # *must* exist in this package. 
    6029use vars qw( $VERSION $RELEASE $SHORTDESCRIPTION $debug $pluginName $NO_PREFS_IN_TOPIC ); 
    61  
    62 # This should always be $Rev$ so that TWiki can determine the checked-in 
    63 # status of the plugin. It is used by the build automation tools, so 
    64 # you should leave it alone. 
    6530$VERSION = '$Rev$'; 
    66  
    67 # This is a free-form string you can use to "name" your own plugin version. 
    68 # It is *not* used by the build automation tools, but is reported as part 
    69 # of the version number in PLUGINDESCRIPTIONS. 
    70 $RELEASE = 'TWiki-4.2'; 
    71  
    72 # Short description of this plugin 
    73 # One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic: 
     31$RELEASE = 'Foswiki-1.0'; 
    7432$SHORTDESCRIPTION = 'add TWiki personality to Foswiki'; 
    75  
    76 # You must set $NO_PREFS_IN_TOPIC to 0 if you want your plugin to use preferences 
    77 # stored in the plugin topic. This default is required for compatibility with 
    78 # older plugins, but imposes a significant performance penalty, and 
    79 # is not recommended. Instead, use $TWiki::cfg entries set in LocalSite.cfg, or 
    80 # if you want the users to be able to change settings, then use standard TWiki 
    81 # preferences that can be defined in your %USERSWEB%.SitePreferences and overridden 
    82 # at the web and topic level. 
    8333$NO_PREFS_IN_TOPIC = 1; 
    84  
    85 # Name of this Plugin, only used in this module 
    8634$pluginName = 'TWikiCompatibilityPlugin'; 
    8735 
     
    9341   * =$user= - the login name of the user 
    9442   * =$installWeb= - the name of the web the plugin is installed in 
    95  
    96 REQUIRED 
    97  
    98 Called to initialise the plugin. If everything is OK, should return 
    99 a non-zero value. On non-fatal failure, should write a message 
    100 using TWiki::Func::writeWarning and return 0. In this case 
    101 %FAILEDPLUGINS% will indicate which plugins failed. 
    102  
    103 In the case of a catastrophic failure that will prevent the whole 
    104 installation from working safely, this handler may use 'die', which 
    105 will be trapped and reported in the browser. 
    106  
    107 You may also call =TWiki::Func::registerTagHandler= here to register 
    108 a function to handle variables that have standard TWiki syntax - for example, 
    109 =%MYTAG{"my param" myarg="My Arg"}%. You can also override internal 
    110 TWiki variable handling functions this way, though this practice is unsupported 
    111 and highly dangerous! 
    112  
    113 __Note:__ Please align variables names with the Plugin name, e.g. if  
    114 your Plugin is called FooBarPlugin, name variables FOOBAR and/or  
    115 FOOBARSOMETHING. This avoids namespace issues. 
    116  
    11743 
    11844=cut 
     
    12753    } 
    12854 
    129     # Example code of how to get a preference value, register a variable handler 
    130     # and register a RESTHandler. (remove code you do not need) 
    131  
    132     # Set plugin preferences in LocalSite.cfg, like this: 
    133     # $TWiki::cfg{Plugins}{TWikiCompatibilityPlugin}{ExampleSetting} = 1; 
    134     # Always provide a default in case the setting is not defined in 
    135     # LocalSite.cfg. See %SYSTEMWEB%.Plugins for help in adding your plugin 
    136     # configuration to the =configure= interface. 
    13755    my $setting = $TWiki::cfg{Plugins}{TWikiCompatibilityPlugin}{ExampleSetting} || 0; 
    13856    $debug = $TWiki::cfg{Plugins}{TWikiCompatibilityPlugin}{Debug} || 0; 
    13957 
    140     # register the _EXAMPLETAG function to handle %EXAMPLETAG{...}% 
    141     # This will be called whenever %EXAMPLETAG% or %EXAMPLETAG{...}% is 
    142     # seen in the topic text. 
    14358    TWiki::Func::registerTagHandler( 'EXAMPLETAG', \&_EXAMPLETAG ); 
    144  
    145     # Allow a sub to be called from the REST interface  
    146     # using the provided alias 
    14759    TWiki::Func::registerRESTHandler('example', \&restExample); 
    14860 
    149     # Plugin correctly initialized 
    15061    return 1; 
    15162} 
     
    17485---++ earlyInitPlugin() 
    17586 
    176 This handler is called before any other handler, and before it has been 
    177 determined if the plugin is enabled or not. Use it with great care! 
    178  
    179 If it returns a non-null error string, the plugin will be disabled. 
    180  
    181 =cut 
    182  
    183 sub DISABLE_earlyInitPlugin { 
    184     return undef; 
     87If the TWiki web does not exist, change the request to the %SYSTEMWEB% 
     88 
     89This may not be enough for Plugins that do have intopic preferences. 
     90 
     91=cut 
     92 
     93sub earlyInitPlugin { 
     94    if (($TWiki::Plugins::SESSION->{webName} eq 'TWiki') && 
     95            (!TWiki::Func::webExists($TWiki::Plugins::SESSION->{webName}))) { 
     96        my $TWikiWebTopicNameConversion = $TWiki::cfg{Plugins}{TWikiCompatibilityPlugin}{TWikiWebTopicNameConversion}; 
     97        $TWiki::Plugins::SESSION->{webName} = $TWiki::cfg{SystemWebName}; 
     98        if (defined($TWikiWebTopicNameConversion->{$TWiki::Plugins::SESSION->{topicName}})) { 
     99            $TWiki::Plugins::SESSION->{topicName} = 
     100                    $TWikiWebTopicNameConversion->{$TWiki::Plugins::SESSION->{topicName}}; 
     101        } 
     102    } 
     103    my $MainWebTopicNameConversion = $TWiki::cfg{Plugins}{TWikiCompatibilityPlugin}{MainWebTopicNameConversion}; 
     104    if (($TWiki::Plugins::SESSION->{webName} eq 'Main') && 
     105            (defined($MainWebTopicNameConversion->{$TWiki::Plugins::SESSION->{topicName}}))) { 
     106        $TWiki::Plugins::SESSION->{topicName} = 
     107            $MainWebTopicNameConversion->{$TWiki::Plugins::SESSION->{topicName}}; 
     108    } 
     109     
     110    return; 
    185111} 
    186112 
  • trunk/TWikiCompatibilityPlugin/lib/TWiki/Plugins/TWikiCompatibilityPlugin/MANIFEST

    r805 r806  
    22data/TWiki/TWikiCompatibilityPlugin.txt 0644 Documentation 
    33lib/TWiki/Plugins/TWikiCompatibilityPlugin.pm 0644 Perl module 
     4lib/TWiki/Plugins/TWikiCompatibilityPlugin/Configu.spec configuration defaults 
    45 
Note: See TracChangeset for help on using the changeset viewer.