Jump to content

User:Quarl/copyvio.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// [[User:Quarl/copyvio.js]] - add copyvio tag and add entry to 'copyright
// problems' page

// depends: wikipage.js, addlilink.js

// <pre><nowiki>

var copyvio = new Object();

copyvio.logEntry = function(wp, url, callback) {
    copyvio._getLogWP().getEditorAsync(copyvio._logEntryEdit, wp, url, callback);
}

copyvio._logEntryEdit = function(editor, wp, url, callback) {
    if (editor.wpTextbox1.indexOf('[['+wp.page+']]') == -1) {
        editor.wpTextbox1 += '* {{subst:article-cv|'+wp.page+'}} from ['+url+']. ~~~~';
        editor.wpSummary += 'Listing [['+wp.page+']] as copyvio of '+url;
        editor.submitAsync(callback, wp, url);
    } else {
        alert("[["+wp.page+"]] already on log page; not relisting!");
        callback(wp, url);
    }
}

copyvio.tagEntry = function(wp, url) {
    wp.getEditorAsync(copyvio._tagEntryEdit, url);
}

copyvio._tagEntryEdit = function(editor, url) {
    // **replace** content!
    editor.wpTextbox1 = '{' + '{' + 'copyvio|url='+url+'}}\n~~~~';
    editor.wpSummary = '[[Wikipedia:Copyrights|copyvio]] of '+url+' ([['+copyvio._getLogWP().page+'|log]])';
    editor.submit();
}

copyvio._getLogWP = function() {
    var logPageName = 'Wikipedia:Copyright problems/' + datestampYYYYMonthD();
    return new WikiPage(null, logPageName);
}

copyvio.logAndTagWp = function(wp, url) {
    copyvio.logEntry(wp, url, copyvio.tagEntry)
}

copyvio.queryLogAndTag = function() {
    var url = window.prompt("Copyvio of which URL?");
    if (!url) return;

    copyvio.logAndTagWp(wikiPage, url);
}

copyvio._load = function() {
    //if (wikiPage.nsSpecialP) return;
    if (!wikiPage.nsMainP) return; // copyvios generally only in article space
    addTab('javascript:copyvio.queryLogAndTag()', 'CopyVio', 'ca-copyvio', 'Tag for copyright violation');
}

$(copyvio._load);

// </nowiki></pre>