CategoryClasses retrieves a list of all categories to which the current page belongs. It then adds a class to the page's body for each of those categories. This enables CSS targeting of pages based on category membership. The retrieved list of categories for a page includes hidden categories but not ancestor or descendent categories.
Installation
Usage
The class for each category is generated using the following procedure.
- Obtain the category's name: The result is similar to the result from using {{PAGENAME}} except spaces (U+0020) are replaced by underscores (U+005F).
- Sanitize the name for use in a class: This is done in a manner similar to the function
escapeClassin MediaWiki's Sanitizer.php.- Replace all non-alphanumeric basic ASCII characters with underscores except for hyphen-minus (U+002D), underscore, and delete (U+007F)
- Replace non-breaking spaces (U+00A0) with underscores
- Replace consecutive underscores with a single underscore
- Remove leading and trailing underscores
- Prepend
category-
The classes are added to the page's body along side those inserted by MediaWiki (such as for page-specific and namespace-specific CSS).
Example
This example would change the main article text color to red for all pages in Category:JavaScript/Site enhancements.
.category-JavaScript_Site_enhancements #mw-content-text {
color: red;
}
Text above can be found here (edit)