User:Miniapolis/vector.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.
importScript('User:Lupin/recent2.js');
importScript("User:Drilnoth/delresized.js");
importScript("User:Animum/easyblock.js"); //[[User:Animum/easyblock.js]]
//mw.loader.load('//ru.wikipedia.org/w/index.php?title=MediaWiki:Gadget-markblocked.js&action=raw&ctype=text/javascript');
importScript('User:Anomie/linkclassifier.js'); // Linkback: [[User:Anomie/linkclassifier.js]]
importStylesheet('User:Anomie/linkclassifier.css'); // Linkback: [[User:Anomie/linkclassifier.css]]
importScript('User:Relentlessly/hiderefs.js');
importScript('User:Magog the Ogre/cleanup.js');
//Mass rollback function
//Written by John254 and modified/rewritten by Writ Keeper; original is at https://en.wikipedia.org/wiki/User:John254/mass_rollback.js
//Adapted from User:Mr.Z-man/rollbackSummary.js
//Instructions: Selecting the "rollback all" tab when viewing a user's contributions history
//will open all rollback links displayed there. (Use with caution)
  
function rollbackEverythingWKMR(editSummary) 
{
	if(editSummary === null)
	{
		return false;
	}
	var userName = mw.config.get("wgRelevantUserName");
	var titleRegex = /title=([^&]+)/;
	
	$.post("/w/api.php",{action:"query",meta:"tokens",type:"rollback",format:"json"}, function(data)
	{
		rollbackToken = data.query.tokens.rollbacktoken;
		$("a[href*='action=rollback']").each(function(ind, el)
		{
			var postInfo = {action:"rollback",title:titleRegex.exec(el.href)[1],token:rollbackToken,user:userName};
			if(editSummary != "")
			{
				postInfo.summary = editSummary;
			}
			$.post("/w/api.php", postInfo, function()
			{
				$(el).after("reverted");
				$(el).remove();
			});
		});
	});
	return false;
}
$(function()
{
	if(mw.config.get("wgCanonicalSpecialPageName") == "Contributions" && $("span.mw-rollback-link").length > 0)
	{
		mw.loader.using("mediawiki.util").done(function ()
		{
			mw.util.addPortletLink('p-cactions', '#', "rollback all", "ca-rollbackeverything", "rollback all edits displayed here");
			$("#ca-rollbackeverything").click(function()
			{
				return rollbackEverythingWKMR(prompt("Enter an edit summary, or leave blank to use the default (or hit Cancel to cancel the rollback entirely)"));
			});
		});
	}
});
importScript('User:Evad37/FFDcloser.js'); // [[User:Evad37/FFDcloser]]
//mw.loader.load('//en.wikipedia.org/w/index.php?title=User%3ADr+pda%2Farticlehistory.js&action=raw&ctype=text/javascript'); // [[User:Dr pda/articlehistory.js]]
importScript('User:Lourdes/PageCuration.js'); // Linkback: [[User:Lourdes/PageCuration.js]]
importScript('User:Anomie/unsignedhelper.js'); // Linkback: [[User:Anomie/unsignedhelper.js]]

// This function will add a link to your Wikipedia toolbar.  It is required both for [[User:Howcheng/quickimgdelete.js|Howcheng's image deletion script]] and my template replacement script.
// It is not the right way to do things - we should be using mw.loader, but that doesn't seem to be working right now for some reason and plugging in this old code is easier than looking up
// the new API parameters.  Please, MediaWiki developers, don't have breaking changes.

/* This code may be problematic when it comes to titles with ampersands, etc, which are stored as ''& amp ;'' in HTML (without the spaces).
  A solution that solves this is the following:
    return document.title.substr(0, document.title.lastIndexOf(' - Wikipedia, the free'));
*/

