Benutzer:Ireas/düp-setzen-monobook/main.js

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen

Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.

  • Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
  • Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
  • Internet Explorer/Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
  • Opera: Strg+F5
// DÜP-Template overlay
    var DuepTemplate = {
        name:   "Dateiüberprüfung",
        rows:   [
            { element: 'duep_quelle',       field: "Quelle",                title: "Wenn nicht deutlich wird, woher der Uploader die Datei hat"                                 },  
            { element: 'duep_urheber',      field: "Urheber",               title: "Wenn nicht deutlich wird, wer der Urheber der Datei ist"                                    },
            { element: 'duep_lizenz',       field: "Lizenz",                title: "Wenn die Datei nicht unter einer freien Lizenz veröffentlicht wurde"                        },
            { element: 'duep_freigabe',     field: "Freigabe",              title: "Wenn nicht deutlich wird, dass der Urheber einer freien Lizenz zugestimmt hat"              },
            { element: 'duep_gezeigtes',    field: "Gezeigtes Werk",        title: "Wenn nicht klar ist, dass der Urheber des Originalwerks einer freien Lizenz zugestimmt hat" },
            { element: 'duep_besonderer',   field: "Besonderer Fall",       title: "Wenn ein besonderer Fall vorliegt (persönliche Benachrichtigung)"                           },
            { element: 'duep_1923',   field: "1923",       title: "Für Bilder nach der 1923er-Regel, deren Diskussionslink fehlt."                           }
        ],
        eachRow: function(it) {
            for (var i=0; i<this.rows.length; i++) {
                it(this.rows[i]);
            }
        }
    };

    var freiErklaerung = "(optional) Freitext";
