Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Bugzilla.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

$wgBugzillaExtVersion = '1.0.0';
$wgBugzillaQueryDefaults = [ 'ssl_verify_peer' => false ];

$wgExtensionCredits['other'][] = array(
'name' => 'Bugzilla',
Expand Down
31 changes: 17 additions & 14 deletions BugzillaOutput.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function setup_template_data() {
$this->response->full_query_url = $this->query->full_query_url();

// Set the bug data for the templates
if(isset($this->query->data['bugs']) && count($this->query->data['bugs']) > 0) {
if( !empty($this->query->data['bugs']) ) {
$this->response->bugs = $this->query->data['bugs'];
}

Expand Down Expand Up @@ -135,19 +135,16 @@ public function setup_template_data() {
include_once 'pchart/class/pData.class.php';

global $wgBugzillaChartUrl;
global $wgBugzillaCacheTimeOut;
global $wgMainCacheType;

$fileName = sha1(serialize([$this->query->id, $this->_get_size(), get_class($this)]));
$key = implode(':', ['mediawiki', 'bugzilla', 'chart', $fileName]);
$cache = wfGetCache($wgMainCacheType);

// We use the cache only to invalidate/recompute the charts:
// the key is its own value. Only the TTL is useful here.
if ($cache->get($key) === false) {
if ($this->generate_chart($fileName)) {
$cache->set($key, $fileName);
}

$key = md5($this->query->id . $this->_get_size() . get_class($this));
$cache = $this->_getCache();
if($result = $cache->get($key)) {
$image = $result;
$this->response->image = $wgBugzillaChartUrl . '/' . $image;
} elseif ( !empty( $this->query->data['data'] ) ) {
$this->response->image = $wgBugzillaChartUrl . '/' . $this->generate_chart($key) . '.png';
} else {
$this->response->image = "";
}

$this->response->image = $wgBugzillaChartUrl.'/'.$fileName.'.png';
Expand All @@ -159,6 +156,9 @@ class BugzillaPieGraph extends BugzillaGraph {

public function generate_chart($chart_name)
{
if ( empty( $this->query->data['data'] ) ) {
return "";
}
include_once "pchart/class/pPie.class.php";

global $wgBugzillaChartStorage;
Expand Down Expand Up @@ -233,6 +233,9 @@ class BugzillaBarGraph extends BugzillaGraph {
public function generate_chart($chart_name)
{
global $wgBugzillaChartStorage, $wgBugzillaFontStorage;
if ( empty( $this->query->data['data'] ) ) {
return "";
}
$pData = new pData();
$pData->addPoints($this->query->data['data'], 'Counts');
$pData->setAxisName(0, 'Bugs');
Expand Down
52 changes: 27 additions & 25 deletions BugzillaQuery.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ public function rebased_options()
return $options;
}

protected function getUA( $method, $url, $caller = __METHOD__ ) {
global $wgBugzillaQueryDefaults;
return MWHttpRequest::factory( $url,
array_merge( $wgBugzillaQueryDefaults, [
'method' => $method,
'follow_redirects' => true,
] ), $caller );
}

/**
* Wrap around sub-classes actual fetch action, with caching.
* Uses MediaWiki main cache strategy.
Expand All @@ -109,6 +118,16 @@ public function rebased_options()
*
* @return string
*/
protected function getUA( $method, $url, $caller = __METHOD__ ) {
global $wgBugzillaQueryDefaults;
return MWHttpRequest::factory( $url,
array_merge( $wgBugzillaQueryDefaults, [
'method' => $method,
'follow_redirects' => true,
] ), $caller );
}

// Connect and fetch the data
public function fetch() {

global $wgMainCacheType;
Expand Down Expand Up @@ -233,14 +252,8 @@ public function user_agent() {
public function _fetch_by_options() {

// Add the requested query options to the request
$ua = MWHttpRequest::factory( $this->url . '?'
. http_build_query( $this->options ),
[
'method' => 'GET',
'follow_redirects' => true,
// TODO: Not sure if I should do this
'ssl_verify_peer' => false
], __METHOD__ );
$ua = $this->getUA( 'GET', $this->url . '?' . http_build_query( $this->options ),
__METHOD__ );

// The REST API requires these
$ua->setHeader('Accept', 'application/json');
Expand All @@ -251,8 +264,7 @@ public function _fetch_by_options() {
if (200 == $ua->getStatus()) {
$this->data = json_decode($ua->getContent(), TRUE);
} else {
$errors = $response->getStatusValue()->getErrors();
$this->error = $errors[0];
$this->error = $response->getWikiText();
return;
}
} catch (MWException $e) {
Expand Down Expand Up @@ -307,18 +319,14 @@ protected function getJsonData($method, $params)
$query = json_encode($params, true);
$url = $this->url."?method=$method&params=[".urlencode($query)."]";

$req = MWHttpRequest::factory($url, array(
'sslVerifyHost' => false,
'sslVerifyCert' => false
)
);
$status = $req->execute();
$ua = $this->getUA( 'GET', $url, __METHOD__ );
$status = $ua->execute();

if(!$status->isOK()) {
$this->error = $res->getMessage();
return false;
} else {
$this->rawData = $req->getContent();
$this->rawData = $ua->getContent();
$params = json_decode($this->rawData, true);
$this->data = $params['result'];
return true;
Expand Down Expand Up @@ -363,12 +371,7 @@ public function _fetch_by_options() {
</methodCall>
X;

$ua = MWHttpRequest::factory( $this->url, [
'method' => 'POST',
'follow_redirects' => true,
// TODO: Not sure if I should do this
'ssl_verify_peer' => false
], __METHOD__ );
$ua = $this->getUA( 'POST', $this->url, __METHOD__ );

$ua->setHeader('Accept', 'text/xml');
$ua->setHeader('Content-Type', 'text/xml;charset=utf-8');
Expand All @@ -395,8 +398,7 @@ public function _fetch_by_options() {
$this->data['bugs'][] = $bug;
}
} else {
$errors = $response->getStatusValue()->getErrors();
$this->error = $errors[0];
$this->error = $response->getWikiText();
return;
}
} catch (MWException $e) {
Expand Down
5 changes: 4 additions & 1 deletion templates/bug/list.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
}

// Print out the data
$data = $bug[$field];
$data = null;
if ( isset( $bug[$field] ) ) {
$data = $bug[$field];
}
require($subtemplate);

echo "</span>";
Expand Down
2 changes: 1 addition & 1 deletion templates/error.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<div class="bugzilla errorbox">
<h2>Bugzilla query error</h2>
<p>
<?php echo implode(", ", $error); ?>
<?php echo $error; ?>
</p>
</div>