Catisect

From Support Wiki
Jump to navigation Jump to search
Catisect
(Category Intersection)
Version
1.0.0
Author(s)
Foxlit (original author)
Requirements
MediaWiki 1.39+
Description
Displays category intersections in the Intersection namespace.
Default?
NoN

Catisect (or Category Intersection) is an extension that allows for searching through a set of categories to find pages that share two or more categories. Bots can also use this to target these filtered articles.

Intersection namespace

The Intersection namespace is automatically created when the extension is enabled.

Usage

[[Intersection:<category1>::<category2>::<category3>]]

Example: Intersection:World of Warcraft common items::Funny items

Using Warcraft Wiki for the example, this intersection grabs articles from "Category:World of Warcraft common items" and "Category:Funny items", then filters and displays only articles that happen to be in both. In this case, it will display articles that are joke items but only if they're of common quality.

Gadget

Category Intersection can also be improved with a gadget that allows the selection of categories directly from any article with two or more categories. To enable this tool, the Gadgets extension needs to be enabled and the following pages need to be edited and created/added to for the gadget to work:

Adding the gadget

Definition of the gadget

Create or edit MediaWiki:Gadgets-definition and add the following text:

* intersection[ResourceLoader]|intersection.js

JavaScript for the gadget

Create MediaWiki:Gadget-intersection.js and add the following code:

$(function() {
	var links = $("#catlinks ul a");
	if (links.length <= 1) return;
	links.before('<input type="checkbox" checked="checked" class="intersect-checkbox" />&nbsp;');
	$("#catlinks ul").last().append('<li class="intersect-item"><button type="button" id="intersect-button">Find similar pages</button></li>');
	mw.util.addCSS('#catlinks li.intersect-item {border-left: none}');
	$("#intersect-button").click(function() {
		var outList = "", outCount = 0;
		$("#catlinks .intersect-checkbox:checked + a").each(function() {
			outList += (outCount++ ? '::' : '') + $(this).text();
		});
		if (outCount == 0) {
			alert("You must select at least one category to find similar pages.");
			return;
		} else if (outCount == 1) {
			window.location = mw.util.getUrl('Category:' + outList);
		} else {
			window.location = mw.util.getUrl('Intersection:' + outList);
		}
		$(this).text("Redirecting...");
	});
});

Text on the Preferences page Gadgets tab

Create MediaWiki:Gadget-intersection and add the following text:

Enable the Category Intersection (Catisect) gadget

Using the gadget

For users to be able to use the gadget, they must enable it via their personal user Preferences, on the Gadgets tab.

The default installation of this extension and the accompanying gadget add a button to the Category links (#catlinks) section at the bottom of the wiki page. Checking the boxes by multiple categories and clicking the "Find similar items" button directs the user to the corresponding Intersection page.

The following is a view of the category links section when the gadget is enabled:

Catisect catlinks.png

Customizing the gadget

The text shown on the button can be changed by editing the JavaScript shown above ("Find similar pages"), and the button itself can be styled using the button selector. Unstyled buttons are rectangular with a light grey background.