function addLinkUserBRescaledSidebar(where, url, name, id, title, key, after){
    //* where is the id of the toolbar where the button should be added;
    //   i.e. one of "p-cactions", "p-personal", "p-navigation", or "p-tb".
    //
    //* url is the URL which will be called when the button is clicked.
    //   javascript: urls can be used to do more complex things.
    //
    //* name is what will appear as the name of the button.
    //
    //* id is the id of the button; it's best to define one.  
    //   Use a prefix to make sure its unique. Optional.
    //
    //* title is the tooltip title that gives a longer description 
    //   of the button; if you define a accesskey, mention it here. Optional.
    //
    //* key is the char you want for the accesskey. Optional.
    //
    //* after is the id of the button you want to follow this one. Optional.
    //
    var na = document.createElement('a');
    na.href = url;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    if(id) li.id = id;
    li.appendChild(na);
    var tabs = document.getElementById(where).getElementsByTagName('div')[0].getElementsByTagName('ul')[0];

    if(after) 
{
        tabs.insertBefore(li,document.getElementById(after));
    } else {
        tabs.appendChild(li);
    }
/*
    if(id) {
        if(key && title) { ta[id] = [key, title]; }
        else if(key) { ta[id] = [key, '']; }
        else if(title) { ta[id] = ['', title];} 
    }
    // re-render the title and accesskeys from existing code in wikibits.js
    akeytt();*/
    return li;
}


if ( mw.config.get('wgNamespaceNumber') == 6 ) {
	// Note: this code stopped working in January 2019
	/*
	mw.loader.using( ['mediawiki.util', 'mediawiki.api'], function() {
		var rescaled = mw.util.addPortletLink( 'p-tb', '#',
			'rescaled', 'ca-rescaled', 'Rescaled per F5', 's');
		$( rescaled ).click( do_it );
	});*/
	
	// Temporary workaround until we figure out why the above stopped working
    addLinkUserBRescaledSidebar('p-tb', 'javascript:OnUserBRescaledSidebarClick();', 'Remove Orphaned old version', 'ca-rescaled', 'Remove old version per F5');
}
 
function OnUserBRescaledSidebarClick() {
	var api = new mw.Api();
	api.get( {
		action: 'query',
		prop: 'imageinfo|revisions',
		titles: mw.config.get('wgPageName'),
		iiprop: 'archivename',
		iilimit: 'max',
		rvprop: 'content',
		rvlimit: '1'
	}).done( function ( data ) {
		var pgdata = data.query.pages[mw.config.get('wgArticleId')];
		var imgs = pgdata.imageinfo;
		console.log(imgs);
		var todelete = [];
		$.each( imgs, function ( index, value ) {
			if ( index === 0 ) {
				return;
			}
			todelete.push( value.archivename.split('!')[0] );
		});
		api.postWithToken( 'delete', {
			action: 'revisiondelete',
			type: 'oldimage',
			target: mw.config.get('wgPageName'),
			ids: todelete.join('|'),
			hide: 'content',
			reason: 'Orphaned non-free file(s) deleted per [[WP:F5|F5]]'
		}).done( function( data ) {
				mw.notify("Deleted old revision.");
		});
 
		// Also edit!
		var text = pgdata.revisions[0]['*'];
		// from drilnoth's script
		text = text.replace(/\n*\{\{\s?(Non\-free reduced|Orphaned non\-free revisions)\s?\|\s?(?:\d|date)?\=?(\d\d\:\d\d\,\s\d\d?\s.*\s\d\d\d\d(\s\(UTC\))?|.*\d\d?(?:\s[a-z]+)?\s\d\d\d\d)\s?\}\}/ig,'');
		text = text.trim();
		api.postWithToken( 'edit', {
			action: 'edit',
			title: mw.config.get('wgPageName'),
			summary: 'Previous version(s) deleted per [[WP:F5|F5]])',
			text: text
		}).done( function ( data ) {
			mw.notify("Removed the template."); setTimeout(function() { window.location.reload();}, 3000);
		});
 
	});
}
importScript('User:Frietjes/findargdups.js'); // [[User:Frietjes/findargdups]]
importScript('User:Evad37/duplinks-alt.js'); // [[User:Evad37/duplinks-alt]]
mw.loader.load( '/w/index.php?title=User:Ritenerek/js/goce_nav.js&action=raw&ctype=text/javascript' ); // Backlink: [[User:Ritenerek/js/goce_nav]]
mw.config.set('wgPostEditConfirmationDisabled', true);