Defnyddiwr:MGA73/LicenseUpdate.js

Nodyn: Ar ôl cyhoeddi, efallai y bydd rhaid i chi fynd heibio celc eich porwr er mwyn gweld y newidiadau.

  • Firefox / Safari: Pwyswch Shift wrth glicio Adnewyddu / Reload, neu bwyswch naill ai Ctrl-F5 neu Ctrl-R (⌘-R ar Mac);
  • Google Chrome: Pwyswch Ctrl-Shift-R (⌘-Shift-R ar Mac)
  • Edge: Pwyswch Ctrl wrth glicio Adnewyddu / Refresh, neu bwyswch Ctrl-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 and 6 when live
            var actions = [
                // Relicense GFDL
                {
                    fn: function (){
                        var needAppend = document.editform.wpTextbox1.value;
                        document.editform.wpTextbox1.value = needAppend.replace(/{{([Gg][Ff][Dd][Ll]|GDFL|GFDL-self|GFDL-with-disclaimers)}}/g, "{{$1|migration=relicense}}");

                        document.editform.wpSummary.value = "File is eligible for relicense of GFDL - see [[:en: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]|GDFL|GFDL-self|GFDL-with-disclaimers)}}/g, "{{$1|migration=not-eligible}}");

                            document.editform.wpSummary.value = "File is not eligible for relicense of GFDL - see [[:en:Wikipedia:Image license migration|here]] - uploader please consider to relicense and add cc-by-sa-4.0 (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]|GDFL|GFDL-self|GFDL-with-disclaimers)}}/g, "{{$1|migration=review}}");

                        document.editform.wpSummary.value = "File need review for relicense of GFDL - see [[:en: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>