MediaWiki:AutoEditPages/code.js

if (mw.config.get('skin') === 'monobook') { mw.util.addPortletLink('creates', '#', 'Création', 'creates'); } else { $('#AccountNavigation > li > .subnav > li:last-child').after(          $('').append('Création')         ); $('#my-tools-menu').prepend(' Création'); } function posts(pages,content) { var actions; actions = $('.adding:checked').val + "text"; if (actions == "appendtext") { $.post(mw.util.wikiScript( 'api' ), { 		format: 'json',  		action: 'edit',  		title: encodeURIComponent(pages),  		appendtext: content,                minor: true,                bot: true,  		token: mw.user.tokens.get("editToken")  	}, function( data ) {		if (!data.error) {         console.log('Succesful !');		} else {         console.log('Failed.');		$('#text-error-output').append('Failed to edit page '+pages+': '+data.error.info+' ');		}  }); } else { $.post(mw.util.wikiScript( 'api' ), { 		format: 'json',  		action: 'edit',  		title: encodeURIComponent(pages),  		prependtext: content,                minor: true,                bot: true,  		token: mw.user.tokens.get("editToken")  	}, function( data ) {		if (!data.error) {         console.log('Edit of '+pages+ ' has been made successfully !');		} else {         console.log('Failed.');		$('#text-error-output').append('Failed to edit page '+pages+': '+data.error.info+' ');		}  }); } } function addpages(category) { if (!category) { return false; }	$.getJSON("/api.php?action=query&list=categorymembers&cmtitle=Category:" + encodeURIComponent(category) + "&cmprop=title&cmlimit=5000&format=json", function(result){		var categoryUsage = result.query.categorymembers;               console.log(categoryUsage);		console.log("Category usage successfully retrieved");		if (categoryUsage.length > 0){		for (var currentPage = 0; currentPage < categoryUsage.length; currentPage++){			var title = categoryUsage[currentPage].title;			if (title){				$('#Names').append(title + "\n");			}		} } }); alert('Done !'); } var form = '\  \ \       \            Append \ Prepend \ \            Text to add :  \ Pages :  \ Add pages from a category :  \ Any errors encountered will appear below \ \ '; $('.creates').click(function { $.showCustomModal("Add contents to pages", form, { id: 'writeafter', width: 500, buttons: [{ id: 'startButton', message: 'Submit', defaultButton: true, handler: function { var pages = $('#Names').val.split('\n'); content = $('#Text').val; if (!pages || !content) { alert('Please fill the text and pages inputs'); return false; }    for (i = 0; i < pages.length; i++) { setTimeout(posts(pages[i],content),100); if (i + 1 == pages.length) { $('#text-error-output').append('Done !').delay(3000).css("background-color", "green"); }    }        }    },    {       id: 'Categorysubmit', message: 'Add pages from the category', handler: function { var categoryname = $('#Categoriename').val; addpages(categoryname); }   },    {        message: 'Annuler', handler: function { $('#writeafter').closeModal; location.reload; }   }]  }); });