Skip to content

Commit

Permalink
Merge pull request #1 from ULYSSIS-KUL/1_2_0
Browse files Browse the repository at this point in the history
1.2.0
  • Loading branch information
Joachim Vandersmissen authored Feb 7, 2019
2 parents 26eacce + cdf102e commit 13a44fa
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 28 deletions.
27 changes: 11 additions & 16 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,28 @@
"author": "ULYSSIS VZW, by Joachim Vandersmissen",
"url": "https://ulyssis.org/",
"description": "This extension replaces the vanilla login mechanics with a KU Leuven Shibboleth login",
"version": "1.1.0",
"version": "1.2.0",
"license-name": "GPL-2.0+",
"type": "other",
"AutoloadNamespaces": {
"MediaWikiShibboleth\\": "includes/"
},
"Hooks": {
"PersonalUrls": ["MediaWikiShibboleth::onPersonalUrls"],
"SpecialPage_initList": ["MediaWikiShibboleth::onSpecialPage_initList"],
"UserLogout": ["MediaWikiShibboleth::onUserLogout"]
"PersonalUrls": ["MediaWikiShibboleth\\MediaWikiShibboleth::onPersonalUrls"],
"SpecialPage_initList": ["MediaWikiShibboleth\\MediaWikiShibboleth::onSpecialPage_initList"],
"UserLogout": ["MediaWikiShibboleth\\MediaWikiShibboleth::onUserLogout"]
},
"SpecialPages": {
"ShibbolethLogin": "SpecialShibbolethLogin"
},
"AutoloadClasses": {
"MediaWikiShibboleth": "MediaWikiShibboleth_body.php",
"ShibbolethSessionProvider": "includes/ShibbolethSessionProvider.php",
"bKULshib": "includes/bKULshib.php",
"SpecialShibbolethLogin": "includes/SpecialShibbolethLogin.php"
"ShibbolethLogin": "MediaWikiShibboleth\\SpecialShibbolethLogin"
},
"SessionProviders": {
"ShibbolethSessionProvider": {
"class": "ShibbolethSessionProvider",
"class": "MediaWikiShibboleth\\ShibbolethSessionProvider",
"args": []
}
},
"config": {
"MWSStudentsOnly": false,
"MWSAllowedKULids": "",
"MWSAllowedDegrees": ""
"MessagesDirs": {
"MediaWikiShibboleth": ["i18n"]
},
"manifest_version": 1
}
Expand Down
7 changes: 7 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"mediawikishibboleth-login": "Log in using Central KU Leuven login:",
"mediawikishibboleth-password-login": "Login without Central KU Leuven login:",
"mediawikishibboleth-students-only": "Only students are allowed to sign in!",
"mediawikishibboleth-forbidden-student": "You are not allowed to sign in: your student number is not allowed by the website administrator!",
"mediawikishibboleth-forbidden-degree": "You are not allowed to sign in: you are not enrolled in any of the programmes allowing access to this website!"
}
7 changes: 7 additions & 0 deletions i18n/nl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"mediawikishibboleth-login": "Aanmelden met Centrale KU Leuven login:",
"mediawikishibboleth-password-login": "Aanmelden zonder Centrale KU Leuven login",
"mediawikishibboleth-students-only": "Alleen studenten kunnen zich aanmelden!",
"mediawikishibboleth-forbidden-student": "U mag u niet aanmelden: uw studentennummer is niet toegestaan door de website administrator!",
"mediawikishibboleth-forbidden-degree": "U mag u niet aanmelden: u volgt geen van de opleidingen die toegang geven tot deze website!"
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?php
$wgRevokePermissions['Shibboleth']['editmyprivateinfo'] = true;
$wgGroupPermissions['*']['createaccount'] = false;

namespace MediaWikiShibboleth;

use Title;
use SkinTemplate;

