Amire80 has uploaded a new change for review. https://gerrit.wikimedia.org/r/53752
Change subject: (bug 45540) Show the "Accept" tooltip to first-time proofreaders ...................................................................... (bug 45540) Show the "Accept" tooltip to first-time proofreaders Added a tux-did-proofread user preference for this. Change-Id: Icff6250195c1c23e21eb419d2ff57a039217d4b5 --- M resources/js/ext.translate.proofread.js M utils/UserToggles.php 2 files changed, 58 insertions(+), 27 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate refs/changes/52/53752/1 diff --git a/resources/js/ext.translate.proofread.js b/resources/js/ext.translate.proofread.js index a8459a6..e16b4db 100644 --- a/resources/js/ext.translate.proofread.js +++ b/resources/js/ext.translate.proofread.js @@ -20,17 +20,21 @@ * @return {jqXHR} */ proofread: function ( params, ok, err ) { - var useTokenToPost, getTokenIfBad, - api = this; + var useTokenToPost, getTokenIfBad, promise, + proofreadPlugin = this, + api = new mw.Api(), + didProofreadOption = 'tux-did-proofread'; + if ( cachedToken === null ) { // We don't have a valid cached token, so get a fresh one and try posting. // We do not trap any 'badtoken' or 'notoken' errors, because we don't want // an infinite loop. If this fresh token is bad, something else is very wrong. useTokenToPost = function ( token ) { params.token = token; - new mw.Api().post( params, ok, err ); + api.post( params, ok, err ); }; - return api.getProofreadToken( useTokenToPost, err ); + + promise = proofreadPlugin.getProofreadToken( useTokenToPost, err ); } else { // We do have a token, but it might be expired. So if it is 'bad' then // start over with a new token. @@ -39,13 +43,32 @@ if ( code === 'badtoken' ) { // force a new token, clear any old one cachedToken = null; - api.proofread( params, ok, err ); + proofreadPlugin.proofread( params, ok, err ); } else { err( code, result ); } }; - return new mw.Api().post( params, { ok : ok, err : getTokenIfBad }); + + promise = api.post( params, { ok : ok, err : getTokenIfBad }); } + + if ( mw.user.options.get( didProofreadOption ) !== '1' ) { + mw.user.options.set( didProofreadOption, '1' ); + + api.get( { + action: 'tokens', + type: 'options' + } ).done( function ( data ) { + api.post( { + action: 'options', + token: data.tokens.optionstoken, + optionname: didProofreadOption, + optionvalue: '1' + } ); + } ); + } + + return promise; }, /** @@ -201,6 +224,10 @@ $proofreadEdit.tipsy( { gravity: 'n' } ); + + if ( mw.user.options.get( 'tux-did-proofread' ) !== '1' ) { + $proofreadAction.tipsy( 'show' ); + } }, hide: function () { diff --git a/utils/UserToggles.php b/utils/UserToggles.php index 4ffc2ba..4953cbb 100644 --- a/utils/UserToggles.php +++ b/utils/UserToggles.php @@ -14,38 +14,42 @@ */ class TranslatePreferences { /** - * Add 'translate-pref-nonewsletter' preference. - * This is most probably specific to translatewiki.net. Can be enabled + * Add 'translate-pref-nonewsletter' preference, + * which is most probably specific to translatewiki.net. Can be enabled * with $wgTranslateNewsletterPreference. + * Add 'tux-did-proofread', for tracking whether the user already proofread + * anything using TUX. * * @param $user User * @param $preferences array * @return bool true */ public static function onGetPreferences( $user, &$preferences ) { + $preferences['tux-did-proofread'] = array( + 'type' => 'api', + ); + global $wgTranslateNewsletterPreference; - if ( !$wgTranslateNewsletterPreference ) { - return true; - } + if ( $wgTranslateNewsletterPreference ) { + global $wgEnableEmail, $wgEnotifRevealEditorAddress; - global $wgEnableEmail, $wgEnotifRevealEditorAddress; + // Only show if email is enabled and user has a confirmed email address. + if ( $wgEnableEmail && $user->isEmailConfirmed() ) { + // 'translate-pref-nonewsletter' is used as opt-out for + // users with a confirmed email address + $prefs = array( + 'translate-nonewsletter' => array( + 'type' => 'toggle', + 'section' => 'personal/email', + 'label-message' => 'translate-pref-nonewsletter' + ) + ); - // Only show if email is enabled and user has a confirmed email address. - if ( $wgEnableEmail && $user->isEmailConfirmed() ) { - // 'translate-pref-nonewsletter' is used as opt-out for - // users with a confirmed email address - $prefs = array( - 'translate-nonewsletter' => array( - 'type' => 'toggle', - 'section' => 'personal/email', - 'label-message' => 'translate-pref-nonewsletter' - ) - ); - - // Add setting after 'enotifrevealaddr'. - $preferences = wfArrayInsertAfter( $preferences, $prefs, - $wgEnotifRevealEditorAddress ? 'enotifrevealaddr' : 'enotifminoredits' ); + // Add setting after 'enotifrevealaddr'. + $preferences = wfArrayInsertAfter( $preferences, $prefs, + $wgEnotifRevealEditorAddress ? 'enotifrevealaddr' : 'enotifminoredits' ); + } } return true; -- To view, visit https://gerrit.wikimedia.org/r/53752 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Icff6250195c1c23e21eb419d2ff57a039217d4b5 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Translate Gerrit-Branch: master Gerrit-Owner: Amire80 <amir.ahar...@mail.huji.ac.il> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits