CryoKey has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/70831


Change subject: JavaScript file compatibility improvements
......................................................................

JavaScript file compatibility improvements

The JavaScript file now works fine for IE. Also, we're using
BeforePageDisplay and GetLocalURL::Internal (mainly for logout link
handling).

Change-Id: Ic784a576393283831b4944d53d47edf3db89efeb
---
M cryokey.js
M cryokey.php
2 files changed, 59 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CryoKey 
refs/changes/31/70831/1

diff --git a/cryokey.js b/cryokey.js
index 92e0fb9..8a329f8 100644
--- a/cryokey.js
+++ b/cryokey.js
@@ -21,7 +21,6 @@
   throw new Error("Could not create HTTP request object.");
 }
 
-
 // Attempt to clear cached authentication information.
 function ck_logout(_url)
 {
@@ -39,28 +38,42 @@
   if (/(iPad|iPhone|iPod)/.test(navigator.userAgent))
   {
     CK_ATTEMPTS = 1;
-    ck_ticket(_url, _ip, _pass);
+    ck_ticket(_url, _ip, _pass, _start, _abort, _fail);
+    return;
   }
-  else
+  if (/MSIE ([0-9]{1,}[\.0-9]{0,})/.test(navigator.userAgent))
   {
-    var flush = ck_get_connector();
-    flush.onreadystatechange = function()
-    {
-      if (flush.readyState == 4)
-      {
-        CK_ATTEMPTS = 3;
-        ck_ticket(_url, _ip, _pass, _start, _abort, _fail);
-      }
-    };
-    flush.open("GET", "https://www.cryokey.com/public/flush";, true);
-    flush.send();
+    document.execCommand('ClearAuthenticationCache');
+    CK_ATTEMPTS = 3;
+    ck_ticket(_url, _ip, _pass, _start, _abort, _fail);
+    return;
   }
+  if (window.crypto && window.crypto.logout)
+  {
+    window.crypto.logout();
+    CK_ATTEMPTS = 3;
+    ck_ticket(_url, _ip, _pass, _start, _abort, _fail);
+    return;
+  }
+
+  var flush = ck_get_connector();
+  flush.onreadystatechange = function()
+  {
+     if (flush.readyState == 4)
+     {
+       CK_ATTEMPTS = 3;
+       ck_ticket(_url, _ip, _pass, _start, _abort, _fail);
+     }
+  }
+  flush.open("GET", "https://www.cryokey.com/public/flush";, true);
+  flush.send();
 }
 
 // Acquire a ticket from CryoKey's ticketing module.
 function ck_ticket(_url, _ip, _pass, _start, _abort, _fail)
 {
-  var ticketer = "https://www.cryokey.com/private/ticket.php?mode=js&url="; + 
escape(_url) + "&ip=" + escape(_ip);
+  var now = new Date().getTime() / 1000;
+  var ticketer = "https://www.cryokey.com/private/ticket.php?mode=js&url="; + 
escape(_url) + "&ip=" + escape(_ip) + "&skew=" + now;
   var status = document.getElementById("ck_message");
 
   status.innerHTML = _start;
diff --git a/cryokey.php b/cryokey.php
index 921edb8..b90c852 100644
--- a/cryokey.php
+++ b/cryokey.php
@@ -21,6 +21,19 @@
 $wgCKAutoRegister = false;
 
 /**
+ * The CryoKey JavaScript should always be available to handle
+ * additional logout behavior. Also, the script should be in the head
+ * for the sake of logging in. In any case, the script is small, so
+ * the impact should be small as well.
+ */
+function wgck_enscript(&$_page, &$_skin)
+{
+  $js = wgck_locate("cryokey.js");
+  $_page->addHeadItem("cryokey", "<script type='text/javascript' 
src='{$js}'></script>");
+  return true;
+}
+
+/**
  * Check a CryoKey ticket to see if it's valid. If it's still valid,
  * then we can use it to grant access to a user.
  */
@@ -82,18 +95,17 @@
 
 /**
  * Given the current UserLogin Template module instance, add a link
- * that authenticates using CryoKey (using the Lite mechanism).
+ * that authenticates using CryoKey (using the Lite mechanism). The
+ * UserLogin Template is a direct derivative of QuickTemplate.
  */
 function wgck_form($_template)
 {
   global $wgScriptPath;
-  //global $wgRequest, $wgOut;
 
   $ip = $_SERVER['REMOTE_ADDR'];
   $icon = wgck_locate('ckicon.png');
   $service = $wgScriptPath;
   $pass = $_SERVER['PHP_SELF'];
-  $script = wgck_locate('cryokey.js');
 
   $msg_start = wfMessage('cryokey-start');
   $msg_abort = wfMessage('cryokey-abort');
@@ -104,10 +116,21 @@
   // scrubbing.
   $action = "javascript:ck_initiate('{$service}', '{$ip}', '{$pass}', 
'{$msg_start}', '{$msg_abort}', '{$msg_fail}');";
   $message = "<span id='ck_message'>" . wfMessage('cryokey-label') . "</span>";
-  $extras = @$_template->data['extrafields'];
-  $extras .= "<script type='text/javascript' src='{$script}'></script>";
-  $extras .= "<a href=\"{$action}\"><img src='{$icon}' width='16' 
height='16'/>{$message}</a>";
+  $extras = @$_template->data['extrafields'] . "<a href=\"{$action}\"><img 
src='{$icon}' width='16' height='16'/>{$message}</a>";
   $_template->set('extrafields', $extras);
+
+  return true;
+}
+
+/**
+ * Change the link URL to log out using JavaScript, if possible.
+ */
+function wgck_logout_link($_title, &$_url, $_query)
+{
+  if (($_title->isSpecial("UserLogout")) || ($_title->isSpecial("Userlogout")))
+  {
+    $_url = "javascript:ck_logout('" . $_url . "');";
+  }
 
   return true;
 }
@@ -155,6 +178,8 @@
     return 
file_get_contents("https://www.cryokey.com/public/redeem.php?mode=name&tid="; . 
urlencode($_tid) . "&from=" . urlencode($_SERVER['REMOTE_ADDR']) . "&to=" . 
urlencode($_service));
 }
 
+$wgHooks['BeforePageDisplay'][] = 'wgck_enscript';
 $wgHooks['UserLoginForm'][] = 'wgck_form';
 $wgHooks['UserLoadFromSession'][] = 'wgck_check';
+$wgHooks['GetLocalURL::Internal'][] = 'wgck_logout_link';
 ?>

-- 
To view, visit https://gerrit.wikimedia.org/r/70831
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic784a576393283831b4944d53d47edf3db89efeb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CryoKey
Gerrit-Branch: master
Gerrit-Owner: CryoKey <cryo...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to