Utilizator:MGA73/LicenseUpdate.js

De la Wikipedia, enciclopedia liberă

Notă: După salvare, trebuie să treceți peste cache-ul browser-ului pentru a vedea modificările.

  • Mozilla, Google Chrome, Safari, Konqueror: țineți apăsat Shift în timp ce apăsați butonul Reload (sau apăsați Ctrl-Shift-R).
  • Internet Explorer: apăsați Ctrl-F5.
  • Opera: apăsați F5.
//<source lang=javascript>
/*global $, mw */
/**
 * This script is meant to make it easier to mark GFDL files for relicense or not-eligible.
 * 
 * To use it add this to you vector.js (or other) ---> importScript('Користувач:MGA73/LicenseUpdate.js');
 * 
 * URL: https://ro.wikipedia.org/wiki/User:MGA73/LicenseUpdate.js
 * 
 * It is based on some old code from https://en.wikipedia.org/wiki/User:MGA73/nowcommonsreview.js
 * And I did not bother to clean it all up.
 * NowCommonsReview tagger
 * URL: http://en.wikipedia.org/wiki/User:MGA73/nowcommonsreview.js
 * Credits:
 * MGA73, ZooFari, Krinkle and Magog the Ogre
 *
 * Based on http://commons.wikimedia.org/wiki/User:ZooFari/licensereviewer.js by Patstuart
 */

(function (window, $){
    window.nonfreeoldversionsreview = "0.20 (2010-06-23)";
    $.when(mw.loader.using( ["mediawiki.util"] ), $.ready.promise).then(function () {
        if (mw.config.get("wgNamespaceNumber") === 6) {  //NS 2 when testing
            var actions = [
                // Relicense GFDL
                {
                    fn: function (){
                        var needAppend = document.editform.wpTextbox1.value;
                        document.editform.wpTextbox1.value = needAppend.replace(/{{([Gg][Ff][Dd][Ll]|GFDL-self)}}/g, "{{$1|migration=relicense}}");

                        document.editform.wpSummary.value = "File is eligible for relicense of GFDL - see [[Wikipedia:Image license migration|here]] (using [[User:MGA73/LicenseUpdate.js]]).";
                        document.editform.wpMinoredit.checked = true;

                        document.editform.submit();
                    },
                    name: "Relicense",
                    displayName: "Relicense"
                },

                // Not-eligible GFDL
                {
                    fn: function (){
                        var needAppend = document.editform.wpTextbox1.value;
//
//                        var reason = window.prompt("Reason for failed NowCommons review:","");
//                        /* on cancel button, actually cancel */
//                        if (reason !== null) {
                            document.editform.wpTextbox1.value = needAppend.replace(/{{([Gg][Ff][Dd][Ll]|GFDL-self)}}/g, "{{$1|migration=not-eligible}}");

                            document.editform.wpSummary.value = "File is not eligible for relicense of GFDL - see [[Wikipedia:Image license migration|here]] - uploader please consider to relicense (using [[User:MGA73/LicenseUpdate.js]]).";
                            document.editform.wpMinoredit.checked = true;

                            document.editform.submit();
//                        }
                    },
                    name: "Not-eligible",
                    displayName: "Not-eligible"
                },
                
                                // Review GFDL
                {
                    fn: function (){
                        var needAppend = document.editform.wpTextbox1.value;
                        document.editform.wpTextbox1.value = needAppend.replace(/{{([Gg][Ff][Dd][Ll]|GFDL-self)}}/g, "{{$1|migration=review}}");

                        document.editform.wpSummary.value = "File need review for relicense of GFDL - see [[Wikipedia:Image license migration|here]] (using [[User:MGA73/LicenseUpdate.js]]).";
                        document.editform.wpMinoredit.checked = true;

                        document.editform.submit();
                    },
                    name: "Review",
                    displayName: "Review"
                },
            ];


            // [review] link inserter
//            var html;
//            if (mw.config.get("wgCategories").join("|").match(/Wikipedia files reviewed on Wikimedia Commons/)){
//                // This page is in a reviewed category. Dont display links.
//                html = "<small>Already reviewed</small>";
//
//            } else { // This NowCommons page isn't reviewed yet. Show links.
                html = actions.map(function (action){
                    return "[" + $("<a></a>").attr("href", mw.config.get("wgScript") + "?title=" +
                            encodeURIComponent(mw.config.get("wgPageName")) + "&action=edit&functionName=" +
                            action.name).text(action.displayName)[0].outerHTML + "]";
                }).join(" ");
//            }
            $("div.GFDL-reviewme").css("text-align", "center").html(html);

            // Link/Button maker
            actions.forEach(function (action){
                //functionNameString, buttonDisplayName, callback
                if (mw.util.getParamValue("functionName") == action.name){
                    action.fn(true);
                } else {
                    var _href;
                    var callback;
                    if (["edit", "submit"].indexOf(mw.config.get("wgAction")) > -1){
                        _href = "javascript:void(0);";
                        callback = action.fn;
                    } else {
                        _href = mw.config.get("wgScript") + "?title=" + encodeURIComponent(mw.config.get("wgPageName")) + "&action=edit&functionName=" + action.name;
                    }

                    // Add buttons
                    [["cactions", "ca"], ["tb", "tb"]].forEach(function (actionData) {
                        var node = mw.util.addPortletLink("p-" + actionData[0], _href, action.displayName, "ca-" + actionData[1], "", null, 0);
                        if (callback) {
                            $(node).click(callback);
                        }
                    });
                }
            });
        }
    });
}(window, $));
//</source>