User:Joshurtree/multicat.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Joshurtree/multicat. |
//<pre><nowiki>
function PageQuery(q) {
if (q.length > 1)
this.query = q.substring(1, q.length);
else
this.query = null;
this.values = new Object();
if (q) {
for (var i = 0; i < this.query.split("&").length; i++) {
var pair = this.query.split("&")[i];
this.values[pair.split("=")[0]] = pair.split("=")[1];
}
}
}
PageQuery.prototype.getValue = function(s) {
return this.values[s];
}
PageQuery.prototype.getParameters = function() {
return keys;
}
PageQuery.prototype.getLength = function() {
return this.values.length;
}
PageQuery.create = function() {
var retText = prefix ? wgScriptPath + '/' + prefix + '?' : '';
for (x in parameters) {
if (parameters[x] != null)
retText += x + '=' + parameters[x] + '&';
}
return retText.substring(0, retText.length - 1);
}
function CategoryIntersection() {
var query = new PageQuery(location.search);
this.category1 = wgTitle;
this.category2 = query.getValue("intersection");
this.from = query.getValue("from");
this.request = sajax_init_object();
this.request.parentObj = this;
var query = {
'action': 'query',
'generator': 'categorymembers',
'gcmtitle': this.category1,
'gcmlimit': 500,
'prop': 'categories',
'clprop': 'sortkey'
};
this.request.open('GET', PageQuery.create(query), true);
this.request.onload = function() { this.parentObj.handleCategoryQuery; };
this.request.send();
}
CategoryIntersection.prototype.handleCategoryQuery = function() {
var pages = this.request.responseXML.getElementsByTagName('page');
XMLDocument output =
for (page in pages) {
var sortkey;
var intersection;
var xmlDoc = loadXMLDoc();
xmlDoc
for (category in page.firstChild.childNodes) {
var title = category.getAttribute('title');
if (title == this.category1)
sortkey = category.getAttribute('sortkey');
else if (title == this.category2)
intersection = true;
if (intersection) {
}
function loadXMLDoc(fname)
{
var xmlDoc;
// code for IE
if (window.ActiveXObject)
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
xmlDoc=document.implementation.createDocument("","",null);
else
alert('Your browser cannot handle this script');
xmlDoc.async = false;
if (fname)
xmlDoc.load(fname);
return(xmlDoc);
}
addOnLoadHook(function() {
if (wgNamespaceNumber == 14 && location.URL.indexOf("&intersection=") > 0)
new CategoryIntersection();
}
//</pre></nowiki>