Benutzer:Matteo1234321 de/common.js

Aus Vikidia
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
//Ajoute des liens utiles personnalisables
(function(){ //Fonction pour afficher les liens
	window.MyTools = {};
	window.MyTools.Purge = function(pageName) {
		var Api = new mw.Api();
		Api.post({
			titles: pageName,
			format: "json",
			action: "purge"
		}).then(function(){
			location.reload();
		});
	};

	var ArticleFullPath = "https://de.vikidia.org/wiki/"; //Raccourci pour les liens
	var ArticleFullPath2 = "https://de.vikidia.org/w/index.php?"; //Idem
	var ArticleFullPathFr = "https://fr.vikidia.org/wiki/"; //Pour les liens sur la Vikidia française
	function AddLink(href, text, where){ //Fonction pour indiquer ou les placer
		var pos = ["p-navigation"/* Sidebar : en-haut (section "Navigation") */, "p-Contribuer"/* N’EXISTE PAS */, "p-personal"/* En-haut, à côté ou en-dessous de "Déconnexion" */, "p-tb" /* Sidebar : Section "Outils" */, "p-cactions" /* Liste "Plus" en-haut des pages */];
		mw.util.addPortletLink(pos[where], href, text);
	}

AddLink(ArticleFullPath + 'Vikidia:Anfragen_an_Administratoren', 'Anfragen an Administratoren', 0); //Le 0 signifie "section "Navigation""
AddLink(ArticleFullPath + 'Vikidia:Anfragen_an_Bürokraten', 'Anfragen an Bürokraten', 0);
AddLink(ArticleFullPathFr + 'Utilisateur:Matteo1234321/Bac_à_sable', 'Meine Spielwiese', 0);
AddLink(ArticleFullPath + 'Vikidia:Spielwiese', 'Vikidia Spielwiese', 0);
AddLink(ArticleFullPath + 'Benutzer:Matteo1234321 de/common.js', 'Common.js : de', 0);
AddLink(ArticleFullPathFr + 'Utilisateur:Matteo1234321/common.js', 'Common.js : fr', 0);
//Le 2 signifie "Au-dessus des pages"
AddLink(ArticleFullPath + 'Special:AllMessages', 'MediaWiki Seiten', 3); //Le 3 signifie "section "Werkzeuge""
AddLink('', 'Seite neu laden', 3);
})();

/**
 * fr:MediaWiki:Gadget-Onglets.js
 *
 */
$.when( mw.loader.using( 'mediawiki.util' ), $.ready ).then( function () {
    if ( (mw.config.get( 'wgNamespaceNumber' ) >= 0) ) {
        var encodedPageName = encodeURIComponent( mw.config.get( 'wgPageName' ) ).replace(/%20/g, '_').replace(/%3A/g, ':').replace(/%2F/g, '/');
        mw.util.addPortletLink(
            'p-views', // Im Original: p-cactions
            mw.config.get( 'wgScript' ) + '?title=' + encodedPageName + '&action=purge',
            'Cache leeren',
            'ca-purge',
            'Leeren des Caches'
        );
        if ( mw.config.get( 'wgAction' ) === 'purge' ) {
            $( '#ca-purge' ).addClass( 'selected' );
        }
        mw.util.addPortletLink(
            'p-cactions',
            mw.config.get( 'wgScript' ) + '?title=' + encodedPageName + '&action=info',
            'Infos',
            'ca-info',
            'Informationen über die Seite'
        );
        if ( mw.config.get( 'wgAction' ) === 'info' ) {
            $( '#ca-info' ).addClass( 'selected' );
        }
        mw.util.addPortletLink(
            'p-cactions',
            mw.config.get( 'wgScript' ) + '?title=Spezial:Logbücher&page=' + encodedPageName,
            'Logbücher',
            'ca-log',
            'Logbücher der Aktion zeigen'
        );
        mw.util.addPortletLink(
            'p-cactions',
            mw.config.get( 'wgScript' ) + '?title=Spezial:Präfixindex=' + encodedPageName + "%2F",
            'Unterseiten',
            't-index',
            'Liste der Unterseiten'
        );
    }
});

//Smart patrol (code de Vivi-1 sous licence CC-BY-SA 3.0)

/*
* This script adds a tab which allows a mass patrolling on the current page. Because it was pointless to mark as patrolled 10 intermediate versions when we can read the difference between the first and the last
*/

var totalRevisions;
var treatedRevisions = 0;

if (mw.config.get('wgNamespaceNumber') >= 0) {
  mw.loader.using( [ 'mediawiki.util', 'mediawiki.api', 'mediawiki.notify', 'oojs-ui' ], function() {
    mw.util.addPortletLink( 'p-views', 'javascript:markAllAsPatrolled()', 'Smart patrol', 'Smart patrol' );
  } );
}

function markAllAsPatrolled() {
  new OO.ui.confirm('Veux-tu marquer toutes les révisions de cette page comme relues ?').then( function( response ) {
    if ( response === true ) {
        getRevisionsList();
    }
  } );
}

function getRevisionsList() {
  var api = new mw.Api();
  api.get( {
	'action': 'query',
	'format': 'json',
	'prop': 'revisions',
	'titles': mw.config.get( 'wgPageName' ),
	'formatversion': '2',
	'rvprop': 'ids|user',
	'rvlimit': 'max'
  } ).then( function ( data ) {
    var revisions = data.query.pages[ 0 ].revisions;
    //var user = revisions[ 0 ].user;
    totalRevisions = revisions.length;
    revisions.forEach( function ( revision ) {
      treatedRevisions++;
      //if ( user === revision.user ) {
        markRevAsPatrolled( revision.revid );
      //}
    } );

  } ).fail( function ( error ) {
      mw.notification.notify( 'Something went wrong: ' + error, { title: 'Smart Patrol', type: 'error' } );
  } );
}

function markRevAsPatrolled( revid ) {
  var api = new mw.Api();
  api.postWithToken( 'patrol', {
	'action': 'patrol',
	'revid': revid

  } ).then( function ( info ) {
    console.log( 'Success for ' + revid, { title: 'Smart Patrol', type: 'info' } );
    if ( totalRevisions == treatedRevisions ) { window.location.reload(); }

  } ).fail( function ( error ) {
    console.log( 'Something went wrong: ' + error, { title: 'Smart Patrol', type: 'error' } );
  } );
}