Utilisateur:DreZhsh/Test.js
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;
Firefox (sur GNU/Linux) / Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5./* jshint esversion: 6 */
mw.loader.using( [ 'mediawiki.util', 'oojs-ui-windows', 'mediawiki.api' ], () => {
$( function () {
const portletLink = mw.util.addPortletLink( 'p-tb', '#', 'IP Checker', 'IPCPortlet' );
let IPCheckWindowManager;
if ( portletLink === null ) {
return;
}
/**
* ipLinks
*
* Crée les liens à insérer dans la panneau
*
* @param {string} ipAdress - L'adresse IP
* @param {string} introLink - Le lien d'introduction
*/
function ipLinks( ipAdress, introLink = `<a href="https://fr.m.vvikipidea.org/wiki/Spécial:Contributions/${ipAdress}" target="_blank">${ipAdress}</a>` ) {
const whois = `<a href="https://whois-referral.toolforge.org/gateway.py?lookup=true&ip=${ipAdress}" target="_blank">Whois</a> - <a href="https://bullseye.toolforge.org/ip/${ipAdress}" target="_blank">Bullseye</a>`;
const proxy = `<a href="https://www.ipqualityscore.com/free-ip-lookup-proxy-vpn-test/lookup/${ipAdress}" target="_blank">IPQualityScore</a> - <a href="https://ipcheck.toolforge.org/index.php?ip=${ipAdress}" target="_blank">IPCheck</a>`;
const wikimedia = `<a href="https://meta.toolforge.org/stalktoy/${ipAdress}" target="_blank">Blocages</a> - <a href="https://guc.toolforge.org/?by=date&user=${ipAdress}" target="_blank">Contributions globales</a>`;
$( document.getElementsByClassName( 'ipCheckScriptList' ) ).append( $.parseHTML( `<li>${introLink} <br>(<small>${whois} - ${proxy} - ${wikimedia}</small>)</li>` ) );
}
/**
* getIpInRc
*
* Obtient les IPs en fonction de la page
* que l'utilisateur consulte
*/
function getIpInRc() {
const ipAlredyChecked = [];
const avaibleSpecialPage = [ 'BlockList', 'AbuseLog', 'Newpages', 'Log', 'Recentchanges', 'Watchlist' ];
$( document.getElementsByClassName( 'ipCheckScriptList' ) ).empty();
if ( avaibleSpecialPage.indexOf( mw.config.get( 'wgCanonicalSpecialPageName' ) ) !== -1 ) {
$( document.getElementsByClassName( 'mw-anonuserlink' ) ).each( function () {
const ipAdress = $( this ).children().first().text();
if ( ipAlredyChecked.indexOf( ipAdress ) === -1 ) {
ipAlredyChecked.push( ipAdress );
ipLinks( ipAdress );
}
} );
} else if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) {
new mw.Api().get( {
action: 'query',
formatversion: 2,
prop: 'revisions',
titles: mw.config.get( 'wgPageName' ),
rvprop: 'ids|user',
rvlimit: 500
} ).then( ( data ) => {
const revisions = data.query.pages[ 0 ].revisions;
for ( const rev of revisions ) {
const ipAdress = rev.user;
if ( rev.anon === true &&
ipAlredyChecked.indexOf( ipAdress ) === -1
) {
ipAlredyChecked.push( ipAdress );
ipLinks( ipAdress, `(<a href="https://fr.m.vvikipidea.org/wiki/Spécial:Diff/${rev.revid}" target="_blank">Diff</a>) <a href="https://fr.m.vvikipidea.org/wiki/Spécial:Contributions/${ipAdress}" target="_blank">${ipAdress}</a>` );
}
}
} );
} else {
new mw.Api().get( {
action: 'query',
format: 'json',
list: 'recentchanges',
utf8: 1,
formatversion: '2',
rcprop: 'user',
rcshow: 'anon',
rclimit: '100'
} ).then( ( data ) => {
const recentchanges = data.query.recentchanges;
for ( const rc of recentchanges ) {
const ipAdress = rc.user;
if ( ipAlredyChecked.indexOf( ipAdress ) === -1 ) {
ipAlredyChecked.push( ipAdress );
ipLinks( ipAdress );
}
}
} );
}
}
/**
* DefinePageName
*
* Définit le nom à utiliser dans le panneau
*
* @return {string} Le nom à utiliser dans le panneau
*/
function definePageName() {
if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) {
mw.config.set( 'wgPageName', mw.config.get( 'wgPageName' ).replace( /_/g, ' ' ) );
return `l'historique de ${mw.config.get( 'wgPageName' )}`;
} else if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'BlockList' ) {
return 'la liste des blocages';
} else if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'AbuseLog' ) {
return 'le journal des filtrages';
} else if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Newpages' ) {
return 'les nouvelles pages';
} else if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Log' ) {
return 'les journaux';
} else if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Watchlist' ) {
return 'la liste de suivi';
} else {
return 'les modifications récentes';
}
}
/**
* initializeIPC
*
* Création du panneau d'IPCheck
*/
function initializeIPC() {
function LongProcessDialog( config ) {
LongProcessDialog.super.call( this, config );
}
OO.inheritClass( LongProcessDialog, OO.ui.ProcessDialog );
LongProcessDialog.static.name = 'LongProcessDialog';
LongProcessDialog.static.title = 'IP Check';
LongProcessDialog.static.actions = [
{ action: 'save', label: 'Cherchons', icon: 'check', flags: [ 'primary', 'progressive' ] },
{ action: 'cancel', label: 'Fermer la fenêtre', flags: [ 'safe', 'close' ] }
];
LongProcessDialog.prototype.initialize = function () {
LongProcessDialog.super.prototype.initialize.apply( this, arguments );
const htmlElement = mw.html.element( 'div', { style: 'text-align:center; font-size:1.5em', id: 'ipCheckDiv' }, new mw.html.Raw( mw.html.element( 'strong', {}, `Recherche des IPs dans ${definePageName()}` ) ) );
const htmlElement2 = mw.html.element( 'ul', { class: 'ipCheckScriptList', style: 'column-count:2;' }, '' );
const htmlContent = ( htmlElement + htmlElement2 );
this.content = new OO.ui.PanelLayout( { padded: true, expanded: false } );
this.content.$element.append( htmlContent );
this.$body.append( this.content.$element );
};
LongProcessDialog.prototype.getActionProcess = function ( action ) {
const dialogAction = this;
if ( action === 'cancel' ) {
dialogAction.close();
} else if ( action === 'save' ) {
getIpInRc();
}
return LongProcessDialog.super.prototype.getActionProcess.call( this, action );
};
IPCheckWindowManager = new OO.ui.WindowManager();
$( document.body ).append( IPCheckWindowManager.$element );
window.IPCheckDialog = new LongProcessDialog( { size: 'full' } );
IPCheckWindowManager.addWindows( [ window.IPCheckDialog ] );
IPCheckWindowManager.openWindow( window.IPCheckDialog );
}
portletLink.addEventListener( 'click', ( e ) => {
e.preventDefault();
if ( IPCheckWindowManager === undefined ) {
initializeIPC();
} else {
IPCheckWindowManager.openWindow( window.IPCheckDialog );
}
} );
} );
} );