MediaWiki:Gadget-espandiCategoria.js

Ocio: Daspò ver salvà, podaria esare neçesario snetare ła cache dal propio navegadore web par vedare i canbiamenti.

  • Firefox / Safari: tegner strucà el boton de łe letare grande Shift e schiciare sora Ricarga, o se nò struca Ctrl-F5 o Ctrl-R (⌘-R so Mac)
  • Google Chrome: strucare Ctrl-Shift-R (⌘-Shift-R so on Mac)
  • Internet Explorer / Edge: tegner strucà el boton Ctrl e schiciare so Ajorna, o sinò Ctrl-F5
  • Opera: Va in tel Menu → Inpostasion (Opera → Prefarense so on Mac) e pò in Privacy & sicuresa → Sneta dati del navegadore → Imajini e file in te ła cache.
(function($,mw) {
	mw.loader.using("mediawiki.api", function() {
		var api = new mw.Api();
	
		//function that puts the page titles in a wikitext and parses it
		parseText = function(titles, tlName, parent, temp, i) {
			j = i;
			textToParse = '';
			while (j < titles.length) {
				addText = '\n*{' + '{' + tlName + '|' + titles[j] + '|' + titles[j].replace(/\s*\(.*\)/, '') + '}}';
				textToParse += addText;
				j++;
			}
	
			console.log('Gadget EspandiCategoria - loading items ' + (i+1) + '-' + j + ' (from \"' + titles[i] + '\" to \"' + titles[j-1] + '\")');
			//parse wikitext into an html fragment
			api.post({
				action: 'parse', contentmodel: 'wikitext', prop: 'text', disablelimitreport: true, text: textToParse
			}).done(function (data) {
				if (data && data.parse && data.parse.text) {
					//put the html in the temporary container, then replace every list element with the one generated by the parsing
					temp.append(data.parse.text["*"]);
					temp.find('ul li').each(function(index) {
						link = $(this).find('i a').attr('title').replace(/"/g, '\\"');
						parent.find('li a[title="' + link + '"]').parent('li').empty().append($(this).html());
					});
					
					temp.remove();
				}
			});
		};
		
		//search for titles to be "expanded"
		if (mw.config.get("wgCanonicalNamespace") == "Category") {
			
			//get list of ns0 pages in the category we're in
			api.get({
				action: 'query', 
				format: 'json', 
				list: 'categorymembers', 
				cmnamespace: '0', 
				cmtype: 'page',
				cmlimit: 200, 
				cmtitle: mw.config.get("wgPageName"),
				cmstartsortkeyprefix: $('#mw-pages ul li:first a').attr('title')
			}).done(function (data) {
				if (data.query && data.query.categorymembers) {
					titles = [];
					//exclude subpages
					for (i = 0; i < data.query.categorymembers.length; i++) {
						thisTitle = data.query.categorymembers[i].title;
						if (thisTitle.indexOf('/') === -1) {
							titles.push(thisTitle);
						}
					}
					console.log('EspandiCategoria - found ' + titles.length + ' ns0 pages');
					if (titles.length > 0) {
						//temporary container for the generated html
						$('#mw-pages').after('<div id="espandiCategoria" style="display:none">');
						parseText(titles, 'TAA', $('#mw-pages'), $('#espandiCategoria'), 0);
					}
				}
			});
		}
	});
})($,mw);
Traesto fora da Wikipèdia - L'ençiclopedia łìbara e cołaboradiva in łéngua Vèneta "https://vec.wikisource.org/w/index.php?title=MediaWiki:Gadget-espandiCategoria.js&oldid=72566"