MediaWiki:Common.js: Difference between revisions

From Startupidia
Added link opening in new tab
Redirecting anonymous user to login when they try to edit
Tag: Reverted
Line 23: Line 23:
   $('a.external').attr('target', '_blank');
   $('a.external').attr('target', '_blank');
});
});
// Redirect anonymous users to login if they try to edit
if (mw.config.get('wgAction') === 'edit' && mw.config.get('wgUserName') === null) {
    window.location.href = mw.util.getUrl('Special:UserLogin') + '?returnto=' + encodeURIComponent(mw.config.get('wgPageName'));
}

Revision as of 18:00, 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 if they try to edit
if (mw.config.get('wgAction') === 'edit' && mw.config.get('wgUserName') === null) {
    window.location.href = mw.util.getUrl('Special:UserLogin') + '?returnto=' + encodeURIComponent(mw.config.get('wgPageName'));
}