Extension:Highlight Links in Category/zh

Highlight Links in Category is an extension that adds a CSS class to links pointing to members of a category.

For reporting an issue or a bug, please use Miraheze Phabricator.

Configuration parameters

 * $wgHighlightLinksInCategory
 * This global is an array that configures which categories get an added CSS class. The keys are the Category names, which must include underscores instead of spaces. Do not include the Category: namespace. The value for each key is the CSS class you would like to add to that category. For example:

If you want add more than one class, separate the class names with spaces, like

You can add as many of these as you want, but from a UX perspective it's probably not awesome to add 500 different style links.

If $wgHighlightLinksInCategory is not set or empty, this extension will do nothing. If you're running a wiki farm and need to turn it off on some wikis, set ; using   could lead to incorrect behavior.

Styling
Simply add the styles you need for these links to MediaWiki:Common.css on your wiki. For example:

If you want one category to override another, you'll have to specify it with CSS.

Or alternatively, you could have defined the original  rule as   instead.

There's also the link icon approach:

User Toggles
An easy way to set up toggling this highlighting on or off is to make a Gadget with CSS in it. Yes, this is a personalization extension that outsources the personalization part to other extensions; I can still sleep at night.

How this works
Right after MediaWiki determines which linked pages exist (to make redlinks), it runs the  hook (see LinkHolderArray.php). As we have a list of all of the page ids which are linked on that page, we can run one database query to see which of these links are in the set of categories we want to highlight. Because the query only happens on an index of the  table, it's reasonably fast. Then CSS classes are assigned based on the result, using the configuration values the user sets in.

Explaining how CSS works is outside the scope of this document.

Known Issues

 * CSS styles are not added in Flow, because it doesn't appear to call the GetLinkColors hook there.