diff --git a/Bugzilla.php b/Bugzilla.php index a7190ae..b528fc3 100755 --- a/Bugzilla.php +++ b/Bugzilla.php @@ -19,6 +19,7 @@ */ $wgBugzillaExtVersion = '1.0.0'; +$wgBugzillaQueryDefaults = [ 'ssl_verify_peer' => false ]; $wgExtensionCredits['other'][] = array( 'name' => 'Bugzilla', diff --git a/BugzillaOutput.class.php b/BugzillaOutput.class.php index 65f493e..819fd67 100644 --- a/BugzillaOutput.class.php +++ b/BugzillaOutput.class.php @@ -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']; } @@ -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'; @@ -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; @@ -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'); diff --git a/BugzillaQuery.class.php b/BugzillaQuery.class.php index 3a3ef9d..1b92f07 100644 --- a/BugzillaQuery.class.php +++ b/BugzillaQuery.class.php @@ -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. @@ -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; @@ -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'); @@ -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) { @@ -307,18 +319,14 @@ protected function getJsonData($method, $params) $query = json_encode($params, true); $url = $this->url."?method=$method¶ms=[".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; @@ -363,12 +371,7 @@ public function _fetch_by_options() { 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'); @@ -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) { diff --git a/templates/bug/list.tpl b/templates/bug/list.tpl index 2651f8a..37e0e36 100644 --- a/templates/bug/list.tpl +++ b/templates/bug/list.tpl @@ -25,7 +25,10 @@ } // Print out the data - $data = $bug[$field]; + $data = null; + if ( isset( $bug[$field] ) ) { + $data = $bug[$field]; + } require($subtemplate); echo ""; diff --git a/templates/error.tpl b/templates/error.tpl index ffde693..2e89d15 100644 --- a/templates/error.tpl +++ b/templates/error.tpl @@ -2,6 +2,6 @@
- +