User:DannyS712 test/wikied.js

mw.loader.using( 'mediawiki.util', function {    $(document).ready( function  { //console.log ( mw.config.get( 'wgPageName' ) ); var link = mw.util.addPortletLink( 'p-cactions', null, 'Wikied', 'ca-Wikied-NPP', 'Wikied'); $( link ).click( function ( event ) {	           event.preventDefault;	            wikied;	        } ); } ); } );

function wikied{ alert( "step 1" ); var pages = get_pages; alert( "step 2" ); var less_pages = cut_pages( pages ); alert( "step 3" ); var as_string = to_string( less_pages ); alert( "Step 4" ); var revs = get_revs( as_string ); alert( "Step 5" ); }

function get_pages{ var request = { action: 'query', list: 'logevents', lenamespace: 2, lelimit: 'max', leaction: 'create/create', leprop: 'ids|title|user|userid|tags', format: 'json', formatversion: 2 };   var result = null; var scriptUrl = mw.config.get( 'wgScriptPath' ) + '/api.php'; $.ajax({		url: scriptUrl,		type: 'get',		data: request,		dataType: 'json',		async: false,		success: function(new_pages) {		   //console.log( new_pages );		    result = new_pages.query.logevents;		    //console.log( results );		} 	}); return result; }

function cut_pages ( pages ){ var good_pages = []; for (var i = 0; i < pages.length; i++){ if (pages[i] && pages[i]["tags"] && pages[i]["tags"].length > 0 && pages[i]["tags"][0] && pages[i]["tags"][0] == "OAuth CID: 1232") { good_pages.push( pages[i] ); }	}	var min_info = []; for (var j = 0; j < good_pages.length && j < 50; j++){ min_info.push( good_pages[j].pageid); }	//console.log( min_info ); return min_info; } function to_string ( min_info ){ //console.log( min_info ); var as_string = ""; if ( min_info[0] ) as_string = String(min_info[0]); for (var k = 1; k < min_info.length; k++){ as_string = as_string + "|" + String(min_info[k]); }	console.log ( as_string ); return as_string; } function get_revs( as_string ){ var request = { action: 'query', pageids: as_string, prop: 'revisions', rvprop: 'ids', format: 'json', formatversion: 2 };   var result = null; var scriptUrl = mw.config.get( 'wgScriptPath' ) + '/api.php'; $.ajax({		url: scriptUrl,		type: 'get',		data: request,		dataType: 'json',		async: false,		success: function(rev_ids) {		   console.log( rev_ids );		    result = rev_ids;		} 	}); return result; }