User:Indic-TechCom/Script/massMover.js

/*   This is userscirpt is usefull for Mass pages Move. @Author User:Jayprakash12345 @Author from User:Legoktm/massrename.js @OwnBy Indic-TechCom

$( document ).ready( function {   function init {    $('#mw-content-text > p').remove;    $('#firstHeading').text('MassMover');

var listofPages = new OO.ui.MultilineTextInputWidget( {               placeholder: 'List of Pages',                autosize: true,                 rows: 10            } ), findInput = new OO.ui.TextInputWidget( {                placeholder: 'Find'            } ); replaceInput = new OO.ui.TextInputWidget( {                placeholder: 'Replace'            } ), reasonInput = new OO.ui.TextInputWidget( {                placeholder: 'Reason'            } ), treatAsRegex = new OO.ui.FieldLayout(                treatAsRegexInside = new OO.ui.CheckboxInputWidget( { selected: false } ), {                label: 'Treat search string as a regular expression',                 align: 'inline'             } ), notleaveRedirect = '', moveStart = new OO.ui.ButtonWidget( {                label: 'Start Moving',                 icon: 'alert',                flags: [ 'primary', 'progressive' ]            } ), cancelBtn = new OO.ui.ButtonWidget( {               label: 'Cancel',                flags: [ 'primary', 'destructive' ],                href: 'https:' + mw.config.get( 'wgServer' )            } ), moveLogHeading = $(" ").hide; label1 = $(' ').text('List of Pages:').css('font-weight','bold' );

label2 = $(' ').text('Find:').css('font-weight','bold' );

label3 = $(' ').text('Replace:').css('font-weight','bold' );

label4 = $(' ').text('Reason:').css('font-weight','bold' );

if ( $.inArray( 'sysop', mw.config.get('wgUserGroups') ) !== -1 ) { notleaveRedirect = new OO.ui.FieldLayout(                notleaveRedirectInside = new OO.ui.CheckboxInputWidget( { selected: false } ), {                label: 'Don\'t leave the redirect behind (Be careful)',                 align: 'inline'             } ); }       $( '#mw-content-text' ).append(             label1, listofPages.$element,             label2, findInput.$element,            label3, replaceInput.$element,            label4, reasonInput.$element,            treatAsRegex.$element,            notleaveRedirect.$element,            ' ',            moveStart.$element,            cancelBtn.$element,            ' ',            moveLogHeading        );

// Thanks User:Legoktm, Stolen from User:Legoktm/massrename.js function rename_file( old, newname, reason, noRedirect, callback ) { ( new mw.Api ).postWithToken ( 'csrf', {               action: 'move',                from: old,                to: newname,                reason: reason,                movetalk: 1,                noredirect: noRedirect            }, {				async: false // Don't run parallel requests, be nice to sever kittens!			}) .done( callback ) .fail( callback ); }       function escapeRegExp(str) { // From MDN return str.replace(/([.*+?^=!:${}|\[\]\/\\])/g, "\\$1"); }		function missingAlertMsg ( str ) { return alert( "Did not find " + str + " :(" );		}

function responeHanddler( data ) { var orderedList = $("").appendTo( moveLogHeading ); /*			// If source page is not exist if ( data === "missingtitle") { orderedList.append( " Page " + pageToMoveByMassMover + " not found. " ); }			// If old name and new name are same if ( data === "selfmove") { orderedList.append( "" + pageToMoveByMassMover + " no changes made. " ); }			*/			if( data.move ) { orderedList.append( "" + data.move.from + " moved to " + data.move.to + "." ); }		}       moveStart.on( 'click', function {            pagesList = listofPages.getValue.replace(/^\s*[\r\n]/gm, '').split("\n");

var find = findInput.getValue.trim; var replace = replaceInput.getValue.trim; var reason = reasonInput.getValue.trim + " (By MassMover)"; var noRedirect = false; var AsRegex = treatAsRegexInside.isSelected; if( pagesList[0].trim !== "" && find !== "" && replace !== "" ) { moveLogHeading.empty; $(" ").wrapInner( " Move Log ").appendTo( moveLogHeading ); moveLogHeading.show; } else { missingAlertMsg( "any source page" ); return; }           if ( find === "" ) { missingAlertMsg( "\'find\' string" ); return; }           if ( replace === "" ) { missingAlertMsg( "replace string" ); return; }           if ( $.inArray( 'sysop', mw.config.get('wgUserGroups') ) !== -1 ) { noRedirect = notleaveRedirectInside.isSelected; }           pagesList.forEach( function(page){            	// Lengthy name to aviod override in the global variable                window.pageToMoveByMassMover = page.trim;                // Simple find/replace without Regex                if ( !AsRegex ) {                	find = escapeRegExp(find);                    newPagename = pageToMoveByMassMover.replace( find, replace );                    rename_file( pageToMoveByMassMover, newPagename, reason, noRedirect, responeHanddler );                }                // Find/replace with Regex                else {                	// Check whether the Regex is correct or not                	try {						find = new RegExp( find, 'gi' );					} catch (e) {						alert( "Regex Error: " + e );						// Hack to break the loop						pagesList.length = 0;						return;					}                    newPagename = pageToMoveByMassMover.replace( find, replace ); rename_file( pageToMoveByMassMover, newPagename, reason, noRedirect, responeHanddler); }           });        });    }

// On every page $.when(mw.loader.using('mediawiki.util'), $.ready).then(function {        mw.util.addPortletLink( 'p-tb', mw.util.getUrl('Special:BlankPage/MassMover'), 'MassMover' );   });

if ( mw.config.get('wgCanonicalSpecialPageName') === 'Blankpage' && mw.config.get('wgTitle').split('/', 2)[1] === 'MassMover' ) { $.when(mw.loader.using('oojs-ui-core'), $.ready).then(function {            init;        }); } });