«Մասնակից:Vadgt/Քվեարկություն.js»–ի խմբագրումների տարբերություն

Content deleted Content added
No edit summary
No edit summary
Տող 1.
( function ( $, mw ) {
/*
var options = {}, // options modifiable by the user
* [[m:user:Hoo man]]; Version 2.0.8; 2015-02-09;
$dialog = null, // dialog jQuery object
* Provides an easy way to vote in steward elections
gallery = {},
* Most up to date version can be found on https://github.com/mariushoch/MediaWiki-Helpers/blob/master/stewardVote.js
api = new mw.Api();
*
* use:
$dialog.dialog({
 
width: 800,
if ( mw.config.get( 'wgPageName' ).indexOf( 'Stewards/Elections_' ) === 0 && mw.config.get( 'wgPageName' ).indexOf( '/Votes/' ) !== -1 && mw.config.get( 'wgUserName' ) !== null ) {
position: ['center', 80],
mw.loader.load( '//meta.wikimedia.org/w/index.php?title=User:Hoo_man/stewardVote.js&action=raw&ctype=text/javascript' );
autoOpen: false,
}
modal: true,
 
resizable: false
* to import
*/
 
/*global mw, alert, confirm, multilingual */
 
//<nowiki>
 
mw.loader.using( [ 'mediawiki.util', 'jquery.ui.dialog', 'jquery.cookie', 'jquery.spinner', 'mediawiki.api', 'user.tokens', 'json' ], function() {
'use strict';
 
var year = ( 1900 + new Date().getYear() ),
config = {
// Translations (keep in synch with https://meta.wikimedia.org/w/index.php?title=MediaWiki:StewardVote/en)
messages: {
windowTitle : 'Քվեարկել',
windowButton : 'Քվեարկություն',
vote : 'Խնդրեմ քվեարկեք՝',
pleaseSelectVote : 'Խնդրեմ քվեարկե՛ք',
confirmPossibleDouble : 'Պարզվում է, որ դուք նախկինում այս թեկնածուին մեկնաբանել եք: Դուք վստա՞հ եք, որ պետք է շարունակել: Խնդրում եմ հանեք նախկին ձայնը:',
editError : 'Սխալ՝ Էջը վերաբացեք (F5) և նորից քվեարկեք',
comment : 'Մեկնաբանություն (ըստ ցանկության)՝',
signatureAutoAdd : 'Ձեր ստորագրությունը կավելացվի ավտոմատ:',
yes : 'Կողմ',
no : 'Դեմ',
neutral : 'Ձեռնպահ'
},
 
title: "Քվեարկել",
button: "Քվեարկություն",
vote: "Խնդրեմ քվեարկեք՝",
pleaseSelectVote : "Խնդրեմ քվեարկե՛ք",
confirmPossibleDouble : "Պարզվում է, որ դուք նախկինում այս թեկնածուին մեկնաբանել եք: Դուք վստա՞հ եք, որ պետք է շարունակել: Խնդրում եմ հանեք նախկին ձայնը:",
editError : "Սխալ՝ Էջը վերաբացեք (F5) և նորից քվեարկեք",
comment: "Մեկնաբանություն (ըստ ցանկության)՝",
signatureAutoAdd : "Ձեր ստորագրությունը կավելացվի ավտոմատ:",
yes : "Կողմ",
no : "Դեմ",
neutral : "Ձեռնպահ"
// General config
 
Տող 45 ⟶ 32՝
minRegistration: ( year -1 ) + '-11-01T00:00:00Z'
},
api = new mw.Api(),
page = mw.config.get( 'wgPageName' ),
user = mw.config.get( 'wgUserName' ),
$dialog, $voteButton, voteText;
 
 
/**
* Finds out whether the user is eligible to vote and saves that information into a cookie (for the sake of performance)
* Calls onUserIsEligible or onUserIsNotEligible
*/
function onGlobaluserinfoLoad( data ) {
var editCount = 0,
eligible = false,
i, wikis, oldestAccount;
 
// List unattached and attached wikis
wikis = data.query.globaluserinfo.merged;
wikis.concat( data.query.globaluserinfo.unattached );
if ( wikis.length === 0 ) {
return false;
}
 
// Get edit count and oldest registration date
oldestAccount = wikis[0].timestamp;
 
for ( i = 0; i < wikis.length; i++ ) {
editCount += parseInt( wikis[i].editcount, 10 );
if ( wikis[i].timestamp < oldestAccount ) {
oldestAccount = wikis[i].timestamp;
}
 
if ( editCount >= config.minEditCount && oldestAccount <= config.minRegistration) {
eligible = true;
break;
}
}
 
// Save to cookie to not always look that up again
if ( eligible ) {
$.cookie(
'isEligible',
'true',
{
expires: 7,
path: '/'
}
);
onUserIsEligible();
} else {
// Expires after a day, cause this might change
$.cookie(
'isEligible',
'false',
{
expires: 1,
path: '/'
}
);
onUserIsNotEligible();
}
}
 
/**
* Called after the user was verified to be eligible. Loads the messages.
*/
function onUserIsEligible() {
var i, messagePage, lang;
 
if ( typeof multilingual === 'object' ) {
lang = multilingual.getLanguage();
} else {
// Fallback to the user interface language if multilingual hasn't yet been loaded
lang = mw.user.options.get( 'language' );
}
 
// Are we on the right page?
if ( page.indexOf( 'Վիքիպեդիա:Ադմինիստրատորի իրավունքների դիմումներ/' + year + '/' ) !== 0 ) {
return false;
}
 
// Use the currently selected language (if avaiable), fallback to en (which is already loaded)
for ( i = 0; i < config.availableLangs.length; i++ ) {
if ( config.availableLangs[i] === lang && lang !== 'en' ) {
messagePage = 'MediaWiki:StewardVote/' + lang;
break;
}
}
 
if ( messagePage ) {
$.ajax( {
url: mw.util.wikiScript(),
data: {
title: messagePage,
action: 'raw'
},
cache: true
} )
.done( onMessageLoad );
} else {
onMessageLoad();
}
}
 
/**
* Called after the user was verified to not be eligible
*/
function onUserIsNotEligible() {
$( '#Se-banner' ).hide();
}
 
/**
* Called by the time the messages have been loaded successfully. Displays the vote button. Only called for eligible users
*/
function onMessageLoad( data ) {
if ( data ) {
$.extend( config.messages, JSON.parse( data ) );
}
 
voteText = config.messages.windowTitle.replace( /\$1/g, page.replace( /.*\//, '' ) );
 
var sections, i;
 
$( '#voteButtons' )
.empty()
.append(
$( '<button>' )
.css( {
border: '1px solid darkgray',
'border-radius': '3px',
background: 'url("//upload.wikimedia.org/wikipedia/commons/7/79/Button_shade.png") black',
padding: '2px',
'margin-bottom': '5px',
width: '200px',
'font-size': '2.5em',
color: '#fff',
cursor: 'pointer'
} )
.click( openDialog )
.text( voteText )
)
.show();
 
$( '#Se-banner' ).hide();
 
// Small section vote links (replaces edit)
sections = [ '#Կողմ', '#Դեմ', '#Ձեռնպահ'];
 
for ( i = 0; i < sections.length; i++ ) {
if ( !$( sections[ i ] ).length ) {
continue;
}
 
$( sections[ i ] )
.parent()
.find( '.editsection a' )
.replaceWith(
$( '<a>' )
.text( voteText )
.attr( 'href', '#' )
.addClass( 'wmf-steward-vote-section-link' )
.click( openDialog )
);
}
}
 
/**
* Opens the dialog which allows users to vote
*/
function openDialog( event ) {
/*jshint validthis:true */
 
var preSelect;
event.preventDefault();
 
if ( $dialog && $dialog.length ) {
$dialog.remove();
}
$dialog = $( '<form>' )
.attr( 'name', 'stewardVoteForm' )
.dialog( {
title: voteText,
width: 450,
height: 333,
resizable: true,
buttons: [ {
text: config.messages.windowButton,
id: 'wmf-steward-vote-button',
disabled: 'disabled',
click: doVote
} ]
} )
.append(
$( '<p>' )
.text( config.messages.vote )
)
.append( dialogFormInput( 'yes' ) )
.append( dialogFormInput( 'no' ) )
.append( dialogFormInput( 'neutral' ) )
.append(
$( '<br />' )
)
.append(
$( '<label>' )
.attr( {
'for': 'wmf-steward-vote-comment'
} )
.text( config.messages.comment )
)
.append(
$( '<br />' )
)
.append(
$( '<textarea>' )
.attr( {
id: 'wmf-steward-vote-comment',
name: 'comment',
type: 'text',
rows: 3,
} )
.css( {
width: '90%'
} )
)
.append(
$( '<p>' )
.text( config.messages.signatureAutoAdd )
);
 
$voteButton = $( '#wmf-steward-vote-button' );
 
// Pre select an option and enable the vote button if opened from a section link
if ( $( this ).hasClass( 'wmf-steward-vote-section-link' ) ) {
preSelect = $( this ).parent().parent().find( 'span.mw-headline' ).attr( 'id' ).toLowerCase();
$voteButton.button( 'enable' );
}
}
 
/**
* Get a <input> and a label for the given type, helper function for openDialog
*/
function dialogFormInput( type ) {
return $( '<input>' )
.attr( {
type: 'radio',
name: 'vote',
value: type,
id: 'wmf-steward-vote-' + type
} )
.one( 'click', function() {
// Enable the vote button by the time the user selects an option
$voteButton.button( 'enable' );
} )
.add(
$( '<label>' )
.attr( {
'for': 'wmf-steward-vote-' + type
} )
.text( config.messages[ type ] )
)
.add(
$( '<br>' )
);
}
 
/**
* Performs the actual edit
*/
function doVote() {
/**
* Called in case anything goes wrong in here
*/
function onFail() {
$spinner.remove();
$voteButton.show();
alert( config.messages.editError );
}
 
var vote, i, $spinner, comment, section, voteLine;
 
// Vote?
for ( i = 0; i < document.stewardVoteForm.vote.length; i++ ) {
if (document.stewardVoteForm.vote[i].checked ) {
vote = document.stewardVoteForm.vote[i].value;
}
}
 
if ( !vote ) {
alert( config.messages.pleaseSelectVote );
return false;
}
 
$spinner = $.createSpinner();
$voteButton
.hide()
.after( $spinner );
 
comment = document.stewardVoteForm.comment.value;
 
if ( vote === 'yes' ) {
section = 1;
} else if (vote === 'no' ) {
section = 2;
} else {
section = 3;
}
 
voteLine = '\n# ' + comment + ' --~~~~';
 
// Get the page text (to detect potential double votes)
$.ajax( {
url: mw.util.wikiScript(),
data: {
title: page,
action: 'raw'
},
cache: false
} )
.fail( onFail )
.done( function( pageText ) {
 
if ( pageText.indexOf() !== -1 ) {
if ( !confirm ( config.messages.confirmPossibleDouble ) ) {
$dialog.dialog( 'close' );
return false;
}
}
 
api.post( {
action: 'edit',
title: page,
appendtext: voteLine,
section: section,
summary: config.editSummary + vote,
token: mw.user.tokens.get( 'editToken' )
} )
.done( function() {
// Just reload the page
window.location.href = mw.util.getUrl( page );
} )
.fail( onFail );
} );
}
 
$.each( targets, function ( index, target ) {
// Init code
var sendData = {
$( document ).ready( function() {
action: 'vote',
if ( document.getElementById( 'Se-banner' ) && !mw.user.isAnon() ) {
title: 'Վիքիպեդիա:Ադմինիստրատորի իրավունքների դիմումներ/' + year '/',
main();
type: type,
}
text: wikitext,
} );
message: vote,
} );
subject: subject
};