Page MenuHomePhabricator
Paste P41805

(An Untitled Masterwork)
ActivePublic

Authored by Ladsgroup on Nov 29 2022, 9:54 PM.
Tags
None
Referenced Files
F35839019: raw-paste-data.txt
Dec 5 2022, 8:43 PM
F35839004: raw-paste-data.txt
Dec 5 2022, 8:35 PM
F35838946: raw-paste-data.txt
Dec 5 2022, 7:52 PM
F35838919: raw-paste-data.txt
Dec 5 2022, 7:31 PM
F35838918: raw-paste-data.txt
Dec 5 2022, 7:30 PM
F35824640: raw-paste-data.txt
Nov 29 2022, 10:04 PM
F35824633: raw-paste-data.txt
Nov 29 2022, 9:54 PM
Subscribers
None
(function(mw) {
if (!['Commons:Sound_Logo_Vote/id', 'Commons:Sound_Logo_Vote/de', 'Commons:Sound_Logo_Vote', 'Commons:Sound_Logo_Vote/es', 'Commons:Sound_Logo_Vote/fr', 'Commons:Sound_Logo_Vote/pt-br', 'Commons:Sound_Logo_Vote/ar', 'Commons:Sound_Logo_Vote/ks-arab', 'Commons:Sound_Logo_Vote/hi', 'Commons:Sound_Logo_Vote/bn', 'Commons:Sound_Logo_Vote/ko'].includes(mw.config.get('wgPageName'))) {
return;
}
const i18n = {
'en': {
"non-eligible-error": 'You are not eligible to vote yet. You can become eligible by making at least ten edits in any Wikimedia project.',
"your-vote-is-recorded": 'Your vote has been recorded. Thank you! You will be redirected soon.',
"edit-could-not-save": 'Your vote could not be saved.',
"your-vote": 'Your vote:',
"your-top-choice": 'Your top choice is:',
"submit-your-vote": 'Submit your vote',
"you-already-voted": 'Each person is allowed one vote from a single Wikimedia account. You have already voted, only your last vote will be counted.',
"reorder-please": 'Please reorder the sound logos below in order of preference, from favourite to least favourite:',
"login-first": 'Please login or create an account first.'
},
'ar': {
"non-eligible-error": 'لست مؤهلًا للتصويت بعد. يُمكنك أن تصبح مؤهلًا بإجراء عشرِ تعديلاتٍ على الأقل في أحد مشاريع ويكيميديا.',
"your-vote-is-recorded": 'سجَّل تصويتك. شكرًا لك! سيُعاد توجيهك قريبًا.',
"edit-could-not-save": 'لا يمكن حفظ تصويتك.',
"your-vote": 'تصويتك:',
"your-top-choice": 'خيارك المُفضل هو:',
"submit-your-vote": ' أرسل صوتك',
"you-already-voted": 'يُسمح لكل شخصٍ بصوتٍ واحدٍ من حساب ويكيميديا واحد. لقد شاركت بالفعل، سيُحسب توصيتك الأخير فقط.',
"reorder-please": 'يرجى إعادة ترتيب الشعارات الصوتية أدناه حسب التفضيل، الأكثر تفضيلًا إلى الأقل تفضيلاً:',
"login-first": 'يرجى تسجيل الدخول أو إنشاء حساب أولًا.'
},
'id': {
"non-eligible-error": 'Anda tidak memenuhi syarat untuk ikut memberikan suara. Anda bisa memberikan suara jika sudah memenuhi syarat dengan memiliki jumlah suntingan setidaknyasepuluh dalam proyek Wikimedia manapun.',
"your-vote-is-recorded": 'Voting Anda telah Kami simpan. Terima kasih! Anda akan segera dialihkan.',
"edit-could-not-save": 'Suara yang Anda berikan tidak dapat disimpan.',
"your-vote": 'Pilihan Anda:',
"your-top-choice": 'Karya favorit Anda adalah:',
"submit-your-vote": 'Kumpulkan voting Anda',
"you-already-voted": 'Setiap orang hanya diperbolehkan untuk memberikan suara dari satu akun Wikimedia yang dipunyai. Anda sudah memberikan suara, hanya suara terakhir yang akan diperhitungkan.',
"reorder-please": 'Silakan susun ulang logo suara di bawah ini berdasarkan ketertarikan Anda, mulailah dari logo yang Anda paling sukai hingga yang kurang disukai:',
"login-first": 'Silakan masuk log atau buatlah akun terlebih dahulu.'
},
'fr': {
"non-eligible-error": "Vous n'êtes pas encore éligible pour voter. Vous pouvez devenir éligible en effectuant au moins dix modifications dans n'importe quel projet Wikimédia.",
"your-vote-is-recorded": 'Votre vote a été enregistré. Merci! Vous serez bientôt redirigé.',
"edit-could-not-save": "Votre vote n'a pas pu être enregistré.",
"your-vote": 'Votre vote:',
"your-top-choice": 'Votre premier choix est:',
"submit-your-vote": 'Soumettre votre vote',
"you-already-voted": "Chaque personne a droit à un vote à partir d'un seul compte Wikimédia. Vous avez déjà voté, seul votre dernier vote sera comptabilisé",
"reorder-please": 'Veuillez réordonner les logos sonores ci-dessous par ordre de préférence, du favori au moins préféré:',
"login-first": "Veuillez d'abord vous connecter ou créer un compte."
},
'de': {
"non-eligible-error": 'Du bist noch nicht wahlberechtigt. Wenn du mindestens zehn Bearbeitungen in einem Wikimedia-Projekt tätigst, wirst du wahlberechtigt.',
"your-vote-is-recorded": 'Deine Stimme wurde registriert. Danke fürs Abstimmen! Du wirst gleich weitergeleitet.',
"edit-could-not-save": 'Deine Stimme konnte nicht registriert werden.',
"your-vote": 'Deine Wahl:',
"your-top-choice": 'Deine erste Wahl ist:',
"submit-your-vote": 'Stimme abgeben',
"you-already-voted": 'Pro Person ist nur eine Stimme über einen einzigen Wikimedia-Account zulässig. Du hast bereits abgestimmt, nur deine letzte Stimme wird gezählt.',
"reorder-please": 'Bitte bringe die untenstehenden Soundlogos in eine Rangfolge, von deinem bevorzugten Beitrag zum am wenigsten ansprechenden Beitrag:',
"login-first": 'Bitte melde dich an oder erstelle erst einen Account.'
},
'hi': {
"non-eligible-error": 'आप अभी तक मतदान करने के पात्र नहीं हैं। आप किसी भी विकिमीडिया परियोजना में कम से कम दस सम्पादन करके इस हेतु पात्र बन सकते हैं।',
"your-vote-is-recorded": 'आपका मत रिकॉर्ड कर लिया गया है। आपको धन्यवाद! आपको जल्द ही पुनर्निर्देशित किया जाएगा।',
"edit-could-not-save": 'आपका मत सहेजा नहीं जा सका।',
"your-vote": 'आपका मत:',
"your-top-choice": 'आपकी शीर्ष पसंद:',
"submit-your-vote": 'अपना मतदान करें',
"you-already-voted": 'प्रत्येक व्यक्ति एक विकिपीडिया खाते से, एक ही मत दे सकता है।आप पहले ही अपना मत दे चुके हैं, आपका केवल अंतिम मत ही गिना जाएगा।',
"reorder-please": 'कृपया अधिक पसंदीदा से कम पसंदीदा, के वरीयता के क्रम में नीचे ध्वनि लोगो को फिर से व्यवस्थित करें:',
"login-first": 'कृपया लॉगिन करें या पहले एक खाता बनाएँ।'
},
'ko': {
"non-eligible-error": '아직 투표에 참여할 수 있는 선거권이 없습니다. 위키미디어 프로젝트에 적어도 10개의 편집을 하면 투표에 참여하실 수 있습니다.',
"your-vote-is-recorded": '감사합니다! 귀하의 투표는 기록되었습니다. 잠시후 자동으로 자동으로 이동할 것입니다. ',
"edit-could-not-save": '귀하의 투표가 저장되지 못했습니다.',
"your-vote": '귀하의 선택:',
"your-top-choice": '우선 순위:',
"submit-your-vote": '투표 제출하기',
"you-already-voted": '각 사용자는 한개의 위키미디어 계정으로부터 한번의 투표를 행사할 수 있습니다. 이미 투표했다면, 가장 최근에 투표한 것만 집계됩니다.',
"reorder-please": '가장 선호하는, 가장 선호하지 않는 것을 아래의 사운드 로고를 선호하는 순서대로 재정렬 해주세요:',
"login-first": '로그인을 하시거나 계정을 만들어 주세요.'
},
'pt': {
"non-eligible-error": 'Você ainda não pode votar. Você pode se qualificar para votar fazendo pelo menos dez edições em qualquer projeto da Wikimedia.',
"your-vote-is-recorded": 'Seu voto foi gravado. Agradecemos! Você será redirecionado em breve.',
"edit-could-not-save": 'Não foi possível salvar seu voto.',
"your-vote": 'Seu voto:',
"your-top-choice": 'Sua opção preferida:',
"submit-your-vote": 'Enviar seu voto',
"you-already-voted": 'Cada pessoa tem direito a um voto de uma única conta da Wikimedia. Você já votou, apenas seu último voto será contabilizado.',
"reorder-please": 'Reordene os logos sonoros abaixo em ordem de preferência, do favorito ao menos favorito:',
"login-first": 'Faça o login ou crie uma conta primeiro.'
},
'es': {
"non-eligible-error": 'Todavía no reúnes las condiciones para votar. Para reunir los requisitos necesarios, deberás hacer al menos diez ediciones en cualquier proyecto de Wikimedia.',
"your-vote-is-recorded": 'Su voto ha sido registrado. ¡Muchas gracias! Redireccionando…',
"edit-could-not-save": 'Tu voto no pudo ser guardado.',
"your-vote": 'Su voto:',
"your-top-choice": 'Su opción preferida:',
"submit-your-vote": 'Emitir su voto',
"you-already-voted": 'Cada persona puede emitir un voto desde una única cuenta de Wikimedia. Si ya has votado, solo se tendrá en cuenta tu último voto.',
"reorder-please": 'Por favor, reordena los logos sonoros abajo en orden de preferencia, desde tu favorito hasta el menos preferido:',
"login-first": 'Por favor, inicia sesión o crea una cuenta primero.'
}
};
const lang = mw.config.get('wgPageContentLanguage');
$.i18n().load( i18n );
$.i18n({ locale: lang });
/**
* Shuffles array in place.
* @param {Array} a items An array containing the items.
* From https://stackoverflow.com/a/6274381/2596051
*/
function shuffle(a) {
var j, x, i;
for (i = a.length - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1));
x = a[i];
a[i] = a[j];
a[j] = x;
}
return a;
}
function checkForEligibility() {
var api = new mw.Api();
var promise = api.get({
'action': 'query',
'meta': 'globaluserinfo',
'guiprop': 'editcount'
}).then( function (data) {
if ( data.query.globaluserinfo.editcount > 10 || data.query.globaluserinfo.registration < "2022-12-05T00:00:00Z" ) {
return;
}
OO.ui.alert($.i18n('non-eligible-error'));
})
return promise;
}
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
function escapeReplacement(string) {
return string.replace(/\$/g, '$$$$');
}
function saveVote( draggableGroupWidget ) {
var api = new mw.Api();
api.edit('Commons:Sound Logo Vote/Votes', function(revision) {
var newText = revision.content,
votes = draggableGroupWidget.getItems().map(function(i) {
return i.getData().replace('\n', '')
}).join(" - "),
usernameText = '*[[User:' + mw.config.get('wgUserName') + ']]';
if ( revision.content.indexOf(usernameText) !== -1 ) {
newText = newText.replace(
new RegExp(escapeRegExp(usernameText) + '.+(\n|$)', 'g'),
escapeReplacement(usernameText + ': ' + votes)
)
} else {
newText += '\n' + usernameText + ': ' + votes;
}
return {
text: newText,
summary: 'Voting using the vote gadget'
}
}).done(function() {
var messageText = $.i18n('your-vote-is-recorded');
if (mw.config.get('wgUserName') === 'TK-999') {
messageText += ' <3';
}
OO.ui.alert(messageText);
setTimeout(function() {
window.location.href = 'https://commons.wikimedia.org/wiki/Commons:Sound_Logo_Vote/Thank_You'
}, 5000);
}).fail(function() {
OO.ui.alert($.i18n('edit-could-not-save'));
});
}
function main() {
var DraggableGroupWidget = function DraggableGroupWidget(config) {
config = config || {};
DraggableGroupWidget.super.call(this, config);
OO.ui.mixin.DraggableGroupElement.call(this, $.extend({
$group: this.$element
}, config));
};
OO.inheritClass(DraggableGroupWidget, OO.ui.Widget);
OO.mixinClass(DraggableGroupWidget, OO.ui.mixin.DraggableGroupElement);
var DraggableItemWidget = function DraggableItemWidget(config) {
config = config || {};
DraggableItemWidget.super.call(this, config);
OO.ui.mixin.DraggableElement.call(this, config);
};
OO.inheritClass(DraggableItemWidget, OO.ui.Widget);
OO.mixinClass(DraggableItemWidget, OO.ui.mixin.DraggableElement);
var items = [];
$('.wikitable tr').each(function(i) {
if (i == 0) {
return;
}
var element = new DraggableItemWidget({
content: [new OO.ui.HtmlSnippet('<br>'), new OO.ui.HtmlSnippet($(this).find('td:eq(2) img').clone())],
data: $(this).find('td:first').text(),
text: $(this).find('td:first').text()
});
element.$element
.css('border', '1px solid #a2a9b1')
.css('background-color', '#f8f9fa')
.css('padding', '5px')
.css('border-radius', '2px')
.css('margin', '5px');
items.push(element);
})
shuffle(items);
var draggableGroupWidget = new DraggableGroupWidget({
orientation: 'horizontal',
id: 'votes-draggable-box',
items: items
});
var noticeText = '<strong>' + $.i18n('your-vote') + '</strong><br>';
draggableGroupWidget.$element
.css('border', '1px solid #a2a9b1')
.css('padding', '5px')
.css('border-radius', '2px')
.css('margin', '5px')
.css('margin-bottom', '16px');
var topChoice = '<br><strong style="line-height: 200%;">' + $.i18n('your-top-choice') + '</strong> ';
var massege = new OO.ui.MessageWidget({
type: 'notice',
label: new OO.ui.HtmlSnippet(noticeText + draggableGroupWidget.getItems().map(function(i) {
return i.getData()
}).join(" - ") + topChoice + draggableGroupWidget.getItems()[0].getData())
});
draggableGroupWidget.on('reorder', function(item) {
massege.setLabel(new OO.ui.HtmlSnippet(noticeText + draggableGroupWidget.getItems().map(function(i) {
return i.getData()
}).join(" - ") + topChoice + draggableGroupWidget.getItems()[0].getData()));
});
var saveButton = new OO.ui.ButtonInputWidget({
type: 'submit',
label: $.i18n('submit-your-vote'),
flags: [
'primary',
'progressive'
]
});
saveButton.on('click', function() {
var api = new mw.Api();
api.get( {
'action': 'query',
'prop': 'revisions',
'titles': 'Commons:Sound Logo Vote/Votes',
'rvslots': '*',
'rvprop': 'content'
}).then( function(data) {
if ( data.query.pages['125944070'].revisions[0].slots.main['*'].indexOf('*[[User:' + mw.config.get('wgUserName') + ']]') !== -1 ) {
OO.ui.confirm( $.i18n('you-already-voted') ).done( function ( confirmed ) {
if ( confirmed ) {
saveVote( draggableGroupWidget );
}
} );
} else {
saveVote( draggableGroupWidget );
}
})
})
$('#mw-content-text').append('<br><strong style="padding: 5px;">' + $.i18n('reorder-please') + '</strong><br>');
$('#mw-content-text').append(draggableGroupWidget.$element);
saveButton.$element.css('margin-top', '8px');
massege.$element.append(saveButton.$element);
$('#mw-content-text').append(massege.$element);
}
$('.mw-ui-button.mw-ui-progressive').on('click', function() {
mw.loader.using(['oojs', 'oojs-ui', 'oojs-ui-core', 'oojs-ui-widgets']).then(function() {
if ( !mw.config.get('wgUserName') ) {
OO.ui.alert($.i18n('login-first'));
return;
}
$('.mw-ui-button.mw-ui-progressive').css('display', 'none');
var progressBar = new OO.ui.ProgressBarWidget( {
progress: false,
id: 'progressBar'
} );
$('#mw-content-text').css('margin', '16px').append( progressBar.$element );
checkForEligibility().then( function () {
$('#progressBar').remove();
main();
})
})
});
})(mediaWiki);