MediaWiki:Gadget-ImageUploader.js
Catatan: Setelah disimpan, Anda mungkin perlu melewati tembolok peramban web untuk melihat perubahan.
- Firefox/Safari: Tekan dan tahan Shift sembari mengeklik Reload, atau tekan Ctrl-F5 atau Ctrl-R (⌘-R di Mac)
- Google Chrome: Tekan Ctrl-Shift-R (⌘-Shift-R di Mac)
- Internet Explorer / Edge: Tahan Ctrl sembari mengeklik Refresh, atau tekan Ctrl-F5
- Opera: Tekan Ctrl-F5.
/*
* Simple gadget to add image upload links to the Wikisource Image Upload
* to the sidebar and elsewhere.
*/
( function ( $, mw ) {
var ImageUpload = {
hostname: 'https://ws-image-uploader.toolforge.org',
toolname: 'Wikisource Image Uploader',
accesskey: 'u',
toolbarIcon: '//upload.wikimedia.org/wikipedia/commons/thumb/c/c8/Wikisource-logo-green.svg/22px-Wikisource-logo-green.svg.png'
};
var wikiEditorConfigIncantation = function ( callback ) {
mw.loader.using( 'user.options' ).then( function () {
// This can be the string '0' if the user disabled the preference
// ([[phab:T54542#555387]])
if ( mw.user.options.get( 'usebetatoolbar' ) === 1 ) {
$.when(
mw.loader.using( 'ext.wikiEditor' ), $.ready
).then( function () {
/* eslint-disable-next-line no-jquery/no-global-selector */
var $tb = $( '#wpTextbox1' );
callback( $tb.wikiEditor.bind( $tb ) );
} );
}
} );
};
$( function () {
var indexPage = mw.config.get( 'wgTitle' ).replace( /\/[0-9]+$/, '' );
var params = {
index: 'Index:' + indexPage
};
var page;
if ( mw.config.get( 'wgCanonicalNamespace' ) === 'Page' ) {
page = mw.config.get( 'prpFormattedPageNumber' ) || undefined;
}
if ( page ) { // T285218
params.pageNumber = page;
}
// eslint-disable-next-line compat/compat
var url = ImageUpload.hostname + '?' + new URLSearchParams( params );
if ( ImageUpload.accesskey ) {
$( 'a[accesskey="' + ImageUpload.accesskey + '"]' ).attr( 'accesskey', null );
}
mw.util.addPortletLink( 'p-tb',
url, 'Upload image', 'ws-img-upload',
'Upload an image for this page using ' + ImageUpload.toolname,
ImageUpload.accesskey
);
function setUpWikiEditorButton( wikiEditor ) {
wikiEditor( 'addToToolbar', {
section: 'main',
group: 'insert',
tools: {
smile: {
label: 'Upload image with ' + ImageUpload.toolname,
type: 'button',
icon: ImageUpload.toolbarIcon,
action: {
type: 'callback',
execute: function () {
window.open( url );
}
}
}
}
} );
}
wikiEditorConfigIncantation( setUpWikiEditorButton );
} );
mw.hook( 'gadget-imageuploader.config' ).fire( ImageUpload );
// eslint-disable-next-line no-undef
}( jQuery, mediaWiki ) );