Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialICalendar.php |
— | — | @@ -2,13 +2,21 @@ |
3 | 3 | |
4 | 4 | if (!defined('MEDIAWIKI')) die(); |
5 | 5 | |
| 6 | +/** |
| 7 | + * TODO |
| 8 | + * |
| 9 | + * This page copies a lot of code from SMW_SpecialAsk.php, which sucks high |
| 10 | + * time. But we cannot keep adding such exporters to the SMW_SpeciaAsk file |
| 11 | + * (like the RSS exporter), it is easy to think of further exporters like a |
| 12 | + * for KML, VCard, Bibtext, and heck, even Java, Python, or such (anyone |
| 13 | + * cares about distributed literate programming?). So we obviously need |
| 14 | + * some structure to allow us to make this kind of exporters without such |
| 15 | + * spurious repetition, and then refactor the RSS and iCalendar code to it |
| 16 | + */ |
| 17 | + |
6 | 18 | global $IP; |
7 | 19 | include_once($IP . '/includes/SpecialPage.php'); |
8 | 20 | |
9 | | -global $wgAutoloadClasses, $wgSpecialPages; |
10 | | -$wgSpecialPages['ICalendar'] = array('SMWICalendarPage'); |
11 | | - |
12 | | - |
13 | 21 | /** |
14 | 22 | * @author Markus Krötzsch |
15 | 23 | * @author Denny Vrandecic |
— | — | @@ -28,13 +36,13 @@ |
29 | 37 | */ |
30 | 38 | public function __construct() { |
31 | 39 | smwfInitUserMessages(); |
32 | | - parent::__construct('ICalendar'); |
| 40 | + parent::__construct('ICalendar', '', false); |
33 | 41 | } |
34 | 42 | |
35 | | - function execute($p = '') { |
| 43 | + function execute($query = '') { |
36 | 44 | global $wgOut, $wgRequest, $smwgIP, $smwgQEnabled, $smwgRSSEnabled; |
37 | 45 | wfProfileIn('doSpecialICalendar (SMW)'); |
38 | | - if ( ($wgRequest->getVal( 'query' ) != '') ) { // old processing |
| 46 | + if ( ($wgRequest->getVal( 'query' ) != '') or ( $query == '') ) { // old processing |
39 | 47 | $wgOut->addHTML('<br /> This is the special page for iCalendar exports.'); |
40 | 48 | wfProfileOut('doSpecialICalendar (SMW)'); |
41 | 49 | return; |
— | — | @@ -45,7 +53,7 @@ |
46 | 54 | return; |
47 | 55 | } |
48 | 56 | |
49 | | - $this->extractQueryParameters($p); |
| 57 | + $this->extractQueryParameters($query); |
50 | 58 | |
51 | 59 | $this->makeICalendarResult(); |
52 | 60 | |
— | — | @@ -118,7 +126,7 @@ |
119 | 127 | if ( !array_key_exists('limit',$this->m_params) ) { |
120 | 128 | $this->m_params['limit'] = $wgRequest->getVal( 'limit' ); |
121 | 129 | if ($this->m_params['limit'] == '') { |
122 | | - $this->m_params['limit'] = 50; // magic number TODO |
| 130 | + $this->m_params['limit'] = 200; // magic number TODO |
123 | 131 | } |
124 | 132 | } |
125 | 133 | if ( !array_key_exists('offset',$this->m_params) ) { |
— | — | @@ -135,8 +143,8 @@ |
136 | 144 | foreach ($this->m_printouts as $printout) { |
137 | 145 | if ((strtolower($printout->getLabel()) == "start") and ($printout->getTypeID() == "_dat")) { |
138 | 146 | $newprintouts[] = $printout; |
139 | | - $this->m_params['sort'] = $printout->getTitle()->getText(); |
140 | | - $this->m_params['order'] = 'DESC'; |
| 147 | + //$this->m_params['sort'] = $printout->getTitle()->getText(); |
| 148 | + //$this->m_params['order'] = 'DESC'; |
141 | 149 | } |
142 | 150 | if ((strtolower($printout->getLabel()) == "end") and ($printout->getTypeID() == "_dat")) { |
143 | 151 | $newprintouts[] = $printout; |
— | — | @@ -145,6 +153,17 @@ |
146 | 154 | $this->m_printouts = $newprintouts; |
147 | 155 | |
148 | 156 | $queryobj = SMWQueryProcessor::createQuery($this->m_querystring, $this->m_params, false, '', $this->m_printouts); |
| 157 | + |
| 158 | + // figure out if this is a singletong query. if yes we need to save the |
| 159 | + // singleton for later use, as the query result will not include it. |
| 160 | + $page = null; |
| 161 | + if ($queryobj->getDescription()->isSingleton()) { |
| 162 | + $desc = $queryobj->getDescription(); |
| 163 | + if ($desc instanceof SMWValueDescription) { |
| 164 | + $page = $desc->getDataValue(); |
| 165 | + } |
| 166 | + } |
| 167 | + |
149 | 168 | $res = smwfGetStore()->getQueryResult($queryobj); |
150 | 169 | |
151 | 170 | if (!array_key_exists('icalendartitle', $this->m_params)) { |
— | — | @@ -164,20 +183,22 @@ |
165 | 184 | // for now we ignore everything but start and end |
166 | 185 | // later we may add more things like a generic |
167 | 186 | // mechanism to add whatever you want :) |
| 187 | + // could include funny things like geo, location etc. though |
168 | 188 | $req = $result->getPrintRequest(); |
169 | 189 | if (strtolower($req->getLabel()) == "start") { |
170 | 190 | $content = $result->getContent(); |
171 | | - foreach ($content as $entry) { |
| 191 | + foreach ($content as $entry) { // saves only the last one |
172 | 192 | $startdate = $entry->getShortWikiText(); |
173 | 193 | } |
174 | 194 | } |
175 | 195 | if (strtolower($req->getLabel()) == "end") { |
176 | 196 | $content = $result->getContent(); |
177 | | - foreach ($content as $entry) { |
| 197 | + foreach ($content as $entry) { // saves only the last one |
178 | 198 | $enddate = $entry->getShortWikiText(); |
179 | 199 | } |
180 | 200 | } |
181 | 201 | } |
| 202 | + if ($page !== null) $wikipage = $page; |
182 | 203 | $items[] = new SMWICalendarEntry($wikipage->getTitle(), $startdate, $enddate); |
183 | 204 | $row = $res->getNext(); |
184 | 205 | } |
— | — | @@ -207,7 +228,11 @@ |
208 | 229 | private $label; |
209 | 230 | private $startdate; |
210 | 231 | private $enddate; |
| 232 | + private $sequence; |
| 233 | + private $dtstamp; |
| 234 | + private $lastmodified; |
211 | 235 | private $title; |
| 236 | + private $revid; |
212 | 237 | |
213 | 238 | /** |
214 | 239 | * Constructor for a single item in the feed. Requires the URI of the item. |
— | — | @@ -219,9 +244,15 @@ |
220 | 245 | $this->label = $t->getText(); |
221 | 246 | $this->startdate = $this->parsedate($startdate); |
222 | 247 | $this->enddate = $this->parsedate($enddate); |
| 248 | + |
| 249 | + $this->sequence = $t->getLatestRevID(); |
| 250 | + |
| 251 | + $article = new Article($t); |
| 252 | + $this->dtstamp = $this->parsedate($article->getTimestamp()); |
223 | 253 | } |
224 | 254 | |
225 | 255 | static private function parsedate($d) { |
| 256 | + if ($d=='') return ''; |
226 | 257 | return date("Ymd", strtotime(str_replace(" ", " ", $d))) . "T" . date("His", strtotime(str_replace(" ", " ", $d))); |
227 | 258 | } |
228 | 259 | |
— | — | @@ -230,13 +261,15 @@ |
231 | 262 | */ |
232 | 263 | public function text() { |
233 | 264 | $text = "BEGIN:VEVENT\n"; |
234 | | - $text .= "SUMMARY=$this->label\n"; |
235 | | - $text .= "URL=$this->uri\n"; |
236 | | - $text .= "DTSTART=$this->startdate\n"; |
237 | | - if ($this->enddate !== "") $text .= "DTEND=$this->enddate\n"; |
| 265 | + $text .= "SUMMARY:$this->label\n"; |
| 266 | + $text .= "URL:$this->uri\n"; |
| 267 | + $text .= "UID:$this->uri\n"; |
| 268 | + if ($this->startdate !== "") $text .= "DTSTART:$this->startdate\n"; |
| 269 | + if ($this->enddate !== "") $text .= "DTEND:$this->enddate\n"; |
| 270 | + $text .= "DTSTAMP:$this->dtstamp\n"; |
| 271 | + $text .= "SEQUENCE:$this->sequence\n"; |
238 | 272 | $text .= "END:VEVENT\n"; |
239 | 273 | return $text; |
240 | 274 | } |
241 | 275 | |
242 | 276 | } |
243 | | - |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Query.php |
— | — | @@ -51,7 +51,7 @@ |
52 | 52 | |
53 | 53 | public function setDescription(SMWDescription $description) { |
54 | 54 | $this->m_description = $description; |
55 | | - foreach ($extraprintouts as $printout) { |
| 55 | + foreach ($this->m_extraprintouts as $printout) { |
56 | 56 | $this->m_description->addPrintRequest($printout); |
57 | 57 | } |
58 | 58 | $this->applyRestrictions(); |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php |
— | — | @@ -31,7 +31,8 @@ |
32 | 32 | 'template' => 'SMWTemplateResultPrinter', |
33 | 33 | 'count' => 'SMWListResultPrinter', |
34 | 34 | 'debug' => 'SMWListResultPrinter', |
35 | | - 'rss' => 'SMWRSSResultPrinter'); |
| 35 | + 'rss' => 'SMWRSSResultPrinter', |
| 36 | + 'icalendar' => 'SMWiCalendarResultPrinter'); |
36 | 37 | |
37 | 38 | /** |
38 | 39 | * Parse a query string given in SMW's query language to create |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php |
— | — | @@ -77,6 +77,7 @@ |
78 | 78 | $wgAutoloadClasses['SMWEmbeddedResultPrinter'] = $smwgIP . '/includes/SMW_QP_Embedded.php'; |
79 | 79 | $wgAutoloadClasses['SMWTemplateResultPrinter'] = $smwgIP . '/includes/SMW_QP_Template.php'; |
80 | 80 | $wgAutoloadClasses['SMWRSSResultPrinter'] = $smwgIP . '/includes/SMW_QP_RSSlink.php'; |
| 81 | + $wgAutoloadClasses['SMWiCalendarResultPrinter']= $smwgIP . '/includes/SMW_QP_iCalendar.php'; |
81 | 82 | //// datavalues |
82 | 83 | $wgAutoloadClasses['SMWDataValue'] = $smwgIP . '/includes/SMW_DataValue.php'; |
83 | 84 | $wgAutoloadClasses['SMWDataValueFactory'] = $smwgIP . '/includes/SMW_DataValueFactory.php'; |
— | — | @@ -102,6 +103,9 @@ |
103 | 104 | $wgSpecialPages['URIResolver'] = array('SMWURIResolver'); |
104 | 105 | $wgAutoloadClasses['SMWAdmin'] = $smwgIP . '/specials/SMWAdmin/SMW_SpecialSMWAdmin.php'; |
105 | 106 | $wgSpecialPages['SMWAdmin'] = array('SMWAdmin'); |
| 107 | + $wgAutoloadClasses['SMWICalendarPage'] = $smwgIP . '/specials/AskSpecial/SMW_SpecialICalendar.php'; |
| 108 | + $wgSpecialPages['ICalendar'] = array('SMWICalendarPage'); |
| 109 | + |
106 | 110 | // suboptimal special pages using the SMWSpecialPage wrapper class: |
107 | 111 | $wgAutoloadClasses['SMWSpecialPage'] = $smwgIP . '/includes/SMW_SpecialPage.php'; |
108 | 112 | $wgSpecialPages['Properties'] = array('SMWSpecialPage','Properties', 'smwfDoSpecialProperties', $smwgIP . '/specials/QueryPages/SMW_SpecialProperties.php'); |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_LanguageEn.php |
— | — | @@ -22,6 +22,8 @@ |
23 | 23 | 'smw_baduri' => 'Sorry, URIs of the form “$1” are not allowed.', |
24 | 24 | // Link to RSS feeds |
25 | 25 | 'smw_rss_link' => 'RSS', |
| 26 | + // Link to iCalendar files |
| 27 | + 'smw_icalendar_link' => 'iCalendar', |
26 | 28 | // Messages and strings for inline queries |
27 | 29 | 'smw_iq_disabled' => "Sorry. Semantic queries have been disabled for this wiki.", |
28 | 30 | 'smw_iq_moreresults' => '… further results', |