MediaWiki:Centralnotice-template-stewvote
<style>
@font-face {
font-family: 'Montserrat'; font-style: normal; src: local('Montserrat'), local('Montserrat'), url(https://upload.wikimedia.org/wikipedia/donate/c/cd/Montserrat.woff2) format('woff2');}
/* Main banner container. Banner: background, border colour and width and adding a margin between banner and article header*/ .cnotice {
position: relative; overflow: hidden; background: #f8f9fa; border: 1px solid #a2a9b1; border-radius: 2px; margin-bottom: 1em; cursor: pointer; color: #222; font-weight: 500;
}
/* Sets the minimum banner height. If img + logo-container margins > height. Banner will be larger*/
- cnotice-main {
display: table; width: 100%; height: 80px; /* need to set height for height 100% to work on elements within it */
}
/*MOBILE - Adjust mobile height of banner*/ body.skin-minerva #cnotice-main {
height: 100px;
}
/*IMPORTANT - don't touch*/ .cnotice-message-container, .cnotice-logo-container, .cnotice-misc-container {
display: table-cell; height: 100%; vertical-align: middle;
}
/* --- Main message --- */ .cnotice-message {
position: relative; margin: 0; line-height: 1.2; padding: 5px 5px 5px 5px;
}
@media (min-width: 1200px) {
.cnotice-message { padding: 15px 0px 11px 30px; }
}
body.rtl .cnotice-message {
padding: 5px 5px 5px 5px;
}
.cnotice-message p {
margin: 0; color: #222; font-family: Arial, sans-serif; font-weight: bold; font-size: 100%; opacity: 1; text-align: center; padding-top: 10px; padding-bottom: 10px;
}
@media (min-width: 1200px) {
.cnotice-message p { font-size: 120%; }
}
/* --- Logo Image text --- */
.cnotice-logo-container {
width: 10%;
}
body.rtl .cnotice-logo-container {
padding: 0 .25em 0 .9em;
}
.cnotice-logo-container img {
opacity: 1; display: block; margin-left: 15%; margin-top: 2px; margin-bottom: 1px;
}
/*Misc containter stuff starts here*/ .cnotice-misc-container {
width: 10%; padding-right: 40px;
}
/*Detects and adjusts for mobile skin */ body.skin-minerva .cnotice-misc-container {
padding-right: 10px;
}
/* --- Close Options --- */
- cnotice-toggle-box-options {
display: table-cell; font-size: .8em; text-transform: uppercase; width: 38px; height: 38px; border-radius: 19px; vertical-align: middle;
}
- cnotice-toggle-box {
cursor: pointer; position: absolute; top: 2px; right: 3px; z-index: 1; opacity: .8;
}
body.rtl #cnotice-toggle-box {
left: 3px; right: unset;
}
- cnotice-toggle-box:hover {
opacity: 1;
}
/* --- Full Banner Link --- */ .cnotice a.cnotice-full-banner-click {
display: block; height: 100%; width: 100%; cursor: pointer; text-decoration: none;
}
.cnotice a.cnotice-full-banner-click:hover {
text-decoration: underline;
}
.cnotice-button {
display: inline-block; border: 2px solid #36c; border-radius: 2px; color: #fff; padding: 5px 5px; text-align: center; font-weight: bold; text-decoration: none; font-size: 14px; margin: 4px 2px; -moz-transition-duration: 100ms; /* Firefox */ -webkit-transition-duration: 100ms; /* Safari */ transition-duration: 100ms; cursor: pointer; z-index: 1; min-width: 80px;
}
@media (min-width: 1100px) {
.cnotice-button { min-width: 110px; width: 25%; margin: auto; }
}
/* --- Buttons --- */ .cnotice a.cnotice-buttonlink {
cursor: pointer; text-decoration: none; color: #000;
}
.cnotice a.cnotice-buttonlink:hover {
color: #fff;
}
.cnotice-button1 {
background-color: #36c; border-color: #36c; color: #fff;
}
.cnotice-button1:hover {
background-color: #447ff5; border-color: #447ff5;
}
.cnotice-button1:active {
background-color: #2a4b8d; border-color: #2a4b8d;
}
.rtl .cnotice-button1 {
left: 23px; right: auto; margin-left: 20px;
}
- cnotice-translation-link {
position: absolute; right: 65px; bottom: 0px; font-size: 0.8em; white-space: nowrap;
}
- cnotice-translation-link:hover {
text-decoration: underline;
}
.rtl #cnotice-translation-link {
text-align: left; left: 65px;
} </style>
<script> /**
* This script does not check the actual requirements on Guidelines page. It only * checks whether the user's global edit count is more than MIN_EDIT_COUNT and whether * the global account was registered before MIN_REGISTRATION. If the user's global account * registration time is newer, then we also try to find whether there is a local account * which was registered before the minimum registration time. Users who do not match these * criteria are considered as ineligible. */
var stewardVoteBanner = ( function() {
var MIN_REGISTRATION = '2023-11-01T00:00:00Z', MIN_EDIT_COUNT = 600, STORAGE_KEY = 'StewardVoteEligible', username = mw.config.get( 'wgUserName' ), $notice = $( '#bannerContent' ), cn = mw.centralNotice, eligible = false;
function getGlobalAccountInfo() { return new mw.Api().get( { action: 'query', meta: 'globaluserinfo', guiprop: [ 'editcount', 'merged' ], guiuser: username } ).then( function( result ) { return result.query.globaluserinfo; }, function() { return null; } ); }
function isEligible( globalInfo ) { if ( globalInfo.editcount < MIN_EDIT_COUNT ) { // User doesn't have the required number of edits globally return false; } if ( globalInfo.registration <= MIN_REGISTRATION ) { // Global account was created before minimum registration // (and above global editcount threshold) so this user is eligible return true; }
// Global account registration time may be newer than registration time for // a local account so we'll iterate through all local accounts and find // the oldest account to compare with minimum registration time var wikis = globalInfo.merged, wikiCount = wikis.length, oldestRegistration = wikis[0].registration; // default to first account on wikis array for ( var i = 0; i < wikiCount; i++ ) { if ( wikis[i].registration < oldestRegistration ) { oldestRegistration = wikis[i].registration; } if ( oldestRegistration <= MIN_REGISTRATION ) { // A local account registered before the minimum registration // time so this user is eligible return true; } }
// We couldn't find a local account registered before the minimum // registration time - ultimately the user is not eligible to vote return false; }
function setStorage( eligible ) { if ( !cn.kvStore.isAvailable() ) { return; } cn.kvStore.setItem( STORAGE_KEY, eligible, cn.kvStore.contexts.CAMPAIGN, 29 ); }
function setDisplay( eligible ) { if ( !eligible ) { console.log( 'Not displaying stewvote banner, user is not eligible' ); } $notice.css( 'display', eligible ? 'block' : 'none' ); }
// Provide correct data about whether the banner was really shown. /*cn.bannerData.alterImpressionData = function( impressionData ) { if ( !eligible ) { impressionData.reason = 'NotEligible'; } return eligible; };*/
return { initialize: function() { // Not logged in but just to be safe - this shouldn't actually // happen because the banner should only be loaded for logged-in users if ( username === null ) { mw.log.warn( 'steward vote CNbanner loaded on an anon user - not showing' ); return; } if ( $notice.length === 0 ) { mw.log.warn( 'Could not locate banner content element' ); return; }
eligible = cn.kvStore.isAvailable() ? cn.kvStore.getItem( STORAGE_KEY, cn.kvStore.contexts.CAMPAIGN ) : null;
// If storage information was available, display based on that info if ( eligible !== null ) { setDisplay( eligible ); return; }
// There's no information from storage, we'll perform the check getGlobalAccountInfo().done( function( globalInfo ) { eligible = isEligible( globalInfo ); setStorage( eligible ); setDisplay( eligible );
} ).fail( function() { // We don't have the required info so this defaults to the hidden banner mw.log.warn( 'API request failed for steward vote CNbanner' ); } ); } };
} () ); stewardVoteBanner.initialize(); </script>