class MediaWikiShibboleth {
public static function onPersonalUrls(array &$personal_urls, Title $title, SkinTemplate $skin) {
unset($personal_urls['createaccount']);
}

public static function onSpecialPage_initList(&$specialPages) {
$specialPages['Userlogin'] = "SpecialShibbolethLogin";
$specialPages['Userlogin'] = "MediaWikiShibboleth\\SpecialShibbolethLogin";
return true;
}

Expand All @@ -23,3 +25,4 @@ public static function onUserLogout(&$user) {
return true;
}
}

12 changes: 8 additions & 4 deletions includes/ShibbolethSessionProvider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

namespace MediaWikiShibboleth;

use WebRequest;
use User;
use MediaWiki\Session\SessionProvider;
use MediaWiki\Session\ImmutableSessionProviderWithCookie;
use MediaWiki\Session\SessionBackend;
Expand Down Expand Up @@ -48,10 +52,10 @@ public function provideSessionInfo(WebRequest $request) {

if (!$user->getId()) {
$user = User::createNew($kulid, [
"email" => $shib->single_email(),
"real_name" => $shib->fullname(),
"email_authenticated" => wfTimestamp(TS_MW) + 100
]);
// 'email' => $shib->single_email(),
'real_name' => $shib->fullname(),
'email_authenticated' => wfTimestamp(TS_MW) + 100
]);
$user->addGroup("Shibboleth");
}

Expand Down
31 changes: 26 additions & 5 deletions includes/SpecialShibbolethLogin.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
<?php

namespace MediaWikiShibboleth;

use SpecialUserLogin;

