Help:Categories

From Lockwiki
Jump to: navigation, search

Help:Categories

Categories are a software feature of MediaWiki, which enables pages to be added to automatic listings. These help structure a project such as Lockwiki by grouping together pages on similar subjects.

Contents


Summary

The MediaWiki software maintains tables of categories, to which any editable page can be added. To add a page to a category, include "[[Category:Category name]]" or "[[Category:Category name|Sortkey]]" in that page's source. The categories to which a page belongs appear in a box at the bottom of the page.

A category is usually associated with a category page in the "Category:" namespace. A category page contains text that can be edited, like any other page, but when the page is displayed it includes an automatically generated list of links to all pages in that category. Other category pages which appear in this list are treated separately, as subcategories.

Putting pages in categories

A page belongs to a category if the page's wikitext contains a declaration for that category. A category declaration takes the form [[Category:Category name]] or [[Category:Category name|Sortkey]]. The declaration must be processed, i.e. it will not work if it appears between <nowiki>...</nowiki> or <includeonly>...</includeonly> tags, or in a comment. The declaration may however come from a transcluded page; see Categories in templates below.

A category name can be any string which would be a legitimate page title. It cannot begin with a lower-case letter. If the category name given in a category declaration begins with a lower-case letter, then it is interpreted as if it were capitalized.

In Lockwiki, it is customary to place category declarations at the end of the wikitext, but before any stub templates (which themselves transclude categories).

When a page has been added to one or more categories, a categories box appears at the bottom of the page. This box contains a list of the categories the page belongs to, in the order in which the category declarations appear in the processed wikitext. The category names are linked to the corresponding category pages. They appear as red links if no category page currently exists.

Hidden categories are not displayed, except as described below under Hiding categories.

To link to a category page without putting the current page in that category, precede the link with a colon: [[:Category:Category name]]. Such a link can be piped like a normal wikilink.

Category pages

A category page is a page in the "Category:" namespace. The page "Category:Name" corresponds to the category called "Name". New category pages can be created like any other pages – by clicking on redlinks or entering the name in the search box and clicking "Go".

A category page can be edited like any other page. However, when it is displayed, the editable part of the page is followed by automatically generated lists of pages belonging to the category, as follows:

  • First a count and list of subcategories (other category pages belonging to the category) is shown, if any exist. The name of each subcategory is followed by a count of its own subcategories. These further subcategories are displayed if the "+" sign alongside the subcategory is clicked.
  • Next a count and list of pages in the category (excluding subcategories and images) is shown. If the category has no members, a message to that effect is displayed.
  • Next a count and list of image and other media files in the category appears, if any exist. These are shown with thumbnails. The first 20 characters of the file name are shown, with an ellipsis if that is not the full name; also the file size is shown.

The items in the lists all link to the pages concerned; in the case of the images this applies both to the image itself and to the text below it (the name of the image).

For the way in which the lists are ordered, see Sort order below. The first and second lists are divided into sections, according to the first character of the sort key. These initial characters are displayed above the sections. To suppress these, make all sort keys start with a space.

A category page can only display a limited number of items (currently 200). If more pages belong to the category, there will be a link to the next ones.

The categories box for the category page appears at the bottom, in the same place as for other pages. This contains the categories to which the current category page has been added, i.e. its parent categories (the categories of which it is a subcategory). Add a category page to other categories in the normal way, using the "[[Category:Category name]]" or "[[Category:Category name|Sortkey]]" syntax.

Hiding categories

When the magic word __HIDDENCAT__ is placed on a category page, that category becomes hidden, meaning that it will not be displayed on the pages belonging to that category. This feature is mostly used to prevent project maintenance categories from showing up to ordinary readers on article pages.

However, hidden categories are displayed (although listed as hidden):

  • on category pages;
  • at preview during editing;
  • if the user has selected "Show hidden categories" in user preferences.

When listed as subcategories on other category pages, hidden categories appear normally.

