Help:Calendar format

From semantic-mediawiki.org
Help:Calendar formatCalendar format/zh-hans
Calendar format
Displays time-associated pages on a calendar
Scenarios, examples, demos
Example: Calendar
Further Information
Provided by: Extension "Semantic Result Formats"
Added: 1.4.0
Removed: still supported
Requirements: none
Format name: calendar
Enabled? Indicates whether the result format is enabled by default upon installation of the respective extension. yes
Authors: Yaron Koren
Categories: time
Table of Contents

The result format calendar, part of the Extension "Semantic Result Formats" extension, can be used to display pages that have an associated time, for example events, on a calendar.

Starting with Semantic Result Formats 1.8, the eventcalendar format was introduced as a further alternative.

Parameters[edit]

Format specific
Parameter Type Default Description
lang text no The code for the language in which to display the calendar
template text empty The name of a template with which to display the printouts
userparam text empty A value passed into each template call, if a template is used
color text empty The color to mark calendar entries
colors text empty The color to display for each date property (example: "Start date=>green,End date=>#09c")
startmonth text 11 The month, the calendar display is initialized with (defaults to current month)
startyear text 2024 The year, the calendar display is initialized with (defaults to current year)

NoteNote:  Starting with Semantic Result Formats 2.2, this format also allows the specification of a particular year and month to be shown on the initial display. Thus, the "startmonth" and "startyear" parameters were introduced, which default to the current month and year if not specified.[1]

Usage[edit]

A query in calendar format should be called in the following way:

{{#ask:
  [[Category:Events]]
  [[Has date::>{{#calendarstartdate:}}]]
  [[Has date::<{{#calendarenddate:}}]]
  |?Has date
  |format=calendar
}}

...in other words, the date property being queried against should also be used to filter dates: #calendarstartdate (2024-10-27) and #calendarenddate (2024-12-01) will return a day a week earlier to the first and a day a weak after the last date for any specific month. This is done so that only those dates within the current month, including a week earlier and later, instead of all, are passed in to be displayed by the calendar.

Some notes on creating such queries:

  • Make sure to include the colon, ':', in the #calendarstartdate and #calendarenddate parser function calls; otherwise, they won't work.
    The #calendarstartdate and #calendarenddate parser functions do not work for annotations done with the #set_recurring_event parser function. Instead you need to define these dates using variables like {{CURRENTYEAR}}, {{CURRENTMONTH2}} and, or {{CURRENTDAY2}}, e.g.,{{CURRENTYEAR}}-{{CURRENTMONTH2}}-01, etc.
  • Don't worry that the comparison operators are '<' and '>' instead of '<=' and '>='; the return values of the parser functions are set so that this will not be an issue
  • You can also add a "sort=" parameter, like "sort=Has date," so that events within each day will be sorted according to the time they occur (assuming the "Has date" property in this case also includes a time value).

Display options[edit]

You can set the color the entries are marked with by adding the color option in the query:

|color=red

Different colors for each set of events can be displayed using Extension "Semantic Compound Queries".

The option template = <template name>, can be used to alter the display of a calendar item/event display:

|format=calendar
|template=''<...>''

For more information about the template used, see the help page on the template format

As of SRF 1.6.0, you can also set the day of the week on which weeks begin (by default, it's Sunday) across the entire wiki by setting the variable $srfgFirstDayOfWeek in LocalSettings.php, after the inclusion of Semantic Result Formats. To change it to Monday, for instance, you would add the following if using an English-language wiki:

$srfgFirstDayOfWeek = 'Monday';
NoteNote: The day has to be set in the wiki's language. Depending on the language, this value may also be capitalized, e.g., for German installations.

Changing the results limit[edit]

The default limit of results displayed by an inline query is 20. If you have more than 20 events in any month, you should add a 'limit=' parameter to the query with a number greater than the maximum number you have. An example is:

{{#ask:
  [[Category:Events]]
  [[Has date::>{{#calendarstartdate:}}]]
  [[Has date::<{{#calendarenddate:}}]]
  |?Has date
  |format=calendar
  |limit=300
}}
Result
MondayTuesdayWednesdayThursdayFridaySaturdaySunday
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1


Suppose the number of events you have in any month is greater than 500, though. In that case, you will need to take a second step - add the following line to your "LocalSettings.php" file after the inclusion of Semantic MediaWiki:

$smwgQMaxInlineLimit = 1000;
NoteNote: The value can be any number greater than the maximum number of events you have per month.


See also[edit]

References
  1. See this pull request for further information.



This documentation page applies to all SMW versions from 1.6.0 to the most current version.
Other versions: 1.4.0 – 1.5.6       Other languages: defrzh-hans