MediaWiki:ReplyAndClose/code.js

/** * ReplyAndClose.js * * Gives admins and discussions moderators the ability to simultaneously post a final reply and close the thread * @author: w:User:Slyst */

if (!{1201: 1, 2001: 1}[mw.config.get('wgNamespaceNumber')] && $(['sysop', 'threadmoderator']).not(mw.config.get('wgUserGroups')).length > 1) { return; }   var replyAndClose = $.extend({        reason: 'see reply $1',        def: '',        generic: {}    }, window.replyAndClose); replyAndClose.parent = mw.config.get('wgTitle'); var i18n = { en: { title: 'Reply and close', placeholder: 'Write your reply here', cancel: 'Cancel', preview: 'Preview', post: 'Post', generic: 'Choose a generic reply', empty: 'Your reply cannot be empty!', statusPreview: 'Generating preview', statusPost: 'Posting reply', statusClose: 'Closing thread', errorClose: 'An error occurred while closing the thread', errorPost: 'An error occurred while posting your reply', errorPreview: 'An error occurred while generating preview' },       es: { title: 'Respuesta y cerrar', placeholder: 'Escriba su respuesta aqui', cancel: 'Cancelar', preview: 'Avance', post: 'Enviar', generic: 'Elige una respuesta generica', empty: 'Su respuesta no puede estar vacia!', statusPreview: 'Generando avance', statusPost: 'Enviando respuesta', statusClose: 'Cerrando hilo', errorClose: 'Se ha producido un error mientras se cerraba su hilo', errorPost: 'Se ha producido un error mientras se enviaba su respuesta', errorPreview: 'Se ha producido un error mientras se generaba su avance' }   };    i18n = $.extend(i18n.en, i18n[mw.config.get('wgUserLanguage')]); $('.message-main > .speech-bubble-message .buttons .WikiaMenuElement').append(function {       if (!$('.reopen-thread').length) {            return '' + i18n.title + '';        }    }); $('.reply-and-close').bind('click', function {       require(['wikia.ui.factory'], function(ui) { ui.init(['modal']).then(function(modal) {               var content = ;                if (replyAndClose.generic && !$.isEmptyObject(replyAndClose.generic)) {                    content += ' ' + i18n.generic + ': ';                    for (var i in replyAndClose.generic) {                        content += '' + i + ' ';                    }                    content += ' ';                }                content += '' + (replyAndClose.def ==  ? '' : replyAndClose.def) + ' ';               modal.createComponent({ vars: { id: 'reply-and-close-modal', size: 'medium', title: i18n.title + ': Thread:' + replyAndClose.parent, content: content, buttons: [{ vars: { value: i18n.cancel, data: [{ key: 'event', value: 'close' }]                           }                        }, {                            vars: { value: i18n.preview, classes: ['normal', 'secondary', 'reply-and-close-preview'], data: [{ key: 'event', value: 'preview' }]                           }                        }, {                            vars: { value: i18n.post, classes: ['normal', 'primary', 'reply-and-close-post'], data: [{ key: 'event', value: 'post' }]                           }                        }]                    }                }, function(replyModal) { $('.reply-and-close-post').before(' '); replyModal.bind('post', function(e) {                       if ($('#reply-body').val == '') {                            alert(i18n.empty);                            return;                        }                        $('.reply-and-close-post').attr('disabled', 'disabled');                        $('.current-status').text(i18n.statusPost);                        $('#loading').show;                        $.nirvana.sendRequest({ controller: 'WallExternal', method: 'replyToMessage', type: 'POST', data: { parent: replyAndClose.parent, body: $('#reply-body').val, token: mw.user.tokens.values.editToken },                           callback: function(data) { if (data.status) { $('.current-status').text('Closing'); $.nirvana.sendRequest({                                       controller: 'WallExternal',                                        method: 'changeThreadStatus',                                        data: {                                            msgid: replyAndClose.parent,                                            newState: 'close',                                            formdata: [{                                                name: 'reason',                                                value: replyAndClose.reason.replace(/\$1/g, '')                                            }]                                        },                                        callback: function(newData) {                                            if (newData.status) {                                                window.location.reload; } else { $('.reply-and-close-post').removeAttr('disabled'); $('.current-status').text(i18n.errorClose); $('#loading').hide; }                                       },                                        onErrorCallback: function { $('.reply-and-close-post').removeAttr('disabled'); $('.current-status').text(i18n.errorClose); $('#loading').hide; }                                   });                                } else {                                    $('.reply-and-close-post').removeAttr('disabled');                                    $('.current-status').text(i18n.errorPost);                                    $('#loading').hide;                                }                            },                            onErrorCallback: function {                                $('.reply-and-close-post').removeAttr('disabled');                                $('.current-status').text(i18n.errorPost);                                $('#loading').hide;                            }                        }); });                   replyModal.bind('preview', function { $('.reply-and-close-preview').attr('disabled', 'disabled'); $('.current-status').text(i18n.statusPreview); $('#loading').show; $.nirvana.sendRequest({                           controller: 'WallExternal',                            method: 'preview',                            data: {                                body: $('#reply-body').val                            },                            callback: function(data) {                                $('.reply-and-close-preview').removeAttr('disabled');                                $('.current-status').text('');                                $('#loading').hide;                                $('#preview.WikiaArticle').html(function { if (data.body) { return ' ' + i18n.preview + ' ' + data.body; } else { $('.current-status').text(i18n.errorPreview); }                               });                            },                            onErrorCallback: function {                                $('.reply-and-close-preview').removeAttr('disabled');                                $('.current-status').text(i18n.errorPreview);                                $('#loading').hide;                            }                        }); });                   replyModal.show;                    $('#reply-and-close-generic').bind('change', function { $('#reply-body').val(replyAndClose.generic[$(this).val]); });               });            });        });    }); });
 * (function {