Menú alternativo
Menú alternativo personal
No has accedido
Tu dirección IP será visible si haces alguna edición

Diferencia entre revisiones de «MediaWiki:Common.js»

Página de la interfaz de MediaWiki
Sin resumen de edición
Sin resumen de edición
 
(No se muestran 9 ediciones intermedias de 2 usuarios)
Línea 1: Línea 1:
// ocultar mw-pt-translate-header para los anónimos
// ocultar mw-pt-translate-header para los anónimos


mw.loader.using( [ 'mediawiki.user' ], function ( ) {
mw.loader.using( [ 'mediawiki.user' ], function () {
if ( mw.user.isAnon() == 1 ) {
if ( mw.user.isAnon() === 1 ) {
mw.util.addCSS( '.mw-pt-translate-header {display:none}' );
mw.util.addCSS( '.mw-pt-translate-header { display: none; }' );
}
}
} );
} );


// barra de progreso
const ELECTION_2024_PAGE_ID = 1792;
if ( mw.config.get( 'wgPageName' ) === 'Usuario:Hasley/b' ) {
const ELECTION_2024_STATEMENTS_PAGE_ID = 1794;
const ELECTION_2024_RESULTS_PAGE_ID = 1794;


$.when( $.ready, mw.loader.using( [ 'oojs-ui' ] ) ).then( function () {
const ELECTION_2024_PAGE_IDS = [
ELECTION_2024_PAGE_ID,
ELECTION_2024_STATEMENTS_PAGE_ID,
ELECTION_2024_RESULTS_PAGE_ID
];


barId = 1;
if ( ELECTION_2024_PAGE_IDS.includes( mw.config.get( 'wgArticleId' ) ) ) {
barId2 = 2;
$( '.navbar li:has(a.selflink)' )
barId3 = 3;
.css( {
barId4 = 4;
  'border-radius': '5px 5px 0 0',
barId5 = 5;
'border-bottom-left-radius': '0px',
'border-bottom': '3px solid #833ab4'
} );
}


var number  = $( '#progress-bar-' + barId ).attr( 'data-id-'  + barId );
mw.loader.using( [
var number2 = $( '#progress-bar-' + barId2 ).attr( 'data-id-' + barId2 );
'oojs-ui',
var number3 = $( '#progress-bar-' + barId3 ).attr( 'data-id-' + barId3 );
'mediawiki.api',
var number4 = $( '#progress-bar-' + barId4 ).attr( 'data-id-' + barId4 );
'mediawiki.widgets.DateInputWidget'
var number5 = $( '#progress-bar-' + barId5 ).attr( 'data-id-' + barId5 );
] ).then( () => {
if (
mw.config.get( 'wgArticleId' ) !== ELECTION_2024_STATEMENTS_PAGE_ID ||
!mw.config.get( 'wgUserName' )
) {
return;
}
const FALLBACK_LANGUAGE_CODE = 'es';


var progressBar = new OO.ui.ProgressBarWidget( {
const userLanguage = mw.user.options.get( 'language' );
progress: number
const messages = {
} );
realNameInputPlaceholder: {
en: 'Your real name (optional)',
es: 'Tu nombre real (opcional)'
},
realNameInputLabel: {
en: 'Real name',
es: 'Nombre real'
},
statementInputPlaceholder: {
en: 'Why do you want to join the Administrative Council?',
es: 'Por qué quieres ser miembro del Consejo de Administración...'
},
statementInputLabel: {
en: 'Statement',
es: 'Presentacion'
},
submitButtonLabel: {
en: 'Submit',
es: 'Publicar'
},
spokenLanguagesInputLabel: {
en: 'Spoken languages',
es: 'Idiomas hablados'
},
signupDateInputLabel: {
en: 'Sign-up date',
es: 'Fecha de ingreso'
},
projectsInputLabel: {
en: 'Projects',
es: 'Proyectos'
},
agreesWithPoliciesCheckboxLabel: {
en:  'I confirm I have read and understood <a href="$1">this group\'s policies</a>, ' +
'which I am committed to abide with, if elected.',
es: 'He leído <a href="$1">las políticas del grupo</a> ' +
'y tengo el compromiso suficiente en caso de ser electo.'
},
legalAgeCheckboxLabel: {
en: 'I am of legal age in my country of residence.',
es: 'Soy mayor de edad en mi país de residencia.'
},
fieldsetLabel: {
en: 'Insert your data',
es: 'Ingresa los datos de tu candidatura'
},
formSubmitted: {
en: 'Statement added successfully. Reloading...',
es: 'Candidatura agregada con éxito. Recargando...'
}
};
function getMessage( key, language, ...parameters ) {
const parsedParameters = parseParameters( parameters );
const message = findMessage( key, language );
const parsedMessage = parseMessage( message, parsedParameters );
return parsedMessage;
}
function parseParameters( ...parameters ) {
const parsedParameters = {};
var progressBar2 = new OO.ui.ProgressBarWidget( {
for ( const [ index, value ] of parameters.entries() ) {
progress: number2
parsedParameters[ `$${index + 1}` ] = value;
} );
}
 
var progressBar3 = new OO.ui.ProgressBarWidget( {
progress: number3
} );
var progressBar4 = new OO.ui.ProgressBarWidget( {
return parsedParameters;
progress: number4
}
} );
function findMessage( key, language ) {
return (
messages[ key ][ language ] ||
messages[ key ][ FALLBACK_LANGUAGE_CODE ]
);
}
function parseMessage( message, parameters ) {
let parsedMessage = message;
var progressBar5 = new OO.ui.ProgressBarWidget( {
for ( const [ key, value ] of Object.entries( parameters ) ) {
progress: number5
parsedMessage = parsedMessage.replaceAll( key, value );
} );
}
progressBar.$element.css({
return parsedMessage;
borderRadius: '.2rem',
}
margin: '0 auto',
});
const realNameInput = new OO.ui.TextInputWidget( {
placeholder: getMessage( 'realNameInputPlaceholder', userLanguage )
} );
const spokenLanguagesInput = new OO.ui.TextInputWidget( {
placeholder: 'es-n, en-2, ...',
required: true,
indicator: 'required'
} );
const signupDateInput = new mw.widgets.DateInputWidget( {
required: true,
indicator: 'required'
} );
const projectsInput = new OO.ui.TextInputWidget( {
placeholder: 'eswiki, eswikivoyage, ...',
required: true,
indicator: 'required'
} );
const statementInput = new OO.ui.MultilineTextInputWidget( {
placeholder: getMessage( 'statementInputPlaceholder', userLanguage ),
required: true,
indicator: 'required',
rows: 5
} );
const agreesWithPoliciesCheckbox = new OO.ui.CheckboxInputWidget( {
required: true
} );
const legalAgeCheckbox = new OO.ui.CheckboxInputWidget( {
required: true
} );


progressBar2.$element.css({
const submitButton = new OO.ui.ButtonInputWidget( {  
borderRadius: '.2rem',
label: getMessage( 'submitButtonLabel', userLanguage ),
margin: '0 auto',
type: 'submit',
});
flags: [
'primary',
progressBar3.$element.css({
'progressive'
borderRadius: '.2rem',
]
margin: '0 auto',
} );
});
const fieldset = new OO.ui.FieldsetLayout( {
progressBar4.$element.css({
label: getMessage( 'fieldsetLabel', userLanguage ),
borderRadius: '.2rem',
classes: [ 'container' ]
margin: '0 auto',
} );
});
fieldset.addItems( [
progressBar5.$element.css({
new OO.ui.FieldLayout( realNameInput, {
borderRadius: '.2rem',
label: getMessage( 'realNameInputLabel', userLanguage )
margin: '0 auto',
} ),
});
new OO.ui.FieldLayout( spokenLanguagesInput, {
label: getMessage( 'spokenLanguagesInputLabel', userLanguage )
} ),
new OO.ui.FieldLayout( signupDateInput, {
label: getMessage( 'signupDateInputLabel', userLanguage )
} ),
new OO.ui.FieldLayout( projectsInput, {
label: getMessage( 'projectsInputLabel', userLanguage )
} ),
new OO.ui.FieldLayout( statementInput, {
label: getMessage( 'statementInputLabel', userLanguage )
} ),
new OO.ui.FieldLayout( agreesWithPoliciesCheckbox, {
label: $(
`<span>${getMessage(
'agreesWithPoliciesCheckboxLabel',
userLanguage,
'https://wikisp.org/wiki/Pol%C3%ADtica_electoral'
)}</span>`
),
align: 'inline'
} ),
new OO.ui.FieldLayout( legalAgeCheckbox, {
label: getMessage( 'legalAgeCheckboxLabel', userLanguage ),
align: 'inline'
} ),
new OO.ui.FieldLayout( submitButton )
] );
const form = new OO.ui.FormLayout( {
items: [ fieldset ],
id: 'create-new-statement'
} );
 
form.on( 'submit', ( event ) => {
const username = mw.config.get( 'wgUserName' );
const realName = realNameInput.getValue();
const spokenLanguages = spokenLanguagesInput.getValue();
const signupDate = signupDateInput.getValue();
const projects = projectsInput.getValue();
const statement = statementInput.getValue();
 
const template = `
{{election/statement
|username = ${username}
|real-name = ${realName}
|languages = ${spokenLanguages}
|signup-date = ${signupDate}
|projects = ${projects}
|statement = ${statement}
}}`.replace( /\s{2,}/g, '\n');
 
const parameters = {
action: 'edit',
title: 'Internal:Elecciones/CA/2024/Candidaturas/lista',
appendtext: template,
format: 'json'
};
const api = new mw.Api();


if ( ( progressBar.progress || progressBar2.progress ||
api.postWithToken( 'csrf', parameters ).done( () => {
progressBar3.progress || progressBar4.progress ||
mw.notify( getMessage( 'formSubmitted', userLanguage ) );
progressBar5.progress ) < 100 ) {
progressBar.pushPending();
progressBar2.pushPending();
    progressBar3.pushPending();
    progressBar4.pushPending();
    progressBar5.pushPending();
}


$( '#progress-bar-' + barId ).append( progressBar.$element );
setTimeout( () => {
$( '#progress-bar-' + barId2 ).append( progressBar2.$element );
window.location.reload();
$( '#progress-bar-' + barId3 ).append( progressBar3.$element );
}, 3000 );
$( '#progress-bar-' + barId4 ).append( progressBar4.$element );
} );
$( '#progress-bar-' + barId5 ).append( progressBar5.$element );
} );
} );
}
 
$( '#form-anchor' ).append( form.$element );
} );

