mAucun résumé des modifications |
(Système terminé) |
||
Ligne 111 : | Ligne 111 : | ||
translationSearch(); |
translationSearch(); |
||
} ); |
} ); |
||
+ | |||
+ | // Outdated or untranslated pages table |
||
+ | $( '.mw-translation-list' ).each( function () { |
||
+ | var $table = $( this ); |
||
+ | var namespace = $table.attr( 'data-translation-list-ns' ) || 0 |
||
+ | Promise.all( [ |
||
+ | wikiQueryFetchAllPages( true , namespace ), |
||
+ | wikiQueryFetchAllPages( false, namespace ), |
||
+ | wikiCargoQueryFetch( false, 'tables=maintenance&fields=_pageName=page,revision&limit=500' ) |
||
+ | ] ).then( function ( r ) { |
||
+ | $( '.mw-translation-list > tbody' ).empty(); |
||
+ | for ( var twp in r[1] ) |
||
+ | addTransationRow( $table, r[0], r[2], r[1][twp] ); |
||
+ | } ); |
||
+ | } ); |
||
} ); |
} ); |
||
+ | |||
+ | function addTransationRow( $table, sourceWikiPages, translatedPages, targetWikiPage ) { |
||
+ | var translatedPage = translatedPages.find( function ( p ) { |
||
+ | return p.title.page == targetWikiPage.title; |
||
+ | } ); |
||
+ | if ( !translatedPage ) { |
||
+ | $table.append( '<tr class="mw-translation-list-nosource"><td><a href="https://bindingofisaacrebirth-fr.gamepedia.com/index.php?curid=' + targetWikiPage.pageid + '">' + targetWikiPage.title + '</a></td><td>→</td><td style="color: darkred">☒</td><td style="color: grey">⬾</td><td></td></tr>' ); |
||
+ | return; |
||
+ | } |
||
+ | translatedPage = translatedPage.title; |
||
+ | var sourceWikiPage = {}; |
||
+ | wikiQueryFetch( true, 'prop=revisions&revids=' + translatedPage.revision ) |
||
+ | .then( function ( r ) { return r.pages; } ) |
||
+ | .then( function ( r ) { |
||
+ | if ( !r ) |
||
+ | throw new Error(); |
||
+ | var sourceWikiPageID; |
||
+ | for ( sourceWikiPageID in r ) |
||
+ | break; |
||
+ | sourceWikiPage = sourceWikiPages.find( function ( p ) { |
||
+ | return p.pageid == sourceWikiPageID; |
||
+ | } ); |
||
+ | return wikiQueryFetch( true, 'prop=info&pageids=' + sourceWikiPageID ); |
||
+ | } ) |
||
+ | .then( function ( r ) { return r.pages; } ) |
||
+ | .then( function ( r ) { |
||
+ | for ( var p in r ) |
||
+ | return r[p]; |
||
+ | } ) |
||
+ | .then( function ( r ) { |
||
+ | var lastSourceWikiPageRevisionID = r.lastrevid; |
||
+ | $table.append( translatedPage.revision == lastSourceWikiPageRevisionID ? '<tr class="mw-translation-list-uptodate"><td><a href="https://bindingofisaacrebirth-fr.gamepedia.com/index.php?curid=' + targetWikiPage.pageid + '">' + targetWikiPage.title + '</a></td><td>→</td><td style="color: green">☑</td><td>←</td><td><a href="https://bindingofisaacrebirth.gamepedia.com/index.php?curid=' + targetWikiPage.pageid + '">' + sourceWikiPage.title + '</a></td></tr>' : '<tr class="mw-translation-list-outdated"><td><a href="https://bindingofisaacrebirth-fr.gamepedia.com/index.php?curid=' + targetWikiPage.pageid + '&action=edit">' + targetWikiPage.title + '</a></td><td>→</td><td><a href="https://bindingofisaacrebirth.gamepedia.com/index.php?type=revision&diff=' + lastSourceWikiPageRevisionID + '&oldid=' + translatedPage.revision + '" style="color: red">☒</a></td><td>←</td><td><a href="https://bindingofisaacrebirth.gamepedia.com/index.php?curid=' + targetWikiPage.pageid + '">' + sourceWikiPage.title + '</a></td></tr>' ); |
||
+ | } ) |
||
+ | .catch( function () { console.log( 'invalid revision ID ("' + translatedPage.revision + '") from translation template on page "' + targetWikiPage.title + '"' ); } ); |
||
+ | } |
||
+ | |||
+ | function wikiQueryFetchAllPages( fromSource, namespace, f_args, f_storage ) { |
||
+ | return wikiFetch( 'query', fromSource, 'list=allpages&rawcontinue=1&aplimit=500&apnamespace=' + namespace + ( f_args || '' ) ).then( function ( r ) { |
||
+ | f_storage = f_storage ? f_storage.concat( r.query.allpages ) : r.query.allpages; |
||
+ | if ( !r['query-continue'] ) |
||
+ | return f_storage; |
||
+ | f_args = ''; |
||
+ | for ( var p in r['query-continue'] ) |
||
+ | for ( var f_arg in r['query-continue'][p] ) |
||
+ | f_args += '&' + f_arg + '=' + r['query-continue'][p][f_arg]; |
||
+ | return wikiQueryFetchAllPages( fromSource, namespace, f_args, f_storage ); |
||
+ | } ); |
||
+ | } |
||
function wikiCargoQueryFetch( fromSource, args ) { |
function wikiCargoQueryFetch( fromSource, args ) { |
||
Ligne 122 : | Ligne 185 : | ||
function wikiFetch( action, fromSource, args ) { |
function wikiFetch( action, fromSource, args ) { |
||
− | return fetch( 'https://bindingofisaacrebirth' + ( fromSource ? '.gamepedia.com/api.php?origin=*&' : '-fr.gamepedia.com/api.php?' ) + 'format=json&action=' + action + '&' + |
+ | return fetch( 'https://bindingofisaacrebirth' + ( fromSource ? '.gamepedia.com/api.php?origin=*&' : '-fr.gamepedia.com/api.php?' ) + 'format=json&action=' + action + ( args ? '&' + args : '' ) ).then( function ( r ) { return r.json(); } ); |
} |
} |
||
Version du 8 février 2020 à 17:22
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */
$( function () {
// Cache purge shortcut
var purge_href = $( '#ca-cargo-purge > a' ).attr( 'href' );
$( '#ca-cargo-purge' ).remove();
$( '#p-views > ul' ).append( '<li></li>' );
$( '#p-views > ul > li:not([id])' ).attr( 'id', 'ca-cargo-purge' );
$( '#ca-cargo-purge' ).append( '<span><a>⟳</a></span>' );
$( '#ca-cargo-purge > span > a' )
.attr( { 'title': 'Purge the cache [alt-shift-g]', 'href': purge_href, 'accesskey': 'g' } )
.css( { 'line-height': 0, 'font-size': 'large' } );
// Links titles
$( '.notitle, .tooltip' )
.find( 'a' )
.attr( 'title', '' );
// Nav
$( '.nav-master-button-visible, .nav-master' ).hide();
$( '.nav-master-button-collapsed' ).show();
$( '.nav-master-button-visible' ).click( function () {
$( '.nav-master-button-visible, .nav-master' ).hide();
$( '.nav-master-button-collapsed' ).show();
} );
$( '.nav-master-button-collapsed' ).click( function () {
$( '.nav-master-button-visible, .nav-master' ).show();
$( '.nav-master-button-collapsed' ).hide();
} );
// Slideshows initialization
var $slideshows = $( '.infobox-slideshow' );
var anim = new Array( $slideshows.size() ).fill( 0 );
$slideshows.each( function ( _, slideshow ) {
var maxHeight = 0;
var maxWidth = 0;
$( slideshow )
.find( '.slide' )
.each( function ( _, slide ) {
maxHeight = Math.max( maxHeight, $( slide ).height() );
maxWidth = Math.max( maxWidth , $( slide ).width() );
} );
$( slideshow )
.height( maxHeight )
.width ( maxWidth );
} );
// Slideshows loop
setInterval( function () {
$slideshows.each( function ( i, slideshow ) {
var $slides = $( slideshow ).find( '.slide' );
if ( $slides.length > 1 )
if ( $( slideshow ).hasClass( 'infobox-slideshow-smooth' ) ) {
$( $slides.get( anim[i] ) ).fadeOut( 'slow' );
anim[i] = ( anim[i] + 1 ) % $slides.length;
$( $slides.get( anim[i] ) ).fadeIn( 'slow' );
} else {
$( $slides.get( anim[i] ) ).fadeOut( 'slow' );
anim[i] = ( anim[i] + 1 ) % $slides.length;
$( $slides.get( anim[i] ) ).fadeIn( 'slow' );
}
} );
}, 3000 );
} );
// Tooltips
$( document ).on( 'mousemove', function ( event ) {
$( '.tooltip:hover > .tooltip-block' ).css( { 'left': event.clientX + 10 + 'px', 'top': event.clientY + 20 + 'px' } );
} );
/**********************
* TRANSLATION SYSTEM *
**********************/
$( function () {
// Translation progress
var translatedRevision;
wikiCargoQueryFetch( false, 'tables=maintenance&fields=revision&where=_pageID=' + mw.config.get( 'wgArticleId' ) + '&limit=1' )
.then( function ( r ) {
if ( !r.length )
throw new Error();
translatedRevision = r[0].title.revision;
return wikiQueryFetch( true, 'prop=revisions&revids=' + translatedRevision );
} )
.then( function ( r ) { return r.pages; } )
.then( function ( r ) {
for ( var page in r )
return wikiQueryFetch( true, 'prop=revisions&pageids=' + r[page].pageid );
} )
.then( function ( r ) { return r.pages; } )
.then( function ( r ) {
for ( var page in r ) {
var lastRevision = r[page].revisions[0].revid;
if ( $( 'body.action-view' ).length )
$( '#firstHeading' ).prepend( lastRevision == translatedRevision ?
'<a target="_blank" rel="noopener noreferrer" href="https://bindingofisaacrebirth.gamepedia.com/index.php?curid=' + page + '" title="Traduction à jour"><div class="translation-icon translation-icon-uptodate"></div></a>' :
'<a target="_blank" rel="noopener noreferrer" href="https://bindingofisaacrebirth.gamepedia.com/index.php?type=revision&diff=' + lastRevision + '&oldid=' + translatedRevision + '"><div class="translation-icon translation-icon-toupdate"></div></a>'
);
else if ( $( 'body.action-edit' ).length )
$( '#mw-translation-editnotice' )
.css( 'background', lastRevision == translatedRevision ? 'green' : 'darkred' )
.html( lastRevision == translatedRevision ?
'<b>Cette page est à jour.</b><br>Elle est une traduction de la révision <code>' + lastRevision + '</code> de la page <a target="_blank" rel="noopener noreferrer" href="https://bindingofisaacrebirth.gamepedia.com/index.php?curid=' + page + '">' + r[page].title + '</a>.' :
'<b>Cette page n’est pas à jour.</b><br>Vous pouvez aider en <a target="_blank" rel="noopener noreferrer" href="https://bindingofisaacrebirth.gamepedia.com/index.php?type=revision&diff=' + lastRevision + '&oldid=' + translatedRevision + '">la mettant à jour</a>, puis en remplaçant <code>{{révision | ' + translatedRevision + ' }}</code> par <code>{{révision | ' + lastRevision + ' }}</code> en bas de la page.'
);
break;
}
} )
.catch( function () {
$( 'body.action-edit #mw-translation-editnotice' ).append( '<br><br>Entrer le nom d’une page pour obtenir le texte correspondant à la dernière révision.<br><div class="oo-ui-widget oo-ui-widget-enabled oo-ui-inputWidget oo-ui-textInputWidget oo-ui-textInputWidget-type-text oo-ui-labelElement" style="width: 40%; display: inline-block"><input type="text" id="mw-translation-editnotice-search" class="oo-ui-inputWidget-input" value="' + mw.config.get( 'wgPageName' ).replace( /_/g, ' ' ).replace( 'Aide:', 'Help:' ).replace( 'Catégorie:', 'Category:' ).replace( 'Modèle:', 'Template:' ) + '"></div><a class="mw-ui-button button" style="min-width: 30px; margin-right: 0.5em" onclick="translationSearch()"><b>></b></a><br><code>{{révision | <span id="mw-translation-editnotice-revision"></span> }}</code>' );
translationSearch();
} );
// Outdated or untranslated pages table
$( '.mw-translation-list' ).each( function () {
var $table = $( this );
var namespace = $table.attr( 'data-translation-list-ns' ) || 0
Promise.all( [
wikiQueryFetchAllPages( true , namespace ),
wikiQueryFetchAllPages( false, namespace ),
wikiCargoQueryFetch( false, 'tables=maintenance&fields=_pageName=page,revision&limit=500' )
] ).then( function ( r ) {
$( '.mw-translation-list > tbody' ).empty();
for ( var twp in r[1] )
addTransationRow( $table, r[0], r[2], r[1][twp] );
} );
} );
} );
function addTransationRow( $table, sourceWikiPages, translatedPages, targetWikiPage ) {
var translatedPage = translatedPages.find( function ( p ) {
return p.title.page == targetWikiPage.title;
} );
if ( !translatedPage ) {
$table.append( '<tr class="mw-translation-list-nosource"><td><a href="https://bindingofisaacrebirth-fr.gamepedia.com/index.php?curid=' + targetWikiPage.pageid + '">' + targetWikiPage.title + '</a></td><td>→</td><td style="color: darkred">☒</td><td style="color: grey">⬾</td><td></td></tr>' );
return;
}
translatedPage = translatedPage.title;
var sourceWikiPage = {};
wikiQueryFetch( true, 'prop=revisions&revids=' + translatedPage.revision )
.then( function ( r ) { return r.pages; } )
.then( function ( r ) {
if ( !r )
throw new Error();
var sourceWikiPageID;
for ( sourceWikiPageID in r )
break;
sourceWikiPage = sourceWikiPages.find( function ( p ) {
return p.pageid == sourceWikiPageID;
} );
return wikiQueryFetch( true, 'prop=info&pageids=' + sourceWikiPageID );
} )
.then( function ( r ) { return r.pages; } )
.then( function ( r ) {
for ( var p in r )
return r[p];
} )
.then( function ( r ) {
var lastSourceWikiPageRevisionID = r.lastrevid;
$table.append( translatedPage.revision == lastSourceWikiPageRevisionID ? '<tr class="mw-translation-list-uptodate"><td><a href="https://bindingofisaacrebirth-fr.gamepedia.com/index.php?curid=' + targetWikiPage.pageid + '">' + targetWikiPage.title + '</a></td><td>→</td><td style="color: green">☑</td><td>←</td><td><a href="https://bindingofisaacrebirth.gamepedia.com/index.php?curid=' + targetWikiPage.pageid + '">' + sourceWikiPage.title + '</a></td></tr>' : '<tr class="mw-translation-list-outdated"><td><a href="https://bindingofisaacrebirth-fr.gamepedia.com/index.php?curid=' + targetWikiPage.pageid + '&action=edit">' + targetWikiPage.title + '</a></td><td>→</td><td><a href="https://bindingofisaacrebirth.gamepedia.com/index.php?type=revision&diff=' + lastSourceWikiPageRevisionID + '&oldid=' + translatedPage.revision + '" style="color: red">☒</a></td><td>←</td><td><a href="https://bindingofisaacrebirth.gamepedia.com/index.php?curid=' + targetWikiPage.pageid + '">' + sourceWikiPage.title + '</a></td></tr>' );
} )
.catch( function () { console.log( 'invalid revision ID ("' + translatedPage.revision + '") from translation template on page "' + targetWikiPage.title + '"' ); } );
}
function wikiQueryFetchAllPages( fromSource, namespace, f_args, f_storage ) {
return wikiFetch( 'query', fromSource, 'list=allpages&rawcontinue=1&aplimit=500&apnamespace=' + namespace + ( f_args || '' ) ).then( function ( r ) {
f_storage = f_storage ? f_storage.concat( r.query.allpages ) : r.query.allpages;
if ( !r['query-continue'] )
return f_storage;
f_args = '';
for ( var p in r['query-continue'] )
for ( var f_arg in r['query-continue'][p] )
f_args += '&' + f_arg + '=' + r['query-continue'][p][f_arg];
return wikiQueryFetchAllPages( fromSource, namespace, f_args, f_storage );
} );
}
function wikiCargoQueryFetch( fromSource, args ) {
return wikiFetch( 'cargoquery', fromSource, args ).then( function ( r ) { return r.cargoquery; } );
}
function wikiQueryFetch( fromSource, args ) {
return wikiFetch( 'query', fromSource, args ).then( function ( r ) { return r.query; } );
}
function wikiFetch( action, fromSource, args ) {
return fetch( 'https://bindingofisaacrebirth' + ( fromSource ? '.gamepedia.com/api.php?origin=*&' : '-fr.gamepedia.com/api.php?' ) + 'format=json&action=' + action + ( args ? '&' + args : '' ) ).then( function ( r ) { return r.json(); } );
}
function translationSearch() {
wikiQueryFetch( true, 'prop=revisions&titles=' + $( '#mw-translation-editnotice-search' ).val() )
.then( function ( r ) { return r.pages; } )
.then( function ( r ) {
for ( var p in r ) {
$( '#mw-translation-editnotice-revision' ).html( p === '-1' ? '' : r[p].revisions[0].revid );
break;
}
} );
}