User:Kanonkas/projectscope.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
importScript('User:Animum/urlparameters.js');
 
if(UrlParameters["action"] == "edit" && UrlParameters["projectscope"] == 1 && wgNamespaceNumber == 0) {
    addOnloadHook(function() {
        var req = sajax_init_object();
        req.open("GET", wgScriptPath + "/api.php?action=query&prop=revisions&titles=" + wgPageName + "&rvlimit=1&rvprop=user&rvdir=newer&format=json", false);
        req.send(null);
        var text = eval("(" + req.responseText + ")").query.pages;
        for(var index in text) {
            text = text[index];
            var user = text.revisions[0].user;
        }
        document.forms["editform"].wpTextbox1.value = "\{\{speedydelete\|Outside the \[\[Commons:Project scope\|project's scope\]\]\}\}\n\n" + document.forms["editform"].wpTextbox1.value;
        document.forms["editform"].wpSummary.value = "Outside the \[\[Commons:Project scope\|project's scope\]\]";
        document.forms["editform"].wpMinoredit.checked = true;
        document.forms["editform"].submit();
        if(typeof(user) != 'undefined') window.setTimeout(function() { location.href = mw.config.get('wgServer') + mw.config.get('wgScript') + "?title=User_talk:" + encodeURIComponent(user) + "&action=edit&autowelcome=1"; }, 1000);
    });
}
 
if(UrlParameters["action"] == "edit" && UrlParameters["autowelcome"] == 1 && document.forms["editform"].wpTextbox1.value.search(/\=\= ?Welcome/) == -1 && document.forms["editform"].wpTextbox1.value.indexOf("\'\'\'Welcome") == -1 && wgNamespaceNumber == 3) {
    addOnloadHook(function() {
        document.forms["editform"].wpTextbox1.value += "\n\n== Welcome! ==\n\n\{\{subst\:welcome\}\} '''<font face="Arial">[[User:Kanonkas|<font color="#FF7133">Kanonkas</font>]]<sub><small>[[User talk:Kanonkas|<font color="blue">(talk)</font>]]</small></sub></font>''' 17:27, 28 September 2008 (UTC)";
        document.forms["editform"].wpSummary.value = "Welcome to Wikimedia Commons, " + wgTitle + "!";
        document.forms["editform"].wpMinoredit.checked = true;
        document.forms["editform"].submit();
    });
}
 
$(function() {
    if(wgNamespaceNumber == 0 && !UrlParameters["projectscope"]) mw.util.addPortletLink("p-cactions", wgScript + "?title=" + wgPageName + "&action=edit&projectscope=1", "scope", "ca-scope");
});