Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:Enterprisey/sync-template-sandbox. |
$( function() {
// 10 is "Template:" and 828 is "Module:"
if ( ( mw.config.get( "wgNamespaceNumber" ) === 10 || mw.config.get( "wgNamespaceNumber" ) === 828 ) && mw.config.get( "wgPageName" ).includes( "/sandbox" ) ) {
var link = mw.util.addPortletLink(
"p-cactions",
"#",
"Sync with main",
"ca-sync",
"Overwrite the sandbox code with the code from the main template"
);
mw.loader.using( "mediawiki.api", function () {
link.addEventListener( "click", function () {
var api = new mw.Api();
api.get( {
prop: 'revisions',
rvprop: 'content',
rvlimit: 1,
titles: mw.config.get( "wgPageName" ).replace( "/sandbox", "" )
} ).done( function ( data ) {
if ( !data.query || !data.query.pages ) return;
var pageid = Object.getOwnPropertyNames( data.query.pages )[0],
text = data.query.pages[pageid].revisions[0]["*"];
api.postWithEditToken( {
action: "edit",
title: mw.config.get( "wgPageName" ),
summary: "Syncing sandbox code with main template ([[User:APerson/sync-template-sandbox|sync-template-sandbox.js]])",
text: text
} ).done ( function ( data ) {
if ( data && data.edit && data.edit.result && data.edit.result == 'Success' ) {
mw.notify( "Synced successfully! Reloading in 5 seconds..." );
window.setTimeout( function () {
document.location.reload( true );
}, 5000 );
}
} );
} );
} );
} );
}
} );