// END global variables

    /** adds form overlay if the file is a local file (not on Commons) */
    function addFormIfLocal () {
    if (isALocalFile()) {
        addForm();
    } else {
        addFormCommons();
    }
    }

    function isALocalFile () {
    if (mw.config.get("wgArticleId") === 0) {  // check wgArticleId. 0 for Commons files, >0 for local files.
        return false; //Commons file
    } else {
        return true; //local file
    }
    }

    /** add the form overlay */
    function addForm() {
        var overlay = document.createElement("div");
        overlay.setAttribute("id", "overlay-duep");
        overlay.style.cssText   = "position:absolute; "
                                + "top:200px; "
                                + "left:200px; "
                                + "border:2px solid black; "
                                + "background-color:#DDDDDD; "
                                + "z-index:99999; "
                                + "padding:10px; "
                                + "font-size:12pt; "
                                + "-moz-box-shadow: 1px 3px 9px #444444; -webkit-box-shadow: 1px 3px 9px #444444; box-shadow: 1px 3px 9px #444444;";
                                
        var form = document.createElement("form");
        form.setAttribute("id", "duep_overlay_form");
        DuepTemplate.eachRow(function(row) {
            var input   = document.createElement("input");
            input.setAttribute("id",        row.element);           
            input.setAttribute("type",      "checkbox");
            // input.setAttribute("checked",   "checked");
            form.appendChild(input);
            
            var label = document.createElement("label");
            label.setAttribute("for", row.element);
            label.setAttribute("title", row.title);
            label.textContent   = row.field;
            form.appendChild(label);
            
            form.appendChild(document.createElement("br"));
        });

    //add free entry text box
        var freiBox   = document.createElement("textarea");
        freiBox.setAttribute("id", "duep_frei");
        freiInit (freiBox);
        
        $(freiBox).focus(function() {
            if (freiBox.value == freiErklaerung)  {
                freiBox.style.cssText = "";
                this.cols=40;
                this.rows=3;
                this.value = '';
            }
        });
        
        $(freiBox).blur(function() {
            if (freiBox.value == '')  {
                freiInit (freiBox);
            }
        });
    
        form.appendChild(freiBox);
    
    
    form.appendChild(document.createElement("br"));


        form.appendChild(document.createElement("br"));
        form.appendChild(MiniUtil.jsLink("Markieren!",       execute));
//        form.appendChild(document.createTextNode("\u00A0\u00A0"));
//        form.appendChild(MiniUtil.jsLink("☐ leeren",    clearForm));
        form.appendChild(document.createTextNode("\u00A0\u00A0\u00A0"));
        form.appendChild(MiniUtil.jsLink("Abbrechen",   removeForm));
        
        overlay.appendChild(form);
        document.getElementsByTagName("body")[0]
                .appendChild(overlay);
    }

    function freiInit (freiBox) {
    freiBox.style.cssText = "color:grey"
    freiBox.value = freiErklaerung;
    freiBox.rows=1;
    freiBox.cols=(freiBox.value.length);
    }

  /** add the form overlay for files on Commons */
    function addFormCommons() {
        var overlay = document.createElement("div");
        overlay.setAttribute("id", "overlay-duep");
        overlay.style.cssText   = "position:absolute; "
                                + "top:200px; "
                                + "left:200px; "
                                + "max-width: 70%; "
                                + "border:2px solid #C00000; "
                                + "background-color:#75d0ff; "
                                + "z-index:99999; "
                                + "padding:10px; "
                                + "font-size:12pt;"
                                + "-moz-box-shadow: 1px 3px 9px #444444; -webkit-box-shadow: 1px 3px 9px #444444; box-shadow: 1px 3px 9px #444444;";
                                
        var form = document.createElement("form");
        form.setAttribute("id", "duep_overlay_form");
 
    var textabsatz = document.createElement("p");

        textabsatz.appendChild(document.createTextNode("Dies ist eine Datei, die in Wikimedia Commons gespeichert ist! Gehe auf die Dateibeschreibungsseite auf Commons und schlage die Datei dort zur Löschung vor (Link am linken Seitenrand in der Werkzeuge-Box auf der Dateiseite) oder verwende für Dateien mit fehlenden Urheberrechtsinformationen die dortigen Vorlagen (\"Problem tags\") zum Markieren von einfachen Mängeln. Genaueres findest du in den "));
    var comLLink = document.createElement("a");
    comLLink.setAttribute('href', 'http://commons.wikimedia.org/wiki/Commons:L%C3%B6schrichtlinien');
    comLLink.appendChild(document.createTextNode("Commons:Löschrichtlinien"));
    textabsatz.appendChild(comLLink);
    textabsatz.appendChild(document.createTextNode("."));

    form.appendChild(textabsatz);
        
        form.appendChild(MiniUtil.jsLink("Abbrechen",   removeForm));
        
        overlay.appendChild(form);
        document.getElementsByTagName("body")[0]
                .appendChild(overlay);
    }



/** remove the form overlay */
    function removeForm() {
        MiniUtil.removeNode(
            document.getElementById("overlay-duep"));
    }

/** reset checkboxes in the form overlay */
    function clearForm() {
        DuepTemplate.eachRow(function(row) {
            document.getElementById(row.element).checked    = false;
        });
    }

/** change the current page by replacing duep-templates with new ones */
    function execute() {
        var newText = compile();
    
        function change(text) {
            var out1 = text.replace(/\{\{Dateiüberprüfung.*\}\}/, newText);
            var out2 = text.replace(/\{\{DÜP.*\}\}/,              newText);
            return out1 != text ? out1 :
                    out2 != text ? out2 :
                    newText + "\n\n" + text;
        }
        MiniWiki.changeText(wgPageName, change, "Dateiüberprüfung", MiniUtil.reloader());
        
        removeForm();
    }

/** compile checkboxes into a template string */
function compile() {
    var newText = "{{" + DuepTemplate.name;
        DuepTemplate.eachRow(function(row) {
        if (document.getElementById(row.element).checked)
            newText += "|" + row.field;
        });
    newText += "}}";
    //if freiBox not empty
    if (!((document.getElementById("duep_frei").value == freiErklaerung) ||
             (document.getElementById("duep_frei").value == ""))) {
        newText += "\n" + document.getElementById("duep_frei").value + " --~~" + "~~\n";
    }
    return newText;
}

/////////// init

addFormIfLocal(); //start!