Cambios

Saltar a: navegación, buscar

MediaWiki:Gadget-RequestDeletion.js

16 838 bytes añadidos, 08:58 9 abr 2014
Página creada con «/*************************************************** * Adds a small link to the top of the page of * * each item with a link for quickly requesting a * * deletion o...»
/***************************************************
* Adds a small link to the top of the page of *
* each item with a link for quickly requesting a *
* deletion on [[Wikidata:Requests for deletion]]. *
* Author: [[User:Bene*]] *
***************************************************/

//<nowiki>
( function ( mw, $ ) {
var i18nData = {
'en': {
'title': 'Request deletion',
'description': 'Request deletion for this item.',
'reason': 'Please give the reason for deletion:',
'error-reason': 'You must give a reason!',
'error-requested': 'Deletion already requested',
'error-api': 'An error occured while requesting the deletion: $1',
'success': 'Request successful',
'close': 'Close'
},
'bn': {
'title': 'অপসারণের অনুরোধ',
'description': 'এই উপাদানটির জন্য অপসারণের অনুরোধ',
'reason': 'অপসারণের কারণ:',
'error-reason': 'কারণ নির্দেশ করতে হবে!',
'error-requested': 'অপসারণের অনুরোধ ইতিমধ্যে করা হয়েছে',
'success': 'অনুরোধ সফলভাবে সম্পন্ন',
'close': 'বন্ধ'
},
'cs': {
'title': 'Požádat o smazání',
'description': 'Požádat o smazání této položky.',
'reason': 'Prosíme, zadejte důvod smazání:',
'error-reason': 'Musíte zadat důvod!',
'error-requested': 'Smazání bylo již zažádáno',
'error-api': 'Nastala chyba při žádosti o smazání: $1',
'success': 'Žádost úspěšně uložena',
'close': 'Zavřít'
},
'de': {
'title': 'Löschantrag',
'description': 'Stelle einen Löschantrag für diese Seite.',
'reason': 'Gib bitte den Grund für den Antrag an:',
'error-reason': 'Du musst einen Grund angeben!',
'error-requested': 'Löschantrag wurde schon gestellt',
'error-api': 'Ein Fehler ist beim stellen des Löschantrags aufgetreten: $1',
'success': 'Löschantrag wurde erfolgreich gestellt.',
'close': 'Schließen'
},
'eo': {
'title': 'Forigpeto',
'description': 'Peti forigon de ĉi tiu ero.',
'reason': 'Forigkialo:',
'error-reason': 'Vi devas mencii iun forigkialon !',
'error-requested': 'Forigo jam estis petita.',
'success': 'Sukcesa forigpeto.'
},
'es': {
'title': 'Solicitar el borrado',
'description': 'Solicitar el borrado de este elemento.',
'reason': 'Motivo de borrado:',
'error-reason': '¡Debe especificar un motivo!',
'error-requested': 'Este elemento ya ha sido propuesto para borrado',
'success': 'Petición realizada',
'close': 'Cerrar'
},
'fa': {
'title': 'درخواست حذف',
'description': 'درخواست حذف برای این مورد.',
'reason': 'لطفا علت درخواست را بیان نمائید:',
'error-reason': 'شما باید علت درخواست را بیان نمائید!',
'error-requested': 'درخواست حذف انجام شد',
'error-api': 'هنگام درخواست حذف یک خطا رخ داد: $1',
'success': 'درخواست با موفقیت انجام شد',
'close': 'بستن'
},
'fi': {
'title': 'Ehdota poistamista',
'description': 'Ehdota tämän kohteen poistamista.',
'reason': 'Anna perustelu poistolle:',
'error-reason': 'Sinun täytyy perustella poistopyyntö!',
'error-requested': 'Poistoa on jo pyydetty',
'success': 'Pyyntö tehty',
'close': 'Sulje'
},
'fr': {
'title': 'Demande de suppression',
'description': 'Demander la suppression de cet élément.',
'reason': 'Motif de suppression:',
'error-reason': 'Vous devez indiquer un motif de suppression !',
'error-requested': 'Une demande de suppression a déjà été effectuée.',
'success': 'Demande effectuée avec succès.',
'close': 'Fermer'
},
'gl': {
'title': 'Solicitar o borrado',
'description': 'Solicitar o borrado deste elemento.',
'reason': 'Motivo do borrado:',
'error-reason': 'Debes especificar un motivo!',
'error-requested': 'Este elemento xa foi proposto para ser borrado',
'success': 'Petición realizada',
'close': 'Pechar'
},
'he': {
'title': 'בקשת מחיקה',
'description': 'בקשת מחיקה עבור פריט זה',
'reason': 'אנא הזן סיבה עבור המחיקה:',
'error-reason': 'אתה מוכרח להזין סיבה!',
'error-requested': 'המחיקה כבר נתבקשה',
'success': 'בקשתך התקבלה'
},
'hu': {
'title': 'Törlési kérés',
'description': 'Törlésre jelöli ezt a lapot.',
'reason': 'Kérlek, add meg a törlés okát:',
'error-reason': 'Meg kell adnod egy okot!',
'error-requested': 'A lapot már jelölték törlésre.',
'success': 'A kérés sikerült.'
},
'id': {
'title': 'Permintaan penghapusan',
'description': 'Permintaan penghapusan untuk item ini.',
'reason': 'Berikan alasan penghapusan:',
'error-reason': 'Anda harus memberikan alasan!',
'error-requested': 'Penghapusan sudah diminta',
'error-api': 'Kesalahan terjadi saat meminta penghapusan: $1',
'success': 'Permintaan berhasil',
'close': 'Tutup'
},
'it': {
'title': 'Richiesta di cancellazione',
'description': 'Richiesta di cancellazione per questo elemento',
'reason': 'Motivo della cancellazione:',
'error-reason': 'Devi indicare il motivo!',
'error-requested': 'Cancellazione già richiesta',
'success': 'Richiesta effettuata con successo',
'close': 'Chiudi'
},
'ja': {
'title': '削除依頼',
'description': 'この項目を削除依頼に出す。',
'reason': '削除の理由を記入してください:',
'error-reason': '削除理由が必要です!',
'error-requested': '既に削除依頼済み',
'success': '削除依頼完了',
'close': '中止'
},
'ko': {
'title': '삭제 요청',
'description': '이 항목을 삭제 신청합니다.',
'reason': '이유를 제시해 주세요:',
'error-reason': '반드시 이유를 제시해 주셔야 합니다!',
'error-requested': '이미 요청이 올라와 있습니다.',
'success': '요청이 성공적으로 등록되었습니다',
'close': '중지'
},
'lv': {
'title': 'Pieprasīt dzēšanu',
'description': 'Pieprasīt šī ieraksta dzēšanu.',
'reason': 'Dzēšanas iemesls:',
'error-reason': 'Tev ir jāsniedz dzēšanas iemesls!',
'error-requested': 'Dzēšana jau ir tikusi pieprasīta',
'success': 'Pieprasījums ir veiksmīgs',
'close': 'Aizvērt'
},
'min': {
'title': 'Mintak dihapuih',
'description': 'Tolong hapuih item ko.',
'reason': 'Agiah alasan pangapuihan:',
'error-reason': 'Harus ado alasan!',
'error-requested': 'Alah dimintak',
'error-api': 'Kasalahan tajadi sangkek mamintak pangapuihan: $1',
'success': 'Sukses',
'close': 'Tutuik'
},
'mk': {
'title': 'Побарај бришење',
'description': 'Поднесува барање за бришење на овој предмет.',
'reason': 'Наведете причина за бришење:',
'error-reason': 'Мора да наведете причина!',
'error-requested': 'Бришењето е веќе побарано',
'error-api': 'Се појави грешка при поднесувањето на барањето: $1',
'success': 'Барањето е успешно поднесено',
'close': 'Затвори'
},
'nb': {
'title': 'Be om sletting',
'description': 'Be om sletting for dette elementet.',
'reason': 'Oppgi hvorfor elementet bes slettet:',
'error-reason': 'Du må oppgi en grunn!',
'error-requested': 'Sletting er allerede forespurt',
'success': 'Forespørsel var vellykket',
'close': 'Lukk'
},
'nl': {
'title': 'Nomineren voor verwijdering',
'description': 'Verzoek een verwijdering voor dit item.',
'reason': 'Geef de reden voor verwijdering:',
'error-reason': 'Je moet een reden geven!',
'error-requested': 'Verzoek ter verwijdering is al ingediend',
'success': 'Verzoek succesvol ingediend',
'close': 'Sluiten'
},
'pl': {
'title': 'Zgłoszenie do usunięcia',
'description': 'Zgłoś usunięcie tego elementu.',
'reason': 'Podaj powód usunięcia:',
'error-reason': 'Musisz podać powód!',
'error-requested': 'Element został już zgłoszony do usunięcia.',
'success': 'Zgłoszenie zakończone powodzeniem.',
'close': 'Zamknij'
},
'pt': {
'title': 'Pedir eliminação',
'description': 'Pedir eliminação para este item.',
'reason': 'Por favor, dê o motivo para a eliminação:',
'error-reason': 'Você deve especificar um motivo!',
'error-requested': 'Este item já foi proposto para eliminação',
'success': 'Pedido realizado com sucesso',
'close': 'Fechar'
},
'ru': {
'title': 'Запрос на удаление',
'description': 'Запрос на удаление выбранного объекта.',
'reason': 'Пожалуйста, укажите причину удаления:',
'error-reason': 'Вы должны указать причину!',
'error-requested': 'Запрос на удаление уже существует',
'success': 'Запрос сохранён',
'close': 'Выход'
},
'vi': {
'title': 'Đề nghị xóa',
'description': 'Đề nghị xóa mục này.',
'reason': 'Xin đưa ra lý do để xóa:',
'error-reason': 'Bạn cần phải đưa ra lý do!',
'error-requested': 'Xóa theo đề nghị',
'error-api': 'Đã xảy ra lỗi trong khi đề nghị xóa: $1',
'success': 'Đề nghị thành công',
'close': 'Đóng'
},
'zh': {
'title': '提请删除',
'description': '提请删除此数据项',
'reason': '理由:',
'error-reason': '请给出理由。',
'requested': '已有提删请求',
'success': '请求成功',
'close': '关闭'
},
};
i18nData['pt-br'] = i18nData.br;
i18nData.no = i18nData.nb;

// set Language
var lang = mw.user.options.get( 'language' );
if( !( lang in i18nData ) ) {
lang = 'en';
}

// set Entity-Id
var entityId = mw.config.get( 'wbEntityId' );
if( !entityId ) {
return;
}
var entityNamespace = '';
if( entityId.substr( 0, 1 ) === 'p' ) {
entityNamespace = 'Property:';
}
entityId = entityId.toUpperCase();

// if already requested
var requested = false;

/**
* Return the localized version of a message.
*/
function i18n( key ) {
if( i18nData[ lang ][ key ] ) {
return i18nData[ lang ][ key ];
} else {
return i18nData.en[ key ];
}
}

/**
* Checks whether the item is requested for deletion yet.
*/
function check() {
$.ajax( {
type: 'POST',
url: mw.util.wikiScript( 'api' ),
data: {
'format': 'json',
'action': 'query',
'prop': 'revisions',
'rvprop': 'content',
'rvlimit': 1,
'titles': 'Wikidata:Requests for deletions'
},
success: function( data ) {
if( data.error && data.error.info ) {
} else {
for ( var id in data.query.pages ) {
var regex = new RegExp( '==\\s*\\[\\[([Pp]roperty:)?[QqPp]' + entityId.substr( 1 ) + '\\]\\]\\s*==', 'g' );
var bulkRegex = new RegExp( '{{Rfd group/[0-9]+(\\|(\\s*([Pp]roperty:)?[QqPp][0-9]+\\s*)?)*\\|\\s*([Pp]roperty:)?[QqPp]' + entityId.substr( 1 ) + '\\s*\\|((\\s*([Pp]roperty:)?[QqPp][0-9]+\\s*)?\\|)*.*}}', 'g' );
if( data.query.pages[ id ].revisions[ 0 ][ '*' ].match( regex ) != null || data.query.pages[ id ].revisions[ 0 ][ '*' ].match( bulkRegex ) != null ) {
mw.notify(
i18n( 'requested' ),
{
autoHide: false,
title: 'deletionRequest.js :',
tag: 'deletionRequest-exist'
}
);
$( '#content' ).prepend(
$( '<span>' )
.css( {
float: 'right',
'z-index': 10001,
position: 'relative',
top: '4px',
right: '6px'
} )
.attr( 'id', 'requestdeletion-requested' )
.append(
$( '<a>' )
.attr( 'href', mw.util.getUrl( 'Wikidata:Requests for deletions' ) + '#' + entityNamespace + '' + entityId )
.append(
$( '<img>' )
.attr( {
src: '//upload.wikimedia.org/wikipedia/commons/thumb/1/17/Warning.svg/25px-Warning.svg.png',
title: i18n( 'requested' )
} )
)
)
);
requested = true;
}
}
}
},
error: function( jqXHR, textStatus, errorThrown ) {
}
});
}

/**
* Add link to top of page.
*/
function init() {
check();
mw.loader.using( [ 'mediawiki.util', 'jquery.ui.dialog' ], function () {
var $dialog = $( '<div>' )
.attr( 'id', 'requestdeletion' )
.append(
$( '<form>' )
.attr( {
'id': 'requestdeletion-form',
'action': 'javascript:;'
} )
.submit( requestDeletion )
.append(
$( '<fieldset>' )
.append(
$( '<legend>' )
.text( i18n( 'description' ) )
) // </legend>
.append(
$( '<p>' )
.append(
$( '<label>' )
.attr( 'for', 'requestdeletion-reason' )
.text( i18n( 'reason' ) )
) // </label>
.append(
$( '<input>' )
.attr( {
'type': 'text',
'id': 'requestdeletion-reason'
} )
) // </input>
) // </p>
)
) // </form>
.append(
$( '<p>' )
.attr( 'id', 'requestdeletion-result' )
) // </p>
.appendTo( '#content' )
.dialog( {
title: i18n( 'title' ),
autoOpen: false,
modal: true,
width: 500,
buttons: [ {
id: 'requestdeletion-button-request',
text: i18n( 'title' ),
click: requestDeletion
}, {
id: 'requestdeletion-button-close',
text: i18n( 'close' ),
click: function() {
$( '#requestdeletion' ).dialog( 'close' );
}
} ]
} );
var portletLink = mw.util.addPortletLink(
'p-cactions',
'#',
i18n( 'title' ),
'ca-requestdeletion',
i18n( 'description' ),
null,
'#ca-requestdeletion'
);
$( portletLink ).click( function() {
$( '#requestdeletion-result' ).html( '' );
$( '#requestdeletion' ).dialog( 'open' );
} );
} );
}

function requestDeletion() {
var reason = $( '#requestdeletion-reason' ).val();
if( requested ) {
showError( 'requested' );
requested = false; // can retry
}
else if( reason === '' ) {
showError( 'reason' );
}
else {
addRequest(
mw.util.wikiUrlencode( entityId ),
function() {
$( '#requestdeletion' ).dialog( 'close' );
mw.notify( i18n( 'success' ) );
},
reason
);
}
}

function showSpinner() {
$( '#requestdeletion-result' ).html( '<div id="requestdeletion-spinner" />' );
$.createSpinner( {
size: 'large',
type: 'block',
id: 'requestdeletion-spinner'
} ).replaceAll( '#requestdeletion-spinner' );
}

function showError( err, p1 ) {
$( '#requestdeletion-result' ).html(
$( '<p>' )
.attr( 'class', 'error' )
.text( i18n( 'error-' + err ).replace( '$1', p1 ) )
);
}

/**
* Add new error request.
* @param item item to delete
* @param success function called on success
* @param reason reason for deletion
*/
function addRequest( entity, success, reason ) {
var title;
showSpinner();
if(entity.substr( 0, 1 ) === 'P'){
title = 'Wikidata:Properties for deletion';
}else{
title = 'Wikidata:Requests for deletions';
}
// Regex to change "Q####" into "[[Q####]]"
reason = ' ' + reason;
reason = reason.replace( /[ ]([Qq][0-9]+)/g, ' [[$1]]' );
reason = reason.replace( /[ ]([Pp]roperty:[Pp][0-9]+)/g, ' [[$1]]' );
reason = reason.replace( /[ ]([Pp][0-9]+)/g, ' [[Property:$1]]' );
// removing too too much spaces
if( reason.charAt( 0 ) === ' ' ) {
reason = reason.substr( 1 );
}
var entityId = entityNamespace + '' + entity;

$.ajax( {
type: 'POST',
url: mw.util.wikiScript( 'api' ),
data: {
'format': 'json',
'action': 'edit',
'title': title,
'watchlist': 'nochange',
'section' : 'new',
'summary': '/* ' + entityId + ' */ requested deletion ([[MediaWiki talk:Gadget-RequestDeletion.js|RD]])',
'sectiontitle': '[[' + entityId + ']]',
'text': '{{subst:Request for deletion|itemid=' + entityId + '|reason=' + reason + '|header=no}}' + ( reason.indexOf( '~~~~' ) === -1 ? ' ~~~~' : '' ) + '\n',
'token': mw.user.tokens.get( 'editToken' )
},
success: function( data ) {
if( data.error && data.error.info ) {
showError( 'api', data.error.info );
} else {
success();
}
},
error: function( jqXHR, textStatus, errorThrown ) {
showError( 'api', textStatus );
}
} );
}

$( document ).ready( init );
} ( mediaWiki, jQuery ) );
//</nowiki>
552
ediciones

Menú de navegación