Skip to content

Commit

Permalink
Item10092: externalized %WEBLINK from NatSkinPlugin
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/WebLinkPlugin@10104 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed Nov 29, 2010
0 parents commit 34ef1fa
Show file tree
Hide file tree
Showing 6 changed files with 280 additions and 0 deletions.
37 changes: 37 additions & 0 deletions data/System/WebLinkPlugin.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
%META:TOPICINFO{author="micha" comment="" date="1291041934" format="1.1" version="2"}%
---+!! %TOPIC%
%SHORTDESCRIPTION%

%TOC%

This plugin allows to render a link to a web. While linking to a topic is quite essential to wikis,
linking to a web as an object of the wiki isn't that well supported. Most commonly a link to a web points
to the !%HOMETOPIC% topic of a web which serves as the entry point for all of the web. That's
what %WEBLINK does as well. In addition it supports formatting the link in a custom way to
display a more meaningful link text than the normal !WebHome text. If you optionally installed
Foswiki:Extensions/DBCachePlugin, the %WEBLINK will be displaying the !TopicTitle of the target topic.
Otherwise the normal topic name will be displayed as link text.

---++ Usage

%INCLUDE{"VarWEBLINK"}%

---++ Installation Instructions

%$INSTALL_INSTRUCTIONS%

---++ Info
<!--
* Set SHORTDESCRIPTION = %$SHORTDESCRIPTION%
-->

| Author(s): | Michael Daum|
| Copyright: | &copy; 2010 Michael Daum http://michaeldaumconsulting.com |
| License: | [[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]] |
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 29 Nov 2010 | externalized from !NatSkinPlugin |
| Dependencies: | %$DEPENDENCIES% |
| Home page: | Foswiki:Extensions/%TOPIC% |
| Support: | Foswiki:Support/%TOPIC% |
81 changes: 81 additions & 0 deletions lib/Foswiki/Plugins/WebLinkPlugin.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# WebLinkPlugin is Copyright (C) 2010 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details, published at
# http://www.gnu.org/copyleft/gpl.html

package Foswiki::Plugins::WebLinkPlugin;

use strict;
use warnings;

=begin TML
---+ package WebLinkPlugin
=cut

use Foswiki::Func ();

our $VERSION = '$Rev$';
our $RELEASE = '1.00';
our $SHORTDESCRIPTION = 'A parametrized %WEB macro';
our $NO_PREFS_IN_TOPIC = 1;
our $baseWeb;
our $baseTopic;
our $doneInit;


=begin TML
---++ initPlugin($topic, $web, $user) -> $boolean
=cut

sub initPlugin {
($baseTopic, $baseWeb) = @_;

Foswiki::Func::registerTagHandler('WEBLINK', \&WEBLINK);

$doneInit = 0;
return 1;
}

=begin TML
---++ init()
=cut

sub init {
return if $doneInit;

$doneInit = 1;

require Foswiki::Plugins::WebLinkPlugin::Core;
Foswiki::Plugins::WebLinkPlugin::Core::init($baseWeb, $baseTopic);
}

=begin TML
---+ WEBLINK($session, $params, $theTopic, $theWeb) -> $string
stub for WEBLINK to initiate the core before handling the macro
=cut

sub WEBLINK {
init();
return Foswiki::Plugins::WebLinkPlugin::Core::WEBLINK(@_);
}

1;
130 changes: 130 additions & 0 deletions lib/Foswiki/Plugins/WebLinkPlugin/Core.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# WebLinkPlugin is Copyright (C) 2010 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details, published at
# http://www.gnu.org/copyleft/gpl.html

package Foswiki::Plugins::WebLinkPlugin::Core;

use strict;
use warnings;

=begin TML
---+ package WebLinkPlugin::Core
=cut

use Foswiki::Func ();

our $baseWeb;
our $baseTopic;

use constant DEBUG => 0; # toggle me

