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(  '<p>It might take some time. Please be patient :) </p>' );
                    this.content.$element.outerHeight( '150px' );
                    this.$body.append( this.content.$element );
                    this.content.$element.append(  '<p>Started fetching new version...</p>' );
                    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(  '<p>Got the new version, saving...</p>' );
                            (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('<p style="color:#d33;">Saving errored. Reload the page and try again :(</p>');
                                } else {
                                    dialog.content.$element.append('<p style="color:#00af89;">Saving Finishined. Reload the page to see the differences</p>');
                                    setInterval(function(){dialog.close()},3000);
                                }
                            }).fail(function (data) {
                                dialog.content.$element.append('<p style="color:#d33;">Saving errored. Reload the page and try again :(</p>');
                            })
                        } else {
                            dialog.content.$element.append(  '<p style="color:#d33;">Errored out. Not possible. Probably not needed :(</p>' );
                        }
                    })
                };

                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));

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.