Revisión actual - 17:40 28 oct 2024

// ocultar mw-pt-translate-header para los anónimos

mw.loader.using( [ 'mediawiki.user' ], function () {
	if ( mw.user.isAnon() === 1 ) {
		mw.util.addCSS( '.mw-pt-translate-header { display: none; }' );
	}
} );

const ELECTION_2024_PAGE_ID = 1792;
const ELECTION_2024_STATEMENTS_PAGE_ID = 1794;
const ELECTION_2024_RESULTS_PAGE_ID = 1794;

const ELECTION_2024_PAGE_IDS = [
	ELECTION_2024_PAGE_ID,
	ELECTION_2024_STATEMENTS_PAGE_ID,
	ELECTION_2024_RESULTS_PAGE_ID
];

if ( ELECTION_2024_PAGE_IDS.includes( mw.config.get( 'wgArticleId' ) ) ) {
	$( '.navbar li:has(a.selflink)' )
		.css( {
	  		'border-radius': '5px 5px 0 0',
			'border-bottom-left-radius': '0px',
			'border-bottom': '3px solid #833ab4'
		} );
}

mw.loader.using( [
	'oojs-ui',
	'mediawiki.api',
	'mediawiki.widgets.DateInputWidget'
] ).then( () => {
	if (
		mw.config.get( 'wgArticleId' ) !== ELECTION_2024_STATEMENTS_PAGE_ID ||
		!mw.config.get( 'wgUserName' )
	) {
		return;
	}
	
	const FALLBACK_LANGUAGE_CODE = 'es';

	const userLanguage = mw.user.options.get( 'language' );
	const messages = {
		realNameInputPlaceholder: {
			en: 'Your real name (optional)',
			es: 'Tu nombre real (opcional)'
		},
		realNameInputLabel: {
			en: 'Real name',
			es: 'Nombre real'
		},
		statementInputPlaceholder: {
			en: 'Why do you want to join the Administrative Council?',
			es: 'Por qué quieres ser miembro del Consejo de Administración...'
		},
		statementInputLabel: {
			en: 'Statement',
			es: 'Presentacion'
		},
		submitButtonLabel: {
			en: 'Submit',
			es: 'Publicar'
		},
		spokenLanguagesInputLabel: {
			en: 'Spoken languages',
			es: 'Idiomas hablados'
		},
		signupDateInputLabel: {
			en: 'Sign-up date',
			es: 'Fecha de ingreso'
		},
		projectsInputLabel: {
			en: 'Projects',
			es: 'Proyectos'
		},
		agreesWithPoliciesCheckboxLabel: {
			en:  'I confirm I have read and understood <a href="$1">this group\'s policies</a>, ' +
				'which I am committed to abide with, if elected.',
			es: 'He leído <a href="$1">las políticas del grupo</a> ' +
				'y tengo el compromiso suficiente en caso de ser electo.'
		},
		legalAgeCheckboxLabel: {
			en: 'I am of legal age in my country of residence.',
			es: 'Soy mayor de edad en mi país de residencia.'
		},
		fieldsetLabel: {
			en: 'Insert your data',
			es: 'Ingresa los datos de tu candidatura'
		},
		formSubmitted: {
			en: 'Statement added successfully. Reloading...',
			es: 'Candidatura agregada con éxito. Recargando...'
		}
	};
	
	function getMessage( key, language, ...parameters ) {
		const parsedParameters = parseParameters( parameters );
		const message = findMessage( key, language );
		const parsedMessage = parseMessage( message, parsedParameters );
		
		return parsedMessage;
	}
	
	function parseParameters( ...parameters ) {
		const parsedParameters = {};
		
		for ( const [ index, value ] of parameters.entries() ) {
			parsedParameters[ `$${index + 1}` ] = value;
		}
		
		return parsedParameters;
	}
	
	function findMessage( key, language ) {
		return (
			messages[ key ][ language ] ||
			messages[ key ][ FALLBACK_LANGUAGE_CODE ]
		);
	}
	
	function parseMessage( message, parameters ) {
		let parsedMessage = message;
		
		for ( const [ key, value ] of Object.entries( parameters ) ) {
			parsedMessage = parsedMessage.replaceAll( key, value );
		}
		
		return parsedMessage;
	}
	
	const realNameInput = new OO.ui.TextInputWidget( {
		placeholder: getMessage( 'realNameInputPlaceholder', userLanguage )
	} );
	const spokenLanguagesInput = new OO.ui.TextInputWidget( {
		placeholder: 'es-n, en-2, ...',
		required: true,
		indicator: 'required'
	} );
	const signupDateInput = new mw.widgets.DateInputWidget( {
		required: true,
		indicator: 'required'
	} );
	const projectsInput = new OO.ui.TextInputWidget( {
		placeholder: 'eswiki, eswikivoyage, ...',
		required: true,
		indicator: 'required'
	} );
	const statementInput = new OO.ui.MultilineTextInputWidget( {
		placeholder: getMessage( 'statementInputPlaceholder', userLanguage ),
		required: true,
		indicator: 'required',
		rows: 5
	} );
	const agreesWithPoliciesCheckbox = new OO.ui.CheckboxInputWidget( {
		required: true
	} );
	const legalAgeCheckbox = new OO.ui.CheckboxInputWidget( {
		required: true
	} );

	const submitButton = new OO.ui.ButtonInputWidget( { 
		label: getMessage( 'submitButtonLabel', userLanguage ),
		type: 'submit',
		flags: [
			'primary',
			'progressive'
		]
	} );
	 
	const fieldset = new OO.ui.FieldsetLayout( { 
		label: getMessage( 'fieldsetLabel', userLanguage ),
		classes: [ 'container' ]
	} );
	 
	fieldset.addItems( [ 
		new OO.ui.FieldLayout( realNameInput, {
			label: getMessage( 'realNameInputLabel', userLanguage )
		} ),
		new OO.ui.FieldLayout( spokenLanguagesInput, {
			label: getMessage( 'spokenLanguagesInputLabel', userLanguage )
		} ),
		new OO.ui.FieldLayout( signupDateInput, {
			label: getMessage( 'signupDateInputLabel', userLanguage )
		} ),
		new OO.ui.FieldLayout( projectsInput, {
			label: getMessage( 'projectsInputLabel', userLanguage )
		} ),
		new OO.ui.FieldLayout( statementInput, {
			label: getMessage( 'statementInputLabel', userLanguage )
		} ),
		new OO.ui.FieldLayout( agreesWithPoliciesCheckbox, {
			label: $(
				`<span>${getMessage(
					'agreesWithPoliciesCheckboxLabel',
					userLanguage,
					'https://wikisp.org/wiki/Pol%C3%ADtica_electoral'
				)}</span>`
			),
			align: 'inline'
		} ),
		new OO.ui.FieldLayout( legalAgeCheckbox, {
			label: getMessage( 'legalAgeCheckboxLabel', userLanguage ),
			align: 'inline'
		} ),
		new OO.ui.FieldLayout( submitButton )	 
	] );
	 
	const form = new OO.ui.FormLayout(	{
		items: [ fieldset ],
		id: 'create-new-statement'
	} );

	form.on( 'submit', ( event ) => {
		const username = mw.config.get( 'wgUserName' );
		const realName = realNameInput.getValue();
		const spokenLanguages = spokenLanguagesInput.getValue();
		const signupDate = signupDateInput.getValue();
		const projects = projectsInput.getValue();
		const statement = statementInput.getValue();

		const template = `
			{{election/statement
			 |username = ${username}
			 |real-name = ${realName}
			 |languages = ${spokenLanguages}
			 |signup-date = ${signupDate}
			 |projects = ${projects}
			 |statement = ${statement}
			}}`.replace( /\s{2,}/g, '\n');

		const parameters = {
			action: 'edit',
			title: 'Internal:Elecciones/CA/2024/Candidaturas/lista',
			appendtext: template,
			format: 'json'
		};
		const api = new mw.Api();

		api.postWithToken( 'csrf', parameters ).done( () => {
			mw.notify( getMessage( 'formSubmitted', userLanguage ) );

			setTimeout( () => {
				window.location.reload();
			}, 3000 );
		} );
	} );

	$( '#form-anchor' ).append( form.$element );
} );