Butun axtardiqlarinizi tapmaq ucun buraya: DAXIL OLUN
  Mp4 Mp3 Axtar Yukle
  Video Axtar Yukle
  Shekil Axtar Yukle
  Informasiya Melumat Axtar
  Hazir Inshalar Toplusu
  AZERI CHAT + Tanishliq
  1-11 Sinif Derslikler Yukle
  Saglamliq Tibbi Melumat
  Whatsapp Plus Yukle(Yeni)

  • Ana səhifə
  • Təsadüfi
  • Yaxınlıqdakılar
  • Daxil ol
  • Nizamlamalar
İndi ianə et Əgər Vikipediya sizin üçün faydalıdırsa, bu gün ianə edin.

İstifadəçi:MGA73/replaceToCommons.js

  • İstifadəçi səhifəsi
  • Müzakirə
  • Mənbəyə bax
< İstifadəçi:MGA73

Qeyd: Dəyişiklikləri yayımladıqdan sonra etdiyiniz dəyişikliklərin görünməsi üçün brauzerinizin keşinin təmizlənməsi lazım ola bilər.

  • Firefox / Safari: Reload düyməsinə basılı tutarkən Shift düyməsinə basın, və ya Ctrl+F5 və ya Ctrl+R (Mac üçün ⌘-R )
  • Google Chrome: Ctrl-Shift-R (Mac üçün ⌘-Shift-R)
  • Edge: Ctrl düyməsini basılı tutarkən Refresh düyməsinə basın, və ya sadəcə Ctrl+F5.
/* Replace image uses with commons copy or similar file */
$(function(){
if (mw.config.get('wgCanonicalNamespace') !== 'File') return; // valid only in file namespace
function replaceFile(newName) {
    var rgxFrom = new RegExp(/.+?:(.+)/.exec(mw.config.get('wgPageName'))[1].replace(/_/g, '[ _]')),
        process = new $.Deferred(),
        api = new mw.Api(),
        requiredReplacements = $('.mw-imagepage-linkstoimage a').length;

    mw.notify('Replacing with ' + newName);
    process.progress(function(){
        requiredReplacements--; 
        if(requiredReplacements === 0) {
            mw.notify('All file uses have been replaced');
        }
    })
    $('.mw-imagepage-linkstoimage a').each(function(){
        var page = $(this).attr('title');
        api.get({action:'parse', page: page, prop: 'wikitext'}).done(function(d){
            var oldText = d.parse.wikitext['*'];
            var newText = d.parse.wikitext['*'].replace(rgxFrom, newName);
            if(oldText!=newText) {
                api.postWithToken('edit', {action:'edit', summary: '[['+mw.config.get('wgPageName') + ']] => [[:File:' + newName +']]', text: newText, title: page, minor: true }).done(function(){
                mw.notify('File replaced in '+page);
                process.notify();
                });
            } else {
                mw.notify('File not replaced in '+page);
            }
        });
    });
}

function safeReplaceFile(filename) {
    var api = new mw.Api();
    api.get({action: 'query', titles: 'Fayl:' + filename, prop: 'imageinfo', indexpageids: 1}).done((d) => {
        if ( d.query.pages["-1"] && d.query.pages["-1"].imagerepository === 'shared' ) {
            replaceFile(filename);
        } else if ( d.query.pageids.length === 1 && d.query.pageids[0] != -1) {
            mw.notify('Local copy of the file exists');
        }
        else {
            mw.notify('File does not exist. Please check manually.');
        }
    });
}

function getNowCommonsName() {
    var api = new mw.Api();
    api.get({action: 'parse', page: mw.config.get('wgPageName'), prop: 'wikitext'}).done(function(d){
        var wikitext = d.parse.wikitext['*'];
        var match = wikitext.match(/\{\{NowCommons\|([^}]+)\}\}/);
        if (match) {
            var newName = match[1].replace(/Faili:|Fayl:|File:|Image:/,'').replace('_', ' ');
            safeReplaceFile(newName);
        } else {
            var newName = prompt("Enter the name of the replacement image");
            newName = newName.replace(/Faili:|Fayl:|File:|Image:/,'').replace('_', ' ');
            safeReplaceFile(newName);
        }
    });
}

$(mw.util.addPortletLink('p-cactions','#','Replace with Commons','#ca-js-moveToCommons')).click(function(){
    getNowCommonsName();
});
});
Mənbə — "https://az.wikipedia.org/w/index.php?title=İstifadəçi:MGA73/replaceToCommons.js&oldid=8142107"
Informasiya Melumat Axtar