diff --git a/morebits-test.js b/morebits-test.js deleted file mode 100644 index 0e6ef76..0000000 --- a/morebits-test.js +++ /dev/null @@ -1,183 +0,0 @@ -/* global Morebits */ - -// Script depends on jQuery dialog widget, loaded through jquery.ui after -// T219604 (1.35-wmf.2 circa 22 Oct 2019) -mw.loader.using('jquery.ui', function() { - // Construct object (to prevent namespace conflicts) - Twinkle.morebitsTest = { - - launchDialog: function(userInterface) { - userInterface.dialog('open'); - }, - - initSimpleWindow: function() { - var Window = new Morebits.simpleWindow(600, 400); - Window.setTitle('Test morebits.js'); - Window.display(); - var form = new Morebits.quickForm(null); - form.append({ - type: 'select', - name: 'main_group', - event: null - }); - var result = form.render(); - Window.setContent(result); - Window.display(); - result.main_group.root = result; - Morebits.status.init(result); - Morebits.wiki.actionCompleted.redirect = mw.config.get('wgPageName'); - Morebits.wiki.actionCompleted.notice = 'Test complete, reloading talk page in a few seconds'; - }, - - setPageOptions: function(page) { - page.setEditSummary($('#editSummary').val()); - if ($('#runTestForm input[name="followRedirect"]').attr('checked')) { - page.setFollowRedirect(true); - } - if ($('#runTestForm input[name="minorEdit"]').attr('checked')) { - page.setMinorEdit(true); - } - if ($('#runTestForm input[name="watchlist"]').attr('checked')) { - page.setWatchlist(true); - } - if ($('#runTestForm input[name="watchlistFromPreferences"]').attr('checked')) { - page.setWatchlistFromPreferences(true); - } - if ($('#runTestForm input[name="noRetries"]').attr('checked')) { - page.setMaxConflictRetries(0); - page.setMaxRetries(0); - } - var section = $('#runTestForm input[name="sectionNumber"]').val(); - if (section !== '') { - page.setPageSection(Number(section)); - } - page.setCreateOption(window.morebits_test_createOption); - - if ($('#runTestForm input[name="lookupCreator"]').attr('checked')) { - page.lookupCreator(Twinkle.morebitsTest.lookupCreatorCallback); - } - }, - - loadCallbackInsert: function(page) { - var params = page.getCallbackParameters(); - var text = page.getPageText(); - var pos = text.indexOf(params.beforeText); - if (pos === -1) { - alert('Search text "' + params.beforeText + '" not found!'); - return; - } - page.setPageText(text.substr(0, pos) + params.newText + text.substr(pos)); - page.save(Twinkle.morebitsTest.finalSaveCallback); - }, - - loadCallbackReplace: function(page) { - var params = page.getCallbackParameters(); - page.setPageText(params.newText); - page.save(Twinkle.morebitsTest.finalSaveCallback); - }, - - lookupCreatorCallback: function(page) { - alert('Page was created by: ' + page.getCreator()); - }, - - finalSaveCallback: function(page) { - Morebits.wiki.actionCompleted.redirect = page.getPageName(); // get result of redirects - }, - - initialize: function() { - - // Define runTest interface - // Can also use alternative syntax new to jQuery 1.4: - // $('
').html( 'Text to be added:' ) - // → $('
', { css: { 'margin-top': '0.4em' }, text: 'Text to be added:' } ) - - window.morebits_test_createOption = null; - - Twinkle.morebitsTest.$runTests = $('
') - .append($('
').html('Text to be added:
').append($(''))) - .append($('
').html('Insert text before (for insert mode only):
').append($(''))) - .append($('
').html('Edit summary:
').append($(''))) - .append($('
').html('Section number: ')) - .append($('
').html(' Follow redirect')) - .append($('
').html(' Minor edit')) - .append($('
').html(' Add to watchlist')) - .append($('
').html(' Add to watchlist based on preference settings')) - .append($('
').html(' Disable retries')) - .append($('
').html(' Lookup page creator
')) - .append($('
').html(' Create page if needed, unless deleted since loaded
')) - .append($('
').html(' Create page if needed
')) - .append($('
').html(' Only create a new page
')) - .append($('
').html(' Do not create a new page
')) - .dialog({ - width: 500, - autoOpen: false, - title: 'Test Morebits.wiki.page class', - modal: true, - buttons: { - 'Append': function() { - $(this).dialog('close'); - Twinkle.morebitsTest.initSimpleWindow(); - - var page = new Morebits.wiki.page(mw.config.get('wgPageName')); - page.setAppendText($('#message').val()); - Twinkle.morebitsTest.setPageOptions(page); - page.append(Twinkle.morebitsTest.finalSaveCallback); - }, - 'Prepend': function() { - $(this).dialog('close'); - Twinkle.morebitsTest.initSimpleWindow(); - - var page = new Morebits.wiki.page(mw.config.get('wgPageName')); - page.setPrependText($('#message').val()); - Twinkle.morebitsTest.setPageOptions(page); - page.prepend(Twinkle.morebitsTest.finalSaveCallback); - }, - 'Insert': function() { - if ($('#beforeText').val() === '') { - alert('Text to insert before must be specified!'); - return; - } - $(this).dialog('close'); - Twinkle.morebitsTest.initSimpleWindow(); - - var page = new Morebits.wiki.page(mw.config.get('wgPageName')); - page.setCallbackParameters({ - beforeText: $('#beforeText').val(), - newText: $('#message').val() - }); - Twinkle.morebitsTest.setPageOptions(page); - page.load(Twinkle.morebitsTest.loadCallbackInsert); - }, - 'Replace': function() { - $(this).dialog('close'); - Twinkle.morebitsTest.initSimpleWindow(); - - var page = new Morebits.wiki.page(mw.config.get('wgPageName')); - page.setCallbackParameters({ - newText: $('#message').val() - }); - Twinkle.morebitsTest.setPageOptions(page); - page.load(Twinkle.morebitsTest.loadCallbackReplace); - } - } - }); // close .dialog - - } // close initialize function - - }; // close Twinkle.morebitsTest object - - Twinkle.morebitsTest.initialize(); -}); // close mw.loader - -Twinkle.morebitsTestInit = function () { - if (mw.config.get('wgAction') === 'view' && mw.config.get('skin') === 'vector' && mw.config.get('wgNamespaceNumber') >= 0) { - Twinkle.addPortlet('javascript:Twinkle.morebitsTest.launchDialog(Twinkle.morebitsTest.$runTests)', 'Test', 'tw-test', 'Test morebits.js', ''); - } -}; - -// register initialization callback -var Twinkle; -if (typeof Twinkle === 'undefined') { - throw new Error('Attempt to load module "morebits-test" without having loaded Twinkle previously.'); -} -Twinkle.addInitCallback(Twinkle.morebitsTestInit);