User:Nasser Bin Ali/pagesCreated.js

/*
 * Pages Created -- finds all the pages created by a user
 * see User:Jfmantis/pagesCreated

(function {

/* function makeCreatedPageItem(contrib) { var item = document.createElement("li");
 * create  list item for one article
 * right now, just a link to the page & the date

var link = document.createElement("a"); link.href = mw.util.getUrl(contrib.title); link.innerHTML = contrib.title;

item.appendChild(link);

item.innerHTML += " . . " + new Date(contrib.timestamp).toDateString;

return item; }

/* function findPagesCreated(bundle) { bundle.api.get({		action: "query",		rawcontinue: "",		list: "usercontribs",		ucuser: bundle.user,		ucstart: bundle.start,		ucprop: "flags|title|timestamp",		ucshow: "!minor",		uclimit: 500,		ucnamespace: 0	}).done( function(data) {		$.each(data.query.usercontribs, function(index, contrib) { if (contrib.new != undefined) { bundle.list.appendChild(makeCreatedPageItem(contrib)); bundle.count++; }		});
 * looks through all of a user's non-minor namespace 0 edits,
 * looking for edits tagged as "new"
 * the arguments all in one object so that it can be expanded
 * in the future without having to add a bunch more parameters
 * in the future without having to add a bunch more parameters

if (data["query-continue"]) {	// more contributions bundle.start = data["query-continue"].usercontribs.ucstart setTimeout(function { findPagesCreated(bundle); }, 3000); } else {	// done $("#pc-status")[0].innerHTML = " " + bundle.user + " has created " + bundle.count + " articles"; }	}).fail( function(error) { alert(error); }); }

/* function setupPagesCreated(user) { // set new title mw.util.$content.find("#firstHeading")[0].innerHTML = "Pages created by " + user;
 * change title, clear content area, etc.

// status bar (text + waiting gif) var status = document.createElement("span"); status.id = "pc-status"; status.innerHTML = " Fetching user data...";

// heading for results var heading = document.createElement("h3"); heading.innerHTML = "Articles";

// list of results var articles = document.createElement("ul"); articles.id = "pc-articles";

var body = mw.util.$content.find("#bodyContent")[0]; body.innerHTML = ""; body.appendChild(status); body.appendChild(heading); body.appendChild(articles);

var api = new mw.Api; api.get({		action: "query",		list: "users",		ususers: user,		usprop: "editcount"	}).done(function(data) {		// 500 results per request, 1 request every 3 seconds		var count = data.query.users[0].editcount;		status.innerHTML = " User has " + count + " edits, this should take less than ";		status.innerHTML += (3 * Math.round(count / 500)) + " seconds   ";

var waitgif = document.createElement("img"); waitgif.src = "https://upload.wikimedia.org/wikipedia/commons/4/42/Loading.gif"; status.appendChild(waitgif);

findPagesCreated(			{"api": api,			"user": user,			"list": articles,			"start": "",			"count": 0}		); }).fail(function(error) { alert(error); });

return false; }

mw.loader.using("mediawiki.util", function {	// add portlet when page is User or User_talk, but not on subpages	if ((wgNamespaceNumber == 2 || wgNamespaceNumber == 3) && (wgTitle.indexOf("/") == -1)) {		if (mw.util.getParamValue("pagesCreated")) {			setupPagesCreated(wgTitle);		} else {			mw.util.addPortletLink("p-tb", document.location.toString + "?pagesCreated=true", "Pages created", "pc-pages", "Get a list of all pages created by this user" );		}	} });

});