User:Andrewds1021/CategoryCSS

This solution was created in response to Thread:1507300 and debugged in response to Thread:1559477.

The purpose of this script is to apply a specific stylesheet based on the category membership of the current page. The script uses MediaWiki's api.php to check if the page belongs to one of the specified categories. If so, it imports the specified associated stylesheet.

Installation
The following instructions pertain to simply importing the script. If you wish, you may alternatively copy the script and maintain your own copy. Note that while any user may export (help page) the page, only local admins can import pages. Even then, local admins are not permitted to import pages into the MediaWiki namespace.

Limitations/Additional Notes

 * 1) When creating stylesheets, the customization policy must be followed.
 * 2) The script accepts only one (1) stylesheet per category. If you need/want to apply multiple stylesheets to the same category, use @import.
 * 3) If the page belongs to more than one (1) category for which custom CSS has been assigned, only one (1) of the associated stylesheets will be applied. Based on the ambiguity of the JS specifications, the chosen category could be random. However, it is commonly believed that most modern browsers actually do have predictable output. Based on this, the applied stylesheet is likely to be associated with the category which, amongst the matched categories, appears first in the category list.