MediaWiki:Common.js

/** * NoLicenseWarning * Shows banner notification and rejects uploading is user didn't select license * * Original author unknown * Rewritten and improved by Rail  */   'use strict';
 * ( function( mw, window ) {

// Meta-site configuration const conf = mw.config.get( [       'wgCanonicalSpecialPageName',    ] );

// Loading restrictions if ( conf.wgCanonicalSpecialPageName !== 'Upload' || window.NoLicenseWarningLoaded ) { return; }

// Script configuration options window.NoLicenseWarning = {}; window.NoLicenseWarning.forceLicense = true;

/**    * Main function responsible for core functionalities of NoLicenseWarning */   function init { // Get required elements from ids const form = document.getElementById( 'mw-upload-form' ); const license = document.getElementById( 'wpLicense' );

function notify( msg ) { mw.loader.using( 'mediawiki.notification', function {               mw.notification.notify( msg );            } ); }

// Prepare variable for delivery state var isMessageDelivered;

// Listen for upload form being submitted form.addEventListener( 'submit', function( event ) {           // Determine whether license is provided            var isLicenseProvided = ( license.value === '' ? false : true );

/**            * Different behaviour based on script setting * Allow users to upload file without license after showing them warning */           if ( window.NoLicenseWarning.forceLicense === false ) { // Message has been delivered, do nothing if ( isMessageDelivered === true ) return;

// License isn't provided if ( isLicenseProvided === false ) { // Prevent form from being sent event.preventDefault;

// Show warning message alert( "License Required!" );

// Mark message as delivered isMessageDelivered = true; }           } else if ( isLicenseProvided === false ) { // Prevent form from being sent event.preventDefault;

// Show rejection message alert( "Bad License Selection or None Chosen!" ); }       } );

// Mark script as loaded window.NoLicenseWarningLoaded = true; }

} )( mediaWiki, this );