User:Robyn Grayson/wikia.js

setTimeout(function {   if (window.FilePopup) {        return;    }    window.Filepopup = true;    var FilePopup = {        init: function {            mw.loader.using('mediawiki.api').then($.proxy(function {                this.api = new mw.Api;                this.initPopup;                this.initListeners;            }, this));        },        initPopup: function {            mw.util.addCSS('                    \ #FilePopup {                   \ padding: 10px;             \ background-color: #00CED1; \ border-radius: 5px;        \ border: 1px solid #00FFFF; \ position: fixed;           \ z-index: 9999999;          \ color: black;              \ }                              \            ');            var br = mw.html.element('br');            $('#WikiaPage').append( $(' ')                   .attr('id', 'FilePopup') .css('display', 'none') .html(                       'File by: ' + mw.html.element('span', { id: 'FilePopupBy' }) + br +                        'Uploaded at: ' + mw.html.element('span', { id: 'FilePopupAt' }) + br +                        'Used on namespaces: ' + mw.html.element('span', { id: 'FilePopupUsedNS' }) + br +                        'Used on articles: ' + mw.html.element('span', { id: 'FilePopupUsedArticles' }) + br +                        'Categories: ' + mw.html.element('span', { id: 'FilePopupCategories' }) + br +                        'File Dimensions: ' + mw.html.element('span', {id: 'FilePopupFileDimensions' })                    ) );           $('#FilePopup').hover(function { $('#FilePopup').css('display', 'block'); }, function { $('#FilePopup').css('display', 'none'); });       },        initListeners: function {            $('a[href*="/wiki/' + encodeURIComponent(wgFormattedNamespaces[6]) + ':"').each($.proxy(function(_, el) {                el = $(el);                el.hover($.proxy(this.hover, this), function { $('#FilePopup').css('display', 'none'); });               el.removeAttr('title');            }, this));        },        hover: function(e) {            var filename = decodeURIComponent(new mw.Uri($(e.target).closest('a').attr('href')).path.substring(6));            this.api.get({ action: 'query', titles: filename, iutitle: filename, prop: 'imageinfo|categories', iiprop: 'size|user|timestamp', list: 'imageusage' }).done($.proxy(function(d) {               var pages = d.query.pages,                    namespaces = [],                    articles = [],                    info = pages[Object.keys(pages)[0]],                    ii = info.imageinfo[0],                    width = ii.width,                    height = ii.height;                d.query.imageusage.forEach(function(el) { var name = (el.ns === 0) ? 'Article' : el.title.split(':')[0]; if(namespaces.indexOf(name) === -1) { namespaces.push(name); }                   if(el.ns === 0) { articles.push(el.title); }               }, this);                this.updatePopup(e, ii.user, ii.timestamp, namespaces, articles, info.categories ? info.categories.map(function(el) {                   return el.title.split(':')[1];                }) : [' '], width, height);            }, this));        },        updatePopup: function(e, user, timestamp, namespaces, articles, categories, width, height) {            $('#FilePopup').css({ display: 'block', top: e.clientY, left: e.clientX });           $.each({ by: mw.html.element('a', { href: '/wiki/Special:Contributions/' + encodeURIComponent(user) }, user), at: timestamp, usedNS: namespaces.join(', '), usedArticles: articles.join(', '), categories: categories.join(', '), fileDimensions: width + (' x ') + height }, function(k, v) { $('#FilePopup' + k.charAt(0).toUpperCase + k.substring(1)).html(v); });       }    };    $($.proxy(FilePopup.init, FilePopup)); }, 5000);

/* - Custom version requested by Robyn Grayson - put the old names in the first text area and the new ones in the second. mw.loader.using('mediawiki.api', function { var FormHTML = '\  \   \        Put the name of the page you want to rename, then the new name in the second text area. \        For page names with spaces, use underscores instead of spaces. \            Leave a redirect behind?  \			 Before: \             \			 After: \             \    \    Any errors encountered will appear below  \ ', delay = window.massRenameDelay || 1000, moveSummary = window.massRenameSummary || 'automatic'; //Support for Monobook if (mw.config.get('skin') === 'monobook') { mw.util.addPortletLink('p-tb', '#', 'Mass Rename', 't-mr'); } else if ($('#my-tools-menu').length) { $('#my-tools-menu').prepend(' Mass Rename'); } $('#t-mr').click(function {   $.showCustomModal('Mass Rename', FormHTML, { id: 'form-rename', width: 500, buttons: [{ id: 'start-button', message: 'Initiate', defaultButton: true, handler: function { init; }       }, {            message: 'Cancel', handler: function { $('#form-rename').closeModal; }       }]    }); }); function init { var txt1 = document.getElementById('text-rename1'), pages1 = txt1.value.split('\n'), page1 = pages1[0], txt2 = document.getElementById('text-rename2'), pages2 = txt2.value.split('\n'), page2 = pages2[0]; document.getElementById('start-button').setAttribute('disabled','disabled'); if (!page1 || !page2) { document.getElementById('start-button').removeAttribute('disabled'); $.showCustomModal('Finished!', 'Nothing left to do, or next line is blank.', {      id: 'form-complete',       width: 200,       buttons: [{          message: 'Close',          defaultButton: true,          handler: function {            $('#form-complete').closeModal;          }       }]    }); }  else { rename(page1 + " " + page2); } pages1 = pages1.slice(1,pages1.length); txt1.value = pages1.join('\n'); pages2 = pages2.slice(1,pages2.length); txt2.value = pages2.join('\n'); } function rename(nameString) { if (nameString.split(" ").length != 2) { $('#text-error-output').append('The line \"'+nameString+'\" is invalid input! '); } else { var oldName = nameString.split(" ")[0], newName = nameString.split(" ")[1], config = { action: 'move', from: oldName.replace("_", " "), to: newName.replace("_", " "), noredirect: '', reason: moveSummary, bot: true, token: mw.user.tokens.get('editToken') };   if (document.getElementById('redirect-check').checked) delete config.noredirect; (new mw.Api).post(config) .done(function(d) {     if (!d.error) {        console.log('Successfully renamed '+oldName+' to '+newName+'!');      }      else {        console.log('Failed to rename '+oldName+' to '+newName+': '+d.error.code);        $('#text-error-output').append('Failed to rename '+oldName+' to '+newName+': '+d.error.code+' ');      }    }) .fail(function {     console.log('Failed to rename '+oldName+' to '+newName+'!');      $('#text-error-output').append('Failed to rename '+oldName+' to '+newName+'! ');   });  }  setTimeout(init,delay); } });
 * Mass Rename
 * Rename pages quickly
 * @author Ozank Cx