Jayprakash12345
/*
This tool will help you for small edits
@Use Just select the text and press Shift + E
*/
// Load modules
mw.loader.using( 'oojs-ui-windows', 'oojs-ui-widgets', 'oojs-ui-core', 'oojs-ui', 'oojs', 'mediawiki.notify' ).then( function () {
$(this).on('keypress', function(event) {
// Trigger for Shift + E
if (event.which == 69 && event.shiftKey) {
// Take Selected Text
var SelectedText = window.getSelection().toString();
var pageName = mw.config.get('wgPageName');
var Api = new mw.Api();
var wpEditToken = mw.user.tokens.get( 'editToken' );
function QuickEditor( config ) {
QuickEditor.super.call( this, config );
}
OO.inheritClass( QuickEditor, OO.ui.ProcessDialog );
QuickEditor.static.name = 'quickEditor';
QuickEditor.static.title = 'Quick Editor';
QuickEditor.static.actions = [
{ action: 'submit', label: 'Submit', flags: 'primary' },
{ label: 'Cancel', flags: 'safe' }
];
QuickEditor.prototype.initialize = function () {
QuickEditor.super.prototype.initialize.apply( this, arguments );
this.panel = new OO.ui.PanelLayout( { padded: true, expanded: false } );
this.content = new OO.ui.FieldsetLayout();
this.TextAera = new OO.ui.MultilineTextInputWidget( { rows: 20, value: SelectedText } );
this.field = new OO.ui.FieldLayout( this.TextAera, { align: 'top' } );
this.content.addItems( [ this.field ] );
this.panel.$element.append( this.content.$element );
this.$body.append( this.panel.$element );
};
QuickEditor.prototype.getActionProcess = function ( action ) {
var dialog = this;
// Trigger Submit button Action
if ( action === 'submit' ) {
textAeraText = this.TextAera.value;
Api.get({
action: 'parse',
page: pageName,
prop: 'wikitext',
format: 'json'
}).done( function (obj) {
var QuickEditorwikitext = obj.parse.wikitext['*'];
var QuickEditorResult = QuickEditorwikitext.replace( SelectedText, textAeraText )
Api.post({
action: 'edit',
title: pageName,
token: wpEditToken,
summary: 'QuickEditor (Testing)',
text: QuickEditorResult
}, {
success: function () {
// Notify the User
mw.notify("You have successful made a edit.", { type: 'info' });
setTimeout(function(){ window.location.reload() }, 1500);
}
});
});
return new OO.ui.Process( function () {
dialog.close( { action: action } );
} );
}
return QuickEditor.super.prototype.getActionProcess.call( this, action );
};
QuickEditor.prototype.getBodyHeight = function () {
return this.content.$element.outerHeight( true );
};
var windowManager = new OO.ui.WindowManager();
$( 'body' ).append( windowManager.$element );
var quickEditor = new QuickEditor({
size: 'medium'
});
windowManager.addWindows( [ quickEditor ] );
windowManager.openWindow( quickEditor );
}
});
} );
I am working on New Gadget. When I replace small changes then replacement has happened. See https://meta.wikimedia.org/w/index.php?title=User%3AJayprakash12345%2Fsandbox&type=revision&diff=18477902&oldid=18477867
But when I select line and want to replace with new characters then replacement is not happening. What am I doing wrong?