MediaWiki Categories Tutorial - How to create and manage categories in MediaWiki

How to create and manage categories in MediaWiki

In MediaWiki you can group pages (as well as media files) into categories. The category itself is also a page that can have some content, and that lists the pages that are in the category. Each page name in the list is a link to the particular page. The category can have subcategories, which in turn can have subcategories, and in this way you can create a hierarchical structure starting with a more general subject and going down to more specific topics. This is a useful and convenient way for organizing the content on your site. It also makes it easier for users to find articles on a particular subject or on related subjects.

When a page is added to a category, a link to that category is automatically added on the page. Usually it's put at the bottom of the page but this depends on the theme. Of course, the page is also automatically listed on the category page.

In this tutorial we'll show you:

Find and View Categories

MediaWiki comes preconfigured with a few special pages that display lists of the categories on your site. There's a page that lists the categories that have pages and/or subcategories assigned to them. There's another list that shows the existing categories that are empty, meaning that no pages and subcategories are added to them. And there's also a page that shows a list of categories that are not created but there are links on pages to categories with such names.

Of course, you can always use the search function on the site to look for a category.

  • To see a list of the the categories that contain pages and media go to Tools menu on the left>Special pages button>List of pages section>Categories button:
Button for Accessing the List of Categories Containing Pages

This will open a page that lists the categories that are not empty. This means that if a category contains pages and/or media, or even empty subcategories, it will be shown on this list. The list contains both the existing categories and those categories to which there are links on pages but that haven't been created. With the option at the top you can search for categories in the list. Each category name is also a link to that category. If the category doesn't exist the name will be in red and clicking on it will display the form for creating the category.

After the name of a category in the list you'll see in brackets the number of items it contains. Each subcategory to which the category is a direct parent is also counted as one item regardless of how many pages the subcategory itself contains.

  • To view a list of the existing categories that don't contain pages and media go to Tools menu on the left>Special pages button>Maintenance reports section>Unused categories button:
Button for Accessing the List of Categories Without Pages

This will open a page that displays a list of the categories that have been created but that contain no pages.

  • To view a list of categories for which links have been added on pages but the categories haven't been created, go to Tools menu>Special pages button>Maintenance reports section>Wanted categories button:
Button for Accessing the List of Categories that Haven't Been Created

If there are links on pages to categories that don't exist, these categories will be listed on the page that opens after you click on the button. In brackets after the name of the category you'll see the number of pages that contain a link to that category name. The name itself is a link colored in red. If you click on it this will open the form for creating the category.

Add Pages to Categories

We'll discuss how to add a page to a category before going over how to create categories because adding a page to a category is one way to start the process of creating a category. A page is added to a category by placing a link on the page to the category (even if the category is still not created). Since categories are actually created in pretty much the same way as regular pages, and one way to start the creation of a new page is by adding a link to it, then adding a page to a category is also a way to start the creation of that category (if it doesn't exist).

Mind however that for the category to be useful you should also create a page for it. Although this is not obligatory it doesn't make much sense to have a category without its own page since that's where the pages and media belonging to that category are listed. We'll go over how to create a page for a category in more details in the next section.

  • To add a page to a category, go to that page and open the form for editing it. In the text area with the content of the page put under the content the following:

[[Category:Category name]]

You have to replace Category name with the name of the category. If it's the name of an existing category make sure it's exactly the same, including capitalization. If it's a category that still doesn't exist, the page will be added to the category, but the link to it that's added at the bottom of the page will not be active because you also have to create a page for the category.

After you place such a link to a category on a page MediaWiki will automatically put the link at the bottom of the page. The exact location depends on the skin. As an example we use the Vector skin that comes prepackaged with MediaWiki. There's a special area below the content that lists the categories to which the page belongs (a page can be put in more than one category):

List of Categories to Which a Page Belongs

The name of the category is a link to its page where you'll find listed all the pages assigned to that category. If you haven't created a page for the category, the link will be in red and clicking on it will display the form for creating the category page.

The category page displays an alphabetical list of the pages (and media) belonging to the category. Above the list you can also put some content in the same way as for a regular page; it can be, for example, a description of the category. If the category contains subcategories, they will be listed under the content and above the list of the pages that are directly assigned to the parent category:

Category Page

The names of the pages in the list are links to those pages, while the name of a subcategory links to the page of that subcategory (if you have created one) which in turn lists the pages belonging to that subcategory.

  • If you want to add a link to a category without assigning the page to it and/or you also want to add a link to a category page that will appear as a regular link in the content of a page (meaning it will not be automatically put in the section at the bottom that lists the categories to which the page belongs), you can do that by adding the following to the content of the page:

[[:Category:Category name]]

The only difference as compared to adding the page to a category is that you have to put a colon after the first two brackets (before the name of the category). Of course, you have to replace Category name with the actual name of the category.

Create Categories

As we mentioned, a category is pretty much created in the same way as a regular page. In addition to assigning pages to the category you also have to create a page for the category itself. That's the page that contains the list of the items belonging to the category. As with a regular article page, you can open the form for creating the specific category page in a few different ways.

  • We mentioned one of these ways in the section on adding pages to categories. That is you can first add a page to a category that still doesn't exist as explained in the previous section. This will automatically place on the page a link to that category (usually at the bottom of the page, depending on the particular skin). Click on the link to open the form for creating the category page.

  • If before you put pages in the category you want to create the category, one way you can do this is to use the search function on the site to search for the category. If no such category exists, on the page that lists the search results you'll be informed that a page with such name doesn't exist. The name will be shown as a link colored in red. Click on it to open the form for creating a category page with that name. The name of the created category will be the one that you used in the search field. Note that when you type the name of the category in the search field you should also add the Category: namespace in front of it. For example, if you want the category to be named Example Category, then you have to search for Category:Example Category.

    As you probably know, in MediaWiki there are different namespaces to which the pages belong depending on their function. For example, the main pages (the articles) belong to the Main namespace, while category pages are in the Category namespace.

  • A similar way to create a category is to directly open the URL address of the category. If no such category exists, on the page that's displayed after you open the URL you'll see links to create (edit) the page. Again, in the URL address you have to use the Category namespace in front of the name of the category. If the category name consists of more than one word, separate them with underscores. For example, to create a category with the name Example Category and the URL of the homepage of your MediaWiki site is yourdomain.com, then open the URL address yourdomain.com/index.php/Example_Category.

Regardless of the method that you use, the form for creating category pages is the same. It's the form that's used for creating any other page:

Form for Creating a Category Page

If you want the category page to have some content above the list with the pages that belong to the category, you can optionally type that text in the text area that's provided. Then just click on the Save page button at the bottom.

  • Subcategories are created in almost the same way as categories. First you have to create the page of the subcategory in the same way as when creating a category. Use one of the methods described above. Then edit the subcategory and in its content add a link to the category to which you want it to belong. Use the same code as when adding a page to a category:

[[Category:Category name]]

This will automatically put the subcategory in the category and it will place on the category page a link to the subcategory.