Languages |
Help:CategoryA category is a software feature of MediaWiki. Categories provide automatic indexes that are useful as tables of contents. Together with links and templates they structure a project. SummaryEach of the pages in the Category namespace represents a so-called category, a kind of grouping of related pages. For example, this page belongs to "Category:Editor handbook". When a page belongs to one or more categories, this information appears at the bottom of the page (or in the upper-right corner, depending on the skin being used). The page of the category contains text that can be edited, like any other page, but when displaying the page, the last part of what is displayed is an automatically generated, alphabetical list of all pages in that category, in the form of links (in fact ASCII order, see Help:Special page). "Existence" of a category has two independent aspects: the category can obtain one or more pages and/or the category page can exist as an editable page. New categories can be created in the last sense, and edited, in the same way as any other regular page. For a list of categories in this sense, see Special:Allpages/Category: (note the colon at the end). For a list of categories in the first sense, see Special:Categories. You can assign a category to a page simply by adding "[[Category:Category name]]" to the page's wikitext source. In order to reference a category within a page as a normal wiki link (without adding the page to the category) prefix the link name with a colon. For example: [[:Category:Not in this category]] For a complete list of categories, see Special:Categories. Individual wikis may have their own top-level categories, such as w:Category:Contents in Wikipedia. For categories in Meta-Wiki, see m:Meta:Categories. Putting an item in a categoryA page in any namespace can be put in a category by adding a category tag to the page (by convention, at the end of the page), e.g.: [[Category:Category name]] Substitute the actual name of the category in place of Category name. To be specific, in order to add an article called "Albert Einstein" to the category "People", you would edit the article and add "[[Category:People]]" (no quotes) into its page source somewhere. This lists the page on the appropriate category page automatically and also provides a link at the page to the category page, which is in the namespace "Category". Pages can be included in more than one category by adding multiple category tags. These links do not appear at the location where you inserted the tag, but at the page margin in a fixed place, depending on the skin (the bottom for MonoBook, the upper right corner for Standard). Category tags may be placed anywhere in the article, although they are typically added to the end of the article to avoid undesirable text display side effects. At Wikipedia, its policy provides that it should be put after the article text, but before any interlanguage links. Category links are displayed in the order they occur in the article, unlike the automatic ordering of lists in the category pages themselves (see below). Hidden categoriesWhen __HIDDENCAT__ is put on a category page, that category is not listed on pages thus categorised. See category:hidden category demo and hidden category demo for an example. However, hidden categories can be made visible by ticking the item The hidden categories that a page belongs to are listed using the label supplied by the message with id 'hiddencategories' (talk) when editing the page. Hidden categories are automatically added to the category specified by the message with id 'hidden-category-category' (talk). In this wiki it is Category:Hidden categories. Within the Category namespace, the hidden categories a category page belongs to are listed separately from the standard (non-hidden) categories it also belongs to, using the label specified by the message with id 'hidden-categories' (talk). [See category:hidden category demo 1.] For example, suppose a page is categorised under Category pageA category page consists of:
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). The first and second list each have a header for each first character, dispensed with if there are no entries for a header. If no headers are desired, use sort keys all starting with a blank space (see also below). The number of items in each list is shown at the top of each. On Meta and Wikipedia a redirect to a category shows the editable text only. To get the full page after being redirected, use the link "Image", or "Category", respectively. On Commons a redirect to a category gives the full page, but not the subcategories and pages in the redirect page (if that is also a category). Creating a category pageTo create a category page, one can e.g:
[[Category:Category name]] or:
[[:Category:Category name]] Placing the above text on working page will create the link you can use to edit your category page, and will display the link text as a normal wiki link without adding the page to the category. SubcategoriesCreating subcategories takes only a few additional steps. Adding a category tag to a category page makes the edited category a subcategory of the category specified in the tag. First create a new category page for the subcategory the same way you would make a regular category. For example, create [[Category:Soccer]]. Then go to the newly created category page and edit it. Add the category tag for the parent category (e.g. [[Category:Sports]]) to the page. In this example, the Soccer category would then be a subcategory of the Sports category. For a live example see Category:Demo_1 which is a subcategory of Category:Demo. Sort orderThe system uses alphabetical order, or more precisely Unicode order, for pages in categories. The range 32–127 corresponds to ASCII, for more see a table of Unicode characters:
!"#$%&'()*+,-./0123456789:;<=>?
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
'abcdefghijklmnopqrstuvwxyz{|}~
Note in particular that "Z" comes before "a", and "z" before accented / umlauted characters. Although in Special:Allpages and Special:Prefixindex a blank space within a page name is treated as an underscore, and therefore comes after the capitals, and before the lower case letters, this does not apply in category pages: there a space counts as space. Compare the order of Help:Demo1 and Help:Demo a (both without a specified sort key) on Category:Demo and [1]. Sort keyEach of the three lists is in the order explained above. 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|sort_key]] 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. Also, a piped link influences the rendering of the page itself, while a sort key affects the rendering of another page. The displayed name is not changed, and, unfortunately, only visible on the edit pages of the members of the category. An explanation of the sort key system used can be useful on the editable part of a category page. The sort key system should be obvious, otherwise the order seems random and items are hard to find. The system should either be consistently applied to all members of a category, or be such that the listings of members on which it is applied fit in well within the list of members for which no sort key is used. The latter is advisable for large, growing categories with many contributors. See also below. A common system is starting with the last name, then a comma and a space, and then the first name; note that any additions such as "Jr." should come at the end, otherwise the entry would come before the same without the addition, because a space comes before a comma. In e.g. w:Category:Denmark, the sort key of a page consists of the keywords, without "Danish" or "of Denmark", "in Denmark", etc. For the gallery of images in a category the prefix "Image:" is part of the default sort key. E.g. for Image:AlbertEinstein.jpg we can code
to sort the image between Image:D.. and Image:F.. without explicit sort key. If we code
it comes before all images without explicit sort key. The sort key is case sensitive, so a page with the tag [[Category:Foo|Zealand]] is sorted before one with the tag [[Category:Foo|amsterdam]]. This can be inconvenient, requiring a sort key in projects with case-sensitivity of the first character if one wants the A and the a together, but it may also be used to one's advantage: e.g., it allows sorting of the pages into two groups, one put in the range A-Z and one in a-z, using sort keys; see e.g. Category:Demo, where the help pages are put separately by using sort keys with lower-case "h". To get the order right, be consistent in punctuation and spacing. For example, "A Z" with two blank spaces comes before "A A" with one. An underscore in a sort key is distinct from a blank space. As seen from the ASCII sequence above, forcing items to the beginning or end can be done with a sort key starting with a space or ~, respectively. Another common sort key for the beginning of the list is the asterisk (*). To avoid case sensitive sorting results, with Aa coming after AZ, a sort key can be used which is not sensitive to the case of the page. For example, if the bulk of pages use default sorting, a sort key which is all lower case except the first character can be used (for AZ sort key Az), which can be produced automatically with {{ucfirst:{{lc:{{PAGENAME}}}}}}. Non-main namespacesFor some non-main namespaces, the namespace prefix may be included in the sort key the system uses if the category tag does not contain one. In this case, every page in those namespaces will appear under the same header, unless sort keys were given. For example, all pages in the Help namespace will be listed under H. To avoid this one can specify a sort key without the namespace prefix in the category tag. In some namespaces such as the Category namespace and Image namespace the sort key is without prefix, if not specified otherwise, to avoid listing all subcategories by default under the C or all images under I. In these namespaces this can be a reason to write explicit sort keys also without prefix. Default sort key[MW1.10+] 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. Grouping of pages by using sort keysIf e.g. in a list of people sort keys like "scientist Einstein, Albert" are used then all scientists are listed together under the "s". Unfortunately no separate heading "scientist(s)" is possible, and salesmen would be under the same heading. Alternatively "scientist" can have e.g. code K (to be explained in the editable part of the category page) and the sort key "K Einstein, Albert" is used. Labels in the list of imagesAs mentioned above, the first 20 characters of the image name are shown, with dots if that is not the full name. This can be inconvenient, e.g. in commons:Category:William-Adolphe Bouguereau most images have a name starting with "William-Adolphe Bouguereau (1825-1905) -", which are therefore all labeled "William-Adolphe Boug..." (see the last section of the category page). The full names are only shown in the hover box and the status bar, depending on the browser; in the latter possibly with codes such as "%28" for "(". Thus, looking up a name in the alphabetic list is cumbersome. It might have been better to start the names with the shorter "Bouguereau, " and then the title of the painting (unless the software will be improved later). Using templates to populate categoriesIf a template contains the code indicating that it is in a category, this not only puts that template in the category, but also the pages that include the template. The page that contains the template correctly lists the categories to which it belongs. However, adding or deleting a category tag in the template does not add or delete the listings on the category page of pages that use the template, until some edit is made in the page that uses the template. In other words:
Since adding or removing a category or template tag is obviously an edit there is only a complication when a page is indirectly added to or deleted from a category, through a change in a template the page uses. To refresh category pages with respect to the listing of a particular page (adding or deleting the entry), a null edit can be applied to that page: just applying section edit and saving without changes. Sort keyA sort key in a category tag in a template applies to the template as well as to the pages that use it, so it is only useful if it is variable. It can depend on a variable (notably PAGENAME), parameter, or the content of a template. Categorizing templates themselvesTo categorize templates themselves, without the pages that call them, one can use the <noinclude> tag, for example <noinclude>[[Category:category name]]</noinclude> Alternatively one can use e.g. {{#f0f1ff:{{FULLPAGENAME}}|Template:Editthispage|[[Category:category name|{{PAGENAME}}]]|}} Excluding templates and selected pages from categoriesTo add all pages containing a given template to a category, but not the template itself, one can use use: <includeonly>[[Category:category name]]</includeonly> Text between <includeonly> and </includeonly> will be processed and displayed only when the page is being included. However, since the template may be used for secondary purposes, such as adding a template intended for use in the main namespace to a user page, sandbox draft or internal wikispace catalogue page of templates, it is better to provide the option not to put a page calling the template in the category, e.g. with <includeonly>{{{category|[[Category:..]]}}}</includeonly> Calling the template with "category=" disables putting the page in the category. Note that the usual update problems apply -- if you change the categories inside a template, the categories of the referring pages won't be updated until those pages are edited. Categorizing redirect pagesRedirect 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 the category page redirects are displayed with class redirect-in-category, so they can be shown in e.g. italics; this can be defined in MediaWiki:Common.css. See also Wikipedia:Categorizing redirects. Moving a category pageThe 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. The editable first part of a category can be moved like any other page, but that won't move the subcategories, articles, and images in the second, third, and fourth part (see above). 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 almost certainly won't have the desired effect (it can be abused for other purposes). List of all categoriesSpecial:Categories provides an alphabetic list of all categories, with the number of members of each; this number does not include the content of the subcategories, but it includes the subcategories themselves, i.e., each counting as one. Comparing with http://meta.wikimedia.org/w/index.php?title=Special%3AAllpages&namespace=14 :
Visualizing category treeSpecial:CategoryTree enables you to visualize the tree structure of categories. The CategoryTree extension installed on MediaWiki allows in-page display of the tree. <categorytree mode=pages>Africa</categorytree> gives
Applying "Related Changes" to a categoryFor 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)
It does not show the changes in pages linked from the editable parts of the category. Possible workarounds:
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. Dynamic page listThe DynamicPageList2 extension provides a list of last edits to the pages in a category, or optionally, just the list of pages; the simpler DynamicPageList is installed on Meta and Wikinews; the version DPLforum is installed on Wikia, see http://www.wikia.com/wiki/Help:Forums . Detection of additions to a categoryWith "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:
Category considerationsEach page is typically in at least one category. It may be in more, but it may be wise not to put a page in a category and also in a more general category. Each category, except one top-level category, is typically in at least one higher level category. The category structure is (ideally) a multi-hierarchy with a single root category. All categories (except root category 1) should be contained in at least one other category, and there should be no cycles (i.e. a category should not contain itself, directly or indirectly). The category structure should reflect a hierarchy of concepts, from the most generic one down to the very specific. Check the conventionsCheck the conventions in a project and make yourself familiar with the categories in use before assigning pages and subcategories to categories and before creating new categories. It is not obvious whether a page like Amsterdam should be in category City (a description of a member of the category) or Cities (a description of the category as a set of pages). A convention for using one or the other is useful (e.g. on w:en), to avoid ending up with both, with part of the applicable pages in one, and part in the other. Putting a category tag on a test page, user page, etc. (also if done indirectly by including a template with a category tag) is considered to pollute the category, while regular links from such pages showing up in "what links here" is considered harmless. Therefore:
Alternatives for overviewsIn addition to the automatic lists of pages and images, an overview of links to pages or images (by means of thumbnails) can be put in the editable part of a category, just like in any page. This used to be widely used in Wikimedia Commons, but now most of such overviews are moved to article namespaces. See also commons:Commons:Images on normal pages or categories:Vote. ExtensionsCategory intersection, union, etc.Various MediaWiki extensions allow intersection of categories, union of categories, display of info about the pages in a category, and more:
They all also allow further restriction to a namespace; some allow also restriction to a union of namespaces, or the complement of a union of namespaces. They all allow the info to be displayed in any page, not just a separate category page. See also w:Wikipedia:Category intersection. Category flatteningCategory flattening is displaying also the articles in a category's subcategories, sub-subcategories, etc. See also m:Category flatten, and [2]. Wikipedia-specific helpNone. This page is a copy of the master help page at Meta (for general help information all Wikimedia projects can use), with two Wikipedia-specific templates inserted. To update the main text, edit the master help page for all projects at m:Help:Category. For Wikipedia-specific issues, use Template:Ph:Category (the extra text at the bottom of this page) or Template:Phh:Category for a Wikipedia-specific lead (text appears at the top of this page). You are welcome to replace the full wikitext of this page with that of the master page at Meta at any time. To view this page in other languages see the master page at Meta. |