| 1 |
mw.libs.confirmEdit = {}; |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
mw.libs.confirmEdit.CaptchaInputWidget = function MwWidgetsCaptchaInputWidget( captchaData, config ) { |
| 12 |
config = config || {}; |
| 13 |
|
| 14 |
|
| 15 |
mw.libs.confirmEdit.CaptchaInputWidget.parent.call( this, config ); |
| 16 |
|
| 17 |
|
| 18 |
this.$captchaImg = null; |
| 19 |
this.captchaId = null; |
| 20 |
|
| 21 |
|
| 22 |
this.$element.addClass( 'mw-confirmEdit-captchaInputWidget' ); |
| 23 |
this.$element.prepend( this.makeCaptchaInterface( captchaData ) ); |
| 24 |
}; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
OO.inheritClass( mw.libs.confirmEdit.CaptchaInputWidget, OO.ui.TextInputWidget ); |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
mw.libs.confirmEdit.CaptchaInputWidget.prototype.makeCaptchaInterface = function ( captchaData ) { |
| 41 |
let $captchaImg, msg, question; |
| 42 |
|
| 43 |
const $captchaParagraph = $( '<div>' ).append( |
| 44 |
$( '<strong>' ).text( mw.msg( 'captcha-label' ) ), |
| 45 |
document.createTextNode( mw.msg( 'colon-separator' ) ) |
| 46 |
); |
| 47 |
const $captchaDiv = $( '<div>' ).append( $captchaParagraph ); |
| 48 |
|
| 49 |
if ( captchaData.url ) { |
| 50 |
|
| 51 |
|
| 52 |
this.$input.attr( 'placeholder', mw.msg( 'fancycaptcha-imgcaptcha-ph' ) ); |
| 53 |
mw.loader.load( 'ext.confirmEdit.fancyCaptcha' ); |
| 54 |
$captchaDiv.addClass( 'fancycaptcha-captcha-container' ); |
| 55 |
$captchaParagraph.append( mw.message( 'fancycaptcha-edit' ).parseDom() ); |
| 56 |
$captchaImg = $( '<img>' ) |
| 57 |
.attr( 'src', captchaData.url ) |
| 58 |
.data( 'captchaId', captchaData.id ) |
| 59 |
.addClass( 'fancycaptcha-image' ) |
| 60 |
.on( 'load', this.emit.bind( this, 'load' ) ); |
| 61 |
$captchaDiv.append( |
| 62 |
$captchaImg, |
| 63 |
' ', |
| 64 |
$( '<a>' ).addClass( 'fancycaptcha-reload' ).text( mw.msg( 'fancycaptcha-reload-text' ) ) |
| 65 |
); |
| 66 |
} else { |
| 67 |
if ( captchaData.type === 'simple' ) { |
| 68 |
msg = 'captcha-edit'; |
| 69 |
} else if ( captchaData.type === 'question' ) { |
| 70 |
|
| 71 |
msg = 'questycaptcha-edit'; |
| 72 |
} |
| 73 |
|
| 74 |
if ( msg ) { |
| 75 |
switch ( captchaData.mime ) { |
| 76 |
case 'text/html': |
| 77 |
question = $.parseHTML( captchaData.question ); |
| 78 |
break; |
| 79 |
case 'text/plain': |
| 80 |
question = document.createTextNode( captchaData.question ); |
| 81 |
break; |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
$captchaParagraph.append( mw.message( msg ).parseDom(), '<br>', question ); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
if ( $captchaImg ) { |
| 90 |
this.$captchaImg = $captchaImg; |
| 91 |
} else { |
| 92 |
this.captchaId = captchaData.id; |
| 93 |
} |
| 94 |
|
| 95 |
return $captchaDiv; |
| 96 |
}; |
| 97 |
|
| 98 |
mw.libs.confirmEdit.CaptchaInputWidget.prototype.getCaptchaId = function () { |
| 99 |
|
| 100 |
return this.$captchaImg ? this.$captchaImg.data( 'captchaId' ) : this.captchaId; |
| 101 |
}; |
| 102 |
|
| 103 |
mw.libs.confirmEdit.CaptchaInputWidget.prototype.getCaptchaWord = function () { |
| 104 |
return this.getValue(); |
| 105 |
}; |