User:Revansx/Session Notification of Renewal

This script is aimed at wikis using a 3rd party identity provider provided via an immutable session header. Specifically, CA Policy Agent.


 * The problem this script solves is when the 3rd party immutable session provider sets a 15 minute timer on session expiration due to client inactivity.. which happens all the time when people spend more than 15 minutes editing a page without saving.. when the session expires.. the CA Policy agent forces a redirect to renew the session, but for edit pages with pending edits, the pending edits get lost.

Pasting this javascript code into your "Mediawiki:Common.js" page will cause a little bright yellow pop-up dialog box to show up in any page with "action=edit" or "veaction=edit" in the url. This is to notify the user that they may need to re-new their session before attempting to save their work. The javascript dialog box links to the Pasting this javascript code into your "Mediawiki:Common.js" page will cause a little bright yellow pop-up dialog box to show up in any page with "action=edit" or "veaction=edit" in the url. This is to notify the user that they made need to re-new their session before attempting to save their work. The javascript dialog box links to the page "renew.php" that you should implement somewhere on your server that the user can access with an expired session. "renew.php" is essentially a user initiated request that forces the SSO to renew the session.

Mediawiki:Common.js code
/* Any JavaScript here will be loaded for all users on every page load. */

//This is the Session Expiration Notification Timer $( function {       var timeout = 5*60*1000;                mw.loader.load( ['mediawiki.notification', 'mediawiki.api'] );                var notifyFunc = function {                var notifyObj;                var $msg = $( '   --- Attention ---  It has been a while since this page communicated with the server. If you have not yet saved, you should CLICK HERE to extend your session before attempting to save your work. ' )                       .append( $( ' [ -- CLOSE -- ]' ) .click( function(e) {                                var api = new mw.Api;api.get( { action: 'query' } );                                e.preventDefault;                                notifyObj.close;                                window.setTimeout( notifyFunc, timeout);                                } ) );                       notifyObj = mw.notification.notify( $msg, { 'autoHide': false } );              }        if ( location.search.match(/(?:\?|&)(ve)?action=(edit|submit)/ ) ) {                 window.setTimeout( notifyFunc, timeout );        }       $( '#ca-ve-edit a' ).click( function  {  window.setTimeout( notifyFunc, timeout ); } ); } );

renew.php code
Renew the session  function mynotify3  { setTimeout(function { document.body.innerHTML = "This page was generated simply for the purpose of renewing the session. It will automatically close in 3 seconds."; }, 1); } function mynotify2  { setTimeout(function { document.body.innerHTML = "This page was generated simply for the purpose of renewing the session. It will automatically close in 2 seconds."; }, 1000); } function mynotify1  { setTimeout(function { document.body.innerHTML = "This page was generated simply for the purpose of renewing the session. It will automatically close in 1 seconds."; }, 2000); } function closeWindow { setTimeout(function { window.close; }, 3000); } window.onload = mynotify3; window.onload = mynotify2; window.onload = mynotify1; window.onload = closeWindow;