Ero sivun ”Järjestelmäviesti:Gadget-linkclassifier.js” versioiden välillä

Wikipediasta
Siirry navigaatioon Siirry hakuun
Poistettu sisältö Lisätty sisältö
wg muuttujat tulemaan mw.config.get() -funktiolla
maintenance: do not throw errors use mw.log.warn
Rivi 254: Rivi 254:
callback:function(r, cc){
callback:function(r, cc){
if(!r.query) throw new Error('Bad response');
if(!r.query) mw.log.warn('Gadget-linkclassifier.js:Bad response');
if(r['query-continue']){
if(r['query-continue']){
for(var k in r['query-continue']){
for(var k in r['query-continue']){
Rivi 267: Rivi 267:
var a=document.getElementById('wikiPreview');
var a=document.getElementById('wikiPreview');
if(!a) a=document.getElementById('bodyContent');
if(!a) a=document.getElementById('bodyContent');
if(!a) throw new Error('Huh? No body content?');
if(!a) mw.log.warn('Gadget-linkclassifier.js:Huh? No body content?');
a=a.getElementsByTagName('A');
a=a.getElementsByTagName('A');
if(a.length==0) return;
if(a.length==0) return;
Rivi 531: Rivi 531:
if(x.readyState!=4) return;
if(x.readyState!=4) return;
var r=jsondecode(x.responseText);
var r=jsondecode(x.responseText);
if(!r) throw new Error("Could not parse response");
if(!r) mw.log.warn('Gadget-linkclassifier.js:Could not parse response");
cb(r, p);
cb(r, p);
};
};
Rivi 541: Rivi 541:
x.send(data);
x.send(data);
var r=jsondecode(x.responseText);
var r=jsondecode(x.responseText);
if(!r) throw new Error("Could not parse response");
if(!r) mw.log.warn("Could not parse response");
return r;
return r;
}
}

Versio 8. lokakuuta 2020 kello 03.35

/* If you want to use this script, simply add the following line to your [[Special:Mypage/monobook.js]]:

importScript('User:Anomie/util.js');
importScript('User:Anomie/linkclassifier.js'); // Linkback: [[User:Anomie/linkclassifier.js]]

* (Please keep the comment so I can see how many people use this). You will also want to
* add some CSS classes, such as those at [[User:Anomie/linkclassifier.css]].
*/

/* If you want this to run "on demand" instead of on every page, set "LinkClassifierOnDemand=true" and
 * use mw.util.addPortletLink() or the like to add a button calling LinkClassifier.onDemand().
 */

//importScript('User:Zache/util.js');  // for backwards compat

function load_linkclassifier()
{
	var LinkClassifier={
	    /* This object maps classes to the categories for which to apply them. Values may be an array of strings or a regex. */
	    cats:{
	        deletion:[
	            'Luokka:Pikapoisto',
	            'Luokka:Hauki on kala',
	            'Luokka:Merkittävyys kyseenalaistettu',
	            'Luokka:Tekijänoikeusongelmat',
	            'Luokka:Poistettavat'
	        ].sort(),
	        disambiguation:[
	            'Luokka:Täsmennyssivut',
	        ].sort(),
	        sisterproject:[
	            'Luokka:Ohjaukset Wikisanakirjaan'
	        ].sort(),
	        userwarning:[
	            'Luokka:Varoitetut käyttäjät'
	        ].sort(),
	        'set-index':[
	            'Category:All set index articles'
	        ].sort(),
	        'featured-content2':[
	"Luokka:Yleinen wikiluokitusjärjestelmä",
	"Luokka:0 Yleiset tieteet",
	"Luokka:00 Kirja-ala, kirjoitus",
	"Luokka:02 Kirjastotoimi, kirjastotiede, informatiikka",
	"Luokka:06 Yleinen kulttuuripolitiikka",
	"Luokka:07 Viestintä, joukkoviestintä",
	"Luokka:1 Filosofia, psykologia",
	"Luokka:11 Filosofia",
	"Luokka:14 Psykologia",
	"Luokka:15 Rajatieto",
	"Luokka:17 Etiikka",
	"Luokka:2 Uskonto",
	"Luokka:20 Uskonnot yleisesti",
	"Luokka:23 Hindulaisuus",
	"Luokka:24 Buddhalaisuus",
	"Luokka:26 Juutalaisuus",
	"Luokka:27 Kristinusko",
	"Luokka:27.0 Kristinuskon historia, kirkkohistoria",
	"Luokka:27.71 Kristinusko Suomessa",
	"Luokka:27.714 Suomen herätysliikkeet",
	"Luokka:28 Islam",
	"Luokka:29 Muut uskonnot, mytologiat",
	"Luokka:3 Yhteiskuntatieteet",
	"Luokka:30 Yleinen yhteiskuntatiede",
	"Luokka:30.1 Sosiologia",
	"Luokka:30.16 Rikokset, kriminologia",
	"Luokka:30.7 Kansalais- ja järjestötoiminta, kokoustekniikka",
	"Luokka:31 Tilastotiede",
	"Luokka:32 Politiikka",
	"Luokka:32.0 Valtio-oppi, politiikka",
	"Luokka:32.1 Valtiofilosofia, valtiomuodot",
	"Luokka:32.3 Ihmisoikeudet, kansalaisen asema yhteiskunnassa",
	"Luokka:32.4 Sisäpolitiikka, puolueet",
	"Luokka:32.5 Kansainvälinen politiikka",
	"Luokka:33 Oikeustiede",
	"Luokka:34 Aluesuunnittelu, aluepolitiikka",
	"Luokka:35 Hallinto",
	"Luokka:36 Talous",
	"Luokka:37 Sosiaalipolitiikka",
	"Luokka:38 Kasvatus, opetus",
	"Luokka:39 Maanpuolustus",
	"Luokka:39.1 Aseistus, asevarustelu, asekauppa",
	"Luokka:39.4 Maavoimat, maasodankäynti",
	"Luokka:39.5 Merivoimat, merisodankäynti",
	"Luokka:39.6 Ilmavoimat, ilmasodankäynti",
	"Luokka:39.7 Sotilaskoulutus",
	"Luokka:4 Maantiede",
	"Luokka:41 Eurooppa",
	"Luokka:41.1 Suomi",
	"Luokka:41.2 Pohjoismaat",
	"Luokka:41.3 Keski-Eurooppa",
	"Luokka:41.4 Britteinsaaret",
	"Luokka:41.5 Etelä-Eurooppa",
	"Luokka:41.58 Balkanin maat",
	"Luokka:41.585 Kreikka",
	"Luokka:41.6 Itä-Eurooppa",
	"Luokka:41.61 Venäjä",
	"Luokka:41.62 Baltian maat",
	"Luokka:42 Aasia",
	"Luokka:43 Afrikka",
	"Luokka:44 Pohjois-Amerikka",
	"Luokka:45 Etelä-Amerikka",
	"Luokka:46 Australia, Oseania, Napamaat",
	"Luokka:49 Kansantiede, antropologia",
	"Luokka:5 Luonnontieteet",
	"Luokka:51 Matematiikka",
	"Luokka:52 Tähtitiede",
	"Luokka:53 Fysiikka",
	"Luokka:54 Kemia",
	"Luokka:55 Geologia",
	"Luokka:57 Biologia",
	"Luokka:57.4 Ekologia",
	"Luokka:58 Kasvitiede, sienitiede",
	"Luokka:58.1 Kasvimorfologia, kasvianatomia",
	"Luokka:58.4 Putkilokasvit",
	"Luokka:58.41 Puut, pensaat",
	"Luokka:58.5 Levät, jäkälät, sienet, sammalet",
	"Luokka:59 Eläintiede",
	"Luokka:59.2 Nisäkkäät",
	"Luokka:59.3 Linnut",
	"Luokka:59.4 Matelijat, sammakkoeläimet",
	"Luokka:59.5 Kalat",
	"Luokka:59.6 Selkärangattomat",
	"Luokka:6 Soveltavat tieteet, tekniikka",
	"Luokka:61 Lääketiede, terveydenhuolto",
	"Luokka:61.5 Hoitomenetelmät",
	"Luokka:61.51 Lääkehoito, lääkeaineoppi",
	"Luokka:61.7 Kliininen lääketiede",
	"Luokka:61.8 Psykiatria",
	"Luokka:61.81 Päihteiden käyttö",
	"Luokka:62 Tekniikka, kulkuneuvot",
	"Luokka:62.09 Energia",
	"Luokka:62.1 Tieto- ja viestintätekniikka",
	"Luokka:62.4 Liikenneväylät, kulkuneuvot",
	"Luokka:64 Kemianteollisuus, kaivosteollisuus",
	"Luokka:66 Rakennustekniikka",
	"Luokka:67 Maa- ja metsätalous",
	"Luokka:68 Kotitalous",
	"Luokka:69 Liiketalous",
	"Luokka:7 Taiteet, liikunta, huvit",
	"Luokka:70 Taide, taidehistoria",
	"Luokka:70.9 Yleinen taidehistoria",
	"Luokka:71 Uudet taidemuodot",
	"Luokka:72 Arkkitehtuuri",
	"Luokka:72.2 Rakennukset, rakennustyypit",
	"Luokka:72.21 Asuinrakennukset",
	"Luokka:72.22 Linnat, palatsit, kartanot",
	"Luokka:72.24 Uskonnolliset rakennukset",
	"Luokka:72.9 Arkkitehtuurin historia",
	"Luokka:73 Kuvanveisto",
	"Luokka:73.9 Kuvanveiston historia",
	"Luokka:73.91 Suomen kuvanveiston historia",
	"Luokka:74 Maalaustaide, piirustustaide",
	"Luokka:74.1 Maalaustaiteen materiaalit ja tekniikat",
	"Luokka:74.9 Maalaustaiteen historia",
	"Luokka:74.91 Suomen maalaustaiteen historia",
	"Luokka:75 Graafinen taide, valokuvaus",
	"Luokka:77 Näyttämötaide, elokuvataide",
	"Luokka:77.1 Teatteritaide",
	"Luokka:77.4 Elokuvataide",
	"Luokka:77.5 Televisiosarjat",
	"Luokka:78 Musiikki",
	"Luokka:78.1 Musiikin tutkimus, musiikkikasvatus",
	"Luokka:78.3 Laulu-, näyttämö- ja kirkkomusiikki",
	"Luokka:78.6 Soitinmusiikki, soittimet",
	"Luokka:78.8 Populaarimusiikki",
	"Luokka:78.81 Blues, soul",
	"Luokka:78.9 Musiikin historia",
	"Luokka:79 Urheilu, pelit, huvit",
	"Luokka:79.1 Yleisurheilu",
	"Luokka:79.2 Talviurheilu",
	"Luokka:79.3 Palloilu",
	"Luokka:79.4 Voimailu, itsepuolustus",
	"Luokka:79.5 Moottoriurheilu",
	"Luokka:79.8 Pelit, leikit, keräily",
	"Luokka:79.9 Julkiset huvit",
	"Luokka:8 Kirjallisuus, kielitiede",
	"Luokka:82 Runot",
	"Luokka:83 Näytelmät",
	"Luokka:83.2 Suomenkieliset näytelmät",
	"Luokka:84 Kertomakirjallisuus",
	"Luokka:84.2 Suomenkielinen kertomakirjallisuus",
	"Luokka:85 Sadut, kuvakirjat, sarjakuvat",
	"Luokka:86 Kirjallisuustiede",
	"Luokka:86.0 Yleinen kirjallisuustiede",
	"Luokka:86.1 Yleinen kirjallisuudenhistoria",
	"Luokka:87 Kielitiede",
	"Luokka:9 Historia",
	"Luokka:90 Historian tutkimus, maailmanhistoria",
	"Luokka:90.2 Yleinen arkeologia",
	"Luokka:90.3 Historian aputieteet",
	"Luokka:91 Euroopan historia",
	"Luokka:92 Aasian historia",
	"Luokka:93 Afrikan historia",
	"Luokka:94 Pohjois-Amerikan historia",
	"Luokka:95 Etelä-Amerikan historia",
	"Luokka:96 Australia, Oseania, napamaat",
	"Luokka:99 Henkilö- ja sukuhistoria",
	"Luokka:99.1 Filosofit, psykologit",
	"Luokka:99.2 Uskontojen ja kirkkokuntien edustajat",
	"Luokka:99.3 Yhteiskuntaelämän edustajat",
	"Luokka:99.4 Maantieteilijät, tutkimusmatkailijat, kansatieteilijät",
	"Luokka:99.5 Luonnontieteilijät, matemaatikot",
	"Luokka:99.6 Lääketieteen, tekniikan ja talouselämän edustajat",
	"Luokka:99.7 Humanististen tieteiden edustajat",
	"Luokka:99.9 Sukuhistoria, sukututkimus"
	        ].sort(),
	        'featured-content':[
	            'Luokka:Suositellut artikkelit',
	            'Luokka:Suositellut luettelot',
	            'Luokka:Hyvät artikkelit',
	            'Luokka:Lupaavat artikkelit',
	            'Luokka:Tarkistetut artikkelit'
	        ].sort(),
	        'broken-content':[        
	            'Luokka:Tarkistettava',
	            'Luokka:Epäselvät artikkelit',
	            'Luokka:Kesken jääneet artikkelit',
	            'Luokka:Keskeneräiset käännökset',
	            'Luokka:Kielenhuoltoa kaipaavat sivut',
	            'Luokka:Korjattavat sivut',
	            'Luokka:Mahdollisesti väärässä aikamuodossa olevat sivut',
	            'Luokka:Mahdollista mainontaa sisältävät artikkelit',
	            'Luokka:Uudelleenkirjoitusta vaativat sivut',
	            'Luokka:Mahdollisesti väärässä aikamuodossa olevat sivut',
	            'Luokka:Muodon korjausta kaipaavat sivut',
	            'Luokka:Neutraali näkökulma keskustelunalainen',
	            'Luokka:Päivitystä kaipaavat sivut',
	            'Luokka:Resentistiset artikkelit',
	            'Luokka:Määritelmän korjausta kaipaavat sivut'
	        ].sort(),
	        'proxy-ip':[
	            'Luokka:Yhteiskäyttöosoitteet'
	        ].sort(),
	        'spoken-articles':[
	            'Luokka:Puhutut sivut'
	        ].sort(),
	        stubcls:/^Luokka:.*tyngät$/,
	        'nonfree-media':[
	            'Category:All non-free media'
	        ].sort(),
	        unprintworthy:[
	            'Category:Unprintworthy redirects',
	        ].sort(),
	        'unprintworthy-shortcut':[
	            'Category:Redirects from shortcuts',
	        ].sort(),
	        'reviews':[
	            'Luokka:Lupaavaksi ehdotetut artikkelit',
	            'Luokka:Tarkistetuksi ehdotetut artikkelit',
	            'Luokka:Vertaisarviointi',
	        ].sort()
	    },
	 
	    callback:function(r, cc){
	        if(!r.query) mw.log.warn('Gadget-linkclassifier.js:Bad response');
	        if(r['query-continue']){
	            for(var k in r['query-continue']){
	                for(var k2 in r['query-continue'][k]){
	                    cc[k2]=r['query-continue'][k][k2];
	                }
	            }
	            api(cc, arguments.callee);
	        }
	        r=r.query;
	
	        var a=document.getElementById('wikiPreview');
	        if(!a) a=document.getElementById('bodyContent');
	        if(!a) mw.log.warn('Gadget-linkclassifier.js:Huh? No body content?');
	        a=a.getElementsByTagName('A');
	        if(a.length==0) return;
	
	        var redir={};
	        var redirlist=[];
	        if(r.redirects) for(var i=r.redirects.length-1; i>=0; i--){
	            redir[r.redirects[i].from]=r.redirects[i].to;
	            redirlist.push(r.redirects[i].from);
	        }
	        if(redirlist.length>0) api({action:'query', titles:redirlist, prop:'categories', cllimit:'max'}, LinkClassifier.callback);
	
	        var cats={};
	        var missing={};
	        var classes={};
	        if(r.pages) for(var i in r.pages){
	            missing[r.pages[i].title]=(typeof(r.pages[i].missing)!='undefined');
	            if(typeof(r.pages[i].categories)!='undefined'){
	                cats[r.pages[i].title]=r.pages[i].categories.map(function(a){ return a.title; }).sort();
	            }
	            if(typeof(r.pages[i].protection)!='undefined'){
	                classes[r.pages[i].title]=[];
	                var x={};
	                for(var j=r.pages[i].protection.length-1; j>=0; j--){
	                    var p='protection-'+r.pages[i].protection[j].type+'-'+r.pages[i].protection[j].level;
	                    if(typeof(x[p])=='undefined'){
	                        x[p]=1;
	                        classes[r.pages[i].title].push(p);
	                    }
	                    if(r.pages[i].protection[j].expiry=='infinity'){
	                        p+='-indef';
	                        if(typeof(x[p])=='undefined'){
	                            x[p]=1;
	                            classes[r.pages[i].title].push(p);
	                        }
	                    }
	                }
	            }
	            if(typeof(r.pages[i].flagged)!='undefined'){
	                if(r.pages[i].lastrevid!=r.pages[i].flagged.stable_revid){
	                    classes[r.pages[i].title].push('needs-review');
	                }
	            }
	        }
	        Array.forEach(a, function(a){
	            if(typeof(a.wikipage)=='undefined') return;
	            if(typeof(redir[a.wikipage])!='undefined'){
	                addClass(a,'redirect');
	                a.wikipage=redir[a.wikipage];
	                a.title=a.wikipage;
	                if(a.wikipage==(mw.config.get('wgCanonicalNamespace')?mw.config.get('wgCanonicalNamespace')+':':'')+mw.config.get('wgTitle'))
	                    addClass(a,'self-redirect');
	                if(missing[a.wikipage])
	                    addClass(a,'broken-redirect');
	            }
	            var m=a.href.match(/#.*/);
	            if(m){
	                a.title=a.title.replace(/#.*/,'')+m[0].replace(/_/g,' ').replace(/\.([0-9A-F][0-9A-F])/gi, function(x,n){ return String.fromCharCode(parseInt(n,16)); });
	            }
	            if(/ \(disambiguation\)$/.test(a.origwikipage)){
	                addClass(a,'intentional-disambiguation');
	            }
	            if(typeof(classes[a.wikipage])!='undefined'){
	                for(var j=classes[a.wikipage].length-1; j>=0; j--)
	                    addClass(a,classes[a.wikipage][j]);
	            }
	            var c1=[];
	            if(typeof(cats[a.wikipage])!='undefined'){
	                c1=c1.concat(cats[a.wikipage]);
	            }
	            if(a.wikipage!=a.origwikipage && typeof(cats[a.origwikipage])!='undefined'){
	                c1=c1.concat(cats[a.origwikipage]);
	            }
	            if(c1.length>0){
	                c1=c1.sort();
	                for(var cls in LinkClassifier.cats){
	                    var i1=c1.length-1;
	                    var c2=LinkClassifier.cats[cls];
	                    if(c2 instanceof RegExp){
	                        while(i1>=0){
	                            if(c2.test(c1[i1])){
	                                addClass(a,cls);
	                                break;
	                            }
	                            i1--;
	                        }
	                    } else {
	                        var i2=c2.length-1;
	                        while(i1>=0 && i2>=0){
	                            if(c1[i1]==c2[i2]){
	                                addClass(a,cls);
	                                break;
	                            }
	                            (c1[i1]>c2[i2])?--i1:--i2;
	                        }
	                    }
	                }
	            }
	        });
	    },
	
	    getPageName:function(url){
	        var m=url.match(/\/wiki\/([^?#]+)/);
	        if(!m) m=url.match(/\/w\/index.php\?(?:.*&)?title=([^&#]+)/);
	        if(!m) return '';
	        var t=decodeURIComponent(m[1]).replace(/_/g,' ');
	        if(t.substr(0,6)=='Image:') t='File:'+t.substr(6);
	        if(t.substr(0,11)=='Image talk:') t='File talk:'+t.substr(6);
	        if(t.substr(0,8)=='Special:') t='';
	        return t;
	    },
	
	    classifyChildren:function(node){
	        var a=node.getElementsByTagName('A');
	        if(a.length==0) return;
	      
	        var self=LinkClassifier.getPageName(location.href);
	      
	        a=Array.prototype.map.call(a, function(a){
	            a.wikipage='';
	            if(/(^|\s)(external|extiw|NavToggle)(\s|$)/.test(a.className)) return '';
	            if(!/(^|\s)(image)(\s|$)/.test(a.className)) a.className+=" nonimage";
	            a.wikipage=LinkClassifier.getPageName(a.href);
	            if(a.wikipage==self) a.wikipage='';
	            a.origwikipage=a.wikipage;
	            return a.wikipage;
	        }).sort().filter(function(e,i,a){
	            return e!=='' && (i==0 || a[i-1]!==e);
	        });
	        while(a.length>0){
	            api({action:'query', titles:a.splice(0,50), prop:'categories|info|flagged', redirects:1, cllimit:'max', inprop:'protection'}, LinkClassifier.callback);
	        }
	    },
	 
	    classifyTitle:function() {
	
	        var firstHeading=document.getElementById("firstHeading");
	        if (firstHeading) firstHeading.innerHTML="<span>"+ firstHeading.innerHTML +"</span>";      
	
	        var catlinks=document.getElementById("catlinks");
	        if (catlinks) var cats=catlinks.getElementsByTagName("A");
	        if (cats) {
	           var c1=[];
	           for (var n=cats.length-1; n>=0; n--)
	               if (cats[n].href.search("/wiki/Luokka:")!=-1) c1.push("Luokka:" + cats[n].innerHTML);          
	
	           c1=c1.sort();
	           for(var cls in LinkClassifier.cats){
	               var i1=c1.length-1;
	               var c2=LinkClassifier.cats[cls];
	               if(c2 instanceof RegExp){
	                  while(i1>=0){
	                     if(c2.test(c1[i1])){
	                          addClass(firstHeading.firstChild,"a_" + cls);
	                          break;
	                     }
	                     i1--;
	                   }
	               } else {
	                   var i2=c2.length-1;
	                   while(i1>=0 && i2>=0){
	                      if(c1[i1]==c2[i2]){
	                         addClass(firstHeading.firstChild,"a_" + cls);
	                         break;
	                      }
	                      (c1[i1]>c2[i2])?--i1:--i2;
	                    }
	               }
	            }               
	        }
	    },
	
	    onLoad:function(){             
	        if(window.AJAXPreview) window.AJAXPreview.AddOnLoadHook(LinkClassifier.classifyChildren);
	        LinkClassifier.onDemand();
	    },
	 
	    onDemand:function(){
	        LinkClassifier.classifyTitle();
	        var node=document.getElementById('wikiPreview');
	        if(!node) node=document.getElementById('bodyContent');
	        if(node) LinkClassifier.classifyChildren(node);
	      
	    }
	};
	
	if(!window.LinkClassifierOnDemand){
	    $(LinkClassifier.onLoad);
	}

// :en:User:Anomie/util.js alkaa
	function sajax_init_object() {
		var A;
		try {
			// Try the new style before ActiveX so we don't
			// unnecessarily trigger warnings in IE 7 when
			// set to prompt about ActiveX usage
			A = new XMLHttpRequest();
		} catch ( e ) {
			try {
				A = new ActiveXObject( 'Msxml2.XMLHTTP' );
			} catch ( e ) {
				try {
					A = new ActiveXObject( 'Microsoft.XMLHTTP' );
				} catch ( oc ) {
					A = null;
				}
			}
		}
		return A;
	};

	function jsondecode(v){
	    try {
	        return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u\n\r\t]/.test(v.replace(/"(\\.|[^\x22\\])*"/g,''))) && eval('('+v+')');
	    } catch(e){
	        return null;
	    }
	}
	 
	if(!Number.prototype.toHex) Number.prototype.toHex = function(p){
	        var s=this.toString(16);
	        var i=s.indexOf('.');
	        if(i<0) i=s.length;
	        if(typeof(p)!='undefined') for(p-=i; p>0; p--){
	                s='0'+s;
	        }
	        return s;
	}
	if(!Number.toHex) Number.toHex = function(n,p){
		return Number(n).toHex(p);
	}
	 
	if(!RegExp.quote){
	    RegExp.quote = function(s){
	        return s.replace(/[^\t !\x22#%&\x27,:;<=>@_`~a-z0-9]/ig, RegExp.quote.$replacer);
	    }
	    RegExp.quote.$replacer = function(c){
	        c=c.charCodeAt(0);
	        return '\\u'+c.toHex(4);
	    }
	}
	 
	function api(p, cb){
	    var uri=mw.config.get('wgServer')+mw.config.get('wgScriptPath')+'/api.php';
	    var data='format=json';
	    for(var k in p){
	        var v=p[k];
	        if(typeof(v)=='object' && (v instanceof Array))
	            v=v.map(encodeURIComponent).join('|');
	        else
	            v=encodeURIComponent(v);
	        data+='&'+encodeURIComponent(k)+'='+v;
	    }
	 
	    var x = sajax_init_object();
	    if(!x) return false;
	 
	    if(typeof(cb)=='function'){
	        x.open('POST', uri, true);
	        x.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	        x.onreadystatechange=function(){
	            if(x.readyState!=4) return;
	            var r=jsondecode(x.responseText);
	            if(!r) mw.log.warn('Gadget-linkclassifier.js:Could not parse response");
	            cb(r, p);
	        };
	        x.send(data);
	        return true;
	    } else {
	        x.open('POST', uri, false);
	        x.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	        x.send(data);
	        var r=jsondecode(x.responseText);
	        if(!r) mw.log.warn("Could not parse response");
	        return r;
	    }
	}
	 
	function rawpage(pg, cb){
	    var uri=mw.config.get('wgServer')+mw.config.get('wgScriptPath')+'/index.php?action=raw&title='+encodeURIComponent(pg);
	 
	    var x = sajax_init_object();
	    if(!x) return false;
	 
	    if(typeof(cb)=='function'){
	        x.open('GET', uri, true);
	        x.onreadystatechange=function(){
	            if(x.readyState!=4) return;
	            cb(x.responseText);
	        };
	        x.send(null);
	        return true;
	    } else {
	        x.open('GET', uri, false);
	        x.send(null);
	        return x.responseText;
	    }
	}
	 
	function isClass(n, c){
		return n.className.match(new RegExp('(^|\\s)'+c+'(\\s|$)'));
	}
	function addClass(n, c){
		if(!isClass(n,c)) n.className=(n.className=='')?c:(n.className+' '+c);
	}
	function delClass(n, c){
		var cl=n.className;
		cl=cl.replace(new RegExp('(^|\\s)'+c+'(\\s|$)', 'g'), ' ');
		cl=cl.replace(/\s\s+/g, ' ').replace(/^\s+|\s+$/g, '');
		if(n.className!=cl) n.className=cl;
	}
	 
	if(!Array.prototype.map) Array.prototype.map=function(callback, thisObject){
	        var l=this.length;
	        var a=[];
	        if(typeof(thisObject)=='undefined' || thisObject===null){
	                for(var i=0;i<l;i++){
	                        a[i]=callback(this[i],i,this);
	                }
	        } else {
	                for(var i=0;i<l;i++){
	                        a[i]=callback.call(thisObject,this[i],i,this);
	                }
	        }
	        return a;
	}
	if(!Array.map) Array.map=function(obj, callback, thisObject){
	        return Array.prototype.map.call(obj, callback, thisObject);
	}
	 
	if(!Array.prototype.forEach) Array.prototype.forEach=function(callback, thisObject){
		var l=this.length;
		if(typeof(thisObject)=='undefined' || thisObject===null){
			for(var i=0;i<l;i++){
				callback(this[i],i,this);
			}
		} else {
			for(var i=0;i<l;i++){
				callback.call(thisObject,this[i],i,this);
			}
		}
	}
	if(!Array.forEach) Array.forEach=function(obj, callback, thisObject){
		return Array.prototype.forEach.call(obj, callback, thisObject);
	}
	 
	if(!Array.prototype.filter) Array.prototype.filter=function(callback, thisObject){
		var l=this.length;
		var a=[];
		if(typeof(thisObject)=='undefined' || thisObject===null){
			for(var i=0;i<l;i++){
				if(callback(this[i],i,this)) a.push(this[i]);
			}
		} else {
			for(var i=0;i<l;i++){
				if(callback.call(thisObject,this[i],i,this)) a.push(this[i]);
			}
		}
		return a;
	}
	if(!Array.filter) Array.filter=function(obj, callback, thisObject){
		return Array.prototype.filter.call(obj, callback, thisObject);
	}
// :en:User:Anomie/util.js loppuu
}
$(load_linkclassifier);