Jump to content

User:TheTechie/sandbox2

From Wikipedia, the free encyclopedia

// mw.loader.load( 'User:TheTechie/tut.css', 'text/css' ); const archtml = ` <div id="archive"> <h2>Archive page</h2> <input placeholder="Page to archive to"> <button onclick="arcTo(document.getElementsByTagName('input')[0]);">Yay</button> </div> `; const smile = ` <div id="smile"> <h2>Send a smile to a user</h2> <p>Publicly send a smile to this user?</p> <button>Yes</button> <button>No</button> </div> `; importStylesheet( 'User:Mseingth2133444/mut.css' ); var wikitext; function getText(title){ $.getJSON( mw.util.wikiScript('api'), { format: 'json', action: 'query', prop: 'revisions', rvprop: 'content', rvlimit: 1, titles: title } ) .then(function ( data ) { var page; try { for ( page in data.query.pages ) { wikitext = data.query.pages[page].revisions[0]['*']; return wikitext; } } catch ( e ) { alert("An error occured") } }) .catch(function(err) { alert("An error occured, namely: " + err); }); } function arcTo(input){ let toPage = input.value; let fromPage = mw.config.get('wgPageName'); alert("fromPage: " + fromPage + "; toPage:" + toPage); let text = getText(fromPage); alert("Text: " + text); summary = "Archiving page at [[" + fromPage + "]] using [[User:TheTechie/UserTools]]."; alert("Summary: " + summary); editPage(toPage, wikitext, summary); } function editPage(title, text, summary) { var api = new mw.Api(); api.postWithToken("csrf", { action: 'edit', title: title, text: text, // will replace entire page content summary: summary } ).done(function( data ) { alert('Page edited!'); } ).fail( function(code, data) { alert( api.getErrorMessage( data ).text()); } ); } function arch(){ $("#bodyContent").prepend(archtml); } mw.loader.using( ['mediawiki.util', "mediawiki.api"], function () { // Wait for the page to be parsed $( document ).ready( function () { mw.util.addPortlet('p-tut', 'TUT', '#p-cactions'); arc = mw.util.addPortletLink('p-tut', '#', 'Arc'); mw.util.addPortletLink('p-tut', '#', 'TBD2'); $(arc).on("click", function(e){ arch(); }); } ); } ); //