Robert Vogel has uploaded a new change for review. https://gerrit.wikimedia.org/r/173014
Change subject: [WIP] Implementing CR and community feedback ...................................................................... [WIP] Implementing CR and community feedback Implementing feedback from https://gerrit.wikimedia.org/r/#/c/170702/ and https://de.wikipedia.org/wiki/Wikipedia_Diskussion:Teahouse Change-Id: Ie06aa980019b6befca7f8a2a528b5a2a607bd603 --- M Teahouse.php M i18n/de.json M i18n/en.json M i18n/qqq.json M resources/mediawiki.teahouse.board.js M resources/mediawiki.teahouse.gadget.development.js M resources/mediawiki.teahouse.js M resources/ui/dialogs/th.ui.MessageDialog.js M resources/ui/dialogs/th.ui.QuestionDialog.js 9 files changed, 105 insertions(+), 60 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Teahouse refs/changes/14/173014/1 diff --git a/Teahouse.php b/Teahouse.php index c324c23..83fda18 100644 --- a/Teahouse.php +++ b/Teahouse.php @@ -56,8 +56,8 @@ 'th-dialog-label-similar', 'th-dialog-btn-ok', 'th-dialog-btn-cancel', - 'th-dialog-disclaimer', - 'th-dialog-anon-ip-hint', + 'th-dialog-licence-html', + 'th-dialog-anon-ip-hint-html', 'th-dialog-msg-title-save', 'th-dialog-msg-text-save', 'th-dialog-msg-btn-yes', diff --git a/i18n/de.json b/i18n/de.json index 73aeb75..14f35ce 100644 --- a/i18n/de.json +++ b/i18n/de.json @@ -14,8 +14,8 @@ "th-dialog-label-similar": "Ähnliche, bereits gestellte Fragen", "th-dialog-btn-ok": "Veröffentlichen", "th-dialog-btn-cancel": "Abbrechen", - "th-dialog-disclaimer": "Veröffentlichung unter den Nutzungsbedingungen der Wikipedia", - "th-dialog-anon-ip-hint": "Deine IP Adresse wird zusammen mit der Frage veröffentlicht", + "th-dialog-licence-html": "Veröffentlicht unter der <a target=\"_blank\" href=\"//de.wikipedia.org/wiki/Wikipedia:Lizenzbestimmungen_Commons_Attribution-ShareAlike_3.0_Unported\">„Creative Commons Attribution/Share Alike“</a> Lizenz", + "th-dialog-anon-ip-hint-html": "Deine IP Adresse wird zusammen mit der Frage veröffentlicht", "th-dialog-msg-title-save": "Frage veröffentlicht", "th-dialog-msg-text-save": "Deine Frage wurde unter $1 veröffentlicht. Möchtest du die komplette Liste der Fragen sehen?", "th-dialog-msg-btn-yes": "Ja", diff --git a/i18n/en.json b/i18n/en.json index caf7254..fcc7fd3 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -14,8 +14,8 @@ "th-dialog-label-similar": "Similar questions", "th-dialog-btn-ok": "Publish", "th-dialog-btn-cancel": "Cancel", - "th-dialog-disclaimer": "Published under Wikipedia's Terms of Use", - "th-dialog-anon-ip-hint": "Your IP address will be published with the question", + "th-dialog-licence-html": "Published under Wikipedia's Terms of Use", + "th-dialog-anon-ip-hint-html": "Your IP address will be published with the question", "th-dialog-msg-title-save": "Question published", "th-dialog-msg-text-save": "Your question has been published on $1. Do you want to see the complete list of questions?", "th-dialog-msg-btn-yes": "Yes", diff --git a/i18n/qqq.json b/i18n/qqq.json index a5b1796..a7d5b49 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -14,8 +14,8 @@ "th-dialog-label-similar": "Label of a list with links to similar questions", "th-dialog-btn-ok": "Text of the button that sends the question. It should be clear that the action makes the question available to the public.", "th-dialog-btn-cancel": "Text of the button that resets the form and closes the dialog", - "th-dialog-disclaimer": "Hint to the Terms of Use. Links to https://wikimediafoundation.org/wiki/Terms_of_Use", - "th-dialog-anon-ip-hint": "Hint that the IP adress of an anonymous user will be saved", + "th-dialog-licence-html": "Hint to the Terms of Use. Links to https://wikimediafoundation.org/wiki/Terms_of_Use", + "th-dialog-anon-ip-hint-html": "Hint that the IP adress of an anonymous user will be saved", "th-dialog-msg-title-save": "Title of the message dialog that informs the user about the publishing of the question", "th-dialog-msg-text-save": "The text of the message dialog that tells the user about the location of her/his question and asks her/him whether or not to navigate to the Teahouse board page. The parameter $1 is replaced by an anchor tag pointing to the question subpage", "th-dialog-msg-btn-yes": "The message dialog's button that confirms the redirection to the Teahouse board page", diff --git a/resources/mediawiki.teahouse.board.js b/resources/mediawiki.teahouse.board.js index a3ce14f..2fd1c5b 100644 --- a/resources/mediawiki.teahouse.board.js +++ b/resources/mediawiki.teahouse.board.js @@ -85,15 +85,15 @@ var _sqCache = {}; var _lastPromise = undefined; - function _getSimilarQuestions( value, $target, callback ) { + function _getSimilarQuestions( value ) { + var dfd = $.Deferred(); mw.loader.using( 'mediawiki.Title', function() { var cacheKey = value.toLowerCase(); var baseTitle = new mw.Title( _config.basePage ); var prefix = baseTitle.getPrefixedText() + '/'; if( cacheKey in _sqCache ) { - _renderSimilarQuestionsList( _sqCache[cacheKey], prefix, $target ); - callback(); + dfd.resolve( _sqCache[cacheKey] ); return; } @@ -110,18 +110,18 @@ srnamespace: baseTitle.getNamespaceId() }) .done(function( response, jqXHR ){ - _sqCache[cacheKey] = response.query.search; - _renderSimilarQuestionsList( response.query.search, prefix, $target ); - callback(); + _sqCache[cacheKey] = _processSimilarQuestionsList( response.query.search, prefix ); + dfd.resolve( _sqCache[cacheKey] ); _lastPromise = undefined; }); }); + return dfd.promise(); } - function _renderSimilarQuestionsList( items, prefix, $target ) { - var $list = $('<ul>').addClass('th-similar-questions-list'); - var count = 0; + function _processSimilarQuestionsList( items, prefix ) { + var count = 0, + result = {}; for( var i = 0; i < items.length && count < 5; i++ ) { var title = items[i].title; @@ -130,21 +130,11 @@ } var displayTitle = title.replace( prefix, '' ); - var anchor = mw.html.element( 'a', { - href: mw.util.getUrl( title ), - title: title, - target: '_blank' - }, displayTitle ); - $list.append( '<li>'+anchor+'</li>' ); + result[title] = displayTitle; count++; } - $target.empty(); - if( count > 0 ) { - var $label = $('<span>').addClass( 'oo-ui-labelElement-label' ) - .append( mw.message('th-dialog-label-similar').plain() ); - $target.append( $label ); - $target.append( $list ); - } + + return result; } var _config = {}; diff --git a/resources/mediawiki.teahouse.gadget.development.js b/resources/mediawiki.teahouse.gadget.development.js index 22a75fc..2cd98bc 100644 --- a/resources/mediawiki.teahouse.gadget.development.js +++ b/resources/mediawiki.teahouse.gadget.development.js @@ -10,8 +10,8 @@ "th-dialog-label-similar": "Ähnliche, bereits gestellte Fragen", "th-dialog-btn-ok": "Veröffentlichen", "th-dialog-btn-cancel": "Abbrechen", - "th-dialog-disclaimer": "Veröffentlichung unter den Nutzungsbedingungen der Wikipedia", - "th-dialog-anon-ip-hint": "Deine IP Adresse wird zusammen mit der Frage veröffentlicht", + "th-dialog-licence-html": "Die Frage wird unter der <a class=\"internal\" href=\"//de.wikipedia.org/wiki/Wikipedia:Lizenzbestimmungen_Commons_Attribution-ShareAlike_3.0_Unported\">„Creative Commons Attribution/Share Alike“</a> veröffentlicht", + "th-dialog-anon-ip-hint-html": "Deine IP Adresse wird zusammen mit der Frage veröffentlicht", "th-dialog-msg-title-save": "Frage veröffentlicht", "th-dialog-msg-text-save": "Deine Frage wurde unter $1 veröffentlicht. Möchtest du die komplette Liste der Fragen sehen?", "th-dialog-msg-btn-yes": "Ja", diff --git a/resources/mediawiki.teahouse.js b/resources/mediawiki.teahouse.js index f60954f..d224a68 100644 --- a/resources/mediawiki.teahouse.js +++ b/resources/mediawiki.teahouse.js @@ -24,8 +24,8 @@ "th-dialog-label-similar": "Similar questions", "th-dialog-btn-ok": "Publish", "th-dialog-btn-cancel": "Cancel", - "th-dialog-disclaimer": "Published under Wikipedia's Terms of Use", - "th-dialog-anon-ip-hint": "Your IP address will be published with the question", + "th-dialog-licence-html": "Published under Wikipedia's Terms of Use", + "th-dialog-anon-ip-hint-html": "Your IP address will be published with the question", "th-dialog-msg-title-save": "Question published", "th-dialog-msg-text-save": "Your question has been published on $1. Do you want to see the complete list of questions?", "th-dialog-msg-btn-yes": "Yes", @@ -90,6 +90,29 @@ _config._$dlgLink = $(linkMarkup).prependTo( $('#p-personal > ul').first() ); } + /** + * This is a utility method that creates a object structure + * like window.mw.component.subcomponent.concretetype from a string + * like "mw.component.subcomponent.concretetype". This allows the creation + * of complext type structures with a single call. I.e. from the components + * sourcefile. + * @param string type + * @param object baseType + * @returns {undefined} + */ + function _registerType( type, baseType ) { + var baseNS = baseType || window; + var parts = type.split('.'); + if( !baseNS[parts[0]] ) { + baseNS[parts[0]] = {}; + baseNS = baseNS[parts[0]]; + parts.shift(); //Remove first element + if( parts.length > 0 ) { + _registerType( parts.join('.'), baseNS ); + } + } + } + mw.teahouse = { init: function( config ) { //called before merge because $.extend is not recursive @@ -101,12 +124,10 @@ mw.loader.using( ['mediawiki.user', 'mediawiki.cookie'], function() { _init.call(mw.teahouse); }); + }, + util: { + registerType: _registerType } - }; - - //register "th.ui" namespace for OOJS UI components - window.th = { - ui: {} }; })( mediaWiki, jQuery, document ); \ No newline at end of file diff --git a/resources/ui/dialogs/th.ui.MessageDialog.js b/resources/ui/dialogs/th.ui.MessageDialog.js index 229cb05..cfe5afb 100644 --- a/resources/ui/dialogs/th.ui.MessageDialog.js +++ b/resources/ui/dialogs/th.ui.MessageDialog.js @@ -12,6 +12,8 @@ * @param {Object} [config] Configuration options */ +mw.teahouse.util.registerType( 'th.ui.MessageDialog' ); + th.ui.MessageDialog = function ThUiMessageDialog( config ) { th.ui.MessageDialog.super.call( this, config ); }; diff --git a/resources/ui/dialogs/th.ui.QuestionDialog.js b/resources/ui/dialogs/th.ui.QuestionDialog.js index 73dac5d..a552ff2 100644 --- a/resources/ui/dialogs/th.ui.QuestionDialog.js +++ b/resources/ui/dialogs/th.ui.QuestionDialog.js @@ -12,6 +12,8 @@ * @param {Object} [config] Configuration options */ +mw.teahouse.util.registerType( 'th.ui.QuestionDialog' ); + th.ui.QuestionDialog = function ThUiQuestionDialog( config, teahousecfg ) { this._config = teahousecfg; th.ui.QuestionDialog.super.call( this, config ); @@ -68,22 +70,22 @@ } ); - this.btnDisclaimer = new OO.ui.ButtonWidget( { - icon: 'info', - framed: false, - label: mw.message('th-dialog-disclaimer').plain(), - href: 'https://wikimediafoundation.org/wiki/Terms_of_Use', - target: '_blank' - }); + var hintMarkup = '<div >{0}</div>'; - this.btnAnonIPhint = new OO.ui.ButtonWidget( { - classes: [ 'th-pseudoButton' ], - icon: 'info', - framed: false, - label: mw.message('th-dialog-anon-ip-hint').plain() + var infoIcon = new OO.ui.IconWidget({ + icon: 'info' }); + this.$licence = $( hintMarkup.replace( + '{0}', mw.message('th-dialog-licence-html').plain() + 'lorem ipsum dolor sit amet lorem ipsum dolor sit amet amet dolor sit lorem ipsum?' + )); + this.$licence.prepend( infoIcon.$element.clone() ); - this.pnlSimilarQuestions = $('<div>'); + this.$anonIPHint = $( hintMarkup.replace( + '{0}', mw.message('th-dialog-anon-ip-hint-html').plain() + )); + this.$anonIPHint.prepend( infoIcon.$element.clone() ); + + this.$similarQuestions = $('<div>'); var anchor = mw.html.element( 'a', { href: mw.util.getUrl( this._config.basePage ), @@ -96,10 +98,10 @@ ); this.content.$element.append( flQuestion.$element ); - this.content.$element.append( this.pnlSimilarQuestions ); + this.content.$element.append( this.$similarQuestions ); this.content.$element.append( flDesc.$element ); - this.content.$element.append( this.btnDisclaimer.$element.wrap('<p>') ); - this.content.$element.append( this.btnAnonIPhint.$element ); + this.content.$element.append( this.$licence ); + this.content.$element.append( this.$anonIPHint ); this.$body.addClass('th-question-dialog-body'); this.$body.append( this.content.$element ); @@ -113,15 +115,45 @@ //If there is no question entered or it is way too short to be a question //we disable the "save" action if(value !== '' && value.length > 3) { - mw.teahouse.board.getSimilarQuestions( value, this.pnlSimilarQuestions, function() { - me.getManager().updateWindowSize( me ); - }); + this.tiQuestion.pushPending(); + /*this.tiQuestion.$element + .addClass('oo-ui-actionWidget') + .addClass('oo-ui-pendingElement-pending');*/ + + mw.teahouse.board.getSimilarQuestions( value ) + .done( function( items ){ + var $list = $('<ul>').addClass('th-similar-questions-list'); + for( var title in items ) { + + var anchor = mw.html.element( 'a', { + href: mw.util.getUrl( title ), + title: title, + target: '_blank' + }, items[title] ); + + $list.append( '<li>'+anchor+'</li>' ); + } + + if( items.length > 0 ) { + var $label = $('<span>').addClass( 'oo-ui-labelElement-label' ) + .append( mw.message('th-dialog-label-similar').plain() ); + this.$similarQuestions.append( $label ); + this.$similarQuestions.append( $list ); + } + + this.tiQuestion.popPending(); + /*this.tiQuestion.$element + .removeClass('oo-ui-actionWidget') + .removeClass('oo-ui-pendingElement-pending');*/ + + me.getManager().updateWindowSize( me ); + }); actions.list[0].setDisabled(false); return; } - this.pnlSimilarQuestions.empty(); + this.$similarQuestions.empty(); this.getManager().updateWindowSize( this ); actions.list[0].setDisabled(true); }; @@ -131,7 +163,7 @@ //Hide the IP saving hint if user is anon. if( mw.user.isAnon() === false ) { - this.btnAnonIPhint.$element.hide(); + //this.$anonIPHint.hide(); } return th.ui.QuestionDialog.super.prototype.getSetupProcess.call( this, openingData ); }; -- To view, visit https://gerrit.wikimedia.org/r/173014 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie06aa980019b6befca7f8a2a528b5a2a607bd603 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Teahouse Gerrit-Branch: master Gerrit-Owner: Robert Vogel <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
