MediaWiki:Common.js: Difference between revisions
Startupedia (talk | contribs) Redirect anonymous users to login page when they try to edit Tag: Reverted |
Startupedia (talk | contribs) Redirect anonymous users to login when they try to edit Tag: Reverted |
||
Line 24: | Line 24: | ||
}); | }); | ||
// Redirect anonymous users to login | // Redirect anonymous users to login when they try to edit | ||
$(function () { | $(function () { | ||
if (mw.config.get('wgUserName') === null) { | |||
// Override edit and edit source tabs | |||
$('#ca-edit a, #ca-ve-edit a').on('click', function (e) { | |||
e.preventDefault(); | |||
var returnTo = mw.config.get('wgPageName'); | |||
window.location.href = mw.util.getUrl('Special:UserLogin') + '?returnto=' + encodeURIComponent(returnTo); | |||
}); | |||
} | } | ||
}); | }); |
Revision as of 18:05, 31 May 2025
/* Any JavaScript here will be loaded for all users on every page load. */ $(function () { const structuredData = { "@context": "https://schema.org", "@type": "WebSite", "name": "Startupedia", "url": "https://startupwiki.ai", "potentialAction": { "@type": "SearchAction", "target": "https://startupwiki.ai/index.php?search={search_term_string}", "query-input": "required name=search_term_string" } }; const script = document.createElement('script'); script.type = 'application/ld+json'; script.text = JSON.stringify(structuredData); document.head.appendChild(script); }); $(function () { $('a.external').attr('target', '_blank'); }); // Redirect anonymous users to login when they try to edit $(function () { if (mw.config.get('wgUserName') === null) { // Override edit and edit source tabs $('#ca-edit a, #ca-ve-edit a').on('click', function (e) { e.preventDefault(); var returnTo = mw.config.get('wgPageName'); window.location.href = mw.util.getUrl('Special:UserLogin') + '?returnto=' + encodeURIComponent(returnTo); }); } });