Hidden categories are automatically added to Category:Hidden categories.

Sort order

The system uses alphabetical order, or more precisely Unicode order, for pages in categories. The range 32–127 corresponds to ASCII:

 !"#$%&'()*+,-./0123456789:;<=>?
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
'abcdefghijklmnopqrstuvwxyz{|}~

Note in particular that "Z" comes before "a", and "z" before accented/umlauted characters.

Unlike at Special:Allpages and Special:Prefixindex, a space is treated as a space (coming before all other characters), not as an underscore.

Each of the three lists is arranged in the order explained above (except that in the subcategories list, the namespace indicator "Category:" is not considered). If you want an item in a list to be positioned in that order, based on an alternative name (sort key) for that item, then this can be specified in the category tag that places the item in the list:

[[Category:Category name|Sortkey]]

For example to add an article called Albert Einstein to the category "people" and have the article sorted by "Einstein, Albert", you would type "[[Category:People|Einstein, Albert]]".

Although this is like the syntax for a piped link (and in an edit summary it is interpreted like one), there is a clear difference: the second term in the piped link is an alternative term for the first one, while the sort key is an alternative name for the page in which the tag occurs. The name actually displayed is the name of the article, not the sort key. Also, a piped link influences the rendering of the page itself, while a sort key affects the rendering of another page.

It is useful to document the system being used for sort keys on the category page.

Default sort key

It is possible to set a default sort key which is different from {{PAGENAME}} by using the magic word {{DEFAULTSORT}} thus:

{{DEFAULTSORT:new key}}

In the case of multiple default sort key tags, the last one on a page applies for all categories, regardless of the position of the category tags. This also means that a DEFAULTSORT tag in a template, intended for category tags in that template, for categorization of pages calling the template, is not effective if another DEFAULTSORT tag occurs later on these pages, even if it is also "hidden", in another template.

Categories and templates

A template can be used to add pages to a category, usually by placing the category link inside <includeonly></includeonly> tags on the template (e.g. <includeonly>[[Category:category name]]</includeonly>). When the template is transcluded into the page, the category link becomes active, and the page is added to the category page. This is useful for categories that have high turnover or many pages included, like cleanup categories.

Changes to the template, however, may not be reflected immediately on the category page. When you edit an article to add a category tag directly, the list of category members is updated immediately when the page is saved. When a category link is contained in a template, however, this does not happen immediately: instead, whenever a template is edited, all the pages that transclude it are put into the job queue to be recached during periods of low server load. This means that, in busy periods, it may take hours or even days before individual pages are recached and they start to appear in the category list. Performing a null edit to a page will allow it to jump the queue and be immediately recached.

To add the template itself to the category page as well, omit the "includeonly" tags. To add the template to a category without categorizing pages on which the template is transcluded, place the category declaration between <noinclude>...</noinclude> tags.

Parser functions can be used to make the transcluded categories, or the sort key used in them, dependent on other variables, notably PAGENAME.

