Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Item2197: Port BugzillaLinkPlugin
  • Loading branch information
gac410 committed Feb 27, 2017
1 parent 227313e commit dc9fd8b
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 190 deletions.
File renamed without changes.
Expand Up @@ -26,11 +26,11 @@ The following =%<nop>BUG*{...}%= short hand references are supported:
---++ Examples

|You type:|You get: (simulated)|You get: (if installed)|
|%<nop>BUG{242971}%|%ATTACHURL%/bug_small.png [[http://bugzilla.mozilla.org/show_bug.cgi?id=242971][Bug #242971]]|%BUG{242971}%|
|%<nop>BUGLISTMS{Firefox1.0}%|%ATTACHURL%/bug_small.png [[http://bugzilla.mozilla.org/buglist.cgi?target_milestone=Firefox1.0b&target_milestone=Firefox1.0][Buglist for milestone Firefox1.0]]|%BUGLISTMS{Firefox1.0}%|
|%<nop>BUGLISTKEY{highrisk,64bit}%|%ATTACHURL%/bug_small.png [[http://bugzilla.mozilla.org/buglist.cgi?keywords_type=anywords&keywords=highrisk+64bit][Buglist for keyword(s) "highrisk,64bit"]]|%BUGLISTKEY{highrisk,64bit}%|
|%<nop>BUGLISTKEY{crash+fonts}%|%ATTACHURL%/bug_small.png [[http://bugzilla.mozilla.org/buglist.cgi?keywords_type=allwords&keywords=crash+fonts][Buglist for keyword(s) "crash+fonts"]]|%BUGLISTKEY{crash+fonts}%|
|%<nop>MYBUGS{shaver@mozilla.org}%|%ATTACHURL%/bug_small.png [[http://bugzilla.mozilla.org/buglist.cgi?bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&email1=shaver@mozilla.org&emailtype1=exact&emailassigned_to1=1&emailreporter1=1][Buglist for shaver@mozilla.org]]|%MYBUGS{shaver@mozilla.org}%|
|%<nop>BUG{242971}%|<img src='%PUBURLPATH{topic="System.BugzillaLinkPlugin" "bug_small.png"}%' alt='bug' /> [[http://bugzilla.mozilla.org/show_bug.cgi?id=242971][Bug #242971]]|%BUG{242971}%|
|%<nop>BUGLISTMS{Firefox1.0}%|<img src='%PUBURLPATH{topic="System.BugzillaLinkPlugin" "bug_small.png"}%' alt='bug' /> [[http://bugzilla.mozilla.org/buglist.cgi?target_milestone=Firefox1.0b&target_milestone=Firefox1.0][Buglist for milestone Firefox1.0]]|%BUGLISTMS{Firefox1.0}%|
|%<nop>BUGLISTKEY{highrisk,64bit}%|<img src='%PUBURLPATH{topic="System.BugzillaLinkPlugin" "bug_small.png"}%' alt='bug' /> [[http://bugzilla.mozilla.org/buglist.cgi?keywords_type=anywords&keywords=highrisk+64bit][Buglist for keyword(s) "highrisk,64bit"]]|%BUGLISTKEY{highrisk,64bit}%|
|%<nop>BUGLISTKEY{crash+fonts}%|<img src='%PUBURLPATH{topic="System.BugzillaLinkPlugin" "bug_small.png"}%' alt='bug' /> [[http://bugzilla.mozilla.org/buglist.cgi?keywords_type=allwords&keywords=crash+fonts][Buglist for keyword(s) "crash+fonts"]]|%BUGLISTKEY{crash+fonts}%|
|%<nop>MYBUGS{shaver@mozilla.org}%|<img src='%PUBURLPATH{topic="System.BugzillaLinkPlugin" "bug_small.png"}%' alt='bug' /> [[http://bugzilla.mozilla.org/buglist.cgi?bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&email1=shaver@mozilla.org&emailtype1=exact&emailassigned_to1=1&emailreporter1=1][Buglist for shaver@mozilla.org]]|%MYBUGS{shaver@mozilla.org}%|


---++ <nop>%TOPIC% Settings
Expand All @@ -40,19 +40,19 @@ Plugin settings are stored as preferences variables. To reference a plugin setti
* One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic:
* Set SHORTDESCRIPTION = Link to Bugzilla bugs using shorthand references

* Set DEBUG to 1 to get debug messages in =data/debug.txt=. Default: =0=
* Set DEBUG = 0
* #Set DEBUG to 1 to get debug messages in =data/debug.txt=. Default: =0=
* Set BUGZILLALINKPLUGIN_DEBUG = 0

* URL references to your Bugzilla installation and to the bug image
* Set BUGURL = http://bugzilla.mozilla.org/show_bug.cgi?id=
* Set BUGLISTURL = http://bugzilla.mozilla.org/buglist.cgi?
* Set BUGIMGURL = %ATTACHURL%/bug_small.png
* Set BUGZILLALINKPLUGIN_BUGURL = http://bugzilla.mozilla.org/show_bug.cgi?id=
* Set BUGZILLALINKPLUGIN_BUGLISTURL = http://bugzilla.mozilla.org/buglist.cgi?
* Set BUGZILLALINKPLUGIN_BUGIMGURL = %PUBURLPATH{topic="System.BugzillaLinkPlugin" "bug_small.png"}%

* Text references for automatic substitution
* Set BUGTEXT = Bug #
* Set MILESTONEBUGLISTTEXT = Buglist for milestone
* Set KEYWORDSBUGLISTTEXT = Buglist for keyword(s)
* Set MYBUGLISTTEXT = Buglist for user
* Set BUGZILLALINKPLUGIN_BUGTEXT = Bug #
* Set BUGZILLALINKPLUGIN_MILESTONEBUGLISTTEXT = Buglist for milestone
* Set BUGZILLALINKPLUGIN_KEYWORDSBUGLISTTEXT = Buglist for keyword(s)
* Set BUGZILLALINKPLUGIN_MYBUGLISTTEXT = Buglist for user

---++ Limitations and Known Issues

Expand Down
149 changes: 149 additions & 0 deletions lib/Foswiki/Plugins/BugzillaLinkPlugin.pm
@@ -0,0 +1,149 @@
# See bottom of file for default license and copyright information
# =========================
#

# =========================
package Foswiki::Plugins::BugzillaLinkPlugin; # change the package name!!!

use strict;
use warnings;

our $VERSION = '1.400';
our $RELEASE = '1 Mar 2017';
our $SHORTDESCRIPTION = 'Render links to Bugzilla repositories.';
our $NO_PREFS_IN_TOPIC = 1;

my $bugUrl;
my $bugImgUrl;
my $bugListUrl;
my $bugText;
my $milestoneBugListText;
my $keywordsBugListText;
my $myBugListText;
my $debug;

# =========================
sub initPlugin {
my ( $topic, $web, $user, $installWeb ) = @_;

# check for Plugins.pm versions
if ( $Foswiki::Plugins::VERSION < 1 ) {
&Foswiki::Func::writeWarning(
"Version mismatch between BugzillaLinkPlugin and Plugins.pm");
return 0;
}

# Get plugin preferences

$bugUrl = &Foswiki::Func::getPreferencesValue("BUGZILLALINKPLUGIN_BUGURL")
|| "http://localhost/bugzilla/show_bug.cgi?id=";
$bugImgUrl =
&Foswiki::Func::getPreferencesValue("BUGZILLALINKPLUGIN_BUGIMGURL")
|| '%PUBURLPATH{topic="%SYSTEMWEB%.BugzillaLinkPlugin" "bug.gif"}%';
$bugListUrl =
&Foswiki::Func::getPreferencesValue("BUGZILLALINKPLUGIN_BUGLISTURL")
|| "http://localhost/bugzilla/buglist.cgi?";
$bugText = &Foswiki::Func::getPreferencesValue("BUGZILLALINKPLUGIN_BUGTEXT")
|| "Bug #";
$milestoneBugListText = &Foswiki::Func::getPreferencesValue(
"BUGZILLALINKPLUGIN_MILESTONEBUGLISTTEXT")
|| "Buglist for Milestone ";
$keywordsBugListText =
&Foswiki::Func::getPreferencesValue(
"BUGZILLALINKPLUGIN_KEYWORDBUGLISTTEXT")
|| "Buglist for keyword(s) ";
$myBugListText =
&Foswiki::Func::getPreferencesValue("BUGZILLALINKPLUGIN_MYBUGLISTTEXT")
|| "Buglist for user ";

# Get plugin debug flag
$debug = &Foswiki::Func::getPreferencesFlag("BUGZILLAPLUGIN_DEBUG");
$debug = 1;

# Plugin correctly initialized
&Foswiki::Func::writeDebug(
"- Foswiki::Plugins::BugzillaLinkPlugin::initPlugin( $web.$topic ) is OK"
) if $debug;
return 1;
}

# =========================
sub commonTagsHandler {
### my ( $text, $topic, $web ) = @_; # do not uncomment, use $_[0], $_[1]... instead

&Foswiki::Func::writeDebug(
"- BugzillaLinkePlugin::commonTagsHandler( $_[2].$_[1] )")
if $debug;

# This is the place to define customized tags and variables
# Called by sub handleCommonTags, after %INCLUDE:"..."%
$_[0] =~ s/%BUG\{([0-9]+)\}%/&BugzillaShowBug($1)/geo;
$_[0] =~ s/%BUGLISTMS\{(.+)\}%/&BugzillaShowMilestoneBugList($1)/geo;
$_[0] =~ s/%BUGLISTKEY\{(.+)\}%/&BugzillaShowKeywordsBugList($1)/geo;
$_[0] =~ s/%MYBUGS\{(.+)\}%/&BugzillaShowMyBugList($1)/geo;
}

sub BugzillaShowBug {
my ($bugID) = @_;
## display a bug img and the bugzilla url
$bugID =~ s/\s*(\S*)\s*/$1/;
return
"<img src='$bugImgUrl' alt='bug' /> [[$bugUrl$bugID][$bugText$bugID]]";
}

sub BugzillaShowMilestoneBugList {
my ($mID) = @_;
## display a bug img and a bugzilla milesteone bug list
$mID =~ s/\s*(\S*)\s*/$1/;
return
"<img src='$bugImgUrl' alt='bug' /> [[$bugListUrl"
. "target_milestone="
. $mID
. "b&target_milestone=$mID][$milestoneBugListText $mID]]";
}

sub BugzillaShowKeywordsBugList {
my ($keyWords) = @_;

# Determine if AND-type or OR-type search
my $type = "allwords";
$keyWords =~ s/\s*(\S*)\s*/$1/;
my $keyWordsUse = $keyWords;
if ( $_[0] =~ m/\w+,\w+/ ) {
$type = "anywords";
$keyWordsUse =~ s/,/+/;
}
return "<img src='$bugImgUrl' alt='bug' /> [[$bugListUrl"
. "keywords_type=$type&keywords=$keyWordsUse][$keywordsBugListText \"$keyWords\"]]";
}

sub BugzillaShowMyBugList {
my ($mID) = @_;
## display a bug img and a bugzilla milesteone bug list
return "<img src='$bugImgUrl' alt='bug' /> [[$bugListUrl"
. "bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&email1=$mID&emailtype1=exact&emailassigned_to1=1&emailreporter1=1][$myBugListText $mID]]";
}
1;

__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2013 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
# Copyright (C) 2000-2001 Andrea Sterbini, a.sterbini@flashnet.it
# Copyright (C) 2001 Peter Thoeny, Peter@Thoeny.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. For
more details read LICENSE in the root of this distribution.
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.
As per the GPL, removal of this notice is prohibited.
Empty file.
6 changes: 6 additions & 0 deletions lib/Foswiki/Plugins/BugzillaLinkPlugin/MANIFEST
@@ -0,0 +1,6 @@
data/System/BugzillaLinkPlugin.txt 0664
lib/Foswiki/Plugins/BugzillaLinkPlugin.pm 0664
pub/System/BugzillaLinkPlugin/bug.gif 0664
pub/System/BugzillaLinkPlugin/bug_small.gif 0664
pub/System/BugzillaLinkPlugin/bug_small.png 0664
pub/System/BugzillaLinkPlugin/bug_small_white.png 0664
18 changes: 18 additions & 0 deletions lib/Foswiki/Plugins/BugzillaLinkPlugin/build.pl
@@ -0,0 +1,18 @@
#!/usr/bin/perl -w
#
# Build for BugzillaLinkPlugin
#
BEGIN {
foreach my $pc (split(/:/, $ENV{FOSWIKI_LIBS})) {
unshift @INC, $pc;
}
}

use Foswiki::Contrib::Build;

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

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

152 changes: 0 additions & 152 deletions lib/TWiki/Plugins/BugzillaLinkPlugin.pm

This file was deleted.

6 changes: 0 additions & 6 deletions lib/TWiki/Plugins/BugzillaLinkPlugin/MANIFEST

This file was deleted.

0 comments on commit dc9fd8b

Please sign in to comment.