User:Ladsgroup/RefCleaner.js

// License: MIT (function(mw, $){   $(mw.util.addPortletLink('p-cactions',"#", 'Clean references', "ca-refCleaner", null, null)).click(function { mw.loader.using(           [                'oojs',                'oojs-ui',                'jquery.spinner',            ],            function{                function ProcessDialog( config ) {                    ProcessDialog.super.call( this, config );                }                OO.inheritClass( ProcessDialog, OO.ui.ProcessDialog );                ProcessDialog.static.title = 'Article cleaner';                ProcessDialog.static.name = 'fix-formatting-dialog';                ProcessDialog.static.actions = [                    { label: 'Cancel', flags: ['primary','destructive'] }                ];                ProcessDialog.prototype.initialize = function  {                    ProcessDialog.super.prototype.initialize.apply( this, arguments );

this.content = new OO.ui.PanelLayout( { padded: true, expanded: false } ); this.content.$element.append( ' It might take some time. Please be patient :) ' );                    this.content.$element.outerHeight( '150px' );                    this.$body.append( this.content.$element );                    this.content.$element.append(  ' Started fetching new version... ' );                   var dialog = this;                    $.get( 'https://tools.wmflabs.org/dexbot/fix_formatting2.php?page=' + mw.config.get('wgPageName')).done( function (data) { if ( data.content ) { dialog.content.$element.append( ' Got the new version, saving... ' ); (new mw.Api).postWithToken('csrf', {                               action: 'edit',                                title: mw.config.get('wgPageName'),                                text: data.content,                                summary: 'Fixing references styling.',                                minor: ''                            }).done(function(data) {                                if (data.error && data.error.info) {                                    dialog.content.$element.append('Saving errored. Reload the page and try again :( '); } else { dialog.content.$element.append('Saving Finishined. Reload the page to see the differences '); setInterval(function{dialog.close},3000); }                           }).fail(function (data) { dialog.content.$element.append('Saving errored. Reload the page and try again :( ');                           }) } else { dialog.content.$element.append( 'Errored out. Not possible. Probably not needed :( ' );                        }                    }) };

ProcessDialog.prototype.getBodyHeight = function { return this.content.$element.outerHeight( true ); };               var windowManager = new OO.ui.WindowManager; $( 'body' ).append( windowManager.$element );

var processDialog = new ProcessDialog({                   size: 'medium'                }); windowManager.addWindows( [ processDialog ] ); windowManager.openWindow( processDialog ); }       );    }); }(mediaWiki, jQuery));