MediaWiki:Gadget-CreditiTraduzione.js: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
rb test
m dimenticanza
(3 versioni intermedie di uno stesso utente non sono mostrate)
Riga 43:
* @param {string} prepend - Il wikicodice da inserire prima di quello esistente
* @param {string} summary - L'oggetto di modifica; per default è vuoto
* @param {boolean} minor - 'true' se la modifica dev'essere marcata come minore, 'false' altrimenti;se perdev'essere defaultmarcata come non minore; altrimenti viene lasciato il valore predefinito
*/
function autoEdit(prepend, summary="", minor=null) {
if (prepend) {
// aggiungi il template nel codice
letvar editBox = document.editform.wpTextbox1;
editBox.value = prepend + editBox.value;
Riga 60:
// salva la pagina
setTimeout(function() => {
bannerMessage('Il pulsante per il salvataggio della pagina è stato cliccato automaticamente. Attendi che la pagina venga salvata.');
document.title = '(' + document.title + ')';
Riga 73:
$( function () {
// controlla se 1) siamo in un namespace di discussione 2) siamo in modalità modifica 3) il token passato in input è valido
if (mw.config.get('wgNamespaceNumber') % 2 === 1 &&
&& mw.config.get('wgAction') === 'edit' &&
&& mw.util.getParamValue('tdtoken') === getAutoSaveToken()) {
// ricava i parametri HTTP GET
letvar [lang, title, timestamp, oldid] = [mw.util.getParamValue('tdlang'), 'tdtitle', 'tdtimestamp', 'tdoldid']
.map(paramKeytitle => mw.util.getParamValue(paramKey)'tdtitle');,
timestamp = mw.util.getParamValue('tdtimestamp'),
oldid = mw.util.getParamValue('tdoldid');
if (lang && title && timestamp && oldid) {
// genera il wikicodice del template ed esegui l'edit automatico
letvar date = new Date(timestamp).toLocaleString('it-IT', {dateStyle:'long'});
letvar wikicode = `'{{Tradotto da|${' + lang }+ '|${' + title }+ '|${' + date }+ '|${' + oldid }+ '}}\n`',
summary = "Aggiungo [[template:Tradotto da]] tramite [[Utente:Horcrux/CreditiTraduzione.js]]";
autoEdit(wikicode, summary, null);
}
}
Line 103 ⟶ 105:
* @param {string} timestamp - Il timestamp di riferimento (formato: "YYYY-MM-DDThh:mm:ssZ")
* @return {Object} Un oggetto thenable contenente un array costituito dall'oldid desiderato e dal relativo timestamp.
*/
function getOtherWikiRevIdAndTimestamp( lang, title, timestamp ) {
return getOtherWikiRevIdAndTimestampAux( lang, title, timestamp, true );
}
/**
* Funzione ausiliaria per getOtherWikiRevIdAndTimestamp
*
* @param {boolean} firstAttempt - Valore booleano ausiliario, per sapere in quale direzione della cronologia effettuare la ricerca
*/
function getOtherWikiRevIdAndTimestampgetOtherWikiRevIdAndTimestampAux( lang, title, timestamp, firstAttempt = true ) {
// Come da [[mw:API:Cross-site_requests#CORS_usage]]
var apiEndpoint = `'https://${' + lang }+ '.wiki.x.io/w/api.php`';
var params = `'action=query&prop=revisions&rvlimit=1&rvprop=ids|timestamp&titles=${' + title }+ '&rvstart=${' timestamp+ }`timestamp;
var otherParams = firstAttempt ? '' : '&rvdir=newer';
return fetch(`${ apiEndpoint }+ '?${' + params }${+ otherParams }+ '&formatversion=2&format=json&origin=*`')
.then(function(response) { return response.json(); })
.then(function(response) {
if (typeof response.query.pages[0].revisions !== "undefined") {
Line 120 ⟶ 130:
else if (firstAttempt) {
// se nessuna revision è trovata, prova invertendo la direzione di ricerca (rvdir=newer)
return getOtherWikiRevIdAndTimestampgetOtherWikiRevIdAndTimestampAux(lang, title, timestamp, false);
}
});
Line 256 ⟶ 266:
setResultLabel(' ');
Promise.resolve(revisionId).then( function(revId) => {
if (!revId) {
setResultLabel('<p>Impossibile trovare la versione specificata. Assicurati di trovarti nella pagina corretta e di indicare una versione valida.</p>');
Line 263 ⟶ 273:
getTimestampByRevisionId(revId),
getTitleByLang(lang)
]).then( function(values) => {
var [ timestamp, otherWikiTitle] = values;[0],
otherWikiTitle = values[1];
if (typeof otherWikiTitle === "undefined") {
setResultLabel(`'<p>Impossibile rintracciare la pagina di origine su ${' + lang }+ '.wiki. Assicurati di aver collegato questa pagina su Wikidata!</p>`');
}
else {
getOtherWikiRevIdAndTimestamp(lang, otherWikiTitle, timestamp).then( function(response) => {
var [otherWikiRevId, otherWikiTs] = response;[0],
otherWikiTs = response[1];
var autoEditUrl = `'//it.wiki.x.io/wiki/${' + currTitleObj.getTalkPage().getPrefixedText() }+ '?action=edit&tdtoken=${' + getAutoSaveToken() }`+
`'&tdlang=${' + lang }+ '&tdtitle=${' + otherWikiTitle }+ '&tdtimestamp=${' + otherWikiTs }+ '&tdoldid=${' otherWikiRevId+ }`otherWikiRevId;
window.open(autoEditUrl,"_self");
});