Wikipedysta:Matma Rex/prettyref.js
// To narzędzie przenosi zawartość przypisów na koniec strony, pozostawiając
// w tekście głównym tylko odwołanie. Skutkiem ubocznym tej operacji jest
// zamiana szablonów "R"/"U" na znaczniki <ref> oraz "Przypisy" na <references>.
//
// Źródła: https://github.com/MatmaRex/prettyref
// https://github.com/PeterBowman/wikibot (adaptacja, obecnie w użyciu)
// Interfejs: https://pbbot.toolforge.org/pretty-ref
//
// Użycie: dodaj
// importScript("Wikipedysta:Matma Rex/prettyref.js");
// do swojego common.js.
//
// W pasku narzędzi pojawi się nowy przycisk ze słowem "ref".
// Kliknij, aby dokonała się magia.
//
// UWAGA: narzędzie nie współpracuje z gadżetem wikEd!
//
// Autorzy: Matma Rex, Peter Bowman (adaptacja), CC-BY-SA 3.0.
// Błędy prosimy zgłaszać do [[User talk:Peter Bowman]].
( function ( mw, $ ) {
var $wpTextbox1, $wpSummary;
function prettyref_run() {
$( '#mw-editbutton-prettyref' ).attr( 'src', '//upload.wikimedia.org/wikipedia/commons/4/42/Loading.gif' );
$.ajax( {
url: location.protocol + '//pbbot.toolforge.org/pretty-ref',
type: 'POST',
cache: false,
data: {
text: $wpTextbox1.val(),
format: 'json'
},
success: prettyref_callback
} );
}
function prettyref_callback( json ) {
// http://bugs.jquery.com/ticket/10338
if ( typeof json === 'string' ) {
json = JSON.parse( json );
}
if ( json.status !== 200 ) {
if ( json.error === 'no refs section present?' ) {
alert( 'Nie odnaleziono sekcji z przypisami.' );
} else {
alert( 'Błąd (' + json.status + '): ' + json.error +
'. Przypisy na tej stronie są nieprawidłowo sformatowane lub wykorzystują konstrukcje, które jeszcze nie są obsługiwane.' +
'\n\n\nDodatkowe informacje (debug):\n' + json.backtrace );
}
} else {
$wpTextbox1.textSelection( 'setContents', json.content );
$wpSummary.val( $wpSummary.val() + ', [[Wikipedysta:Matma_Rex/prettyref.js|przeniesienie refów na koniec]]' );
$wpSummary.val( $wpSummary.val().replace( /(^|\/\*.+?\*\/ ?), /, '$1' ) );
alert( 'OK. Przed zapisaniem sprawdź wykonane zmiany!' );
}
$( '#mw-editbutton-prettyref' ).attr( 'src', '//upload.wikimedia.org/wikipedia/commons/2/2b/Button_ref_inscription.png' );
}
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
$.when(
mw.loader.using( [ 'jquery.textSelection', 'ext.gadget.lib-toolbar' ] ),
$.ready
).done( function () {
$wpTextbox1 = $( '#wpTextbox1' );
$wpSummary = $( '#wpSummary' );
toolbarGadget.addButton( {
title: 'Przenieś refy na koniec',
alt: '{{r',
id: 'mw-editbutton-prettyref',
icon: '//upload.wikimedia.org/wikipedia/commons/2/2b/Button_ref_inscription.png',
onclick: function () {
prettyref_run();
}
} );
} );
}
}( mediaWiki, jQuery ) );
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.