No edit summary Tag: Reverted |
No edit summary Tag: Reverted |
||
| Line 4: | Line 4: | ||
* Adds tools for citing references to the edit toolbar. | * Adds tools for citing references to the edit toolbar. | ||
* See [[Wikipedia:RefToolbar]] for further documentation. One of two | * See [[Wikipedia:RefToolbar]] for further documentation. One of two | ||
* possible versions will load ( | * possible versions will load (RefToolbar 1.0 or RefToolbar 2.0) | ||
* depending on the user preferences (the usebetatoolbar preference). | * depending on the user preferences (the usebetatoolbar preference). | ||
* | * | ||
| Line 18: | Line 18: | ||
/* jshint browser: true, camelcase: true, curly: true, eqeqeq: true */ | /* jshint browser: true, camelcase: true, curly: true, eqeqeq: true */ | ||
/* global $, mw */ | /* global $, mw */ | ||
(function () { | (function () { | ||
'use strict'; | 'use strict'; | ||
| Line 24: | Line 25: | ||
// 2010 wikitext editor | // 2010 wikitext editor | ||
mw.hook('wikiEditor.toolbarReady').add(() | mw.hook('wikiEditor.toolbarReady').add(function () { | ||
mw.loader.using('ext.gadget.refToolbarBase', function () { | |||
/* | |||
* Load RefToolbar.js first. | |||
* | |||
* This defines the RefToolbar/CiteTB functionality | |||
* required by RefToolbarConfig.js. | |||
*/ | |||
mw.loader.getScript( | |||
'/w/index.php?title=MediaWiki:RefToolbar.js&action=raw&ctype=text/javascript' | |||
).then(function () { | |||
/* | |||
* Load the English messages before the configuration. | |||
*/ | |||
return mw.loader.getScript( | |||
'/w/index.php?title=MediaWiki:RefToolbarMessages-en.js&action=raw&ctype=text/javascript' | |||
); | |||
}).then(function () { | |||
/* | |||
* Load the site-specific citation configuration. | |||
* | |||
* This contains: | |||
* cite web | |||
* cite news | |||
* cite book | |||
* cite journal | |||
* | |||
* and calls CiteTB.init(). | |||
*/ | |||
return mw.loader.getScript( | |||
'/w/index.php?title=MediaWiki:RefToolbarConfig.js&action=raw&ctype=text/javascript' | |||
); | |||
}).then(function () { | |||
console.log( | |||
'RefToolbar: configuration loaded' | |||
); | |||
console.log( | |||
'RefToolbar: template keys:', | |||
Object.keys( | |||
window.CiteTB && | |||
window.CiteTB.Templates | |||
? window.CiteTB.Templates | |||
: {} | |||
) | |||
); | |||
}).catch(function (error) { | |||
}); | |||
console.error( | |||
'RefToolbar failed to load:', | |||
error | |||
); | |||
}); | |||
}); | |||
window.refToolbarInstalled = true; | |||
}); | |||
// 2006 legacy toolbar | // 2006 legacy toolbar | ||
mw.hook('mw.toolbar').add(() | mw.hook('mw.toolbar').add(function () { | ||
mw.loader. | |||
mw.loader.getScript( | |||
'/w/index.php?title=MediaWiki:RefToolbarLegacy.js&action=raw&ctype=text/javascript' | |||
).catch(function (error) { | |||
console.error( | |||
'RefToolbar Legacy failed to load:', | |||
error | |||
); | |||
}); | |||
window.refToolbarInstalled = true; | window.refToolbarInstalled = true; | ||
}); | }); | ||
} | } | ||
if (/^(edit|submit)$/.test(mw.config.get('wgAction')) && | if ( | ||
/^(edit|submit)$/.test(mw.config.get('wgAction')) && | |||
mw.config.get('wgPageContentModel') === 'wikitext' && | mw.config.get('wgPageContentModel') === 'wikitext' && | ||
!$('#wpTextbox1[readonly]').length && | !$('#wpTextbox1[readonly]').length && | ||
Revision as of 19:15, 24 September 2026
/**
* RefToolbar
*
* Adds tools for citing references to the edit toolbar.
* See [[Wikipedia:RefToolbar]] for further documentation. One of two
* possible versions will load (RefToolbar 1.0 or RefToolbar 2.0)
* depending on the user preferences (the usebetatoolbar preference).
*
* @see: [[Wikipedia:RefToolbar]]
* @see: [[MediaWiki:RefToolbar.js]]
* @see: [[MediaWiki:RefToolbarConfig.js]]
* @see: [[MediaWiki:RefToolbarLegacy.js]]
* @see: [[MediaWiki:RefToolbarMessages-en.js]]
* @see: [[MediaWiki:Gadget-refToolbarBase.js]]
* @author: [[User:Mr.Z-man]]
* @author: [[User:Kaldari]]
*/
/* jshint browser: true, camelcase: true, curly: true, eqeqeq: true */
/* global $, mw */
(function () {
'use strict';
function initializeRefTools() {
// 2010 wikitext editor
mw.hook('wikiEditor.toolbarReady').add(function () {
mw.loader.using('ext.gadget.refToolbarBase', function () {
/*
* Load RefToolbar.js first.
*
* This defines the RefToolbar/CiteTB functionality
* required by RefToolbarConfig.js.
*/
mw.loader.getScript(
'/w/index.php?title=MediaWiki:RefToolbar.js&action=raw&ctype=text/javascript'
).then(function () {
/*
* Load the English messages before the configuration.
*/
return mw.loader.getScript(
'/w/index.php?title=MediaWiki:RefToolbarMessages-en.js&action=raw&ctype=text/javascript'
);
}).then(function () {
/*
* Load the site-specific citation configuration.
*
* This contains:
* cite web
* cite news
* cite book
* cite journal
*
* and calls CiteTB.init().
*/
return mw.loader.getScript(
'/w/index.php?title=MediaWiki:RefToolbarConfig.js&action=raw&ctype=text/javascript'
);
}).then(function () {
console.log(
'RefToolbar: configuration loaded'
);
console.log(
'RefToolbar: template keys:',
Object.keys(
window.CiteTB &&
window.CiteTB.Templates
? window.CiteTB.Templates
: {}
)
);
}).catch(function (error) {
console.error(
'RefToolbar failed to load:',
error
);
});
});
window.refToolbarInstalled = true;
});
// 2006 legacy toolbar
mw.hook('mw.toolbar').add(function () {
mw.loader.getScript(
'/w/index.php?title=MediaWiki:RefToolbarLegacy.js&action=raw&ctype=text/javascript'
).catch(function (error) {
console.error(
'RefToolbar Legacy failed to load:',
error
);
});
window.refToolbarInstalled = true;
});
}
if (
/^(edit|submit)$/.test(mw.config.get('wgAction')) &&
mw.config.get('wgPageContentModel') === 'wikitext' &&
!$('#wpTextbox1[readonly]').length &&
!window.refToolbarInstalled
) {
$(initializeRefTools);
}
}());