class SpecialShibbolethLogin extends SpecialUserLogin {
function __construct() {
parent::__construct("ShibbolethLogin");
}

function errorBox($message) {
$errorMessage = wfMessage($message)->parse();
return '<table cellspacing="0" cellpadding="0" border="0" style="background: transparent; margin-top:0.5em;border:1px #b32424 solid;padding:0.5em;background-color: #fee7e6"><tr><td><b>' . $errorMessage . '</b></td></tr></table></p>';
}

function image($shib) {
$login_link = $shib->login_link();
$clickMessage = '<a href="' . $login_link . '">' . wfMessage('mediawikishibboleth-login')->parse() . '</a>';
return '<p>' . $clickMessage . '</p><a href="' . $login_link . '"><img src="extensions/MediaWikiShibboleth/shib.gif" alt="Centrale KU Leuven Login" align="middle"></a>';
}

function password_login($formHtml) {
$passwordLogin = wfMessage('mediawikishibboleth-password-login')->parse();
return '<a href="#" onclick="if(document.getElementById(\'spr\').style.display==\'none\'){document.getElementById(\'spr\').style.display=\'\';document.getElementById(\'spra\').innerHTML=\'' . $passwordLogin . ' &#9660;\'}else{document.getElementById(\'spr\').style.display=\'none\';document.getElementById(\'spra\').innerHTML=\'' . $passwordLogin . ' &#9654;\'}"><p id="spra">' . $passwordLogin . ' &#9654;</p></a><div id="spr" style="display:none">' . $formHtml . '</div>';
}

function getPageHtml($formHtml) {
$shib = new bKULshib();

if ($shib->check_login()) {
global $wgMWSStudentsOnly;
if ($wgMWSStudentsOnly && (!$shib->is_student() || $shib->is_employee())) {
return '<table cellspacing="0" cellpadding="0" border="0" style="background: transparent; margin-top:0.5em;border:1px #b32424 solid;padding:0.5em;background-color: #fee7e6"><tr><td><b>Only students are allowed to access this site!</b></td></tr></table></p><p>Click on image to log in:</p><a href="' . $shib->login_link() . '"><img src="extensions/MediaWikiShibboleth/shib.gif" alt="Centrale KU Leuven Login" align="middle"></a><a href="#" onclick="if(document.getElementById(\'spr\').style.display==\'none\'){document.getElementById(\'spr\').style.display=\'\';document.getElementById(\'spra\').innerHTML=\'Password Login &#9660;\'}else{document.getElementById(\'spr\').style.display=\'none\';document.getElementById(\'spra\').innerHTML=\'Password Login &#9654;\'}"><p id="spra">Password Login &#9654;</p></a><div id="spr" style="display:none">' . $formHtml . '</div>';
return $this->errorBox('mediawikishibboleth-students-only') . $this->password_login($formHtml);
}

global $wgMWSAllowedKULids;
Expand All @@ -24,7 +43,7 @@ function getPageHtml($formHtml) {
}

if (!$found) {
return '<table cellspacing="0" cellpadding="0" border="0" style="background: transparent; margin-top:0.5em;border:1px #b32424 solid;padding:0.5em;background-color: #fee7e6"><tr><td><b>You are not allowed to access this site!</b></td></tr></table></p><p>Click on image to log in:</p><a href="' . $shib->login_link() . '"><img src="extensions/MediaWikiShibboleth/shib.gif" alt="Centrale KU Leuven Login" align="middle"></a><a href="#" onclick="if(document.getElementById(\'spr\').style.display==\'none\'){document.getElementById(\'spr\').style.display=\'\';document.getElementById(\'spra\').innerHTML=\'Password Login &#9660;\'}else{document.getElementById(\'spr\').style.display=\'none\';document.getElementById(\'spra\').innerHTML=\'Password Login &#9654;\'}"><p id="spra">Password Login &#9654;</p></a><div id="spr" style="display:none">' . $formHtml . '</div>';
return $this->errorBox('mediawikishibboleth-forbidden-student') . $this->password_login($formHtml);
}

global $wgMWSAllowedDegrees;
Expand All @@ -38,10 +57,12 @@ function getPageHtml($formHtml) {
}

if (!$found) {
return '<table cellspacing="0" cellpadding="0" border="0" style="background: transparent; margin-top:0.5em;border:1px #b32424 solid;padding:0.5em;background-color: #fee7e6"><tr><td><b>You are not allowed to access this site!</b></td></tr></table></p><p>Click on image to log in:</p><a href="' . $shib->login_link() . '"><img src="extensions/MediaWikiShibboleth/shib.gif" alt="Centrale KU Leuven Login" align="middle"></a><a href="#" onclick="if(document.getElementById(\'spr\').style.display==\'none\'){document.getElementById(\'spr\').style.display=\'\';document.getElementById(\'spra\').innerHTML=\'Password Login &#9660;\'}else{document.getElementById(\'spr\').style.display=\'none\';document.getElementById(\'spra\').innerHTML=\'Password Login &#9654;\'}"><p id="spra">Password Login &#9654;</p></a><div id="spr" style="display:none">' . $formHtml . '</div>';
return $this->errorBox('mediawikishibboleth-forbidden-degree') . $this->password_login($formHtml);
}

$this->successfulAction();
}

return '<p>Click on image to log in:</p><a href="' . $shib->login_link() . '"><img src="extensions/MediaWikiShibboleth/shib.gif" alt="Centrale KU Leuven Login" align="middle"></a><a href="#" onclick="if(document.getElementById(\'spr\').style.display==\'none\'){document.getElementById(\'spr\').style.display=\'\';document.getElementById(\'spra\').innerHTML=\'Password Login &#9660;\'}else{document.getElementById(\'spr\').style.display=\'none\';document.getElementById(\'spra\').innerHTML=\'Password Login &#9654;\'}"><p id="spra">Password Login &#9654;</p></a><div id="spr" style="display:none">' . $formHtml . '</div>';
return $this->image($shib) . '<hr>' . $this->password_login($formHtml);
}
}
2 changes: 2 additions & 0 deletions includes/bKULshib.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace MediaWikiShibboleth;

class bKULshib {
protected $shib = FALSE;
protected $debug = FALSE;
Expand Down

0 comments on commit 13a44fa

Please sign in to comment.