
nimishg at svn
Nov 23, 2009, 5:06 PM
Post #1 of 1
(90 views)
Permalink
|
|
SVN: [59374] trunk/extensions/UsabilityInitiative/ClickTracking
|
|
http://www.mediawiki.org/wiki/Special:Code/MediaWiki/59374 Revision: 59374 Author: nimishg Date: 2009-11-24 01:06:56 +0000 (Tue, 24 Nov 2009) Log Message: ----------- Formatting changes using stylize Modified Paths: -------------- trunk/extensions/UsabilityInitiative/ClickTracking/ApiClickTracking.php trunk/extensions/UsabilityInitiative/ClickTracking/ApiSpecialClickTracking.php trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.hooks.php trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.php Modified: trunk/extensions/UsabilityInitiative/ClickTracking/ApiClickTracking.php =================================================================== --- trunk/extensions/UsabilityInitiative/ClickTracking/ApiClickTracking.php 2009-11-24 01:05:08 UTC (rev 59373) +++ trunk/extensions/UsabilityInitiative/ClickTracking/ApiClickTracking.php 2009-11-24 01:06:56 UTC (rev 59374) @@ -41,9 +41,9 @@ $wgTitle->getNamespace(), // what namespace are they editing? $event_id, // event ID passed in ( $is_logged_in ? $wgUser->getEditCount() : 0 ), // total edit count or 0 if anonymous - $granularity1, //contributions made in granularity 1 time frame - $granularity2, //contributions made in granularity 2 time frame - $granularity3 //contributions made in granularity 3 time frame + $granularity1, // contributions made in granularity 1 time frame + $granularity2, // contributions made in granularity 2 time frame + $granularity3 // contributions made in granularity 3 time frame ); // For links that go off the page, redirect the user @@ -62,7 +62,7 @@ */ protected function validateParams( $params ) { $required = array( 'eventid', 'token' ); - foreach( $required as $arg ) { + foreach ( $required as $arg ) { if ( !isset( $params[$arg] ) ) { $this->dieUsageMsg( array( 'missingparam', $arg ) ); } Modified: trunk/extensions/UsabilityInitiative/ClickTracking/ApiSpecialClickTracking.php =================================================================== --- trunk/extensions/UsabilityInitiative/ClickTracking/ApiSpecialClickTracking.php 2009-11-24 01:05:08 UTC (rev 59373) +++ trunk/extensions/UsabilityInitiative/ClickTracking/ApiSpecialClickTracking.php 2009-11-24 01:06:56 UTC (rev 59374) @@ -23,17 +23,17 @@ $userDefString = $params['userdefs']; // this is if it's asking for tableData - if( isset( $params['tabledata'] ) ) { + if ( isset( $params['tabledata'] ) ) { $tableData = SpecialClickTracking::buildRowArray( $startdate, $enddate, $userDefString ); $this->getResult()->addValue( array( 'tablevals' ), 'vals', $tableData ); - } else{ //chart data + } else { // chart data $click_data = array(); try { $click_data = SpecialClickTracking::getChartData( $event_id, $startdate, $enddate, $increment, $userDefString ); $this->getResult()->addValue( array( 'datapoints' ), 'expert', $click_data['expert'] ); $this->getResult()->addValue( array( 'datapoints' ), 'basic', $click_data['basic'] ); $this->getResult()->addValue( array( 'datapoints' ), 'intermediate', $click_data['intermediate'] ); - } catch( Exception $e ) { /* no result */ } + } catch ( Exception $e ) { /* no result */ } } } @@ -42,32 +42,32 @@ * @param $params params extracted from the POST */ protected function validateParams( $params ) { - $required = array( 'eventid', 'startdate', 'enddate', 'increment', 'userdefs'); - foreach( $required as $arg ) { + $required = array( 'eventid', 'startdate', 'enddate', 'increment', 'userdefs' ); + foreach ( $required as $arg ) { if ( !isset( $params[$arg] ) ) { $this->dieUsageMsg( array( 'missingparam', $arg ) ); } } // check if event id parses to an int greater than zero - if( (int) $params['eventid'] < 0 ) { + if ( (int) $params['eventid'] < 0 ) { $this->dieUsage( 'Invalid event ID', 'badeventid' ); } // check start and end date are of proper format - if( $params['startdate'] != 0 && strptime( SpecialClickTracking::space_out_date( $params['startdate'] ), "%Y %m %d" ) === false ) { + if ( $params['startdate'] != 0 && strptime( SpecialClickTracking::space_out_date( $params['startdate'] ), "%Y %m %d" ) === false ) { $this->dieUsage( "startdate not in YYYYMMDD format: <<{$params['startdate']}>>", 'badstartdate' ); } - if( $params['enddate'] != 0 && strptime( SpecialClickTracking::space_out_date( $params['enddate'] ), "%Y %m %d" ) === false ) { + if ( $params['enddate'] != 0 && strptime( SpecialClickTracking::space_out_date( $params['enddate'] ), "%Y %m %d" ) === false ) { $this->dieUsage( "enddate not in YYYYMMDD format:<<{$params['enddate']}>>", 'badenddate' ); } // check if increment is a positive int - if( (int) $params['increment'] <= 0 ) { + if ( (int) $params['increment'] <= 0 ) { $this->dieUsage( 'Invalid increment', 'badincrement' ); } - if( json_decode( $params['userdefs'] ) == null ) { + if ( json_decode( $params['userdefs'] ) == null ) { $this->dieUsage( "Invalid JSON encoding <<{$params['userdefs']}>>", 'badjson' ); } } @@ -78,7 +78,7 @@ return array( 'eventid' => 'event ID (number)', 'startdate' => 'start date for data in YYYYMMDD format', - 'enddate' =>'end date for the data in YYYYMMDD format', + 'enddate' => 'end date for the data in YYYYMMDD format', 'increment' => 'increment interval (in days) for data points', 'userdefs' => 'JSON object to encode user definitions', 'tabledata' => 'set to 1 for table data instead of chart data' @@ -106,7 +106,7 @@ 'increment' => array( ApiBase::PARAM_TYPE => 'integer', ApiBase::PARAM_MIN => 1, - ApiBase::PARAM_MAX => 365 //1 year + ApiBase::PARAM_MAX => 365 // 1 year ), 'userdefs' => array( ApiBase::PARAM_TYPE => 'string' Modified: trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.hooks.php =================================================================== --- trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.hooks.php 2009-11-24 01:05:08 UTC (rev 59373) +++ trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.hooks.php 2009-11-24 01:06:56 UTC (rev 59374) @@ -99,7 +99,7 @@ 'SUM(contribs)', array( 'user_id' => $wgUser->getId(), - "day >= " . $dbr->addQuotes($time) + "day >= " . $dbr->addQuotes( $time ) ), __METHOD__ ); @@ -133,7 +133,7 @@ // this will be incredibly rare as the whole database will only have a few hundred entries in it at most // and getting DB_MASTER up top would be wasteful // FIXME: Use replace() instead of this selectField --> insert or update logic - if( $id_num === false ) { + if ( $id_num === false ) { $dbw->insert( 'click_tracking_events', array( 'event_name' => (string) $event_name ), @@ -142,7 +142,7 @@ $id_num = $dbw->insertId(); } - if( $id_num === false ){ + if ( $id_num === false ) { return 0; } Modified: trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.php =================================================================== --- trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.php 2009-11-24 01:05:08 UTC (rev 59373) +++ trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.php 2009-11-24 01:06:56 UTC (rev 59374) @@ -8,14 +8,14 @@ class SpecialClickTracking extends SpecialPage { - private static $minimum_date = '20091009'; //YYYYMMDD (+1 for today) - - private static $userTypes = array("basic" => 0, "intermediate" => 1, "expert" => 2); + private static $minimum_date = '20091009'; // YYYYMMDD (+1 for today) + + private static $userTypes = array( "basic" => 0, "intermediate" => 1, "expert" => 2 ); private $user_defs = array(); function __construct() { - parent::__construct( 'ClickTracking' , 'clicktrack'); + parent::__construct( 'ClickTracking' , 'clicktrack' ); wfLoadExtensionMessages( 'ClickTracking' ); UsabilityInitiativeHooks::initialize(); UsabilityInitiativeHooks::addStyle( 'ClickTracking/SpecialClickTracking.css' ); @@ -23,26 +23,26 @@ } - function setDefaults(){ + function setDefaults() { $this->user_defs["basic"] = array( "anonymous" => "1", "total_contribs" => array( - array("operation" => "<=", "value" => "10"), + array( "operation" => "<=", "value" => "10" ), ), ); $this->user_defs["intermediate"] = array( "anonymous" => "0", "total_contribs" => array( - array("operation" => "<", "value" => "400"), - array("operation" => ">", "value" => "10"), + array( "operation" => "<", "value" => "400" ), + array( "operation" => ">", "value" => "10" ), ), ); $this->user_defs["expert"] = array( "anonymous" => "0", "total_contribs" => array( - array("operation" => ">=", "value" => "400"), + array( "operation" => ">=", "value" => "400" ), ), ); @@ -64,24 +64,24 @@ $this->setHeaders(); $this->setDefaults(); - $wgOut->addScript('<script type="text/javascript">'. "var wgClickTrackUserDefs = ".json_encode($this->user_defs). '</script>'); + $wgOut->addScript( '<script type="text/javascript">' . "var wgClickTrackUserDefs = " . json_encode( $this->user_defs ) . '</script>' ); $wgOut->setPageTitle( wfMsg( 'ct-title' ) ); - $outputTable =""; + $outputTable = ""; - //grab top N + // grab top N $events = $this->getTopEvents(); - //open table - $outputTable .= Xml::openElement( "table", array( "class" =>"sortable click-data", "id" => "clicktrack_data_table" ) ); + // open table + $outputTable .= Xml::openElement( "table", array( "class" => "sortable click-data", "id" => "clicktrack_data_table" ) ); - //create a row for every event + // create a row for every event $i = 0; $db_result; - //build row headers + // build row headers $header_row = array(); $header_row["event_header"] = wfMsg( 'ct-event-name' ); @@ -89,30 +89,30 @@ $header_row["intermediate_header"] = wfMsg( 'ct-intermediate-header' ); $header_row["basic_header"] = wfMsg( 'ct-beginner-header' ); $header_row["total_header"] = wfMsg( 'ct-total-header' ); - $outputTable .= Xml::buildTableRow( array( "class"=>"table_headers" ), $header_row ); + $outputTable .= Xml::buildTableRow( array( "class" => "table_headers" ), $header_row ); - //foreach event, build a row - while(($db_result = $events->fetchRow()) != null){ + // foreach event, build a row + while ( ( $db_result = $events->fetchRow() ) != null ) { ++$i; - $outputTable .= $this->buildRow( $db_result, $i, $this->user_defs); + $outputTable .= $this->buildRow( $db_result, $i, $this->user_defs ); } - //close table - $outputTable .= Xml::closeElement("table"); + // close table + $outputTable .= Xml::closeElement( "table" ); $wgOut->addHTML( $outputTable ); - $wgOut->addHTML($this->buildDateRange()); + $wgOut->addHTML( $this->buildDateRange() ); - //build chart - $wgOut->addHTML($this->buildChart("advanced.hide",10, "20090815", "20090902", 1)); + // build chart + $wgOut->addHTML( $this->buildChart( "advanced.hide", 10, "20090815", "20090902", 1 ) ); - //$wgOut->addHTML($this->buildControlBox()); + // $wgOut->addHTML($this->buildControlBox()); + + $wgOut->addHTML( $this->buildChartDialog() ); + $wgOut->addHTML( $this->buildUserDefBlankDialog() ); - $wgOut->addHTML($this->buildChartDialog()); - $wgOut->addHTML($this->buildUserDefBlankDialog()); - } @@ -126,27 +126,27 @@ * @param $isUserDefsJSON true if userDefs is JSON * @return array with chart info */ - static function getChartData($event_id, $minTime, $maxTime, $increment, $userDefs, $isUserDefsJSON=true){ - //get data - date_default_timezone_set('UTC'); + static function getChartData( $event_id, $minTime, $maxTime, $increment, $userDefs, $isUserDefsJSON = true ) { + // get data + date_default_timezone_set( 'UTC' ); - if($maxTime == 0){ - $maxTime = gmdate("Ymd",time()); //today + if ( $maxTime == 0 ) { + $maxTime = gmdate( "Ymd", time() ); // today } - if($minTime == 0){ + if ( $minTime == 0 ) { $minTime = self::$minimum_date; } - //FIXME: On PHP 5.3+, this will be MUCH cleaner + // FIXME: On PHP 5.3+, this will be MUCH cleaner $currBeginDate = new DateTime( $minTime ); $currEndDate = new DateTime( $minTime ); $endDate = new DateTime( $maxTime ); - //get user definitions - if($isUserDefsJSON){ - $userDefs = json_decode($userDefs, true); + // get user definitions + if ( $isUserDefsJSON ) { + $userDefs = json_decode( $userDefs, true ); } $basicUserData = array(); @@ -156,242 +156,242 @@ // PHP 5.3...hurry! $plural = ( $increment == 1 ? "" : "s" ); - while( $currEndDate->format( "U" ) < $endDate->format( "U" ) ){ + while ( $currEndDate->format( "U" ) < $endDate->format( "U" ) ) { $currEndDate->modify( "+$increment day$plural" ); - $minDate = $currBeginDate->format("Ymd"); - $maxDate = $currEndDate->format("Ymd"); + $minDate = $currBeginDate->format( "Ymd" ); + $maxDate = $currEndDate->format( "Ymd" ); $basicUserData[] = self::getTableValue( $event_id, $userDefs['basic'], $minDate, $maxDate ); $intermediateUserData[] = self::getTableValue( $event_id, $userDefs['intermediate'], $minDate, $maxDate ); $expertUserData[] = self::getTableValue( $event_id, $userDefs['expert'], $minDate, $maxDate ); $currBeginDate->modify( "+$increment day$plural" ); } - return array("expert" => $expertUserData, "basic" => $basicUserData, "intermediate" => $intermediateUserData); - } + return array( "expert" => $expertUserData, "basic" => $basicUserData, "intermediate" => $intermediateUserData ); + } - function buildChart($event_name, $event_id, $minTime, $maxTime, $increment){ - $chartData = self::getChartData($event_id, $minTime, $maxTime, $increment, $this->user_defs, false); - $chartSrc = $this->getGoogleChartParams( $event_id, $event_name, $minTime, $maxTime, $chartData["basic"], $chartData["intermediate"], $chartData["expert"]); + function buildChart( $event_name, $event_id, $minTime, $maxTime, $increment ) { + $chartData = self::getChartData( $event_id, $minTime, $maxTime, $increment, $this->user_defs, false ); + $chartSrc = $this->getGoogleChartParams( $event_id, $event_name, $minTime, $maxTime, $chartData["basic"], $chartData["intermediate"], $chartData["expert"] ); return Xml::element( 'img', array( 'src' => $chartSrc , 'id' => 'chart_img' ) ); } function getGoogleChartParams( $event_id, $event_name, $minDate, $maxDate, $basicUserData, $intermediateUserData, $expertUserData ) { - $max = max( max($basicUserData), max($intermediateUserData), max($expertUserData)); + $max = max( max( $basicUserData ), max( $intermediateUserData ), max( $expertUserData ) ); return "http://chart.apis.google.com/chart?" . wfArrayToCGI( array( - 'chs' => '400x400', + 'chs' => '400x400', 'cht' => 'lc', 'chco' => 'FF0000,0000FF,00FF00', 'chtt' => "$event_name from $minDate to $maxDate", 'chdl' => 'Expert|Intermediate|Beginner', 'chxt' => 'x,y', - 'chd' => 't:' . implode( "," , $expertUserData ) . "|" . + 'chd' => 't:' . implode( "," , $expertUserData ) . "|" . implode( "," , $intermediateUserData ) . "|" . implode( "," , $basicUserData ), 'chds' => "0,$max,0,$max,0,$max" - )); + ) ); } - function buildUserDefBlankDialog(){ + function buildUserDefBlankDialog() { $control = ""; - $control .= Xml::openElement("div", array("id" => "user_def_dialog", "class" => "dialog")); + $control .= Xml::openElement( "div", array( "id" => "user_def_dialog", "class" => "dialog" ) ); - //currently editing...----| - $control .= Xml::openElement("form", array("id" => "user_definition_form", "class" => "user_def_form")); - $control .= Xml::openElement("fieldset", array("id" => "user_def_alter_fieldset")); - $control .= Xml::openElement("legend", array("id" => "user_def_alter_legend")); + // currently editing...----| + $control .= Xml::openElement( "form", array( "id" => "user_definition_form", "class" => "user_def_form" ) ); + $control .= Xml::openElement( "fieldset", array( "id" => "user_def_alter_fieldset" ) ); + $control .= Xml::openElement( "legend", array( "id" => "user_def_alter_legend" ) ); $control .= wfMsg( "ct-editing" ); - $control .= Xml::closeElement("legend"); + $control .= Xml::closeElement( "legend" ); - //[] anonymous users? - $control .= Xml::openElement("div", array("id" => "anon_users_div", "class" => "checkbox_div control_div")); - $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "anon_users_checkbox", "class" => "user_def_checkbox")); - $control .= Xml::closeElement("input"); - $control .= wfMsg("ct-anon-users"); - $control .= Xml::closeElement("div"); + // [] anonymous users? + $control .= Xml::openElement( "div", array( "id" => "anon_users_div", "class" => "checkbox_div control_div" ) ); + $control .= Xml::openElement( "input", array( "type" => "checkbox", "id" => "anon_users_checkbox", "class" => "user_def_checkbox" ) ); + $control .= Xml::closeElement( "input" ); + $control .= wfMsg( "ct-anon-users" ); + $control .= Xml::closeElement( "div" ); // ---------------- - $control .= Xml::openElement("hr"); - $control .= Xml::closeElement("hr"); - $control .= Xml::openElement("div", array("id" => "contrib_opts_container")); + $control .= Xml::openElement( "hr" ); + $control .= Xml::closeElement( "hr" ); + $control .= Xml::openElement( "div", array( "id" => "contrib_opts_container" ) ); // [] users with contributions [>=V] [n ] - $control .= Xml::openElement("div", array("id" => "total_users_contrib_div", "class" => "checkbox_div control_div")); - $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "contrib_checkbox", "class" => "user_def_checkbox")); - $control .= Xml::closeElement("input"); - $control .= wfMsg("ct-user-contribs"); + $control .= Xml::openElement( "div", array( "id" => "total_users_contrib_div", "class" => "checkbox_div control_div" ) ); + $control .= Xml::openElement( "input", array( "type" => "checkbox", "id" => "contrib_checkbox", "class" => "user_def_checkbox" ) ); + $control .= Xml::closeElement( "input" ); + $control .= wfMsg( "ct-user-contribs" ); - $control .= Xml::closeElement("div"); + $control .= Xml::closeElement( "div" ); // [] contributions in timespan 1 - $control .= Xml::openElement("div", array("id" => "contrib_span_1_div", "class" => "checkbox_div control_div")); + $control .= Xml::openElement( "div", array( "id" => "contrib_span_1_div", "class" => "checkbox_div control_div" ) ); - $control .= Xml::openElement("div", array("id" => "contrib_span_1_text_div", "class" => "checkbox_div")); - $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "contrib_span_1_checkbox", "class" => "user_def_checkbox")); - $control .= Xml::closeElement("input"); - $control .= wfMsg("ct-user-span") . " 1"; - $control .= Xml::closeElement("div"); - $control .= Xml::closeElement("div"); + $control .= Xml::openElement( "div", array( "id" => "contrib_span_1_text_div", "class" => "checkbox_div" ) ); + $control .= Xml::openElement( "input", array( "type" => "checkbox", "id" => "contrib_span_1_checkbox", "class" => "user_def_checkbox" ) ); + $control .= Xml::closeElement( "input" ); + $control .= wfMsg( "ct-user-span" ) . " 1"; + $control .= Xml::closeElement( "div" ); + $control .= Xml::closeElement( "div" ); // [] contributions in timespan 2 - $control .= Xml::openElement("div", array("id" => "contrib_span_2_div", "class" => "checkbox_div control_div")); + $control .= Xml::openElement( "div", array( "id" => "contrib_span_2_div", "class" => "checkbox_div control_div" ) ); - $control .= Xml::openElement("div", array("id" => "contrib_span_2_text_div", "class" => "checkbox_div")); - $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "contrib_span_2_checkbox", "class" => "user_def_checkbox")); - $control .= Xml::closeElement("input"); - $control .= wfMsg("ct-user-span") . " 2"; - $control .= Xml::closeElement("div"); - $control .= Xml::closeElement("div"); + $control .= Xml::openElement( "div", array( "id" => "contrib_span_2_text_div", "class" => "checkbox_div" ) ); + $control .= Xml::openElement( "input", array( "type" => "checkbox", "id" => "contrib_span_2_checkbox", "class" => "user_def_checkbox" ) ); + $control .= Xml::closeElement( "input" ); + $control .= wfMsg( "ct-user-span" ) . " 2"; + $control .= Xml::closeElement( "div" ); + $control .= Xml::closeElement( "div" ); // [] contributions in timespan 3 - $control .= Xml::openElement("div", array("id" => "contrib_span_3_div", "class" => "checkbox_div control_div")); + $control .= Xml::openElement( "div", array( "id" => "contrib_span_3_div", "class" => "checkbox_div control_div" ) ); - $control .= Xml::openElement("div", array("id" => "contrib_span_3_text_div", "class" => "checkbox_div")); - $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "contrib_span_3_checkbox", "class" => "user_def_checkbox")); - $control .= Xml::closeElement("input"); - $control .= wfMsg("ct-user-span") . " 3"; - $control .= Xml::closeElement("div"); - $control .= Xml::closeElement("div"); + $control .= Xml::openElement( "div", array( "id" => "contrib_span_3_text_div", "class" => "checkbox_div" ) ); + $control .= Xml::openElement( "input", array( "type" => "checkbox", "id" => "contrib_span_3_checkbox", "class" => "user_def_checkbox" ) ); + $control .= Xml::closeElement( "input" ); + $control .= wfMsg( "ct-user-span" ) . " 3"; + $control .= Xml::closeElement( "div" ); + $control .= Xml::closeElement( "div" ); - $control .= Xml::closeElement("div");//close contrib opts - - $control .= Xml::closeElement("fieldset"); - $control .= Xml::closeElement("form"); - $control .= Xml::closeElement("div"); + $control .= Xml::closeElement( "div" );// close contrib opts + + $control .= Xml::closeElement( "fieldset" ); + $control .= Xml::closeElement( "form" ); + $control .= Xml::closeElement( "div" ); return $control; } - function buildUserDefNumberSelect($include_checkbox, $include_and, $ids){ + function buildUserDefNumberSelect( $include_checkbox, $include_and, $ids ) { $control = ""; - if($include_checkbox){ - $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "{$ids}_checkbox", "class" => "number_select_checkbox")); - $control .= Xml::closeElement("input"); + if ( $include_checkbox ) { + $control .= Xml::openElement( "input", array( "type" => "checkbox", "id" => "{$ids}_checkbox", "class" => "number_select_checkbox" ) ); + $control .= Xml::closeElement( "input" ); } - if($include_and){ - $control .= wfMsg("ct-and"); + if ( $include_and ) { + $control .= wfMsg( "ct-and" ); } - $control .= Xml::openElement("select", array("id" => "{$ids}_ltgt", "class" => "number_select_ltgt")); - $control .= Xml::openElement("option", array("id" => "{$ids}_lt", "class" => "number_select_ltgt_opt", "value" => "lt")); + $control .= Xml::openElement( "select", array( "id" => "{$ids}_ltgt", "class" => "number_select_ltgt" ) ); + $control .= Xml::openElement( "option", array( "id" => "{$ids}_lt", "class" => "number_select_ltgt_opt", "value" => "lt" ) ); $control .= "<="; - $control .= Xml::closeElement("option"); - $control .= Xml::openElement("option", array("id" => "{$ids}_gt", "class" => "number_select_ltgt_opt", "value" => "gt")); + $control .= Xml::closeElement( "option" ); + $control .= Xml::openElement( "option", array( "id" => "{$ids}_gt", "class" => "number_select_ltgt_opt", "value" => "gt" ) ); $control .= ">="; - $control .= Xml::closeElement("option"); - $control .= Xml::closeElement("select"); - $control .= Xml::openElement("input", array("type" => "text", "id" => "{$ids}_text", "class" => "number_select_text")); - $control .= Xml::closeElement("input"); + $control .= Xml::closeElement( "option" ); + $control .= Xml::closeElement( "select" ); + $control .= Xml::openElement( "input", array( "type" => "text", "id" => "{$ids}_text", "class" => "number_select_text" ) ); + $control .= Xml::closeElement( "input" ); return $control; } - function buildChartDialog(){ + function buildChartDialog() { $control = ""; - $control .= Xml::openElement("div", array("id" => "chart_dialog", "class" => "dialog")); + $control .= Xml::openElement( "div", array( "id" => "chart_dialog", "class" => "dialog" ) ); - $control .= Xml::openElement("form", array("id" => "chart_dialog_form", "class" => "chart_form")); - $control .= Xml::openElement("fieldset", array("id" => "chart_dialog_alter_fieldset")); - $control .= Xml::openElement("legend", array("id" => "chart_dialog_alter_legend")); + $control .= Xml::openElement( "form", array( "id" => "chart_dialog_form", "class" => "chart_form" ) ); + $control .= Xml::openElement( "fieldset", array( "id" => "chart_dialog_alter_fieldset" ) ); + $control .= Xml::openElement( "legend", array( "id" => "chart_dialog_alter_legend" ) ); $control .= wfMsg( "ct-increment-by" ); - $control .= Xml::closeElement("legend"); + $control .= Xml::closeElement( "legend" ); - $control .= Xml::openElement("table", array("id" => "chart_dialog_increment_table")); - $control .= Xml::openElement("tbody", array("id" => "chart_dialog_increment_tbody")); + $control .= Xml::openElement( "table", array( "id" => "chart_dialog_increment_table" ) ); + $control .= Xml::openElement( "tbody", array( "id" => "chart_dialog_increment_tbody" ) ); - $control .= Xml::openElement("tr", array("id" => "chart_dialog_increment_row")); + $control .= Xml::openElement( "tr", array( "id" => "chart_dialog_increment_row" ) ); - $control .= Xml::openElement("td", array("id" => "chart_dialog_increment_cell")); - $control .= Xml::openElement("input", array("type" => "text", "id" => "chart_increment", "class" => "chart_dialog_area", "value" => '1')); - $control .= Xml::closeElement("input"); - $control .= Xml::closeElement("td"); + $control .= Xml::openElement( "td", array( "id" => "chart_dialog_increment_cell" ) ); + $control .= Xml::openElement( "input", array( "type" => "text", "id" => "chart_increment", "class" => "chart_dialog_area", "value" => '1' ) ); + $control .= Xml::closeElement( "input" ); + $control .= Xml::closeElement( "td" ); - $control .= Xml::openElement("td", array("id" => "chart_dialog_button_cell")); - $control .= Xml::openElement("input", array("type" => "button", "id" => "change_graph", "value" => wfMsg( "ct-change-graph" ) ) ); - $control .= Xml::closeElement("input"); - $control .= Xml::closeElement("td"); + $control .= Xml::openElement( "td", array( "id" => "chart_dialog_button_cell" ) ); + $control .= Xml::openElement( "input", array( "type" => "button", "id" => "change_graph", "value" => wfMsg( "ct-change-graph" ) ) ); + $control .= Xml::closeElement( "input" ); + $control .= Xml::closeElement( "td" ); - $control .= Xml::closeElement("tr"); + $control .= Xml::closeElement( "tr" ); - $control .= Xml::closeElement("tbody"); - $control .= Xml::closeElement("table"); - $control .= Xml::closeElement("fieldset"); - $control .= Xml::closeElement("form"); - $control .= Xml::closeElement("div"); + $control .= Xml::closeElement( "tbody" ); + $control .= Xml::closeElement( "table" ); + $control .= Xml::closeElement( "fieldset" ); + $control .= Xml::closeElement( "form" ); + $control .= Xml::closeElement( "div" ); return $control; } - function buildDateRange(){ - $control = Xml::openElement("form", array("id" => "date_range")); + function buildDateRange() { + $control = Xml::openElement( "form", array( "id" => "date_range" ) ); - $control .= Xml::openElement("fieldset", array("id" => "date_range_fieldset")); - $control .= Xml::openElement("legend", array("id" => "date_range_legend")); - $control .= wfMsg('ct-date-range'); - $control .= Xml::closeElement("legend"); + $control .= Xml::openElement( "fieldset", array( "id" => "date_range_fieldset" ) ); + $control .= Xml::openElement( "legend", array( "id" => "date_range_legend" ) ); + $control .= wfMsg( 'ct-date-range' ); + $control .= Xml::closeElement( "legend" ); - $control .= Xml::openElement("table", array("id" => "date_range_table")); - $control .= Xml::openElement("tbody", array("id" => "date_range_tbody")); + $control .= Xml::openElement( "table", array( "id" => "date_range_table" ) ); + $control .= Xml::openElement( "tbody", array( "id" => "date_range_tbody" ) ); - $control .= Xml::openElement("tr", array("id" => "start_date_row")); + $control .= Xml::openElement( "tr", array( "id" => "start_date_row" ) ); - $control .= Xml::openElement("td", array("id" => "start_date_label", "class" => "date_range_label")); - $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "start_date_checkbox", "class" => "date_range_checkbox", "checked" => "")); - $control .= Xml::closeElement("input"); + $control .= Xml::openElement( "td", array( "id" => "start_date_label", "class" => "date_range_label" ) ); + $control .= Xml::openElement( "input", array( "type" => "checkbox", "id" => "start_date_checkbox", "class" => "date_range_checkbox", "checked" => "" ) ); + $control .= Xml::closeElement( "input" ); $control .= wfMsg( "ct-start-date" ); - $control .= Xml::closeElement("td"); + $control .= Xml::closeElement( "td" ); - $control .= Xml::openElement("td", array("id" => "start_date_textarea")); - $control .= Xml::openElement("input", array("type" => "text", "id" => "start_date", "class" => "date_range_input")); - $control .= Xml::closeElement("input"); - $control .= Xml::closeElement("td"); + $control .= Xml::openElement( "td", array( "id" => "start_date_textarea" ) ); + $control .= Xml::openElement( "input", array( "type" => "text", "id" => "start_date", "class" => "date_range_input" ) ); + $control .= Xml::closeElement( "input" ); + $control .= Xml::closeElement( "td" ); - $control .= Xml::closeElement("tr"); + $control .= Xml::closeElement( "tr" ); - $control .= Xml::openElement("tr", array("id" => "end_date_row")); + $control .= Xml::openElement( "tr", array( "id" => "end_date_row" ) ); - $control .= Xml::openElement("td", array("id" => "end_date_label", "class" => "date_range_label")); - $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "end_date_checkbox", "class" => "date_range_checkbox", "checked" => "")); - $control .= Xml::closeElement("input"); + $control .= Xml::openElement( "td", array( "id" => "end_date_label", "class" => "date_range_label" ) ); + $control .= Xml::openElement( "input", array( "type" => "checkbox", "id" => "end_date_checkbox", "class" => "date_range_checkbox", "checked" => "" ) ); + $control .= Xml::closeElement( "input" ); $control .= wfMsg( "ct-end-date" ); - $control .= Xml::closeElement("td"); + $control .= Xml::closeElement( "td" ); - $control .= Xml::openElement("td", array("id" => "end_date_textarea")); - $control .= Xml::openElement("input", array("type" => "text", "id" => "end_date", "class" => "date_range_input")); - $control .= Xml::closeElement("input"); - $control .= Xml::closeElement("td"); + $control .= Xml::openElement( "td", array( "id" => "end_date_textarea" ) ); + $control .= Xml::openElement( "input", array( "type" => "text", "id" => "end_date", "class" => "date_range_input" ) ); + $control .= Xml::closeElement( "input" ); + $control .= Xml::closeElement( "td" ); - $control .= Xml::closeElement("tr"); + $control .= Xml::closeElement( "tr" ); - $control .= Xml::openElement("tr", array("id" => "update_row")); + $control .= Xml::openElement( "tr", array( "id" => "update_row" ) ); - $control .= Xml::openElement("td"); - $control .= Xml::closeElement("td"); + $control .= Xml::openElement( "td" ); + $control .= Xml::closeElement( "td" ); - $control .= Xml::openElement("td", array("id" => "update_table_button_td")); - $control .= Xml::openElement("input", array("type" => "button", "id" => "update_table_button", "class" => "update_button", "value" =>wfMsg("ct-update-table"))); - $control .= Xml::closeElement("input"); - $control .= Xml::closeElement("td"); + $control .= Xml::openElement( "td", array( "id" => "update_table_button_td" ) ); + $control .= Xml::openElement( "input", array( "type" => "button", "id" => "update_table_button", "class" => "update_button", "value" => wfMsg( "ct-update-table" ) ) ); + $control .= Xml::closeElement( "input" ); + $control .= Xml::closeElement( "td" ); - $control .= Xml::closeElement("tr"); + $control .= Xml::closeElement( "tr" ); - $control .= Xml::closeElement("tbody"); - $control .= Xml::closeElement("table"); - $control .= Xml::closeElement("fieldset"); + $control .= Xml::closeElement( "tbody" ); + $control .= Xml::closeElement( "table" ); + $control .= Xml::closeElement( "fieldset" ); - $control .= Xml::closeElement("form"); + $control .= Xml::closeElement( "form" ); return $control; } @@ -405,31 +405,31 @@ * @param $is_JSON * @return unknown_type */ - public static function buildRowArray($minTime, $maxTime, $userDefs, $is_JSON= true){ + public static function buildRowArray( $minTime, $maxTime, $userDefs, $is_JSON = true ) { - if($minTime == 0){ + if ( $minTime == 0 ) { $minTime = self::$minimum_date; } - if($maxTime == 0){ - $maxTime = gmdate("Ymd",time()); //today + if ( $maxTime == 0 ) { + $maxTime = gmdate( "Ymd", time() ); // today } - if($is_JSON){ - $userDefs = json_decode($userDefs, true); + if ( $is_JSON ) { + $userDefs = json_decode( $userDefs, true ); } - $events = self::getTopEvents($minTime, $maxTime); + $events = self::getTopEvents( $minTime, $maxTime ); $returnArray = array(); - while(($data_result = $events->fetchRow()) != null){ + while ( ( $data_result = $events->fetchRow() ) != null ) { $outputArray = array(); $outputArray['event_name'] = $data_result['event_name']; $outputArray['event_id'] = $data_result['event_id']; - $outputArray['expert'] = self::getTableValue($data_result['event_id'], $userDefs["expert"]); - $outputArray['intermediate'] = self::getTableValue($data_result['event_id'], $userDefs["intermediate"]); - $outputArray['basic'] = self::getTableValue($data_result['event_id'], $userDefs["basic"]); + $outputArray['expert'] = self::getTableValue( $data_result['event_id'], $userDefs["expert"] ); + $outputArray['intermediate'] = self::getTableValue( $data_result['event_id'], $userDefs["intermediate"] ); + $outputArray['basic'] = self::getTableValue( $data_result['event_id'], $userDefs["basic"] ); $outputArray['total'] = $data_result["totalevtid"]; $returnArray[] = $outputArray; } @@ -438,50 +438,50 @@ } - function buildRow($data_result, $row_count, $userDefs){ + function buildRow( $data_result, $row_count, $userDefs ) { - $outputRow = Xml::openElement("tr", array("class" => "table_data_row")); + $outputRow = Xml::openElement( "tr", array( "class" => "table_data_row" ) ); - //event name - $outputRow .=Xml::openElement("td", - array("class" => "event_name", "id" => "event_name_$row_count", "value" =>$data_result['event_id'])); + // event name + $outputRow .= Xml::openElement( "td", + array( "class" => "event_name", "id" => "event_name_$row_count", "value" => $data_result['event_id'] ) ); $outputRow .= $data_result['event_name']; - $outputRow .=Xml::closeElement("td"); + $outputRow .= Xml::closeElement( "td" ); - //advanced users - $cellValue = self::getTableValue($data_result['event_id'], $userDefs["expert"]); - $outputRow .=Xml::openElement("td", - array("class" => "event_data expert_data", "id" => "event_expert_$row_count", - "value" => $cellValue)); + // advanced users + $cellValue = self::getTableValue( $data_result['event_id'], $userDefs["expert"] ); + $outputRow .= Xml::openElement( "td", + array( "class" => "event_data expert_data", "id" => "event_expert_$row_count", + "value" => $cellValue ) ); $outputRow .= $cellValue; - $outputRow .=Xml::closeElement("td"); + $outputRow .= Xml::closeElement( "td" ); - //intermediate users - $cellValue = self::getTableValue($data_result['event_id'], $userDefs["intermediate"]); - $outputRow .=Xml::openElement("td", - array("class" => "event_data intermediate_data", "id" => "event_intermediate_$row_count", - "value" => $cellValue)); + // intermediate users + $cellValue = self::getTableValue( $data_result['event_id'], $userDefs["intermediate"] ); + $outputRow .= Xml::openElement( "td", + array( "class" => "event_data intermediate_data", "id" => "event_intermediate_$row_count", + "value" => $cellValue ) ); $outputRow .= $cellValue; - $outputRow .=Xml::closeElement("td"); + $outputRow .= Xml::closeElement( "td" ); - //basic users - $cellValue = self::getTableValue($data_result['event_id'], $userDefs["basic"]); - $outputRow .=Xml::openElement("td", - array("class" => "event_data basic_data", "id" => "event_basic_$row_count", - "value" => $cellValue)); + // basic users + $cellValue = self::getTableValue( $data_result['event_id'], $userDefs["basic"] ); + $outputRow .= Xml::openElement( "td", + array( "class" => "event_data basic_data", "id" => "event_basic_$row_count", + "value" => $cellValue ) ); $outputRow .= $cellValue; - $outputRow .=Xml::closeElement("td"); + $outputRow .= Xml::closeElement( "td" ); - //totals + // totals $cellValue = $data_result["totalevtid"]; - $outputRow .=Xml::openElement("td", - array("class" => "event_data total_data", "id" => "total_$row_count", - "value" => $cellValue)); + $outputRow .= Xml::openElement( "td", + array( "class" => "event_data total_data", "id" => "total_$row_count", + "value" => $cellValue ) ); $outputRow .= $cellValue; - $outputRow .=Xml::closeElement("td"); + $outputRow .= Xml::closeElement( "td" ); - $outputRow .= Xml::closeElement("tr"); + $outputRow .= Xml::closeElement( "tr" ); return $outputRow; @@ -493,7 +493,7 @@ * @return date with spaces */ public static function space_out_date( $datewithnospaces ) { - return ( substr( $datewithnospaces, 0, 4 ) . ' ' .substr( $datewithnospaces, 4, 2 ) . ' ' . substr( $datewithnospaces, 6, 2 ) ); + return ( substr( $datewithnospaces, 0, 4 ) . ' ' . substr( $datewithnospaces, 4, 2 ) . ' ' . substr( $datewithnospaces, 6, 2 ) ); } @@ -503,23 +503,23 @@ * @param maxTime max day (YYYYMMDD) * NOTE: once some of the constraints have been finalized, this will use more of the Database functions and not raw SQL */ - static function getTimeConstraints( $minTime, $maxTime ){ - if( $minTime == 0 || $maxTime == 0 || + static function getTimeConstraints( $minTime, $maxTime ) { + if ( $minTime == 0 || $maxTime == 0 || ( strptime( SpecialClickTracking::space_out_date( $minTime ), "%Y %m %d" ) === false ) || ( strptime( SpecialClickTracking::space_out_date( $minTime ), "%Y %m %d" ) === false ) ) { return array(); } else { - //the dates are stored in the DB as MW_TIMESTAMP formats, add the zeroes to fix that + // the dates are stored in the DB as MW_TIMESTAMP formats, add the zeroes to fix that $minTime .= "000000"; - $maxTime .= "000000"; + $maxTime .= "000000"; $dbr = wfGetDB( DB_SLAVE ); - //time constraint array + // time constraint array return array( - "`action_time` >= ". $dbr->addQuotes($minTime) , - "`action_time` <= ". $dbr->addQuotes($maxTime) + "`action_time` >= " . $dbr->addQuotes( $minTime ) , + "`action_time` <= " . $dbr->addQuotes( $maxTime ) ); } @@ -533,9 +533,9 @@ * @return unknown_type * NOTE: once some of the constraints have been finalized, this will use more of the Database functions and not raw SQL */ - public static function getTopEvents($minTime = "", $maxTime = "", $normalize_top_results = false){ + public static function getTopEvents( $minTime = "", $maxTime = "", $normalize_top_results = false ) { - $time_constraint_statement = self::getTimeConstraints($minTime,$maxTime); + $time_constraint_statement = self::getTimeConstraints( $minTime, $maxTime ); $time_constraint = $time_constraint_statement; $dbr = wfGetDB( DB_SLAVE ); @@ -559,7 +559,7 @@ " $time_constraint group by event_id order by totalevtid desc"; */ - //returns count(event_id),event_id, event_name, top one first + // returns count(event_id),event_id, event_name, top one first return $dbresult; } @@ -567,12 +567,12 @@ * Gets a table value for a given User ID * NOTE: once some of the constraints have been finalized, this will use more of the Database functions and not raw SQL */ - static function getTableValue($event_id, $userDef, $minTime = '', $maxTime = '', $normalize_results = false){ + static function getTableValue( $event_id, $userDef, $minTime = '', $maxTime = '', $normalize_results = false ) { $dbr = wfGetDB( DB_SLAVE ); $conds = array_merge( - self::getTimeConstraints($minTime,$maxTime), - SpecialClickTracking::buildUserDefConstraints($userDef), + self::getTimeConstraints( $minTime, $maxTime ), + SpecialClickTracking::buildUserDefConstraints( $userDef ), array( 'event_id' => $event_id ) ); return wfGetDB( DB_SLAVE )->selectField( @@ -589,66 +589,66 @@ * @param $contrib_3 array, nonempty AND conditions for user_contribs_1 * @return unknown_type query */ - public static function buildUserDefConstraints($def){ + public static function buildUserDefConstraints( $def ) { $dbr = wfGetDB( DB_SLAVE ); - $include_anon_users = (empty($def['anonymous'])?array():$def['anonymous']); - $total_contribs = (empty($def['total_contribs'])?array():$def['total_contribs']); - $contrib_1 = (empty($def['contrib_1'])?array():$def['contrib_1']); - $contrib_2 = (empty($def['contrib_2'])?array():$def['contrib_2']); - $contrib_3 = (empty($def['contrib_3'])?array():$def['contrib_3']); + $include_anon_users = ( empty( $def['anonymous'] ) ? array():$def['anonymous'] ); + $total_contribs = ( empty( $def['total_contribs'] ) ? array():$def['total_contribs'] ); + $contrib_1 = ( empty( $def['contrib_1'] ) ? array():$def['contrib_1'] ); + $contrib_2 = ( empty( $def['contrib_2'] ) ? array():$def['contrib_2'] ); + $contrib_3 = ( empty( $def['contrib_3'] ) ? array():$def['contrib_3'] ); $or_conds = array(); $and_conds = array(); $sql = ""; - if( (boolean)$include_anon_users ){ - $or_conds[] = array("field" => "is_logged_in", "operation" => "=", "value" =>"0"); + if ( (boolean)$include_anon_users ) { + $or_conds[] = array( "field" => "is_logged_in", "operation" => "=", "value" => "0" ); } - if(!empty($total_contribs)){ - foreach($total_contribs as $contribs){ - $and_conds[] = array("field" => "user_total_contribs", "operation" => SpecialClickTracking::validate_oper($contribs["operation"]), "value" => intval($contribs["value"])); + if ( !empty( $total_contribs ) ) { + foreach ( $total_contribs as $contribs ) { + $and_conds[] = array( "field" => "user_total_contribs", "operation" => SpecialClickTracking::validate_oper( $contribs["operation"] ), "value" => intval( $contribs["value"] ) ); } } - if(!empty($contrib_1)){ - foreach($contrib_1 as $contribs){ - $and_conds[] = array("field" => "user_contribs_span1", "operation" => SpecialClickTracking::validate_oper($contribs["operation"]), "value" => intval($contribs["value"])); + if ( !empty( $contrib_1 ) ) { + foreach ( $contrib_1 as $contribs ) { + $and_conds[] = array( "field" => "user_contribs_span1", "operation" => SpecialClickTracking::validate_oper( $contribs["operation"] ), "value" => intval( $contribs["value"] ) ); } } - if(!empty($contrib_2)){ - foreach($contrib_2 as $contribs){ - $and_conds[] = array("field" => "user_contribs_span2", "operation" => SpecialClickTracking::validate_oper($contribs["operation"]), "value" => intval($contribs["value"])); + if ( !empty( $contrib_2 ) ) { + foreach ( $contrib_2 as $contribs ) { + $and_conds[] = array( "field" => "user_contribs_span2", "operation" => SpecialClickTracking::validate_oper( $contribs["operation"] ), "value" => intval( $contribs["value"] ) ); } } - if(!empty($contrib_3)){ - foreach($contrib_3 as $contribs){ - $and_conds[] = array("field" => "user_contribs_span3", "operation" => SpecialClickTracking::validate_oper($contribs["operation"]), "value" => intval($contribs["value"])); + if ( !empty( $contrib_3 ) ) { + foreach ( $contrib_3 as $contribs ) { + $and_conds[] = array( "field" => "user_contribs_span3", "operation" => SpecialClickTracking::validate_oper( $contribs["operation"] ), "value" => intval( $contribs["value"] ) ); } } - foreach($and_conds as $cond){ - if(!empty($sql)){ + foreach ( $and_conds as $cond ) { + if ( !empty( $sql ) ) { $sql .= " AND "; } $sql .= $cond["field"] . " " . $cond["operation"] . " " . $dbr->addQuotes( $cond["value"] ); } - foreach($or_conds as $cond){ - if(!empty($sql)){ + foreach ( $or_conds as $cond ) { + if ( !empty( $sql ) ) { $sql .= " OR "; } $sql .= $cond["field"] . " " . $cond["operation"] . " " . $dbr->addQuotes( $cond["value"] ); } - return array($sql); + return array( $sql ); } - public static function validate_oper($operation){ - $o_trim = trim($operation); - switch($o_trim){ //valid operations + public static function validate_oper( $operation ) { + $o_trim = trim( $operation ); + switch( $o_trim ) { // valid operations case ">": case "<": case "<=": _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS [at] lists https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs
|