r33491 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r33490‎ | r33491 | r33492 >
Date:16:51, 17 April 2008
Author:vrandezo
Status:old
Tags:
Comment:
Added DTStamp and Sequence to iCalendar export for proper versioning. Added iCalendar export as a proper part of SMW.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Query.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/languages/SMW_LanguageEn.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialICalendar.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialICalendar.php
@@ -2,13 +2,21 @@
33
44 if (!defined('MEDIAWIKI')) die();
55
 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+
618 global $IP;
719 include_once($IP . '/includes/SpecialPage.php');
820
9 -global $wgAutoloadClasses, $wgSpecialPages;
10 -$wgSpecialPages['ICalendar'] = array('SMWICalendarPage');
11 -
12 -
1321 /**
1422 * @author Markus Krötzsch
1523 * @author Denny Vrandecic
@@ -28,13 +36,13 @@
2937 */
3038 public function __construct() {
3139 smwfInitUserMessages();
32 - parent::__construct('ICalendar');
 40+ parent::__construct('ICalendar', '', false);
3341 }
3442
35 - function execute($p = '') {
 43+ function execute($query = '') {
3644 global $wgOut, $wgRequest, $smwgIP, $smwgQEnabled, $smwgRSSEnabled;
3745 wfProfileIn('doSpecialICalendar (SMW)');
38 - if ( ($wgRequest->getVal( 'query' ) != '') ) { // old processing
 46+ if ( ($wgRequest->getVal( 'query' ) != '') or ( $query == '') ) { // old processing
3947 $wgOut->addHTML('<br /> This is the special page for iCalendar exports.');
4048 wfProfileOut('doSpecialICalendar (SMW)');
4149 return;
@@ -45,7 +53,7 @@
4654 return;
4755 }
4856
49 - $this->extractQueryParameters($p);
 57+ $this->extractQueryParameters($query);
5058
5159 $this->makeICalendarResult();
5260
@@ -118,7 +126,7 @@
119127 if ( !array_key_exists('limit',$this->m_params) ) {
120128 $this->m_params['limit'] = $wgRequest->getVal( 'limit' );
121129 if ($this->m_params['limit'] == '') {
122 - $this->m_params['limit'] = 50; // magic number TODO
 130+ $this->m_params['limit'] = 200; // magic number TODO
123131 }
124132 }
125133 if ( !array_key_exists('offset',$this->m_params) ) {
@@ -135,8 +143,8 @@
136144 foreach ($this->m_printouts as $printout) {
137145 if ((strtolower($printout->getLabel()) == "start") and ($printout->getTypeID() == "_dat")) {
138146 $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';
141149 }
142150 if ((strtolower($printout->getLabel()) == "end") and ($printout->getTypeID() == "_dat")) {
143151 $newprintouts[] = $printout;
@@ -145,6 +153,17 @@
146154 $this->m_printouts = $newprintouts;
147155
148156 $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+
149168 $res = smwfGetStore()->getQueryResult($queryobj);
150169
151170 if (!array_key_exists('icalendartitle', $this->m_params)) {
@@ -164,20 +183,22 @@
165184 // for now we ignore everything but start and end
166185 // later we may add more things like a generic
167186 // mechanism to add whatever you want :)
 187+ // could include funny things like geo, location etc. though
168188 $req = $result->getPrintRequest();
169189 if (strtolower($req->getLabel()) == "start") {
170190 $content = $result->getContent();
171 - foreach ($content as $entry) {
 191+ foreach ($content as $entry) { // saves only the last one
172192 $startdate = $entry->getShortWikiText();
173193 }
174194 }
175195 if (strtolower($req->getLabel()) == "end") {
176196 $content = $result->getContent();
177 - foreach ($content as $entry) {
 197+ foreach ($content as $entry) { // saves only the last one
178198 $enddate = $entry->getShortWikiText();
179199 }
180200 }
181201 }
 202+ if ($page !== null) $wikipage = $page;
182203 $items[] = new SMWICalendarEntry($wikipage->getTitle(), $startdate, $enddate);
183204 $row = $res->getNext();
184205 }
@@ -207,7 +228,11 @@
208229 private $label;
209230 private $startdate;
210231 private $enddate;
 232+ private $sequence;
 233+ private $dtstamp;
 234+ private $lastmodified;
211235 private $title;
 236+ private $revid;
212237
213238 /**
214239 * Constructor for a single item in the feed. Requires the URI of the item.
@@ -219,9 +244,15 @@
220245 $this->label = $t->getText();
221246 $this->startdate = $this->parsedate($startdate);
222247 $this->enddate = $this->parsedate($enddate);
 248+
 249+ $this->sequence = $t->getLatestRevID();
 250+
 251+ $article = new Article($t);
 252+ $this->dtstamp = $this->parsedate($article->getTimestamp());
223253 }
224254
225255 static private function parsedate($d) {
 256+ if ($d=='') return '';
226257 return date("Ymd", strtotime(str_replace("&nbsp;", " ", $d))) . "T" . date("His", strtotime(str_replace("&nbsp;", " ", $d)));
227258 }
228259
@@ -230,13 +261,15 @@
231262 */
232263 public function text() {
233264 $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";
238272 $text .= "END:VEVENT\n";
239273 return $text;
240274 }
241275
242276 }
243 -
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Query.php
@@ -51,7 +51,7 @@
5252
5353 public function setDescription(SMWDescription $description) {
5454 $this->m_description = $description;
55 - foreach ($extraprintouts as $printout) {
 55+ foreach ($this->m_extraprintouts as $printout) {
5656 $this->m_description->addPrintRequest($printout);
5757 }
5858 $this->applyRestrictions();
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
@@ -31,7 +31,8 @@
3232 'template' => 'SMWTemplateResultPrinter',
3333 'count' => 'SMWListResultPrinter',
3434 'debug' => 'SMWListResultPrinter',
35 - 'rss' => 'SMWRSSResultPrinter');
 35+ 'rss' => 'SMWRSSResultPrinter',
 36+ 'icalendar' => 'SMWiCalendarResultPrinter');
3637
3738 /**
3839 * Parse a query string given in SMW's query language to create
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php
@@ -77,6 +77,7 @@
7878 $wgAutoloadClasses['SMWEmbeddedResultPrinter'] = $smwgIP . '/includes/SMW_QP_Embedded.php';
7979 $wgAutoloadClasses['SMWTemplateResultPrinter'] = $smwgIP . '/includes/SMW_QP_Template.php';
8080 $wgAutoloadClasses['SMWRSSResultPrinter'] = $smwgIP . '/includes/SMW_QP_RSSlink.php';
 81+ $wgAutoloadClasses['SMWiCalendarResultPrinter']= $smwgIP . '/includes/SMW_QP_iCalendar.php';
8182 //// datavalues
8283 $wgAutoloadClasses['SMWDataValue'] = $smwgIP . '/includes/SMW_DataValue.php';
8384 $wgAutoloadClasses['SMWDataValueFactory'] = $smwgIP . '/includes/SMW_DataValueFactory.php';
@@ -102,6 +103,9 @@
103104 $wgSpecialPages['URIResolver'] = array('SMWURIResolver');
104105 $wgAutoloadClasses['SMWAdmin'] = $smwgIP . '/specials/SMWAdmin/SMW_SpecialSMWAdmin.php';
105106 $wgSpecialPages['SMWAdmin'] = array('SMWAdmin');
 107+ $wgAutoloadClasses['SMWICalendarPage'] = $smwgIP . '/specials/AskSpecial/SMW_SpecialICalendar.php';
 108+ $wgSpecialPages['ICalendar'] = array('SMWICalendarPage');
 109+
106110 // suboptimal special pages using the SMWSpecialPage wrapper class:
107111 $wgAutoloadClasses['SMWSpecialPage'] = $smwgIP . '/includes/SMW_SpecialPage.php';
108112 $wgSpecialPages['Properties'] = array('SMWSpecialPage','Properties', 'smwfDoSpecialProperties', $smwgIP . '/specials/QueryPages/SMW_SpecialProperties.php');
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_LanguageEn.php
@@ -22,6 +22,8 @@
2323 'smw_baduri' => 'Sorry, URIs of the form “$1” are not allowed.',
2424 // Link to RSS feeds
2525 'smw_rss_link' => 'RSS',
 26+ // Link to iCalendar files
 27+ 'smw_icalendar_link' => 'iCalendar',
2628 // Messages and strings for inline queries
2729 'smw_iq_disabled' => "Sorry. Semantic queries have been disabled for this wiki.",
2830 'smw_iq_moreresults' => '&hellip; further results',

Status & tagging log