User:RohitKamalV/common.js

const dialogTrigger = mw.util.addPortletLink( 'p-tb','#' ,'Mass Find and Replace');

mw.loader.using( '@wikimedia/codex' ).then( function( require ) { const Vue = require( 'vue' ); const Codex = require( '@wikimedia/codex' ); const mountPoint = document.body.appendChild( document.createElement( 'div' ) ); Vue.createMwApp( { data: function { return { showDialog: false, count: 0, codexLink: 'https://doc.wikimedia.org/codex/latest/' }; },  template: `    This Dialog component comes from Codex, the new design system for Wikimedia. To learn more about Codex, check out the documentation here. Click these buttons to update the reactive count value: Count: Decrease Increase  `, methods: { openDialog { this.showDialog = true; },  increment {

pagesList = listofPages.getValue.replace(/^\s*[\r\n]/gm, '').split("\n"); find = findInput.getValue.trim, replace = replaceInput.getValue.trim, reason = reasonInput.getValue.trim + " (By FindAndReplace)"; // Check whether the all fields are enough to run the function if( pagesList[0].trim !== "" && find !== "" && replace !== "" ) { divLog.empty; $(" ").wrapInner( " Edit Log ").appendTo( divLog ); orderedList.appendTo( divLog ); divLog.show; } else { missingAlertMsg( "any source page" ); return; }			if ( find === "" ) { missingAlertMsg( "\'find\' string" ); return; } else if ( replace === "" ) { missingAlertMsg( "replace string" ); return; }

pagesList.forEach( function(page){				page = page.trim;

var getContentParam = { "action": "query", "format": "json", "prop": "revisions", "titles": page, "rvprop": "content", "rvslots": "main", "rvlimit": "1" };				api = new mw.Api; api.get( getContentParam, { async: false } ).done( function ( data ) {					try {						oldText = data.query.pages[Object.keys(data.query.pages)[0]].revisions[0].slots.main['*'];					} catch(e){						oldText = -1;					}					if( oldText !== -1 ){						newText = safeReplace( oldText, find, replace );						if ( newText === oldText){							orderedList.append( "" + page + " has no changes." );						} else{							// Edit the page							var editParams = {								action: 'edit',								title: page,								text: newText,								summary: reason,								format: 'json'							};

api.postWithToken( 'csrf', editParams, { async: false } ).done( function ( res ) {								if( res.edit.result === "Success"){									orderedList.append( "Changes made on " + page + "" );								} else{									orderedList.append( "Something went worng with " + page + "" );								}							} ); }					} else { orderedList.append( "" + page + " not found." ); }				});			});   	},   decrement { this.count--; } },  mounted { dialogTrigger.addEventListener( 'click', this.openDialog ); }, unMounted { dialogTrigger.removeEventListener( this.openDialog ); } } ) .component( 'cdx-button', Codex.CdxButton ) .component( 'cdx-dialog', Codex.CdxDialog ) .mount( mountPoint ); } );