Hi Dave,

This looks great. I tested it out, and it seemed to work fine, other than the lack of handling for the "link" parameter, which you noted; I don't think that's a major problem, though. I checked your changes in, so they're now officially part of the Calendar format. Thanks for your contribution! And welcome to the wonderful world of PHP, MediaWiki and SMW programming. :)

-Yaron


On Tue, Feb 24, 2009 at 8:53 PM, Dave Loomer <dloomer@gmail.com> wrote:
Thanks Yaron.  This was a pretty good experience -- I used
SMW_QP_List.php as my guide, and had some troubles along the way due
to some differences between it and the current SRF_Calendar (listed
below), but I figured it out I think.  I also ended up re-using your
code for formatting date output based on whether the SMW version is
1.4 or higher (another note on that below), so I broke that into its
own function.

Next I'll do the same for the Timeline format, and will also create a
third format like Google Calendar's "agenda" view which lists events
vertically, grouped by date.  That is, unless someone knows of an
output format just like this which already exists.


To list some of the challenges I encountered along the way, mostly to
call out areas of my changes that should receive attention if
reviewing the code:

- SRF_Calendar overrides getResult, and streamlines it considerably,
while SMW_QP_List just yields to the base class method.  The base
class method is where all of the parsing of the template text takes
place (calls to $wgParser->replaceVariables and
$wgParser->recursiveTagParse).  I found I couldn't just put the
template-parsing code in the overriden method, because it ended up
escaping some non-MediaWiki-compliant HTML such as anchor and input
tags.  Basically, as far as I can tell getResult needs to treat the
entire body of generated text as either HTML or Wiki Text, and not
both unless all the embedded HTML is MediaWiki-compliant (again, not
the case for SRF_Calendar).  So, I moved the calls to
$wgParser->replaceVariables and $wgParser->recursiveTagParse into the
displayCalendar method, calling them each time it encounters template
code, operating only on that chunk of code (of course, if a template
was not specified in the calling page/template, it just generates a
URL for the given result as it used to).
- Along with the above, I put a <span> around the generated template
text with a color specified when $color is defined.  I haven't been
able to test this to make sure it works properly.
- If the calendar format is specified with "link=none" it has no
effect.  I wasn't sure how best to do this.  I tried mimicking the way
it's done in SMW_QP_List (calling $this->getLinker instead of just
referencing $skin when specifying arguments for getShortText() and
getLongText()) but had issues.  The way it is is useful to me, though.

Also -- a note on the existing code for formatting date output.  I
kept it as-is, but in cases where SMW is not 1.4 or greater, that
branch of the logic references a variable $event_date which I don't
believe will be defined (both in the current and new SRF_Calendar
versions).  Maybe it should reference $object instead, but I decided
not to touch it.



On Sun, Feb 22, 2009 at 5:51 PM, Yaron Koren <yaron57@gmail.com> wrote:
> It's true that the Calendar format doesn't support the 'template' parameter,
> and it's also true that such support would be very useful. No need to create
> a separate Calendar format; if you were to add in handling of templates to
> the existing code, and send your new version to this list, I (or someone
> else) would be very happy to add that in to the official code. Such a
> project might be a good introduction to PHP (and MediaWiki and SMW)
> programming, since it seems like it would be pretty straightforward; mostly
> a matter of copying existing code from SMW and adding it in to the Calendar
> format.
>
> -Yaron
>
>
> On Sun, Feb 22, 2009 at 3:58 PM, David Loomer <dloomer@gmail.com> wrote:
>>
>> I'm having a hard time getting a handle of the options available in using
>> the
>> Calendar and Timeline result formats for an inline query.  As far as I can
>> tell, the Calendar format for example has a "limit" parameter option --
>> and
>> that's it.  That's all that seems documented at
>> http://semantic-mediawiki.org/wiki/Help:Calendar_format, at least.
>>
>> What I'm getting at is: by default, the Calendar format shows each result
>> simply as the name of the page (namespace included) corresponding to the
>> given result for the text linking to the page.  I'd like to have more
>> control over this display, per the "|template=" option I have with other
>> display formats (such as "ul", for instance).  However, when I insert
>> "|template=MyTemplate" nothing is changed, and the list of templates used
>> shown during Edit mode does not list MyTemplate as one of the templates
>> used.
>>
>> At the very least I'd like the option of showing the text of the link
>> without the namespace, which in my particular case creates clutter, but
>> ideally I'd have much more than that, i.e., I would like to build my own
>> test for display using properties on the page itself, using a template.
>>
>> Is this possible?  Or should I just learn PHP (not a stretch for me) and
>> build my own custom Calendar format?
>> --
>> View this message in context:
>> http://www.nabble.com/Use-templates-for-formatting-of-results-in-Calendar-and-Timeline--tp22150785p22150785.html
>> Sent from the Semantic Mediawiki - User mailing list archive at
>> Nabble.com.
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco,
>> CA
>> -OSBC tackles the biggest issue in open source: Open Sourcing the
>> Enterprise
>> -Strategies to boost innovation and cut costs with open source
>> participation
>> -Receive a $600 discount off the registration fee with the source code:
>> SFAD
>> http://p.sf.net/sfu/XcvMzF8H
>> _______________________________________________
>> Semediawiki-user mailing list
>> Semediawiki-user@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/semediawiki-user
>
>