MediaWiki:Common.js:修订间差异
来自生物多样性知识平台
无编辑摘要 |
无编辑摘要 |
||
第25行: | 第25行: | ||
importScriptURI('https://cdnjs.cloudflare.com/ajax/libs/keycloak-js/16.1.1/keycloak.min.js'); | importScriptURI('https://cdnjs.cloudflare.com/ajax/libs/keycloak-js/16.1.1/keycloak.min.js'); | ||
// | // 初始化 Keycloak | ||
function initKeycloak() { | function initKeycloak() { | ||
const keycloak = new Keycloak({ | const keycloak = new Keycloak({ | ||
url: 'https:// | url: 'https://sso.biodiversity.cern.ac.cn/auth', | ||
realm: 'biodiversity', | realm: 'biodiversity', | ||
clientId: 'wiki-client' | clientId: 'wiki-client' | ||
第35行: | 第35行: | ||
keycloak.init({ | keycloak.init({ | ||
onLoad: 'check-sso', | onLoad: 'check-sso', | ||
promiseType: 'native' // Optional: Use native Promises for better compatibility | |||
}).then(function(authenticated) { | }).then(function(authenticated) { | ||
if (authenticated) { | if (authenticated) { | ||
console.log('Authenticated'); | console.log('Authenticated'); | ||
performMediaWikiLogin(); | |||
performMediaWikiLogin( | |||
} else { | } else { | ||
console.log('Not authenticated'); | console.log('Not authenticated'); | ||
第48行: | 第48行: | ||
} | } | ||
initKeycloak(); | // Function to trigger MediaWiki login | ||
function performMediaWikiLogin() { | |||
const currentUrl = window.location.href; | |||
const loginUrl = 'https://wiki.biodiversity.cern.ac.cn/index.php/Special:PluggableAuthLogin'; | |||
if (!currentUrl.includes('Special:PluggableAuthLogin')) { | |||
window.location.href = loginUrl; | |||
} | |||
} | |||
// 等待 Keycloak JS 库加载完成后执行初始化 | |||
mw.loader.using('mediawiki.util', function() { | |||
initKeycloak(); | |||
}); | |||
})(); | })(); |
2024年6月22日 (六) 06:43的版本
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */ $(document).ready(function() { $('.gallery a.image').each(function() { var href = $(this).attr('href'); // 修改链接以指向直接的图片浏览器查看模式 $(this).attr('href', href + '?action=render'); }); // 更改Logo链接 var logoLink = document.querySelector('#p-logo .mw-wiki-logo'); if (logoLink) { logoLink.href = "https://www.biodiversity.cern.ac.cn"; } // 更改标题链接 var titleLink = document.querySelector('#p-logo .mw-wiki-title'); if (titleLink) { titleLink.href = "https://www.biodiversity.cern.ac.cn"; } }); (function() { // 加载 Keycloak JS 库 importScriptURI('https://cdnjs.cloudflare.com/ajax/libs/keycloak-js/16.1.1/keycloak.min.js'); // 初始化 Keycloak function initKeycloak() { const keycloak = new Keycloak({ url: 'https://sso.biodiversity.cern.ac.cn/auth', realm: 'biodiversity', clientId: 'wiki-client' }); keycloak.init({ onLoad: 'check-sso', promiseType: 'native' // Optional: Use native Promises for better compatibility }).then(function(authenticated) { if (authenticated) { console.log('Authenticated'); performMediaWikiLogin(); } else { console.log('Not authenticated'); } }).catch(function() { console.log('Failed to initialize Keycloak'); }); } // Function to trigger MediaWiki login function performMediaWikiLogin() { const currentUrl = window.location.href; const loginUrl = 'https://wiki.biodiversity.cern.ac.cn/index.php/Special:PluggableAuthLogin'; if (!currentUrl.includes('Special:PluggableAuthLogin')) { window.location.href = loginUrl; } } // 等待 Keycloak JS 库加载完成后执行初始化 mw.loader.using('mediawiki.util', function() { initKeycloak(); }); })();