Passing a category by parameter
<includeonly>[[Category:{{{cat|default}}}]]</includeonly> or <includeonly>{{{cat|[[Category:default]]}}}</includeonly>
If the user provides a parameter 'cat=XXX' the page will be categorized at the page [[Category:XXX]], otherwise it will be categorized at the page [[Category:default]]. Calling the template with "cat=" (equal to nothing) disables putting the page in any category.
Excluding non-article pages
<includeonly>{{#if:{{NAMESPACE}} | | [[Category:XXX]]}}</includeonly>
the variable NAMESPACE is null for mainspace articles. For any space other than mainspace, this ParserFunction will produce an empty string, but for regular articles this will include the article in Category:XXX.

Categorizing redirect pages

Redirect pages can be categorized. The category tag has to be put in the first paragraph. In the case that the target of the redirect is a section this has to some extent the effect of categorizing the section: through the redirect the category page links to the section; however, unless an explicit link is put, the section does not link to the category.

On a category page, redirects are listed in italics.

Moving and redirecting category pages

The only way to move a category page is to manually change all category tags that link to the category, and copy the editable part. There is no automatic way to move a category page in the way one moves an article page. For categories entirely populated through templates (see above) modifying the templates allows to move all affected articles to a renamed category, but with the refresh problem mentioned.

Redirecting a category page is possible, but will not cause pages to be recategorized from the redirected category to the target. On Lockwiki soft redirects are preferred for categories, and bots are used to move the pages from redirected categories.

Applying "Related Changes" to a category

For a category the "Related Changes" feature gives the changes in the pages in the category (according to the current category page, so excluding the pages that have potentially been added and including those that have potentially been removed, through addition or deletion of a template to/from the category, as explained above)

  • for subcategories: the changes in their editable parts only
  • for images (image pages): the changes in their editable parts only.

It does not show the changes in pages linked from the editable parts of the category. Possible workarounds:

  • The editable part can be put in a template. The category tags (which have no effect on Related Changes anyway) can better be kept out of the template, because on the pages of these supercategories the template would be listed under the articles in those categories. Whether interwiki links (with or without interlanguage link feature) are in the template or not does not make a difference, provided that the template is not used elsewhere.
  • Related Changes is applied to a page that calls the category as a template: {{:Category:Category name}}; only the editable part is included in the page; the page could be specially created for this purpose and call multiple categories. However, this page will then be listed in the supercategory pages of each category.

As usual (but as opposed to a watchlist) the changes in the corresponding talk pages are not shown.

Applying "Related Changes" to a category, with sufficiently high limits on number and days, is also useful for checking which pages in a category one "watches": they are bolded.

If the category contains pages but does not "exist" as editable page, "Related Changes" can be applied, but no link is supplied, one has to supply the URL oneself. It is more convenient to "create" the page first.

For the "What links here" feature, only the links in the editable part of the page count, not the links to the pages in the category.

Detection of additions to a category

With "Related Changes" one can find pages which are newly in a category due to addition of a category tag or the tag of a template that is in the category. Addition of pages through addition to the category of a template is seen indirectly: one can see the change in the template, and then check which pages call the template. This even shows pages which are only potentially in the category (see above).

Unfortunately there is no similar way to detect a deletion from a category.

Comparison with "What links here"

Backlinks are often used as a by-product of links and inclusions. However, links and inclusion tags can be put specially for the backlinks, just like category tags are.

Thus one can create a kind of "category abc" showing its content with [[Special:Whatlinkshere/abc]] without an entry in the category lists on each page in the category. With inclusion this can be done in two ways:

  • {{#if:|{{:abc}}}} rendering nothing. This works regardless of whether [[abc]] exists.
  • {{:abc}}. This requires creating a blank page to render nothing, or a page with some content to provide an in-page category listing.
In the case of links
  • A redirect corresponds to a supercategory.
Advantages of categories
  • Category listings are alphabetical, for "What links here" this typically applies for the first part only, for the pages already linking to the given page at the time of the last rebuilding of the link tables in the database.
  • Categories have an editable part (however, there is anyway a talk page)
  • A category can have multiple supercategories
Advantage of a pseudo-category system using backlinks
  • Backlinks can show a tree structure: not only pages and subcategories, but also the contents of the subcategories (for each a list of pages and a list of sub-subcategories) and the contents of the sub-subcategories (for each a list of pages and a list of sub-sub-subcategories), but not the contents of the sub-sub-subcategories, up to three levels are shown.
In the case of inclusions
  • also multiple supercategories are possible
  • combined content of subcategories is shown in one list, not grouped by subcategory (the tree structure is not shown, but it can be used by taking the backlinks at a lower node, showing the smaller set)
  • the restriction of three levels (in the case of using redirects) does not apply; for example page Aijkl in the category Aijk in the category Aij in the category Ai in the category A (represented by Aijkl calling template Aijk, etc.) can be shown in the list of pages in category A (the backlinks of template A).

See also

Personal tools