diff -rub BugzillaQueryPlugin/data/TWiki/BugzillaQueryPlugin.txt BugzillaQueryPlugin-RC/data/TWiki/BugzillaQueryPlugin.txt --- data/TWiki/BugzillaQueryPlugin.txt Mon Feb 23 10:37:44 2004 +++ data/TWiki/BugzillaQueryPlugin.txt Mon May 15 15:55:13 2006 @@ -40,7 +40,7 @@ ---+++ %TOPIC% Settings
- * Set URL = https://marvin.in.idoox.com/bugzilla/ + * Set URL = https://www.example.com/bugzilla * Set FORMAT = | $bug_id | $bug_severity | $priority | $bug_status | $resolution | $reporter | $product | $short_desc | * Set SHORTDESCRIPTION = This plugin is useful to display links or data results from Bugzilla. * Set SHOWBUGSCRIPT = show_bug.cgi diff -rub BugzillaQueryPlugin/lib/TWiki/Plugins/BugzillaQueryPlugin.pm BugzillaQueryPlugin-RC/lib/TWiki/Plugins/BugzillaQueryPlugin.pm --- lib/TWiki/Plugins/BugzillaQueryPlugin.pm Mon Feb 23 10:43:50 2004 +++ lib/TWiki/Plugins/BugzillaQueryPlugin.pm Mon May 15 15:53:05 2006 @@ -46,6 +46,43 @@ # in the TWiki::Func module. Do not reference any functions or # variables elsewhere in TWiki!! +# BugzillaQueryPlugin +# +# This plugin makes queries to your bugzilla backend and returns them in +# an arbitarily formatted string. +# +# Author: Richard Baar +# 23 February 2004 +# +# Contrib: Ian Tegebo +# 14 March 2006 +# * Comments +# * Regex fixes +# +# Contrib: Chris Cowart +# 15 May 2006 +# * TWiki-4 configuration syntax +# +# +# Plugin Overview - BugzillaQueryPlugin +# +# Parse Options +# Parse the Plugin arguments +# Get the Data +# Create the return table +# +# +# Configuration: +# The following options must be set in twiki/lib/LocalSite.cfg for TWiki >=4. +# Make sure to use settings appropriate for your site. +# +# $TWiki::cfg{Plugins}{BugzillaQueryPlugin}{dbHost} = +# "your.bugzilla.server.org"; +# $TWiki::cfg{Plugins}{BugzillaQueryPlugin}{dbPort} = "3306"; +# $TWiki::cfg{Plugins}{BugzillaQueryPlugin}{dbName} = "bugs"; +# $TWiki::cfg{Plugins}{BugzillaQueryPlugin}{dbUser} = "bugs"; +# $TWiki::cfg{Plugins}{BugzillaQueryPlugin}{dbPasswd} = 'supersecret'; +# # ========================= package TWiki::Plugins::BugzillaQueryPlugin; # change the package name and $pluginName!!! @@ -84,11 +121,24 @@ $showBugScript = TWiki::Func::getPreferencesValue( "\U$pluginName\E_SHOWBUGSCRIPT" ) || "show_bug.cgi"; $bugListScript = TWiki::Func::getPreferencesValue( "\U$pluginName\E_BUGLISTSCRIPT" ) || "buglist.cgi"; + if ( defined $TWiki::cfg{DataDir} ) { + # TWiki-4 or more recent + $dbHost = $TWiki::cfg{Plugins}{BugzillaQueryPlugin}{dbHost}; + $dbPort = $TWiki::cfg{Plugins}{BugzillaQueryPlugin}{dbPort}; + $dbName = $TWiki::cfg{Plugins}{BugzillaQueryPlugin}{dbName}; + $dbUser = $TWiki::cfg{Plugins}{BugzillaQueryPlugin}{dbUser}; + $dbPasswd = $TWiki::cfg{Plugins}{BugzillaQueryPlugin}{dbPasswd}; + } else { + # Cairo or earlier $dbHost = TWiki::Func::getPreferencesValue( "\U$pluginName\E_BUGZILLA_DB_HOST" ) || ""; # MySQL database host name $dbPort = TWiki::Func::getPreferencesValue( "\U$pluginName\E_BUGZILLA_DB_PORT" ) || ""; # MySQL database port number $dbName = TWiki::Func::getPreferencesValue( "\U$pluginName\E_BUGZILLA_DB_NAME" ) || "bugs"; # MySQL database name $dbUser = TWiki::Func::getPreferencesValue( "\U$pluginName\E_BUGZILLA_USER" ) || "guest"; # MySQL user who has access to $dbName database (read-only access is the best :-))) $dbPasswd = TWiki::Func::getPreferencesValue( "\U$pluginName\E_BUGZILLA_PASSWD" ) || ""; # password for $dbUser + } + + $default_format = '| $bug_id | $bug_severity | $priority | $bug_status |' . + ' $reporter | $product |'; # Plugin correctly initialized TWiki::Func::writeDebug( "- TWiki::Plugins::${pluginName}::initPlugin( $web.$topic ) is OK" ) if $debug; @@ -292,12 +342,18 @@ { my ( $text ) = @_; my $anonymous = ""; - my $format = TWiki::Func::getPreferencesValue( "\U$pluginName\E_FORMAT" ) || "| \$bug_id | \$bug_severity | \$priority | \$bug_status | \$reporter | \$product |"; + my $format = $TWiki::cfg{Plugins}{BugzillaQueryPlugin}{format} || + $default_format; my $dataView = 0; + # %params is a hash with all the data from inside %BGQ{...}%. + # parameter1="value1" parameter2="value2" ... + # Ex. %BGQ{data="on" bug_status="ASSIGNED"}% + # Has the following parameters: + # $params{"bug_status"} == "ASSIGNED"; my %params; $anonymous = $1 if ( $text =~ s/^[\"\'](.*?)[\"\']// ); - $dataView = 1 if ( $text =~ s/data=[\"\']on[\"\']// ); + $dataView = 1 if ( $text =~ s/data=[\"\'][Oo][Nn][\"\']// ); $format = $1 if ( $text =~ s/format=[\"\'](.*?)[\"\']// ); while ( $text =~ s/\s*(.*?)\=[\"\'](.*?)[\"\']// ) { @@ -344,6 +400,10 @@ #&TWiki::Func::writeDebug( "ST = $statement" ); my $tmp = $db->prepare($statement); $tmp->execute(); + + + # Create and Return the Table + # Populate each row of the table using the $format as a template my $result = ""; while ( my $row = $tmp->fetchrow_hashref ) { my $s = $format; @@ -412,10 +472,14 @@ return $db; } +# This routine is for parsing multi-valued paramters such as: +# bug_id="12, 45 , 23" sub makeArray { my ( $str ) = @_; - $str =~ s/\s//g; + # Altered regex to allow whitespace in options: eg, "Foo Bar" shouldn't + # be returned as "FooBar". + $str =~ s/\s*,\s*/,/g; return split( /,/, $str ); }