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.
Localsettings.php code[edit]
This "hook-based extension" is needed to create the html pop-up div as the page is rendered. It is created with a default setting of "display:none" and "visibility:hidden" so that it is invisible upon the page initially loading. Mediawiki:Common.js is used to set the timer that reveals it after a certain amount of time has elapsed.
# Session Expiration Notification Addon #-------------------------------------------------------------------- $wgHooks['BeforePageDisplay'][] = 'zMySessionNotifyDiv'; $wgHooks['onArticleViewHeader'][] = 'zMySessionNotifyDiv'; function zMySessionNotifyDiv( OutputPage &$out, Skin &$skin ) { $out->addHTML("<div name='zSessionNotify' id='zSessionNotify' style='display:none; visibility:hidden; border:5px solid #ff0000; background-color:#ffff00; text-color:#ff0000; position: fixed; top: 50%; left: 50%; margin-top: -50px; margin-left: -50px; width: 250px;'><a href='https://pbs.grc.nasa.gov/renew.php/' target='_blank' style='pointer-events:auto;position:relative;display:inline-block;'><button style='background-color:#ffff00;color:#ff0000;pointer-events:auto;position:relative;' type='button' onclick=\"document.getElementById('zSessionNotify').style.display='none';document.getElementById('zSessionNotify').visibility='hidden';\"><strong><big>--- Attention ---</big></strong><br/>It has been a while since this page communicated with the server. If you have not yet saved, you should <strong><u>CLICK HERE</u></strong> to extend your session <u><strong>BEFORE</strong></u> attempting to save your work.</button></a></div>"); return $out; }
Mediawiki:Common.js code[edit]
/* Any JavaScript here will be loaded for all users on every page load. */
//This is the Session Expiration Notification Timer
$(function () {
setInterval( function(){ document.getElementById('zSessionNotify').style.display='inline';
document.getElementById('zSessionNotify').style.visibility='visible'; }, 12*60*1000 )
}());
renew.php code[edit]
a utility page placed somewhere on your webserver server
<html> <head><title>Renew the session</title></head> <body> This page was generated simply for the purpose of renewing the session. <li>It will attempt to automatically close in 3 seconds.</li> <li>If the browser asks you if you want to close the page, please say "yes".</li> <li>Once closed, you should be returned to your work in the Wiki and you should close the session expiration notification dialog box.</li> <script type="text/javascript">function closeWindow() { setTimeout(function() { window.close(); }, 500); }window.onload = closeWindow;</script> </body> </html>