Thành viên:NgocAnMaster/citations-gadget-vi.js
Chú ý: Sau khi lưu thay đổi trang, bạn phải xóa bộ nhớ đệm của trình duyệt để nhìn thấy các thay đổi. Google Chrome, Firefox, Internet Explorer và Safari: Giữ phím ⇧ Shift và nhấn nút Reload/Tải lại trên thanh công cụ của trình duyệt. Để biết chi tiết và hướng dẫn cho các trình duyệt khác, xem Trợ giúp:Xóa bộ nhớ đệm.
// Dịch từ enwiki: [[:MediaWiki:Gadget-citations.js]] bản 1102335732
// Người dịch: NgocAnMaster, 09:20, ngày 29 tháng 4 năm 2023 (UTC)
// https://en.wikipedia.org/w/index.php?title=MediaWiki:Gadget-citations.js&oldid=1102335732
/* _____________________________________________________________________________
* | |
* | === WARNING: GLOBAL GADGET FILE === |
* | Changes to this page affect many users. |
* | Please discuss changes on the talk page or on [[WT:Gadget]] before editing. |
* |_____________________________________________________________________________|
*
* Imported from version 1.0 as of 17:18, 9 April 2011 (UTC) from [[User:Smith609/citations.js]]
* Adds a "Citation bot" link to the toolbox, and a button beneath edit fields, see [[User:Smith609/citations]]
*/
// @Version 1.0 - Adds an "Expand citations" link to the toolbox, and a button beneath edit fields.
// @Version 1.1 - Modify gadget to use jQuery and Citation Bot's new gadgetapi on Tool Labs
// @Version 1.2 - Make use of new oojs-ui widget style
var $spinnerspan;
var cbButton;
function addCBToToolbox() {
if ( mw.config.get( 'wgCanonicalNamespace' ) !== 'Special' ) {
var pTb = document.getElementById("p-tb");
if ( !pTb ) {
return;
}
var escPageName = encodeURIComponent( mw.config.get( 'wgPageName' ));
mw.util.addPortletLink("p-tb", "//citations.toolforge.org/process_page.php?edit=toolbar&wiki_base=vi&slow=1&page="+escPageName, 'Mở rộng chú thích', 't-citationbot', "Mở rộng chú thích và sửa các lỗi định dạng thường gặp");
}
}
// Add a citation bot button next to the "Show changes" button
function addCitationButton() {
if ( document.getElementById( 'wpDiff' ) ) {
var diff = document.getElementById( 'wpDiffWidget' );
cbButton = new OO.ui.ButtonWidget();
cbButton.setElementId( 'wpCitations' )
.setIcon( 'articleCheck' )
.setLabel( 'Sửa chú thích' )
.setFlags( 'secondary' );
cbButton.on( 'click', function () {
$.ajax( {
timeout: 600000, // thousandths of a second, so 10 minutes
type: 'POST',
url: 'https://citations.toolforge.org/gadgetapi.php?slow=1',
data: {
text: $( '#wpTextbox1' ).textSelection( 'getContents' ),
summary: $( '#wpSummary' ).textSelection( 'getContents' )
},
beforeSend: function() {
$( cbButton.$element ).replaceWith( $spinnerspan );
},
success: function( data ) {
expandedText = data.expandedtext;
editSummary = data.editsummary;
$( '#loader' ).replaceWith( cbButton.$element );
if ( expandedText ) {
// Populate text box with received expanded text
$( '#wpTextbox1' ).textSelection( 'setContents', expandedText );
// Populate edit summary textbox with received edit summary
$( '#wpSummary' ).textSelection( 'setContents', editSummary );
// Click 'Show preview' button
$( '#wpDiff' ).click();
} else {
$( '#loader' ).replaceWith( cbButton.$element );
alert( 'Lỗi: Văn bản thay thế trống' );
}
},
error: function( data ) {
$( '#loader' ).replaceWith( cbButton.$element );
alert( 'Lỗi: Yêu cầu sửa chú thích thất bại' );
}
} );
} );
cbButton.$element.insertBefore( $(diff.nextSibling) );
}
}
// Add a button to allow expanding citations in the text in the edit textbox
mw.hook( 'wikipage.editform' ).add( function() {
if( !$spinnerspan ) {
$spinnerspan = $( '<span id="loader"></span>');
}
if ( document.images ) {
// Loading gif when Citations request is processing
var spinner = new Image();
spinner.src = "//upload.wikimedia.org/wikipedia/commons/4/42/Loading.gif";
$spinnerspan.append( spinner );
}
if( $('#wpCitations').length === 0 ){
mw.loader.using( [ 'oojs-ui-core', 'oojs-ui.styles.icons-content', 'jquery.textSelection' ] ).then( addCitationButton );
}
} );
// Add a toolbox button that runs Citation Bot on the most recent saved revision of the page
if ( $.inArray( mw.config.get( 'skin' ), ['monobook', 'modern', 'vector', 'vector-2022', 'timeless'] ) !== -1 ) {
$( addCBToToolbox );
}