=begin TML
---++ writeDebug($message(
prints a debug message to STDERR when this module is in DEBUG mode
=cut

sub writeDebug {
print STDERR "WebLinkPlugin::Core - $_[0]\n" if DEBUG;
}

=begin TML
---++ init($baseWeb, $baseTopic)
initializer for the plugin core; called before any macro hanlder is executed
=cut

sub init {
($baseWeb, $baseTopic) = @_;
}

=begin TML
---++ WEBLINK($session, $params, $theTopic, $theWeb) -> $result
implementation of this macro
=cut

sub WEBLINK {
my ($session, $params, $topic, $web) = @_;

writeDebug("called WEBLINK()");

# get params
my $theWeb = $params->{_DEFAULT} || $params->{web} || $web;
my $theName = $params->{name};
my $theMarker = $params->{marker} || 'current';
my $theClass = $params->{class} || 'webLink';

my $defaultFormat =
'<a class="'.$theClass.' $marker" href="$url" title="%ENCODE{"$tooltip" type="html"}%">$title</a>';

my $theFormat = $params->{format} || $defaultFormat;

#writeDebug("theFormat=$theFormat, theWeb=$theWeb");

my $theTooltip = $params->{tooltip} ||
Foswiki::Func::getPreferencesValue('WEBSUMMARY', $theWeb) ||
Foswiki::Func::getPreferencesValue('SITEMAPUSETO', $theWeb) || '';

my $homeTopic = Foswiki::Func::getPreferencesValue('HOMETOPIC')
|| $Foswiki::cfg{HomeTopicName}
|| 'WebHome';

my $theUrl = $params->{url} ||
$session->getScriptUrl(0, 'view', $theWeb, $homeTopic);

# unset the marker if this is not the current web
$theMarker = '' unless $theWeb eq $baseWeb;

# normalize web name
$theWeb =~ s/\//\./go;

# get a good default name
unless ($theName) {
$theName = $theWeb;
$theName = $2 if $theName =~ /^(.*)[\.](.*?)$/;
}

my $title = '';
if ($theFormat =~ /\$title/) {
if (Foswiki::Func::getContext()->{DBCachePluginEnabled}) {
require Foswiki::Plugins::DBCachePlugin;
$title = Foswiki::Plugins::DBCachePlugin::getTopicTitle($theWeb, $homeTopic);
}
$title = $theName if $title eq $homeTopic;
}

my $result = $theFormat;
$result =~ s/\$default/$defaultFormat/g;
$result =~ s/\$marker/$theMarker/g;
$result =~ s/\$url/$theUrl/g;
$result =~ s/\$tooltip/$theTooltip/g;
$result =~ s/\$name/$theName/g;
$result =~ s/\$title/$title/g;
$result =~ s/\$web/$theWeb/g;
$result =~ s/\$topic/$homeTopic/g;

#writeDebug("result=$result");
return $result;
}

1;
5 changes: 5 additions & 0 deletions lib/Foswiki/Plugins/WebLinkPlugin/DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Dependencies for WebLinkPlugin
# Example:
# Time::ParseDate,>=2003.0211,cpan,Required.
# Foswiki::Plugins,>=1.2,perl,Requires version 1.2 of handler API.

3 changes: 3 additions & 0 deletions lib/Foswiki/Plugins/WebLinkPlugin/MANIFEST
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data/System/WebLinkPlugin.txt 0644
lib/Foswiki/Plugins/WebLinkPlugin/Core.pm 0644
lib/Foswiki/Plugins/WebLinkPlugin.pm 0644
24 changes: 24 additions & 0 deletions lib/Foswiki/Plugins/WebLinkPlugin/build.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/perl -w
BEGIN { unshift @INC, split( /:/, $ENV{FOSWIKI_LIBS} ); }
use Foswiki::Contrib::Build;

# Create the build object
$build = new Foswiki::Contrib::Build('WebLinkPlugin');

# (Optional) Set the details of the repository for uploads.
# This can be any web on any accessible Foswiki installation.
# These defaults will be used when expanding tokens in .txt
# files, but be warned, they can be overridden at upload time!

# name of web to upload to
$build->{UPLOADTARGETWEB} = 'Extensions';
# Full URL of pub directory
$build->{UPLOADTARGETPUB} = 'http://foswiki.org/pub';
# Full URL of bin directory
$build->{UPLOADTARGETSCRIPT} = 'http://foswiki.org/bin';
# Script extension
$build->{UPLOADTARGETSUFFIX} = '';

# Build the target on the command line, or the default target
$build->build($build->{target});

0 comments on commit 34ef1fa

Please sign in to comment.