Index: trunk/extensions/SemanticResultFormats/Calendar/SRF_Calendar.php |
— | — | @@ -2,8 +2,6 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * A class to print query results in a monthly calendar. |
6 | | - * |
7 | | - * @author Yaron Koren |
8 | 6 | */ |
9 | 7 | |
10 | 8 | if (!defined('MEDIAWIKI')) die(); |
— | — | @@ -13,7 +11,24 @@ |
14 | 12 | |
15 | 13 | class SRFCalendar extends SMWResultPrinter { |
16 | 14 | |
| 15 | + protected $mTemplate = ''; |
| 16 | + protected $mUserParam = ''; |
| 17 | + |
| 18 | + protected function readParameters($params,$outputmode) { |
| 19 | + SMWResultPrinter::readParameters($params,$outputmode); |
| 20 | + |
| 21 | + if (array_key_exists('template', $params)) { |
| 22 | + $this->mTemplate = trim($params['template']); |
| 23 | + } |
| 24 | + if (array_key_exists('userparam', $params)) { |
| 25 | + $this->mUserParam = trim($params['userparam']); |
| 26 | + } |
| 27 | + } |
| 28 | + |
17 | 29 | public function getResult($results, $params, $outputmode) { |
| 30 | + $this->isHTML = false; |
| 31 | + $this->hasTemplates = false; |
| 32 | + |
18 | 33 | // skip checks, results with 0 entries are normal |
19 | 34 | $this->readParameters($params, $outputmode); |
20 | 35 | return $this->getResultText($results, SMW_OUTPUT_HTML); |
— | — | @@ -28,38 +43,54 @@ |
29 | 44 | // print all result rows |
30 | 45 | while ( $row = $res->getNext() ) { |
31 | 46 | $date = $title = $text = $color = ""; |
32 | | - foreach ($row as $i => $field) { |
33 | | - $pr = $field->getPrintRequest(); |
34 | | - if ($i == 2) |
35 | | - $text .= " ("; |
36 | | - elseif ($i > 2) |
37 | | - $text .= ", "; |
38 | | - while ( ($object = $field->getNextObject()) !== false ) { |
39 | | - if ($object->getTypeID() == '_dat') { // use shorter "LongText" for wikipage |
40 | | - // don't add date values to the display |
41 | | - } elseif ($object->getTypeID() == '_wpg') { // use shorter "LongText" for wikipage |
42 | | - if ($i == 0) { |
43 | | - $title = Title::newFromText($object->getShortWikiText(false)); |
| 47 | + |
| 48 | + if ($this->mTemplate != '') { // build template code |
| 49 | + $this->hasTemplates = true; |
| 50 | + if ($this->mUserParam) |
| 51 | + $text = "|userparam=$this->mUserParam"; |
| 52 | + foreach ($row as $i => $field) { |
| 53 | + $pr = $field->getPrintRequest(); |
| 54 | + $text .= '|' . ($i + 1) . '='; |
| 55 | + while ( ($object = $field->getNextObject()) !== false ) { |
| 56 | + if ($object->getTypeID() == '_dat') { |
| 57 | + $test .= SRFCalendar::formatDateStr($object); |
| 58 | + } elseif ($object->getTypeID() == '_wpg') { // use shorter "LongText" for wikipage |
| 59 | + $text .= $object->getLongText($outputmode, NULL); |
44 | 60 | } else { |
45 | | - $text .= $pr->getHTMLText($skin) . " " . $object->getLongText($outputmode, $skin); |
| 61 | + $text .= $object->getShortText($outputmode, NULL); |
46 | 62 | } |
47 | | - } else { |
48 | | - $text .= $pr->getHTMLText($skin) . " " . $object->getShortText($outputmode, $skin); |
| 63 | + if ($pr->getMode() == SMWPrintRequest::PRINT_PROP && $pr->getTypeID() == '_dat') { |
| 64 | + $date = SRFCalendar::formatDateStr($object); |
| 65 | + } |
49 | 66 | } |
50 | | - if ($pr->getMode() == SMWPrintRequest::PRINT_PROP && $pr->getTypeID() == '_dat') { |
51 | | - if (method_exists('SMWTimeValue', 'getYear')) { // SMW 1.4 and higher |
52 | | - // for some reason, getMonth() and getDay() sometimes return a number with a leading zero - |
53 | | - // get rid of it using (int) |
54 | | - $date = $object->getYear() . '-' . (int)$object->getMonth() . '-' . (int)$object->getDay(); |
| 67 | + } |
| 68 | + } else { // build simple text |
| 69 | + foreach ($row as $i => $field) { |
| 70 | + $pr = $field->getPrintRequest(); |
| 71 | + if ($i == 2) |
| 72 | + $text .= " ("; |
| 73 | + elseif ($i > 2) |
| 74 | + $text .= ", "; |
| 75 | + while ( ($object = $field->getNextObject()) !== false ) { |
| 76 | + if ($object->getTypeID() == '_dat') { // use shorter "LongText" for wikipage |
| 77 | + // don't add date values to the display |
| 78 | + } elseif ($object->getTypeID() == '_wpg') { // use shorter "LongText" for wikipage |
| 79 | + if ($i == 0) { |
| 80 | + $title = Title::newFromText($object->getShortWikiText(false)); |
| 81 | + } else { |
| 82 | + $text .= $pr->getHTMLText($skin) . " " . $object->getLongText($outputmode, $skin); |
| 83 | + } |
55 | 84 | } else { |
56 | | - $date = date("Y-n-j", $event_date->getNumericValue()); |
| 85 | + $text .= $pr->getHTMLText($skin) . " " . $object->getShortText($outputmode, $skin); |
57 | 86 | } |
58 | | - |
| 87 | + if ($pr->getMode() == SMWPrintRequest::PRINT_PROP && $pr->getTypeID() == '_dat') { |
| 88 | + $date = SRFCalendar::formatDateStr($object); |
| 89 | + } |
59 | 90 | } |
60 | 91 | } |
| 92 | + if ($i > 1) |
| 93 | + $text .= ")"; |
61 | 94 | } |
62 | | - if ($i > 1) |
63 | | - $text .= ")"; |
64 | 95 | if ($date != '') { |
65 | 96 | // handle the 'color=' value, whether it came |
66 | 97 | // from a compound query or a regular one |
— | — | @@ -94,6 +125,17 @@ |
95 | 126 | return wfMsg('january'); |
96 | 127 | } |
97 | 128 | |
| 129 | + |
| 130 | + function formatDateStr($object) { |
| 131 | + if (method_exists('SMWTimeValue', 'getYear')) { // SMW 1.4 and higher |
| 132 | + // for some reason, getMonth() and getDay() sometimes return a number with a leading zero - |
| 133 | + // get rid of it using (int) |
| 134 | + return $object->getYear() . '-' . (int)$object->getMonth() . '-' . (int)$object->getDay(); |
| 135 | + } else { |
| 136 | + return date("Y-n-j", $event_date->getNumericValue()); |
| 137 | + } |
| 138 | + } |
| 139 | + |
98 | 140 | function displayCalendar($events) { |
99 | 141 | global $wgOut, $srfgScriptPath, $wgParser, $wgRequest; |
100 | 142 | |
— | — | @@ -253,14 +295,25 @@ |
254 | 296 | foreach ($events as $event) { |
255 | 297 | list($event_title, $other_text, $event_date, $color) = $event; |
256 | 298 | if ($event_date == $date_str) { |
257 | | - $event_name = str_replace('_', ' ', $event_title->getPrefixedDbKey()); |
258 | | - if ($color != '') { |
259 | | - $event_url = $event_title->getPrefixedDbKey(); |
260 | | - $event_str = '<a href="' . $event_url . '" style="color: ' . $color . '">' . $event_name . "</a>"; |
| 299 | + if ($this->mTemplate != '') { |
| 300 | + $templatetext = '{{' . $this->mTemplate . $other_text . '}}'; |
| 301 | + $templatetext = $wgParser->replaceVariables($templatetext); |
| 302 | + $templatetext = $wgParser->recursiveTagParse($templatetext); |
| 303 | + if ($color != '') { |
| 304 | + $text .= '<span style="color: ' . $color . '">' . $templatetext . '</span>'; |
| 305 | + } else { |
| 306 | + $text .= $templatetext; |
| 307 | + } |
261 | 308 | } else { |
262 | | - $event_str = $skin->makeLinkObj($event_title, $event_name); |
| 309 | + $event_name = str_replace('_', ' ', $event_title->getPrefixedDbKey()); |
| 310 | + if ($color != '') { |
| 311 | + $event_url = $event_title->getPrefixedDbKey(); |
| 312 | + $event_str = '<a href="' . $event_url . '" style="color: ' . $color . '">' . $event_name . "</a>"; |
| 313 | + } else { |
| 314 | + $event_str = $skin->makeLinkObj($event_title, $event_name); |
| 315 | + } |
| 316 | + $text .= "$event_str $other_text\n\n"; |
263 | 317 | } |
264 | | - $text .= "$event_str $other_text\n\n"; |
265 | 318 | } |
266 | 319 | } |
267 | 320 | $text .=<<<END |