« MediaWiki:Gadget-ScriptoriumInfo.js » : différence entre les versions
Page de l’interface de MediaWiki
Autres actions
mAucun résumé des modifications |
mAucun résumé des modifications |
||
| Ligne 20 : | Ligne 20 : | ||
var STATUT_COLORS = { | var STATUT_COLORS = { | ||
'VALIDE': { bg: '# | 'VALIDE': { bg: '#d4edda', color: '#27500a' }, | ||
'A RELIRE': { bg: '# | 'A RELIRE': { bg: '#e2d9f3', color: '#3C3489' }, | ||
'A COMPLETER': { bg: '# | 'A COMPLETER': { bg: '#fff3cd', color: '#854f0b' }, | ||
'A CORRIGER': { bg: '# | 'A CORRIGER': { bg: '#f8d7da', color: '#791f1f' }, | ||
'A DISCUTER': { bg: '# | 'A DISCUTER': { bg: '#d6e9f8', color: '#0c447c' }, | ||
'OBSOLETE': { bg: '#e0e0e0', color: '#444441' }, | 'OBSOLETE': { bg: '#e0e0e0', color: '#444441' }, | ||
'A SUPPRIMER': { bg: '#f8bbd0', color: '#72243e' }, | 'A SUPPRIMER': { bg: '#f8bbd0', color: '#72243e' }, | ||
Version du 2 juin 2026 à 19:41
/**
* Gadget ScriptoriumInfo
* Affiche les propriétés Scriptorium (Statut, Classification, Bibliothécaire, Notes, Sources)
* sous le titre de chaque page wiki sous forme de chips.
*/
( function () {
'use strict';
var pageName = mw.config.get( 'wgPageName' ).replace( /_/g, ' ' );
var namespace = mw.config.get( 'wgNamespaceNumber' );
var action = mw.config.get( 'wgAction' );
if ( action !== 'view' ) {
return;
}
if ( namespace !== 0 && namespace !== 14 ) {
return;
}
var STATUT_COLORS = {
'VALIDE': { bg: '#d4edda', color: '#27500a' },
'A RELIRE': { bg: '#e2d9f3', color: '#3C3489' },
'A COMPLETER': { bg: '#fff3cd', color: '#854f0b' },
'A CORRIGER': { bg: '#f8d7da', color: '#791f1f' },
'A DISCUTER': { bg: '#d6e9f8', color: '#0c447c' },
'OBSOLETE': { bg: '#e0e0e0', color: '#444441' },
'A SUPPRIMER': { bg: '#f8bbd0', color: '#72243e' },
'A CREER': { bg: '#f0f0f0', color: '#222220' }
};
function buildChip( text, style ) {
var chip = document.createElement( 'span' );
chip.className = 'scrip-chip';
chip.textContent = text;
if ( style ) {
if ( style.bg ) chip.style.backgroundColor = style.bg;
if ( style.color ) chip.style.color = style.color;
chip.style.border = 'none';
}
return chip;
}
function buildNotesBox( text ) {
var box = document.createElement( 'div' );
box.className = 'scrip-notes';
var icon = document.createElement( 'i' );
icon.className = 'fas fa-scroll';
icon.style.marginRight = '8px';
box.appendChild( icon );
box.appendChild( document.createTextNode( text ) );
return box;
}
function insertScriptoriumBar( data ) {
var statut = data.Statut || '';
var classif = data.Classification || '';
var biblio = data[ 'Bibliothécaire' ] || data[ 'Bibliothecaire' ] || '';
var notes = data.Notes || '';
var sources = data.Sources || '';
if ( !statut && !classif && !biblio && !notes && !sources ) {
return;
}
var container = document.createElement( 'div' );
container.id = 'scrip-bar';
var chipsRow = document.createElement( 'div' );
chipsRow.className = 'scrip-chips';
if ( statut ) {
var statutStyle = STATUT_COLORS[ statut ] || { bg: '#f0f0f0', color: '#444' };
chipsRow.appendChild( buildChip( statut, statutStyle ) );
}
if ( classif && classif !== 'NON CLASSIFIE' ) {
chipsRow.appendChild( buildChip( classif, null ) );
} else {
chipsRow.appendChild( buildChip( 'Classification manquante', { bg: '#ffcdd2', color: '#791f1f' } ) );
}
if ( biblio ) {
chipsRow.appendChild( buildChip( biblio, null ) );
}
container.appendChild( chipsRow );
if ( notes ) {
container.appendChild( buildNotesBox( notes ) );
}
var headingContainer = document.querySelector( '.firstHeading-container' ) ||
( document.getElementById( 'firstHeading' ) || {} ).parentNode;
if ( headingContainer ) {
headingContainer.appendChild( container );
}
}
function extractValue( printouts, prop ) {
if ( !printouts[ prop ] || !printouts[ prop ].length ) {
return '';
}
var values = [];
for ( var i = 0; i < printouts[ prop ].length; i++ ) {
var val = printouts[ prop ][ i ];
if ( typeof val === 'object' && val.fulltext ) {
values.push( val.fulltext );
} else if ( typeof val === 'string' ) {
values.push( val );
} else if ( typeof val === 'number' ) {
values.push( String( val ) );
}
}
return values.join( ', ' );
}
var apiUrl = mw.util.wikiScript( 'api' );
var queryName = ( namespace === 14 ) ? ':' + pageName : pageName;
var query = '[[' + queryName + ']]|?Statut|?Classification|?Bibliothécaire|?Notes|?Sources';
$.ajax( {
url: apiUrl,
data: {
action: 'ask',
query: query,
format: 'json'
},
dataType: 'json'
} ).done( function ( response ) {
if ( !response.query || !response.query.results ) {
return;
}
var results = response.query.results;
var pageData = null;
for ( var key in results ) {
if ( results.hasOwnProperty( key ) ) {
pageData = results[ key ];
break;
}
}
if ( !pageData || !pageData.printouts ) {
return;
}
var data = {
Statut: extractValue( pageData.printouts, 'Statut' ),
Classification: extractValue( pageData.printouts, 'Classification' ),
'Bibliothécaire': extractValue( pageData.printouts, 'Bibliothécaire' ),
Notes: extractValue( pageData.printouts, 'Notes' ),
Sources: extractValue( pageData.printouts, 'Sources' )
};
insertScriptoriumBar( data );
} );
}() );