User:MC10/UsefulTabs.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:MC10/UsefulTabs. |
// A few useful tabs
// Author: MC10
// Linkback: [[User:MC10/UsefulTabs.js]]
(function($, undefined) { // Wrap with jQuery
// Purge
$(function() {
if (mw.config.get("wgNamespaceNumber") === -1) // No special pages
return;
var url = mw.config.get("wgServer") + mw.config.get("wgScript") + "?title=" + mw.config.get("wgPageName") + "&action=purge";
mw.util.addPortletLink('p-cactions', url, 'Purge', 'ca-purge', 'Purge server cache for this page', '0');
});
// Special:PrefixIndex
$(function() {
if (mw.config.get("wgTitle").indexOf("/") !== -1 || mw.config.get("wgAction") === "history") // No subpages or history
return;
if (mw.config.get("wgNamespaceNumber") === 2 || mw.config.get("wgNamespaceNumber") === 3) {
var username = encodeURIComponent(mw.config.get("wgTitle")),
checkurl = mw.config.get("wgServer") + mw.config.get("wgScriptPath") + "/index.php?title=Special:PrefixIndex&prefix=" + username + "&namespace=2" ;
mw.util.addPortletLink("p-cactions", checkurl, "Subpages", "ca-contrib", "Subpages of user");
}
});
// Edit count
$(function() {
if (mw.config.get("wgTitle").indexOf("/") !== -1 || mw.config.get("wgAction") === "history") // No subpages or history
return;
if (mw.config.get("wgNamespaceNumber") === 2 || mw.config.get("wgNamespaceNumber") === 3) {
var username = encodeURIComponent(mw.config.get("wgTitle")),
checkurl = "//toolserver.org/~soxred93/pcount/index.php?name=" + username + "&lang=en&wiki=wikipedia";
mw.util.addPortletLink("p-cactions", checkurl, "Edits", "ca-contrib", "Analysis of edits by user");
}
});
// Quick edit count
$(function() {
var quickEditCount = {
retrieveData: function(user) {
$.ajax({
url: mw.config.get("wgServer") + mw.config.get("wgScriptPath") + "/api.php?action=query&format=json&list=users&usprop=editcount&ususers=" + user,
dataType: "json",
success: function(data) {
var info = data.query.users[0];
var editcount = info.editcount;
var name = info.name;
$("#contentSub").html($("#contentSub").html() + "<br /><strong>" + name + " has " + editcount + " total edits.</strong>");
}
});
},
editCount: function() {
var subpagename = mw.config.get("wgTitle").split("/")[1],
countuser;
if ((mw.config.get("wgNamespaceNumber") === 2 || mw.config.get("wgNamespaceNumber") === 3) && !subpagename) {
countuser = mw.config.get("wgTitle").split(":")[0];
} else if (mw.config.get("wgNamespaceNumber") === -1 && mw.config.get("wgTitle").indexOf("Contributions") !== -1) {
if (!document.getElementById("contentSub"))
return;
countuser = mw.config.get("wgTitle").slice(14);
}
this.retrieveData(countuser);
}
}
var subpagename = mw.config.get("wgTitle").split("/")[1];
if (((mw.config.get("wgNamespaceNumber") === 2 || mw.config.get("wgNamespaceNumber") === 3)
&& subpagename === undefined && mw.config.get("wgAction") !== "history")
|| mw.config.get("wgCanonicalSpecialPageName") === "Contributions") {
var portletLink = mw.util.addPortletLink("p-cactions", "#", "Count", "ca-editcount", "Quick edit count of user");
$(portletLink).click(function(e) {
e.preventDefault();
quickEditCount.editCount();
});
}
});
}(jQuery)); // End wrap with jQuery
// [[Category:Wikipedia scripts]]