Index: trunk/extensions/SemanticResultFormats/SemanticResultFormats.php |
— | — | @@ -113,7 +113,7 @@ |
114 | 114 | 'average' => 'SRFMath', |
115 | 115 | 'min' => 'SRFMath', |
116 | 116 | 'max' => 'SRFMath', |
117 | | - 'mean' => 'SRFMath', |
| 117 | + 'median' => 'SRFMath', |
118 | 118 | 'exhibit' => 'SRFExhibit', |
119 | 119 | 'googlebar' => 'SRFGoogleBar', |
120 | 120 | 'googlepie' => 'SRFGooglePie', |
Index: trunk/extensions/SemanticResultFormats/SRF_ParserFunctions.php |
— | — | @@ -15,9 +15,6 @@ |
16 | 16 | * @ingroup SemanticResultFormats |
17 | 17 | * @author David Loomer |
18 | 18 | */ |
19 | | - |
20 | | -if ( !defined( 'MEDIAWIKI' ) ) die(); |
21 | | - |
22 | 19 | class SRFParserFunctions { |
23 | 20 | |
24 | 21 | static function registerFunctions( &$parser ) { |
— | — | @@ -86,38 +83,53 @@ |
87 | 84 | // otherwise fall back to defaults. |
88 | 85 | if ( $wgRequest->getCheck( 'year' ) && $wgRequest->getCheck( 'month' ) ) { |
89 | 86 | $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 ) ) { |
91 | 89 | $lower_year = $query_year; |
92 | | - else |
| 90 | + } |
| 91 | + else { |
93 | 92 | $lower_year = $default_year; |
| 93 | + } |
94 | 94 | |
95 | 95 | $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 ) { |
97 | 97 | $lower_month = $query_month; |
98 | | - else |
| 98 | + } |
| 99 | + else { |
99 | 100 | $lower_month = $default_month; |
| 101 | + } |
100 | 102 | |
101 | 103 | if ( $wgRequest->getCheck( 'day' ) ) { |
102 | 104 | $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 ) { |
104 | 107 | $lower_day = $query_day; |
105 | | - else |
| 108 | + } |
| 109 | + else { |
106 | 110 | $lower_day = '1'; |
| 111 | + } |
| 112 | + |
107 | 113 | $lower_day = $wgRequest->getVal( 'day' ); |
108 | 114 | } elseif ( $calendar_type != 'month' |
109 | 115 | && (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 { |
113 | 120 | $lower_day = '1'; |
| 121 | + } |
114 | 122 | } else { |
115 | 123 | $lower_year = $default_year; |
116 | 124 | $lower_month = $default_month; |
117 | | - if ( $calendar_type == 'month' ) |
| 125 | + |
| 126 | + if ( $calendar_type == 'month' ) { |
118 | 127 | $lower_day = 1; |
119 | | - else |
| 128 | + } |
| 129 | + else { |
120 | 130 | $lower_month = $default_day; |
| 131 | + } |
121 | 132 | } |
| 133 | + |
122 | 134 | $lower_date = mktime( 0, 0, 0, $lower_month, $lower_day, $lower_year ); |
123 | 135 | |
124 | 136 | // Date to be queried |
— | — | @@ -141,13 +153,21 @@ |
142 | 154 | // If necessary, adjust bounds to comply with required days of week for each. |
143 | 155 | if ( $calendar_type == 'month' || $calendar_start_day >= 0 ) { |
144 | 156 | $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 | + |
146 | 162 | if ( $calendar_type == 'month' ) { |
147 | 163 | $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 | + } |
149 | 168 | } else { |
150 | 169 | $upper_offset = 0 - $lower_offset; |
151 | 170 | } |
| 171 | + |
152 | 172 | $lower_date = $lower_date - 86400 * $lower_offset; |
153 | 173 | $upper_date = $upper_date + 86400 * $upper_offset; |
154 | 174 | } |
— | — | @@ -157,4 +177,5 @@ |
158 | 178 | |
159 | 179 | return array( $lower_date, $upper_date, $return_date ); |
160 | 180 | } |
| 181 | + |
161 | 182 | } |
Index: trunk/extensions/SemanticResultFormats/Math/SRF_Math.php |
— | — | @@ -55,7 +55,7 @@ |
56 | 56 | case 'average': |
57 | 57 | return array_sum( $numbers ) / count( $numbers ); |
58 | 58 | break; |
59 | | - case 'mean': |
| 59 | + case 'median': |
60 | 60 | sort( $numbers, SORT_NUMERIC ); |
61 | 61 | $position = ( count( $numbers ) + 1 ) / 2 - 1; |
62 | 62 | return ( $numbers[ceil( $position )] + $numbers[floor( $position )] ) / 2; |
Index: trunk/extensions/SemanticResultFormats/RELEASE-NOTES |
— | — | @@ -6,7 +6,7 @@ |
7 | 7 | |
8 | 8 | Changes in this version: |
9 | 9 | * Added compatibility with SMW 1.6. |
10 | | -* Added product and mean formats. |
| 10 | +* Added product and median formats. |
11 | 11 | * Rewrote math formats for efficiency, correct recursion and handling of multiple numerical properties. |
12 | 12 | * Cleaned up the graph format. |
13 | 13 | * Fixed division by zero issue (oh shii~) in the tagcloud format. |