Basculer le menu
Changer de menu des préférences
Basculer le menu personnel
Non connecté(e)
Votre adresse IP sera visible au public si vous faites des modifications.

« MediaWiki:Gadget-ScriptoriumInfo.js » : différence entre les versions

Page de l’interface de MediaWiki
mAucun résumé des modifications
mAucun résumé des modifications
 
(7 versions intermédiaires par le même utilisateur non affichées)
Ligne 3 : Ligne 3 :
  * Affiche les propriétés Scriptorium (Statut, Classification, Bibliothécaire, Notes, Sources)
  * Affiche les propriétés Scriptorium (Statut, Classification, Bibliothécaire, Notes, Sources)
  * sous le titre de chaque page wiki sous forme de chips.
  * sous le titre de chaque page wiki sous forme de chips.
*
* Installation :
* 1. Copier ce code dans MediaWiki:Gadget-ScriptoriumInfo.js
* 2. Copier le CSS dans MediaWiki:Gadget-ScriptoriumInfo.css
* 3. Ajouter dans MediaWiki:Gadgets-definition :
*    * ScriptoriumInfo[ResourceLoader|default]|ScriptoriumInfo.js|ScriptoriumInfo.css
  */
  */
( function () {
( function () {
Ligne 21 : Ligne 15 :
     }
     }


     if ( namespace !== 0 && namespace !== 14 ) {
     if ( namespace !== 0 && namespace !== 14 && namespace !== 3002 ) {
         return;
         return;
     }
     }
Ligne 31 : Ligne 25 :
         'A CORRIGER':  { bg: '#ffcdd2', color: '#791f1f' },
         'A CORRIGER':  { bg: '#ffcdd2', color: '#791f1f' },
         'A DISCUTER':  { bg: '#bbdefb', color: '#0c447c' },
         'A DISCUTER':  { bg: '#bbdefb', color: '#0c447c' },
         'OBSOLETE':    { bg: '#e0e0e0', color: '#444441' },
         'OBSOLETE':    { bg: '#b8b2c6', color: '#444441' },
         'A SUPPRIMER':  { bg: '#f8bbd0', color: '#72243e' },
         'A SUPPRIMER':  { bg: '#f8bbd0', color: '#72243e' },
         'A CREER':      { bg: '#f0f0f0', color: '#222220' }
         'A CREER':      { bg: '#4f586e', color: '#dbdeea' }
     };
     };


Ligne 66 : Ligne 60 :
         var sources = data.Sources || '';
         var sources = data.Sources || '';


        if ( !statut && !classif && !biblio && !notes && !sources ) {
            return;
        }


         var container = document.createElement( 'div' );
         var container = document.createElement( 'div' );
