Working With MediaWiki
could then add to each such page a query listing all its “children”, i.e. all the places of interest that are listed as being in that area. In a wiki that holds information about museums, for example, we could, add to a page called "Santiago" a query like the following:
{{#ask:[[Category:Museums]][[Has city::Santiago]]}}
This makes it easy for users to see aggregated data without having to create queries or otherwise run a search: by simply going to the page called "Santiago", they can see the full list of museums there, formatted in a way that makes sense for this particular wiki (in addition to any specific information presented about Santiago).
If there’s any more than one or two cities, countries etc. in the wiki, it probably makes sense to create templates called “Country”, “City”, etc. to be used in those pages; and then to have each such template hold an aggregating query (in addition to any data we might want specifically about those places). Here’s a query that could go into a template called “City”:
{{#ask:[[Category:Museums]][[Has city::{{PAGENAME}}]]}}
Adding a call to the “City” template will then display, for any city, the set of museums in that city.
You can also perform what are called inverse queries, where you query on a property in its reverse direction (this can only be done for properties of type Page). Inverse queries are done by adding a “-” before the property name. They are usually not that useful, but in certain cases it can be. Some countries have more than one capital — South Africa has three, for instance — so you could do an inverse query on “Has capital” to list all of a country’s capitals, and information about each one. Here is a query to get all of the capitals of South Africa, and the total area of each of them:
{{#ask:[[-Has capital::South Africa]] |?Has total area}}
In addition to just querying on specific values, you can also do “greater than” or “less than” queries, using the operators “::>” and “::<” (though by default, these actually test for “greater than or equal” and “less than or equal”). Here’s how to get a list of countries, and their populations, for only countries with a population of greater than or equal to 10 million:
{{#ask:[[Category:Countries]][[Has population::>10000000]] |?Has population=Population |mainlabel=Country}}
And for String and Page properties, you can also use the “::~” operator to find partial string matches. Here’s how to get the set of countries with “New” in the name of their capital:
{{#ask:[[Category:Countries]][[Has capital::~*New*]] |?Has capital=Capital |mainlabel=Country}}
The “::~” check may or may not be case-sensitive, depending on the configuration of your database server.
There are various other standard parameters that you can add to #ask queries, to modify the set of results and their display:
format=
- sets the display format for the result (this is covered in depth in the next main section, “Display formats”).
limit=
- sets the number of pages to return (the default is usually 20).
sort=
- the property name, or names, on which to sort.
order=
- the order in which to sort values, if they’re sorted; should be
ascending
(which is the default),
descending
, or
random.
headers=
- whether the headers (by default, the property names) should be shown; the options are
show
(the default),
hide
, or
plain
, which shows headers but not as links.
mainlabel=
- the header given to the page names themselves; if this is set to “
-
”, the page names are not displayed.
link=
- sets what parts of results should be links — the options are
all
(the default),
none
, or
subject
, where only page names are links but printouts are not.
default=
- the default text printed if there are no results.
intro=
- introductory text printed, if there are results.
outro=
- concluding text printed, if there are results.
searchlabel=
- text for the “further results” link; by default, it’s “«… further results»”.
offset=
- the result number at which to start displaying (this is used for pagination, and is rarely included explicitly in queries).
Displaying individual values
#ask is geared for showing lists, tables and other aggregated displays. But what if you want to show just a single value? For that, there’s the #show parser function, which has a similar syntax to #ask, but a simpler one. The following call would simply display the text “Brasilia”, for
Weitere Kostenlose Bücher