# Plugin for TWiki Collaboration Platform, http://TWiki.org/
#
# Copyright (c) 2003 Jonathan Cline, jcline.at.ieee.org
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the software nor the names of its contributors may be
# used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# =========================
#
# XXX Note.
#
# Please see below where it says CONFIGURATION to customize this plugin to
# your DDTS intranet system.
# =========================
package TWiki::Plugins::AutolinkDDTSPlugin;
# =========================
use vars qw(
$web $topic $user $installWeb $VERSION $pluginName
$debug
$DefectUrl
$SiteToken
$Token1
$Token2
);
$VERSION = '1.0';
$pluginName = 'AutolinkDDTSPlugin';
# =========================
sub initPlugin
{
( $topic, $web, $user, $installWeb ) = @_;
# check for Plugins.pm versions
if( $TWiki::Plugins::VERSION < 1 ) {
TWiki::Func::writeWarning(
"Version mismatch between $pluginName and Plugins.pm" );
return 0;
}
# Get plugin debug flag
$debug = TWiki::Func::getPreferencesFlag( "\U$pluginName\E_DEBUG" );
#
# ===
# XXX
#
# CUSTOMIZE this part.
# (Note. For speed, these variables may be removed, and placed in the
# regex below.)
#
# SiteToken is the DDTS site prefix
$SiteToken = 'BDF';
# Token1 maps to DefectUrl1
$Token1 = 'hw';
$DefectUrl1 = 'http://aww.ngn.bel.alcatel.be/cgi-bin/dumpbug.cgi?args=';
# Token2 maps to DefectUrl2
$Token2 = 'aa';
$DefectUrl2 = 'http://aww.ngn.bel.alcatel.be/cgi-bin/dumpbug.cgi?args=';
# Note that in the above example, DefectUrl1 == DefectUrl2.
# But, this is not always the case with DDTS.
#
# End of Customization part
# ===
# Plugin correctly initialized
TWiki::Func::writeDebug(
"- TWiki::Plugins::${pluginName}::initPlugin( $web.$topic ) is OK" )
if $debug;
return 1;
}
# =========================
sub outsidePREHandler
{
##TWiki::Func::writeDebug( "- ${pluginName}::outsidePREHandler( $renderingWeb.$topic )" ) if $debug;
# Note that certain case considerations are handled below.
# Defects are always matched with case-insensitivity.
# However,
# "ssstt12345" --> "SSStt12345" where SSS is sitetoken, tt is type token.
# That is, the site token is always forced to uppercase in the URL.
# Otherwise DDTS has problems with the URL.
#
$_[0] =~ s!
# match Token1, map to Url1
(\s+)($SiteToken)(($Token1)\d{5})
!$1\U$2\E$3!gixo;
$_[0] =~ s!
# match Token2, map to Url2
(\s+)($SiteToken)(($Token2)\d{5})
!$1\U$2\E$3!gixo;
}
# =========================
1;