Ligne 82 : Ligne 73 :


         if ( classif && classif !== 'NON CLASSIFIE' ) {
         if ( classif && classif !== 'NON CLASSIFIE' ) {
             chipsRow.appendChild( buildChip( classif, null ) );
             var classifLink = document.createElement( 'a' );
            classifLink.href = mw.util.getUrl( 'AC:Scriptorium' ) + '#' + classif.replace( / /g, '_' );
            classifLink.className = 'scrip-chip';
            classifLink.textContent = classif;
            classifLink.title = 'Voir dans le Scriptorium';
            chipsRow.appendChild( classifLink );
         } else {
         } else {
             chipsRow.appendChild( buildChip( 'Classification manquante', { bg: '#ffcdd2', color: '#791f1f' } ) );
             chipsRow.appendChild( buildChip( 'Classification manquante', { bg: '#ffcdd2', color: '#791f1f' } ) );
Ligne 88 : Ligne 84 :


         if ( biblio ) {
         if ( biblio ) {
             chipsRow.appendChild( buildChip( biblio, null ) );
             var biblioChip = buildChip( '', null );
            var biblioIcon = document.createElement( 'i' );
            biblioIcon.className = 'fa-solid fa-user';
            biblioIcon.style.marginRight = '6px';
            biblioChip.appendChild( biblioIcon );
            biblioChip.appendChild( document.createTextNode( biblio ) );
            chipsRow.appendChild( biblioChip );
         }
         }


Ligne 124 : Ligne 126 :


     var apiUrl = mw.util.wikiScript( 'api' );
     var apiUrl = mw.util.wikiScript( 'api' );
     var query = '[[' + pageName + ']]|?Statut|?Classification|?Bibliothécaire|?Notes|?Sources';
    var queryName = ( namespace === 14 ) ? ':' + pageName : pageName;
     var query = '[[' + queryName + ']]|?Statut|?Classification|?Bibliothécaire|?Notes|?Sources';


     $.ajax( {
     $.ajax( {
Ligne 135 : Ligne 138 :
         dataType: 'json'
         dataType: 'json'
     } ).done( function ( response ) {
     } ).done( function ( response ) {
         if ( !response.query || !response.query.results ) {
         var data = {
             return;
             Statut: '',
         }
            Classification: '',
            'Bibliothécaire': '',
            Notes: '',
            Sources: ''
         };


         var results = response.query.results;
         if ( response.query && response.query.results ) {
        var pageData = null;
            var results = response.query.results;
            var pageData = null;


        for ( var key in results ) {
            for ( var key in results ) {
            if ( results.hasOwnProperty( key ) ) {
                if ( results.hasOwnProperty( key ) ) {
                pageData = results[ key ];
                    pageData = results[ key ];
                break;
                    break;
                }
             }
             }
        }


        if ( !pageData || !pageData.printouts ) {
            if ( pageData && pageData.printouts ) {
             return;
                data.Statut = extractValue( pageData.printouts, 'Statut' );
                data.Classification = extractValue( pageData.printouts, 'Classification' );
                data[ 'Bibliothécaire' ] = extractValue( pageData.printouts, 'Bibliothécaire' );
                data.Notes = extractValue( pageData.printouts, 'Notes' );
                data.Sources = extractValue( pageData.printouts, 'Sources' );
             }
         }
         }
        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 );
         insertScriptoriumBar( data );

Dernière version du 5 juin 2026 à 10:11

/**
 * 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 && namespace !== 3002 ) {
        return;
    }

    var STATUT_COLORS = {
        'VALIDE':       { bg: '#c8e6c9', color: '#27500a' },
        'A RELIRE':     { bg: '#EEEDFE', color: '#3C3489' },
        'A COMPLETER':  { bg: '#ffe0b2', color: '#854f0b' },
        'A CORRIGER':   { bg: '#ffcdd2', color: '#791f1f' },
        'A DISCUTER':   { bg: '#bbdefb', color: '#0c447c' },
        'OBSOLETE':     { bg: '#b8b2c6', color: '#444441' },
        'A SUPPRIMER':  { bg: '#f8bbd0', color: '#72243e' },
        'A CREER':      { bg: '#4f586e', color: '#dbdeea' }
    };

    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 || '';


        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' ) {
            var classifLink = document.createElement( 'a' );
            classifLink.href = mw.util.getUrl( 'AC:Scriptorium' ) + '#' + classif.replace( / /g, '_' );
            classifLink.className = 'scrip-chip';
            classifLink.textContent = classif;
            classifLink.title = 'Voir dans le Scriptorium';
            chipsRow.appendChild( classifLink );
        } else {
            chipsRow.appendChild( buildChip( 'Classification manquante', { bg: '#ffcdd2', color: '#791f1f' } ) );
        }

        if ( biblio ) {
            var biblioChip = buildChip( '', null );
            var biblioIcon = document.createElement( 'i' );
            biblioIcon.className = 'fa-solid fa-user';
            biblioIcon.style.marginRight = '6px';
            biblioChip.appendChild( biblioIcon );
            biblioChip.appendChild( document.createTextNode( biblio ) );
            chipsRow.appendChild( biblioChip );
        }

        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 ) {
        var data = {
            Statut: '',
            Classification: '',
            'Bibliothécaire': '',
            Notes: '',
            Sources: ''
        };

        if ( response.query && response.query.results ) {
            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 ) {
                data.Statut = extractValue( pageData.printouts, 'Statut' );
                data.Classification = extractValue( pageData.printouts, 'Classification' );
                data[ 'Bibliothécaire' ] = extractValue( pageData.printouts, 'Bibliothécaire' );
                data.Notes = extractValue( pageData.printouts, 'Notes' );
                data.Sources = extractValue( pageData.printouts, 'Sources' );
            }
        }

        insertScriptoriumBar( data );
    } );

}() );
Les témoins (''cookies'') nous aident à fournir nos services. En utilisant nos services, vous acceptez notre utilisation de témoins.