-
Notifications
You must be signed in to change notification settings - Fork 8
/
BugzillaReport.php
219 lines (194 loc) · 6.6 KB
/
BugzillaReport.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
/**
* The bugzilla report objects
*/
/**
* Copyright (C) 2008 - Ian Homer & bemoko
*
* 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.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see <http://www.gnu.org/licenses>.
*/
#
# flag to record whether the head has been included already so that
# we only include it once
#
$bzHeadIncluded=false;
class BugzillaReport extends BMWExtension {
# The handle on the query object
var $query;
# Default max rows for a report
var $maxrowsFromConfig;
var $maxrowsFromConfigDefault=100;
var $dbdriverDefault="mysql";
# Default max rows which are used for aggregation of a bar chart report
var $maxrowsForBarChartFromConfig;
var $maxrowsForBarChartFromConfigDefault=500;
# Output raw HTML (i.e. not Wiki output)
var $rawHTML;
public $dbuser,$bzserver,$interwiki;
public $database,$host,$password;
public $dbdriver;
public $dbencoding;
public $instanceNameSpace;
function BugzillaReport( &$parser ) {
$this->parser =& $parser;
}
public function render($args) {
global $wgBugzillaReports;
global $bzScriptPath;
global $wgDBserver,$wgDBname,$wgDBuser,$wgDBpassword;
global $bzHeadIncluded;
# Initialise query
$this->dbdriver=$this->getProperty("dbdriver",$this->dbdriverDefault);
$connector;
switch ($this->dbdriver) {
case "pg" :
$connector=new BPGConnector($this);
break;
default :
$connector=new BMysqlConnector($this);
}
$this->query=new BugzillaQuery($connector);
#
# Process arguments from default setting across all the wiki
#
$this->extractOptions(explode("|",$this->getProperty("default")));
#
# Process arguments for this particular query
#
$this->extractOptions($args);
if (!$bzHeadIncluded) {
$bzHeadIncluded=true;
$this->parser->mOutput->addHeadItem('<link rel="stylesheet" type="text/css" media="screen, projection" href="' . $bzScriptPath . '/skins/bz_main.css" />');
$this->parser->mOutput->addHeadItem('<script type="text/javascript" src="' . $bzScriptPath . '/scripts/jquery-1.2.6.min.js" ></script>');
$script=<<< EOH
<script type= "text/javascript">
$(document).ready(function(){
$("div.bz_comment").hide();
$("tr.bz_bug").hover(
function () {
$(this).find("td div.bz_comment").show();
},
function () {
$(this).find("td div.bz_comment").hide();
}
)
});
</script>
EOH;
$this->parser->mOutput->addHeadItem($script);
}
if ($this->query->get("instance") != null) {
$this->instanceNameSpace=$this->query->get("instance");
}
#
# Allow the user to specify alternate DB connection info by name
# in his query.
#
if ($this->query->get("bzalternateconfig") != null) {
#
# The user has asked for an alternate BZ install to be queried.
#
$alternateConfigName = $this->query->get("bzalternateconfig");
$bzAlternateConfigs = $this->getProperty("bzAlternateConfigs");
if (is_array($bzAlternateConfigs["$alternateConfigName"])) {
#
# We appear to have an array...set values.
#
$this->dbuser=$bzAlternateConfigs["$alternateConfigName"]["user"];
$this->bzserver=$bzAlternateConfigs["$alternateConfigName"]["bzserver"];
$this->database=$bzAlternateConfigs["$alternateConfigName"]["database"];
$this->host=$bzAlternateConfigs["$alternateConfigName"]["host"];
$this->password=$bzAlternateConfigs["$alternateConfigName"]["password"];
}
} else {
#
# Use the defaults from LocalConfig
#
$this->dbuser=$this->getProperty("user",$wgDBuser);
$this->bzserver=$this->getProperty("bzserver", null);
$this->database=$this->getProperty("database");
$this->host=$this->getProperty("host");
$this->password=$this->getProperty("password");
}
$this->interwiki=$this->getProperty("interwiki", null);
$this->dbencoding=$this->getProperty("dbencoding", "utf8");
$this->maxrowsFromConfig=
$this->getProperty("maxrows",$this->maxrowsFromConfigDefault);
$this->maxrowsForBarChartFromConfig=
$this->getProperty("maxrowsbar",
$this->maxrowsForBarChartFromConfigDefault);
if ($this->query->get("disablecache") != null) {
#
# Extension parameter take priority on disable cache configuration
#
if ($this->query->get("disablecache") == "1") {
$this->disableCache();
}
} elseif ($this->getProperty("disablecache")=="1") {
#
# ... then it's the LocalSettings property
#
$this->disableCache();
}
$this->debug && $this->debug("Rendering BugzillaReport");
return $this->query->render().$this->getWarnings();
}
protected function disableCache() {
$this->debug && $this->debug("Disabling parser cache for this page");
$this->parser->disableCache();
}
#
# Set value - implementation of the abstract function from BMWExtension
#
protected function set($name,$value) {
# debug variable is store on this object
if ($name=="debug") {
$this->$name=$value;
} else {
$this->query->set($name,$value);
}
}
protected function getParameterRegex($name) {
if ($name=="debug") {
return "/^[12]$/";
} else {
return $this->query->getParameterRegex($name);
}
}
function getProperty($name,$default="") {
global $wgBugzillaReports;
$value;
if ($this->instanceNameSpace != null &&
array_key_exists($this->instanceNameSpace.":".$name,$wgBugzillaReports)) {
$value=$wgBugzillaReports[$this->instanceNameSpace.":".$name];
} elseif (array_key_exists($name,$wgBugzillaReports)) {
$value=$wgBugzillaReports[$name];
} else {
$value=$default;
}
$this->debug &&
$this->debug("Env property $name=$value");
return $value;
}
public function getErrorMessage($key) {
$args = func_get_args();
array_shift( $args );
return '<strong class="error">BugzillaReports : '.
wfMsgForContent($key,$args).'</strong>';
}
public function setRawHTML($bool) {
$this->rawHTML=$bool;
}
}
?>