r90974 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90973‎ | r90974 | r90975 >
Date:15:49, 28 June 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
some stylizing
Modified paths:
  • /trunk/extensions/SemanticResultFormats/Math/SRF_Math.php (modified) (history)
  • /trunk/extensions/SemanticResultFormats/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/SemanticResultFormats/SRF_ParserFunctions.php (modified) (history)
  • /trunk/extensions/SemanticResultFormats/SemanticResultFormats.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticResultFormats/SemanticResultFormats.php
@@ -113,7 +113,7 @@
114114 'average' => 'SRFMath',
115115 'min' => 'SRFMath',
116116 'max' => 'SRFMath',
117 - 'mean' => 'SRFMath',
 117+ 'median' => 'SRFMath',
118118 'exhibit' => 'SRFExhibit',
119119 'googlebar' => 'SRFGoogleBar',
120120 'googlepie' => 'SRFGooglePie',
Index: trunk/extensions/SemanticResultFormats/SRF_ParserFunctions.php
@@ -15,9 +15,6 @@
1616 * @ingroup SemanticResultFormats
1717 * @author David Loomer
1818 */
19 -
20 -if ( !defined( 'MEDIAWIKI' ) ) die();
21 -
2219 class SRFParserFunctions {
2320
2421 static function registerFunctions( &$parser ) {
@@ -86,38 +83,53 @@
8784 // otherwise fall back to defaults.
8885 if ( $wgRequest->getCheck( 'year' ) && $wgRequest->getCheck( 'month' ) ) {
8986 $query_year = $wgRequest->getVal( 'year' );
90 - if ( is_numeric( $query_year ) && ( intval( $query_year ) == $query_year ) )
 87+
 88+ if ( is_numeric( $query_year ) && ( intval( $query_year ) == $query_year ) ) {
9189 $lower_year = $query_year;
92 - else
 90+ }
 91+ else {
9392 $lower_year = $default_year;
 93+ }
9494
9595 $query_month = $wgRequest->getVal( 'month' );
96 - if ( is_numeric( $query_month ) && ( intval( $query_month ) == $query_month ) && $query_month >= 1 && $query_month <= 12 )
 96+ if ( is_numeric( $query_month ) && ( intval( $query_month ) == $query_month ) && $query_month >= 1 && $query_month <= 12 ) {
9797 $lower_month = $query_month;
98 - else
 98+ }
 99+ else {
99100 $lower_month = $default_month;
 101+ }
100102
101103 if ( $wgRequest->getCheck( 'day' ) ) {
102104 $query_day = $wgRequest->getVal( 'day' );
103 - if ( is_numeric( $query_day ) && ( intval( $query_day ) == $query_day ) && $query_day >= 1 && $query_day <= 31 )
 105+
 106+ if ( is_numeric( $query_day ) && ( intval( $query_day ) == $query_day ) && $query_day >= 1 && $query_day <= 31 ) {
104107 $lower_day = $query_day;
105 - else
 108+ }
 109+ else {
106110 $lower_day = '1';
 111+ }
 112+
107113 $lower_day = $wgRequest->getVal( 'day' );
108114 } elseif ( $calendar_type != 'month'
109115 && (int)$lower_year == (int)$default_year
110 - && (int)$lower_month == (int)$default_month )
111 - $lower_day = $default_day;
112 - else
 116+ && (int)$lower_month == (int)$default_month ) {
 117+ $lower_day = $default_day;
 118+ }
 119+ else {
113120 $lower_day = '1';
 121+ }
114122 } else {
115123 $lower_year = $default_year;
116124 $lower_month = $default_month;
117 - if ( $calendar_type == 'month' )
 125+
 126+ if ( $calendar_type == 'month' ) {
118127 $lower_day = 1;
119 - else
 128+ }
 129+ else {
120130 $lower_month = $default_day;
 131+ }
121132 }
 133+
122134 $lower_date = mktime( 0, 0, 0, $lower_month, $lower_day, $lower_year );
123135
124136 // Date to be queried
@@ -141,13 +153,21 @@
142154 // If necessary, adjust bounds to comply with required days of week for each.
143155 if ( $calendar_type == 'month' || $calendar_start_day >= 0 ) {
144156 $lower_offset = date( "w", $lower_date ) - $calendar_start_day;
145 - if ( $lower_offset < 0 ) $lower_offset += 7;
 157+
 158+ if ( $lower_offset < 0 ) {
 159+ $lower_offset += 7;
 160+ }
 161+
146162 if ( $calendar_type == 'month' ) {
147163 $upper_offset = $calendar_start_day + 6 - date( "w", $upper_date );
148 - if ( $upper_offset > 6 ) $upper_offset -= 7;
 164+
 165+ if ( $upper_offset > 6 ) {
 166+ $upper_offset -= 7;
 167+ }
149168 } else {
150169 $upper_offset = 0 - $lower_offset;
151170 }
 171+
152172 $lower_date = $lower_date - 86400 * $lower_offset;
153173 $upper_date = $upper_date + 86400 * $upper_offset;
154174 }
@@ -157,4 +177,5 @@
158178
159179 return array( $lower_date, $upper_date, $return_date );
160180 }
 181+
161182 }
Index: trunk/extensions/SemanticResultFormats/Math/SRF_Math.php
@@ -55,7 +55,7 @@
5656 case 'average':
5757 return array_sum( $numbers ) / count( $numbers );
5858 break;
59 - case 'mean':
 59+ case 'median':
6060 sort( $numbers, SORT_NUMERIC );
6161 $position = ( count( $numbers ) + 1 ) / 2 - 1;
6262 return ( $numbers[ceil( $position )] + $numbers[floor( $position )] ) / 2;
Index: trunk/extensions/SemanticResultFormats/RELEASE-NOTES
@@ -6,7 +6,7 @@
77
88 Changes in this version:
99 * Added compatibility with SMW 1.6.
10 -* Added product and mean formats.
 10+* Added product and median formats.
1111 * Rewrote math formats for efficiency, correct recursion and handling of multiple numerical properties.
1212 * Cleaned up the graph format.
1313 * Fixed division by zero issue (oh shii~) in the tagcloud format.