* dialog box. Submitting that dialog box appends its contents to a
* wiki page that you specify, as a new section.
*
- * Not compatible with LiquidThreads.
+ * This feature works with classic MediaWiki pages
+ * and is not compatible with LiquidThreads or Flow.
*
- * Minimal example in how to use it:
+ * Minimal usage example:
*
* var feedback = new mw.Feedback();
* $( '#myButton' ).click( function () { feedback.launch(); } );
target: '_blank'
} );
- // TODO: Use a stylesheet instead of these inline styles
- this.$dialog =
- $( '<div style="position: relative;"></div>' ).append(
- $( '<div class="feedback-mode feedback-form"></div>' ).append(
- $( '<small>' ).append(
- $( '<p>' ).msg(
- 'feedback-bugornote',
- $bugNoteLink,
- fb.title.getNameText(),
- $feedbackPageLink.clone()
- )
- ),
- $( '<div style="margin-top: 1em;"></div>' ).append(
- mw.msg( 'feedback-subject' ),
- $( '<br>' ),
- $( '<input type="text" class="feedback-subject" name="subject" maxlength="60" style="width: 100%; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;"/>' )
- ),
- $( '<div style="margin-top: 0.4em;"></div>' ).append(
- mw.msg( 'feedback-message' ),
- $( '<br>' ),
- $( '<textarea name="message" class="feedback-message" rows="5" cols="60"></textarea>' )
- )
- ),
- $( '<div class="feedback-mode feedback-bugs"></div>' ).append(
- $( '<p>' ).msg( 'feedback-bugcheck', $bugsListLink )
- ),
- $( '<div class="feedback-mode feedback-submitting" style="text-align: center; margin: 3em 0;"></div>' ).append(
- mw.msg( 'feedback-adding' ),
- $( '<br>' ),
- $( '<span class="feedback-spinner"></span>' )
- ),
- $( '<div class="feedback-mode feedback-thanks" style="text-align: center; margin:1em"></div>' ).msg(
- 'feedback-thanks', fb.title.getNameText(), $feedbackPageLink.clone()
- ),
- $( '<div class="feedback-mode feedback-error" style="position: relative;"></div>' ).append(
- $( '<div class="feedback-error-msg style="color: #990000; margin-top: 0.4em;"></div>' )
- )
- );
-
- // undo some damage from dialog css
- this.$dialog.find( 'a' ).css( {
- color: '#0645ad'
- } );
+ // TODO: Use a stylesheet instead of these inline styles in the template
+ this.$dialog = mw.template.get( 'mediawiki.feedback', 'dialog.html' ).render();
+ this.$dialog.find( '.feedback-mode small p' ).msg(
+ 'feedback-bugornote',
+ $bugNoteLink,
+ fb.title.getNameText(),
+ $feedbackPageLink.clone()
+ );
+ this.$dialog.find( '.feedback-form .subject span' ).msg( 'feedback-subject' );
+ this.$dialog.find( '.feedback-form .message span' ).msg( 'feedback-message' );
+ this.$dialog.find( '.feedback-bugs p' ).msg( 'feedback-bugcheck', $bugsListLink );
+ this.$dialog.find( '.feedback-submitting span' ).msg( 'feedback-adding' );
+ this.$dialog.find( '.feedback-thanks' ).msg( 'feedback-thanks', fb.title.getNameText(),
+ $feedbackPageLink.clone() );
- this.$dialog.dialog( {
- width: 500,
- autoOpen: false,
- title: mw.msg( this.dialogTitleMessageKey ),
- modal: true,
- buttons: fb.buttons
- } );
+ this.$dialog.dialog( {
+ width: 500,
+ autoOpen: false,
+ title: mw.message( this.dialogTitleMessageKey ).escaped(),
+ modal: true,
+ buttons: fb.buttons
+ } );
this.subjectInput = this.$dialog.find( 'input.feedback-subject' ).get( 0 );
this.messageInput = this.$dialog.find( 'textarea.feedback-message' ).get( 0 );
-
},
/**
displayBugs: function () {
var fb = this,
bugsButtons = {};
+
this.display( 'bugs' );
bugsButtons[ mw.msg( 'feedback-bugnew' ) ] = function () {
window.open( fb.bugsLink, '_blank' );
displayThanks: function () {
var fb = this,
closeButton = {};
+
this.display( 'thanks' );
closeButton[ mw.msg( 'feedback-close' ) ] = function () {
fb.$dialog.dialog( 'close' );
displayForm: function ( contents ) {
var fb = this,
formButtons = {};
+
this.subjectInput.value = ( contents && contents.subject ) ? contents.subject : '';
this.messageInput.value = ( contents && contents.message ) ? contents.message : '';
displayError: function ( message ) {
var fb = this,
closeButton = {};
+
this.display( 'error' );
this.$dialog.find( '.feedback-error-msg' ).msg( message );
closeButton[ mw.msg( 'feedback-close' ) ] = function () {
var subject, message,
fb = this;
- function ok( result ) {
+ // Get the values to submit.
+ subject = this.subjectInput.value;
+
+ // We used to include "mw.html.escape( navigator.userAgent )" but there are legal issues
+ // with posting this without their explicit consent
+ message = this.messageInput.value;
+ if ( message.indexOf( '~~~' ) === -1 ) {
+ message += ' ~~~~';
+ }
+
+ this.displaySubmitting();
+
+ // Post the message, resolving redirects
+ this.api.newSection(
+ this.title,
+ subject,
+ message,
+ { redirect: true }
+ )
+ .done( function ( result ) {
if ( result.edit !== undefined ) {
if ( result.edit.result === 'Success' ) {
fb.displayThanks();
// edit failed
fb.displayError( 'feedback-error2' );
}
- }
-
- function err() {
+ } )
+ .fail( function () {
// ajax request failed
fb.displayError( 'feedback-error3' );
- }
-
- // Get the values to submit.
- subject = this.subjectInput.value;
-
- // We used to include "mw.html.escape( navigator.userAgent )" but there are legal issues
- // with posting this without their explicit consent
- message = this.messageInput.value;
- if ( message.indexOf( '~~~' ) === -1 ) {
- message += ' ~~~~';
- }
-
- this.displaySubmitting();
-
- this.api.newSection( this.title, subject, message ).done( ok ).fail( err );
+ } );
},
/**
this.$dialog.dialog( 'open' );
this.subjectInput.focus();
}
-
};
-
}( mediaWiki, jQuery ) );