Working With MediaWiki
“carousel”, which lets users use buttons to scroll back and forth through the different pages.
incoming — shows the incoming properties pointing to each page in the results.
Semantic Compound Queries
One thing the #ask parser function can’t do is display the results of more than one query at the same time. There are various circumstances when it makes sense to do that, but the most common is to display multiple sets of points on the same map, with a different marker for each set. For that, you’d need to use the Semantic Compound Queries extension, and the parser function it defines, #compound_query.
As an example, let’s say you want to show a map of all hospitals and banks in a city. Displaying a map requires the Semantic Maps extension (see here ). In our map, hospitals will get a red-cross icon, while banks get a dollar sign — we’ll say that the city is in some country that uses dollars. To complicate things, on the wiki, pages for hospitals have their own category, "Hospitals", while pages for banks are part of the general category "Businesses", with a value of "Bank" for the property "Has business type". Figure 18.5 shows an example of how such a map could appear.
Figure 18.5 Map created using Semantic Compound Queries and the ’googlemaps’ format
The first thing you would need to do is upload images for the icons you want to display. Let’s say you upload images for the two icons shown in Figure 18.5, and name them "Red cross.png" and "Dollar sign.png".
The call to #compound_query would then look like:
{{#compound_query:
[[Category:Hospitals]] ;?Has coordinates ;icon=Red cross.png
|[[Category:Businesses]][[Has business type::Bank]] ;?Has coordinates ;icon=Dollar sign.png
|format=googlemaps
|height=200
|width=400
}}
The syntax for #compound_query consists of, essentially, combining several #ask queries into one call. The parameters of each #ask query are turned into sub-parameters instead, separated by semicolons instead of pipes. Parameters relating to the display are kept as full parameters, since they’re only called once.
The two geographical-coordinates properties being displayed in the query are in this both called “Has coordinates” here, but they could theoretically have different names.
What if we want to add to our map a third set of points, for all businesses that aren’t banks, each point represented with a picture of a building? Thankfully, #compound_query makes it easy to do that: pages that are covered by more than one of the sub-queries are only displayed by the first sub-query that they apply to. So as long as the more specific queries are included before the general ones, the last query or queries can serve as a catch-all for everything that didn’t fit previously. Here’s how you could do it:
{{#compound_query:
[[Category:Hospitals]] ;?Has coordinates ;icon=Red cross.png
|[[Category:Businesses]][[Has business type::Bank]] ;?Has coordinates ;icon=Dollar sign.png
|[[Category:Businesses]] ;?Has coordinates ;icon=Office building.png
|format=googlemaps
|height=200
|width=400
}}
Besides maps, the other somewhat common application of Semantic Compound Queries is to display multiple types of events on calendars, each of which can be differently color-coded. As an example, to display meetings and task deadlines on the same calendar, with meetings in blue and deadlines in orange, you could call the following:
{{#compound_query:
[[Category:Meetings]]
[[Has date::>{{#calendarstartdate:}}]]
[[Has date::<{{#calendarenddate:}}]]
;?Has date ;color=blue
|[[Category:Tasks]]
[[Has deadline::>{{#calendarstartdate:}}]]
[[Has deadline::<{{#calendarenddate:}}]]
;?Has deadline ;color=orange
|format=calendar
|height=200
|width=400
}}
Figure 18.6 shows what such a query could generate.
Figure 18.6 A calendar created using Semantic Compound Queries and the ’calendar’ format
Compound queries can also be used for more basic formats like tables and lists, though in practice that’s rarely done.
You can read more about Semantic Compound Queries here:
https://www.mediawiki.org/wiki/Extension:Semantic_Compound_Queries
19 Additional Semantic MediaWiki functionality
There are over 50 extensions that require Semantic MediaWiki. Many are unmaintained or obsolete, so that number gives a false impression, but nevertheless there is a variety of interesting SMW-related functionality that hasn’t been covered yet in this book. In this chapter we’ll briefly go over some of
Weitere Kostenlose Bücher