Index: trunk/extensions/SemanticResultFormats/SemanticResultFormats.php |
— | — | @@ -20,7 +20,7 @@ |
21 | 21 | die( 'Not an entry point.' ); |
22 | 22 | } |
23 | 23 | |
24 | | -define( 'SRF_VERSION', '1.5.3' ); |
| 24 | +define( 'SRF_VERSION', '1.5.4 alpha' ); |
25 | 25 | |
26 | 26 | // Require the settings file. |
27 | 27 | require dirname( __FILE__ ) . '/SRF_Settings.php'; |
Index: trunk/extensions/SemanticResultFormats/Gallery/SRF_Gallery.php |
— | — | @@ -1,19 +1,14 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | | - * Print query results as a gallery. |
| 5 | + * Result printer that prints query results as a gallery. |
5 | 6 | * |
6 | | - * @file |
| 7 | + * @file SRF_Gallery.php |
7 | 8 | * @ingroup SemanticResultFormats |
8 | 9 | * |
9 | 10 | * @author Rowan Rodrik van der Molen |
10 | 11 | * @author Jeroen De Dauw |
11 | 12 | */ |
12 | | - |
13 | | -if ( !defined( 'MEDIAWIKI' ) ) die(); |
14 | | - |
15 | | -/** |
16 | | - * Result printer that prints query results as a gallery. |
17 | | - */ |
18 | 13 | class SRFGallery extends SMWResultPrinter { |
19 | 14 | |
20 | 15 | public function getName() { |
Index: trunk/extensions/SemanticResultFormats/Calendar/SRF_Calendar.php |
— | — | @@ -1,14 +1,15 @@ |
2 | 2 | <?php |
3 | 3 | |
| 4 | +$wgAutoloadClasses['SRFCHistoricalDate'] = $srfgIP . '/Calendar/SRFC_HistoricalDate.php'; |
| 5 | + |
4 | 6 | /** |
5 | | - * A class to print query results in a monthly calendar. |
| 7 | + * Result printer that prints query results as a monthly calendar. |
| 8 | + * |
| 9 | + * @file SRF_Calendar.php |
| 10 | + * @ingroup SemanticResultFormats |
| 11 | + * |
| 12 | + * @author ... |
6 | 13 | */ |
7 | | - |
8 | | -if ( !defined( 'MEDIAWIKI' ) ) die(); |
9 | | - |
10 | | -global $srfgIP; |
11 | | -$wgAutoloadClasses['SRFCHistoricalDate'] = $srfgIP . '/Calendar/SRFC_HistoricalDate.php'; |
12 | | - |
13 | 14 | class SRFCalendar extends SMWResultPrinter { |
14 | 15 | |
15 | 16 | protected $mTemplate = ''; |
— | — | @@ -16,14 +17,16 @@ |
17 | 18 | protected $mRealUserLang = null; |
18 | 19 | |
19 | 20 | protected function readParameters( $params, $outputmode ) { |
20 | | - SMWResultPrinter::readParameters( $params, $outputmode ); |
| 21 | + parent::readParameters( $params, $outputmode ); |
21 | 22 | |
22 | 23 | if ( array_key_exists( 'template', $params ) ) { |
23 | 24 | $this->mTemplate = trim( $params['template'] ); |
24 | 25 | } |
| 26 | + |
25 | 27 | if ( array_key_exists( 'userparam', $params ) ) { |
26 | 28 | $this->mUserParam = trim( $params['userparam'] ); |
27 | 29 | } |
| 30 | + |
28 | 31 | if ( array_key_exists( 'lang', $params ) ) { |
29 | 32 | global $wgLang; |
30 | 33 | // store the actual user's language, so we can revert |
— | — | @@ -46,24 +49,34 @@ |
47 | 50 | return $this->getResultText( $results, SMW_OUTPUT_HTML ); |
48 | 51 | } |
49 | 52 | |
| 53 | + /** |
| 54 | + * (non-PHPdoc) |
| 55 | + * @see SMWResultPrinter::getResultText() |
| 56 | + * |
| 57 | + * TODO: split up megamoth |
| 58 | + */ |
50 | 59 | protected function getResultText( $res, $outputmode ) { |
51 | 60 | global $smwgIQRunningNumber, $wgUser; |
52 | 61 | $skin = $wgUser->getSkin(); |
53 | | - $result = ""; |
| 62 | + $result = ''; |
54 | 63 | |
55 | 64 | $events = array(); |
56 | 65 | // print all result rows |
57 | 66 | while ( $row = $res->getNext() ) { |
58 | 67 | $dates = array(); |
59 | | - $title = $text = $color = ""; |
| 68 | + $title = $text = $color = ''; |
60 | 69 | |
61 | 70 | if ( $this->mTemplate != '' ) { // build template code |
62 | 71 | $this->hasTemplates = true; |
63 | | - if ( $this->mUserParam ) |
| 72 | + |
| 73 | + if ( $this->mUserParam ) { |
64 | 74 | $text = "|userparam=$this->mUserParam"; |
| 75 | + } |
| 76 | + |
65 | 77 | foreach ( $row as $i => $field ) { |
66 | 78 | $pr = $field->getPrintRequest(); |
67 | 79 | $text .= '|' . ( $i + 1 ) . '='; |
| 80 | + |
68 | 81 | while ( ( $object = $field->getNextObject() ) !== false ) { |
69 | 82 | if ( $object->getTypeID() == '_dat' ) { |
70 | 83 | $text .= $object->getLongWikiText(); |
— | — | @@ -77,6 +90,7 @@ |
78 | 91 | } else { |
79 | 92 | $text .= $object->getShortText( $outputmode, null ); |
80 | 93 | } |
| 94 | + |
81 | 95 | if ( $pr->getMode() == SMWPrintRequest::PRINT_PROP && $pr->getTypeID() == '_dat' ) { |
82 | 96 | $dates[] = SRFCalendar::formatDateStr( $object ); |
83 | 97 | } |
— | — | @@ -93,6 +107,7 @@ |
94 | 108 | // value - cycle through all the values |
95 | 109 | // for this property |
96 | 110 | $textForProperty = ''; |
| 111 | + |
97 | 112 | while ( ( $object = $field->getNextObject() ) !== false ) { |
98 | 113 | if ( $object->getTypeID() == '_dat' ) { |
99 | 114 | // don't add date values to the display |
— | — | @@ -101,12 +116,14 @@ |
102 | 117 | $title = Title::newFromText( $object->getShortWikiText( false ) ); |
103 | 118 | } else { |
104 | 119 | $numNonDateProperties++; |
| 120 | + |
105 | 121 | // handling of "headers=" param |
106 | 122 | if ( $this->mShowHeaders == SMW_HEADERS_SHOW ) { |
107 | | - $textForProperty .= $pr->getHTMLText( $skin ) . " "; |
| 123 | + $textForProperty .= $pr->getHTMLText( $skin ) . ' '; |
108 | 124 | } elseif ( $this->mShowHeaders == SMW_HEADERS_PLAIN ) { |
109 | | - $textForProperty .= $pr->getLabel() . " "; |
| 125 | + $textForProperty .= $pr->getLabel() . ' '; |
110 | 126 | } |
| 127 | + |
111 | 128 | // if $this->mShowHeaders == SMW_HEADERS_HIDE, print nothing |
112 | 129 | // handling of "link=" param |
113 | 130 | if ( $this->mLinkOthers ) { |
— | — | @@ -117,40 +134,47 @@ |
118 | 135 | } |
119 | 136 | } else { |
120 | 137 | $numNonDateProperties++; |
121 | | - $textForProperty .= $pr->getHTMLText( $skin ) . " " . $object->getShortText( $outputmode, $skin ); |
| 138 | + $textForProperty .= $pr->getHTMLText( $skin ) . ' ' . $object->getShortText( $outputmode, $skin ); |
122 | 139 | } |
123 | 140 | if ( $pr->getMode() == SMWPrintRequest::PRINT_PROP && $pr->getTypeID() == '_dat' ) { |
124 | 141 | $dates[] = SRFCalendar::formatDateStr( $object ); |
125 | 142 | } |
126 | 143 | } |
| 144 | + |
127 | 145 | // add the text for this property to |
128 | 146 | // the main text, adding on parentheses |
129 | 147 | // or commas as needed |
130 | 148 | if ( $numNonDateProperties == 1 ) { |
131 | | - $text .= " ("; |
| 149 | + $text .= ' ('; |
132 | 150 | } elseif ( $numNonDateProperties > 1 ) { |
133 | | - $text .= ", "; |
| 151 | + $text .= ', '; |
134 | 152 | } |
135 | 153 | $text .= $textForProperty; |
136 | 154 | } |
137 | 155 | if ( $numNonDateProperties > 0 ) { |
138 | | - $text .= ")"; |
| 156 | + $text .= ')'; |
139 | 157 | } |
140 | 158 | } |
| 159 | + |
141 | 160 | if ( count( $dates ) > 0 ) { |
142 | 161 | // handle the 'color=' value, whether it came |
143 | 162 | // from a compound query or a regular one |
144 | 163 | // handling is different for SMW 1.5+ |
145 | 164 | if ( method_exists( 'SMWQueryResult', 'getResults' ) ) { |
146 | 165 | $res_subject = $field->getResultSubject(); |
147 | | - if ( isset( $res_subject->display_options ) && is_array( $res_subject->display_options ) && array_key_exists( 'color', $res_subject->display_options ) ) |
148 | | - $color = $res_subject->display_options['color']; |
| 166 | + if ( isset( $res_subject->display_options ) |
| 167 | + && is_array( $res_subject->display_options ) |
| 168 | + && array_key_exists( 'color', $res_subject->display_options ) ) { |
| 169 | + $color = $res_subject->display_options['color']; |
| 170 | + } |
149 | 171 | } elseif ( property_exists( $row[0], 'display_options' ) ) { |
150 | | - if ( is_array( $row[0]->display_options ) && array_key_exists( 'color', $row[0]->display_options ) ) |
| 172 | + if ( is_array( $row[0]->display_options ) && array_key_exists( 'color', $row[0]->display_options ) ) { |
151 | 173 | $color = $row[0]->display_options['color']; |
| 174 | + } |
152 | 175 | } elseif ( array_key_exists( 'color', $this->m_params ) ) { |
153 | 176 | $color = $this->m_params['color']; |
154 | 177 | } |
| 178 | + |
155 | 179 | foreach ( $dates as $date ) { |
156 | 180 | $events[] = array( $title, $text, $date, $color ); |
157 | 181 | } |
— | — | @@ -158,37 +182,43 @@ |
159 | 183 | } |
160 | 184 | |
161 | 185 | $result = SRFCalendar::displayCalendar( $events ); |
| 186 | + |
162 | 187 | // go back to the actual user's language, in case a different |
163 | 188 | // language had been specified for this calendar |
164 | 189 | if ( ! is_null( $this->mRealUserLang ) ) { |
165 | 190 | global $wgLang; |
166 | 191 | $wgLang = $this->mRealUserLang; |
167 | 192 | } |
| 193 | + |
168 | 194 | global $wgParser; |
169 | | - if ( is_null( $wgParser->getTitle() ) ) |
| 195 | + |
| 196 | + if ( is_null( $wgParser->getTitle() ) ) { |
170 | 197 | return $result; |
171 | | - else |
| 198 | + } |
| 199 | + else { |
172 | 200 | return array( $result, 'noparse' => 'true', 'isHTML' => 'true' ); |
| 201 | + } |
173 | 202 | } |
174 | 203 | |
175 | | - |
176 | 204 | function intToMonth( $int ) { |
177 | | - if ( $int == '2' ) { return wfMsg( 'february' ); } |
178 | | - if ( $int == '3' ) { return wfMsg( 'march' ); } |
179 | | - if ( $int == '4' ) { return wfMsg( 'april' ); } |
180 | | - if ( $int == '5' ) { return wfMsg( 'may' ); } |
181 | | - if ( $int == '6' ) { return wfMsg( 'june' ); } |
182 | | - if ( $int == '7' ) { return wfMsg( 'july' ); } |
183 | | - if ( $int == '8' ) { return wfMsg( 'august' ); } |
184 | | - if ( $int == '9' ) { return wfMsg( 'september' ); } |
185 | | - if ( $int == '10' ) { return wfMsg( 'october' ); } |
186 | | - if ( $int == '11' ) { return wfMsg( 'november' ); } |
187 | | - if ( $int == '12' ) { return wfMsg( 'december' ); } |
188 | | - // keep it simple - if it's '1' or anything else, return January |
189 | | - return wfMsg( 'january' ); |
| 205 | + $months = array( |
| 206 | + '1' => 'january', |
| 207 | + '2' => 'february', |
| 208 | + '3' => 'march', |
| 209 | + '4' => 'april', |
| 210 | + '5' => 'may', |
| 211 | + '6' => 'june', |
| 212 | + '7' => 'july', |
| 213 | + '8' => 'august', |
| 214 | + '9' => 'september', |
| 215 | + '10' => 'october', |
| 216 | + '11' => 'november', |
| 217 | + '12' => 'december', |
| 218 | + ); |
| 219 | + |
| 220 | + return wfMsg( array_key_exists( $int, $months ) ? $months[$int] : 'january' ); |
190 | 221 | } |
191 | 222 | |
192 | | - |
193 | 223 | function formatDateStr( $object ) { |
194 | 224 | // For some reason, getMonth() and getDay() sometimes return a |
195 | 225 | // number with a leading zero - get rid of it using (int) |
— | — | @@ -203,8 +233,8 @@ |
204 | 234 | $wgOut->addLink( array( |
205 | 235 | 'rel' => 'stylesheet', |
206 | 236 | 'type' => 'text/css', |
207 | | - 'media' => "screen, print", |
208 | | - 'href' => $srfgScriptPath . "/Calendar/skins/SRFC_main.css" |
| 237 | + 'media' => 'screen, print', |
| 238 | + 'href' => $srfgScriptPath . '/Calendar/skins/SRFC_main.css' |
209 | 239 | ) ); |
210 | 240 | |
211 | 241 | // Set variables differently depending on whether this is |
— | — | @@ -215,6 +245,7 @@ |
216 | 246 | $additional_query_string = ''; |
217 | 247 | $hidden_inputs = ''; |
218 | 248 | $in_special_page = is_null( $page_title ) || $page_title->isSpecialPage(); |
| 249 | + |
219 | 250 | if ( $in_special_page ) { |
220 | 251 | global $wgTitle; |
221 | 252 | $page_title = $wgTitle; |
— | — | @@ -233,6 +264,7 @@ |
234 | 265 | } |
235 | 266 | } |
236 | 267 | } |
| 268 | + |
237 | 269 | foreach ( $request_values as $key => $value ) { |
238 | 270 | if ( $key != 'month' && $key != 'year' |
239 | 271 | // values from 'RunQuery' |
— | — | @@ -251,21 +283,23 @@ |
252 | 284 | // and years (same - note that the previous or next month could |
253 | 285 | // be in a different year), the number of days in the current, |
254 | 286 | // previous and next months, etc. |
255 | | - $cur_month_num = date( "n", time() ); |
| 287 | + $cur_month_num = date( 'n', time() ); |
256 | 288 | if ( $wgRequest->getCheck( 'month' ) ) { |
257 | 289 | $query_month = $wgRequest->getVal( 'month' ); |
258 | 290 | if ( is_numeric( $query_month ) && ( intval( $query_month ) == $query_month ) && $query_month >= 1 && $query_month <= 12 ) { |
259 | 291 | $cur_month_num = $wgRequest->getVal( 'month' ); |
260 | 292 | } |
261 | 293 | } |
| 294 | + |
262 | 295 | $cur_month = SRFCalendar::intToMonth( $cur_month_num ); |
263 | | - $cur_year = date( "Y", time() ); |
| 296 | + $cur_year = date( 'Y', time() ); |
264 | 297 | if ( $wgRequest->getCheck( 'year' ) ) { |
265 | 298 | $query_year = $wgRequest->getVal( 'year' ); |
266 | 299 | if ( is_numeric( $query_year ) && intval( $query_year ) == $query_year ) { |
267 | 300 | $cur_year = $wgRequest->getVal( 'year' ); |
268 | 301 | } |
269 | 302 | } |
| 303 | + |
270 | 304 | if ( $cur_month_num == '1' ) { |
271 | 305 | $prev_month_num = '12'; |
272 | 306 | $prev_year = $cur_year - 1; |
— | — | @@ -273,6 +307,7 @@ |
274 | 308 | $prev_month_num = $cur_month_num - 1; |
275 | 309 | $prev_year = $cur_year; |
276 | 310 | } |
| 311 | + |
277 | 312 | if ( $cur_month_num == '12' ) { |
278 | 313 | $next_month_num = '1'; |
279 | 314 | $next_year = $cur_year + 1; |
— | — | @@ -280,13 +315,16 @@ |
281 | 316 | $next_month_num = $cur_month_num + 1; |
282 | 317 | $next_year = $cur_year; |
283 | 318 | } |
| 319 | + |
284 | 320 | // there's no year '0' - change it to '1' or '-1' |
285 | | - if ( $cur_year == "0" ) { $cur_year = "1"; } |
286 | | - if ( $next_year == "0" ) { $next_year = "1"; } |
287 | | - if ( $prev_year == "0" ) { $prev_year = "-1"; } |
| 321 | + if ( $cur_year == '0' ) { $cur_year = '1'; } |
| 322 | + if ( $next_year == '0' ) { $next_year = '1'; } |
| 323 | + if ( $prev_year == '0' ) { $prev_year = '-1'; } |
| 324 | + |
288 | 325 | $prev_month_url = $page_title->getLocalURL( "month=$prev_month_num&year=$prev_year" . $additional_query_string ); |
289 | 326 | $next_month_url = $page_title->getLocalURL( "month=$next_month_num&year=$next_year" . $additional_query_string ); |
290 | 327 | $today_url = $page_title->getLocalURL( $additional_query_string ); |
| 328 | + |
291 | 329 | $today_text = wfMsg( 'srfc_today' ); |
292 | 330 | $prev_month_text = wfMsg( 'srfc_previousmonth' ); |
293 | 331 | $next_month_text = wfMsg( 'srfc_nextmonth' ); |
— | — | @@ -299,7 +337,7 @@ |
300 | 338 | $start_day = 1 - $day_of_week_of_1; |
301 | 339 | $days_in_prev_month = SRFCHistoricalDate::daysInMonth( $prev_year, $prev_month_num ); |
302 | 340 | $days_in_cur_month = SRFCHistoricalDate::daysInMonth( $cur_year, $cur_month_num ); |
303 | | - $today_string = date( "Y n j", time() ); |
| 341 | + $today_string = date( 'Y n j', time() ); |
304 | 342 | $url_year = $wgRequest->getVal( 'year' ); |
305 | 343 | $page_name = $page_title->getPrefixedDbKey(); |
306 | 344 | |
— | — | @@ -424,10 +462,14 @@ |
425 | 463 | return $text; |
426 | 464 | } |
427 | 465 | |
428 | | - public function getParameters() { |
429 | | - $params = parent::getParameters(); |
430 | | - $params[] = array( 'name' => 'lang', 'type' => 'string', 'description' => wfMsg( 'srf_paramdesc_calendarlang' ) ); |
431 | | - return $params; |
432 | | - } |
| 466 | + /** |
| 467 | + * (non-PHPdoc) |
| 468 | + * @see SMWResultPrinter::getParameters() |
| 469 | + */ |
| 470 | + public function getParameters() { |
| 471 | + $params = parent::getParameters(); |
| 472 | + $params[] = array( 'name' => 'lang', 'type' => 'string', 'description' => wfMsg( 'srf_paramdesc_calendarlang' ) ); |
| 473 | + return $params; |
| 474 | + } |
433 | 475 | |
434 | 476 | } |