Permalink
Browse files

Merge pull request #7 from LegNeato/master

Several bugfixes from contributor LegNeato
  • Loading branch information...
2 parents ab4852f + bc55a7f commit 577896384a21e889687a4c6a343b4e2897a118b9 @brandonsavage brandonsavage committed May 30, 2012
View
@@ -1 +1 @@
-*.swp
+*.sw*
View
@@ -74,12 +74,14 @@ function BugzillaCreateCache( $updater ) {
function BugzillaIncludeHTML( &$out, &$sk ) {
global $wgScriptPath;
+ global $wgBugzillaJqueryTable;
- // Use local jquery
- $out->addScriptFile("$wgScriptPath/extensions/Bugzilla/web/jquery/1.6.2/jquery.min.js");
+ if( $wgBugzillaJqueryTable ) {
+ // Use local jquery
+ $out->addScriptFile("$wgScriptPath/extensions/Bugzilla/web/jquery/1.6.2/jquery.min.js");
- // Use local jquery ui
- $out->addScriptFile("$wgScriptPath/extensions/Bugzilla/web/jqueryui/1.8.14/jquery-ui.min.js");
+ // Use local jquery ui
+ $out->addScriptFile("$wgScriptPath/extensions/Bugzilla/web/jqueryui/1.8.14/jquery-ui.min.js");
// Add a local script file for the datatable
$out->addScriptFile("$wgScriptPath/extensions/Bugzilla/web/js/jquery.dataTables.js");
@@ -96,9 +98,18 @@ function BugzillaIncludeHTML( &$out, &$sk ) {
// Add the script to do table magic
$out->addInlineScript('$(document).ready(function() {
- $(".bugzilla").dataTable({
+ $("table.bugzilla").dataTable({
"bJQueryUI": true
})});');
+ }
+
+ // Add local bugzilla extension styles
+ $out->addStyle("$wgScriptPath/extensions/Bugzilla/web/css/bugzilla.css");
+
+ // Let the user optionally override bugzilla extension styles
+ if( file_exists("$wgScriptPath/extensions/Bugzilla/web/css/custom.css") ) {
+ $out->addStyle("$wgScriptPath/extensions/Bugzilla/web/css/custom.css");
+ }
// Let the other hooks keep processing
return TRUE;
@@ -116,13 +127,21 @@ function BugzillaParserInit( Parser &$parser ) {
}
// Function to be called when our tag is found by the parser
-function BugzillaRender($input, array $args, Parser $parser, $frame ) {
+function BugzillaRender($input, array $args, Parser $parser, $frame=null ) {
global $wgBugzillaRESTURL;
// We don't want the page to be cached
// TODO: Not sure if we need this
$parser->disableCache();
+
+ // TODO: Figure out to have the parser not do anything to our output
+ // mediawiki docs are wrong :-(
+ // error_log(print_r($parser->mStripState, true));
+ // $parser->mStripState->addItem( 'nowiki', 'NOWIKI', true);
+ // 'noparse' => true, 'isHTML' => true, 'markerType' => 'nowiki' );
+
$input = $parser->recursiveTagParse($input, $frame);
+
// Create a new bugzilla object
$bz = Bugzilla::create($args, $input, $parser->getTitle());
@@ -138,13 +157,19 @@ function BugzillaRender($input, array $args, Parser $parser, $frame ) {
$wgBugzillaRESTURL = 'https://api-dev.bugzilla.mozilla.org/latest';
$wgBugzillaURL = 'https://bugzilla.mozilla.org';
$wgBugzillaTagName = 'bugzilla';
-$wgBugzillaMethod = 'REST'; // XML-RPC and JSON-RPC may be supported later
-$wgBugzillaUseCache = TRUE;
-$wgBugzillaCacheMins = 5;
-$wgBugzillaJqueryTable = FALSE;
+$wgBugzillaMethod = 'REST'; // XML-RPC and JSON-RPC aren't supported yet
+$wgBugzillaDefaultFields = array(
+ 'id',
+ 'summary',
+ 'priority',
+ 'status',
+);
+$wgBugzillaJqueryTable = TRUE;
// Cache settings
-$wgCacheObject = 'BugzillaCacheMysql';
+$wgBugzillaUseCache = TRUE;
+$wgCacheObject = 'BugzillaCacheMysql';
+$wgBugzillaCacheMins = 5;
$wgBugzillaChartStorage = realpath($cwd . '/charts');
$wgBugzillaFontStorage = $cwd . '/pchart/fonts';
View
@@ -6,40 +6,49 @@
public $cache;
public function __construct($config, $options, $title='') {
- $this->title = $title;
- $this->config = $config;
+ $this->title = $title;
+ $this->config = $config;
+ $this->error = FALSE;
$this->response = new stdClass();
// Make our query and possibly fetch the data
$this->query = BugzillaQuery::create($config['type'], $options, $title);
-
- //error_log($this->query);
- //error_log($this->query->id());
- //error_log(print_r($this->query->data, true));
-
+ // Bubble up any query errors
+ if( $this->query->error ) {
+ $this->error = $this->query->error;
+ }
}
- protected function _render_error() {
- $what = (!empty($this->error)) ? $this->error : 'Unknown Error';
- return "<div class='bugzilla error'>Bugzilla Error: $what</div>";
+ protected function _render_error($error) {
+ $this->template = dirname(__FILE__) . '/templates/error.tpl';
+ ob_start(); // Start output buffering.
+ require($this->template);
+ return ob_get_clean();
}
public function render() {
- global $wgBugzillaURL;
// Get our template path
$this->template = dirname(__FILE__) . '/templates/' .
$this->config['type'] . '/' .
$this->config['display'] . '.tpl';
- //error_log($this->template);
-
// Make sure a template is there
if( !file_exists($this->template) ) {
- $this->error = 'Invalid type and display combination';
+ $this->error = 'Invalid type ' .
+ '(' . htmlspecialchars($this->config['type']) . ')' .
+ ' and display ' .
+ '(' . htmlspecialchars($this->config['display']) . ')' .
+ ' combination';
+ }
+
+ // If there are any errors (either from the template path above or
+ // elsewhere) output them
+ if( $this->error ) {
+ return $this->_render_error($this->error);
}
- $this->_setup_template_data();
+ $this->setup_template_data();
$response = $this->response;
ob_start(); // Start output buffering.
@@ -58,46 +67,185 @@ protected function _getCache()
return $this->cache;
}
-
- abstract public function _setup_template_data();
+
+ abstract protected function setup_template_data();
}
-class BugzillaTable extends BugzillaOutput {
+class BugzillaBugListing extends BugzillaOutput {
+
+ protected function setup_template_data() {
- public function _setup_template_data() {
- if(count($this->query->data->bugs) > 0) {
- $this->response->bugs = $this->query->data->bugs;
- } else {
- $this->response->bugs = array();
+ global $wgBugzillaDefaultFields;
+
+ $this->response->bugs = array();
+ $this->response->fields = array();
+
+ // Set the bug data for the templates
+ if(count($this->query->data['bugs']) > 0) {
+ $this->response->bugs = $this->query->data['bugs'];
+ }
+
+ // Set the field data for the templates
+ if( isset($this->query->options['include_fields']) &&
+ !empty($this->query->options['include_fields']) ) {
+ // User specified some fields
+ $tmp = @explode(',', $this->query->options['include_fields']);
+ foreach( $tmp as $tmp_field ) {
+ $field = trim($tmp_field);
+ // Catch if the user specified the same field multiple times
+ if( !empty($field) &&
+ !in_array($field, $this->response->fields) ) {
+ array_push($this->response->fields, $field);
+ }
+ }
+ }else {
+ // If the user didn't specify any fields in the query config use
+ // default fields
+ $this->response->fields = $wgBugzillaDefaultFields;
}
}
+
+}
+
+class BugzillaList extends BugzillaBugListing {
+
}
+class BugzillaTable extends BugzillaBugListing {
+
+}
+
+
+/* Graphing */
+
abstract class BugzillaGraph extends BugzillaOutput {
+ protected function _get_size() {
+
+ switch($this->config['size']) {
+
+ // whitelist
+ case 'small':
+ case 'medium':
+ case 'large':
+ return $this->config['size'];
+ break;
+
+ default:
+ return 'large';
+ }
+ }
+
+ public function setup_template_data() {
+ include_once 'pchart/class/pDraw.class.php';
+ include_once 'pchart/class/pImage.class.php';
+ include_once 'pchart/class/pData.class.php';
+
+ global $wgBugzillaChartUrl;
+
+ $key = md5($this->query->id . $this->_get_size() . get_class($this));
+ $cache = $this->_getCache();
+ if($result = $cache->get($key)) {
+ $image = $result['data'];
+ $this->response->image = $wgBugzillaChartUrl . '/' . $image;
+ } else {
+ $this->response->image = $wgBugzillaChartUrl . '/' . $this->generate_chart($key) . '.png';
+ }
+ }
+
}
-include 'pchart/class/pDraw.class.php';
-include 'pchart/class/pImage.class.php';
-include 'pchart/class/pData.class.php';
+class BugzillaPieGraph extends BugzillaGraph {
+
+ public function generate_chart($chart_name)
+ {
+ include_once "pchart/class/pPie.class.php";
+
+ global $wgBugzillaChartStorage;
+ global $wgBugzillaFontStorage;
+
+ // TODO: Make all this size stuff trivial for other
+ // graph types to plug into
+ switch($this->_get_size()) {
+ case 'small':
+ $imgX = 200;
+ $imgY = 65;
+ $radius = 30;
+ $font = 6;
+ break;
+
+ case 'medium':
+ $imgX = 400;
+ $imgY = 125;
+ $radius = 60;
+ $font = 7;
+ break;
+
+ case 'large':
+ default:
+ $imgX = 500;
+ $imgY = 245;
+ $radius = 120;
+ $font = 9;
+ }
+
+ $padding = 5;
+
+ $startX = ( isset($startX) ) ? $startX : $radius;
+ $startY = ( isset($startY) ) ? $startY : $radius;
+
+ $pData = new pData();
+ $pData->addPoints($this->query->data['data'], 'Counts');
+ $pData->setAxisName(0, 'Bugs');
+ $pData->addPoints($this->query->data['x_labels'], "Bugs");
+ $pData->setSerieDescription("Bugs", "Bugs");
+ $pData->setAbscissa("Bugs");
+
+ $pImage = new pImage($imgX, $imgY, $pData);
+ $pImage->setFontProperties(array('FontName' => $wgBugzillaFontStorage . '/verdana.ttf', 'FontSize' => $font));
+ $pPieChart = new pPie($pImage, $pData);
+
+ $pPieChart->draw2DPie($startX,
+ $startY,
+ array(
+ "Radius" => $radius,
+ "ValuePosition" => PIE_VALUE_INSIDE,
+ "WriteValues"=>PIE_VALUE_NATURAL,
+ "DrawLabels"=>FALSE,
+ "LabelStacked"=>TRUE,
+ "ValueR" => 0,
+ "ValueG" => 0,
+ "ValueB" => 0,
+ "Border"=>TRUE));
+
+ // Legend
+ $pImage->setShadow(FALSE);
+ $pPieChart->drawPieLegend(2*$radius + 2*$padding, $padding, array("Alpha"=>20));
+
+ $pImage->render($wgBugzillaChartStorage . '/' . $chart_name . '.png');
+ $cache = $this->_getCache();
+ $cache->set($chart_name, $chart_name . '.png');
+ return $chart_name;
+ }
+}
class BugzillaBarGraph extends BugzillaGraph {
public function generate_chart($chart_name)
{
global $wgBugzillaChartStorage, $wgBugzillaFontStorage;
$pData = new pData();
- $pData->addPoints($this->query->data->data, 'Counts');
+ $pData->addPoints($this->query->data['data'], 'Counts');
$pData->setAxisName(0, 'Bugs');
- $pData->addPoints($this->query->data->x_labels, "Bugs");
+ $pData->addPoints($this->query->data['x_labels'], "Bugs");
$pData->setSerieDescription("Bugs", "Bugs");
$pData->setAbscissa("Bugs");
$pImage = new pImage(600,300, $pData);
$pImage->setFontProperties(array('FontName' => $wgBugzillaFontStorage . '/verdana.ttf', 'FontSize' => 6));
$pImage->setGraphArea(75, 30, 580, 280);
- $pImage->drawScale(array("CycleBackground"=>TRUE,"DrawSubTicks"=>FALSE,"GridR"=>0,"GridG"=>0,"GridB"=>0,"GridAlpha"=>10, "Pos"=>SCALE_POS_TOPBOTTOM));
+ $pImage->drawScale(array("CycleBackground"=>TRUE,'Factors'=>array(1),"DrawSubTicks"=>FALSE,"GridR"=>0,"GridG"=>0,"GridB"=>0,"GridAlpha"=>10, "Pos"=>SCALE_POS_TOPBOTTOM));
$pImage->drawBarChart();
$pImage->render($wgBugzillaChartStorage . '/' . $chart_name . '.png');
@@ -106,17 +254,6 @@ public function generate_chart($chart_name)
return $chart_name;
}
- public function _setup_template_data() {
- global $wgBugzillaChartUrl;
- $key = md5($this->query->id . '_bar_chart');
- $cache = $this->_getCache();
- if($result = $cache->get($key)) {
- $image = $result['data'];
- $this->response->image = $wgBugzillaChartUrl . '/' . $image;
- } else {
- $this->response->image = $wgBugzillaChartUrl . '/' . $this->generate_chart($key) . '.png';
- }
- }
}
?>
Oops, something went wrong.

0 comments on commit 5778963

Please sign in to comment.