Fandom Developers Wiki
Advertisement

本页面或其中部分内容仍未翻译。请将其翻译为适当的语言(中文(简体))。

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.

安装[]

使用方法[]

The class for each category is generated using the following procedure.

  1. 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).
  2. Sanitize the name for use in a class: This is done in a manner similar to the function escapeClass in MediaWiki's Sanitizer.php.
    1. Replace all non-alphanumeric basic ASCII characters with underscores except for hyphen-minus (U+002D), underscore, and delete (U+007F)
    2. Replace non-breaking spaces (U+00A0) with underscores
    3. Replace consecutive underscores with a single underscore
    4. Remove leading and trailing underscores
  3. 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).

示例[]

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;
}
Advertisement