Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.hooks.php |
— | — | @@ -107,7 +107,7 @@ |
108 | 108 | // Add javascript to document |
109 | 109 | if ( count( self::$messages ) > 0 ) { |
110 | 110 | $out->addScript( Html::inlineScript( |
111 | | - 'mw.usability.addMessages({' . implode( ',', self::$messages ) . '});' |
| 111 | + '$j.ArticleAssessment.fn.addMessages({' . implode( ',', self::$messages ) . '});' |
112 | 112 | ) ); |
113 | 113 | } |
114 | 114 | |
Index: trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.js |
— | — | @@ -6,6 +6,7 @@ |
7 | 7 | 'pageID': wgArticleId, |
8 | 8 | 'revID': wgCurRevisionId |
9 | 9 | }, |
| 10 | + 'messages': {}, |
10 | 11 | 'settings': { |
11 | 12 | 'endpoint': wgScriptPath + '/api.php?', |
12 | 13 | 'fieldMessages' : [ |
— | — | @@ -86,27 +87,27 @@ |
87 | 88 | } |
88 | 89 | // setup our markup using the template varibales in settings |
89 | 90 | var $output = $( settings.structureHTML |
90 | | - .replace( /\{INSTRUCTIONS\}/g, mw.usability.getMsg('articleassessment-pleaserate') ) |
91 | | - .replace( /\{FEEDBACK\}/g, mw.usability.getMsg('articleassessment-featurefeedback') |
| 91 | + .replace( /\{INSTRUCTIONS\}/g, $.ArticleAssessment.fn.getMsg('articleassessment-pleaserate') ) |
| 92 | + .replace( /\{FEEDBACK\}/g, $.ArticleAssessment.fn.getMsg('articleassessment-featurefeedback') |
92 | 93 | .replace( /\[\[([^\|\]]*)\|([^\|\]]*)\]\]/, '<a href="' + wgArticlePath + '">$2</a>' ) ) |
93 | | - .replace( /\{YOURFEEDBACK\}/g, mw.usability.getMsg('articleassessment-yourfeedback') ) |
94 | | - .replace( /\{ARTICLERATING\}/g, mw.usability.getMsg('articleassessment-articlerating' ) ) |
95 | | - .replace( /\{RESULTSHIDE\}/g, mw.usability.getMsg('articleassessment-results-hide' ) |
| 94 | + .replace( /\{YOURFEEDBACK\}/g, $.ArticleAssessment.fn.getMsg('articleassessment-yourfeedback') ) |
| 95 | + .replace( /\{ARTICLERATING\}/g, $.ArticleAssessment.fn.getMsg('articleassessment-articlerating' ) ) |
| 96 | + .replace( /\{RESULTSHIDE\}/g, $.ArticleAssessment.fn.getMsg('articleassessment-results-hide' ) |
96 | 97 | .replace( /\[\[\|([^\]]*)\]\]/, '<a href="#">$1</a>' ) ) |
97 | | - .replace( /\{RESULTSSHOW\}/g, mw.usability.getMsg('articleassessment-results-show' ) |
| 98 | + .replace( /\{RESULTSSHOW\}/g, $.ArticleAssessment.fn.getMsg('articleassessment-results-show' ) |
98 | 99 | .replace( /\[\[\|([^\]]*)\]\]/, '<a href="#">$1</a>' ) ) ); |
99 | 100 | for( var field in settings.fieldMessages ) { |
100 | 101 | $output.find( '.article-assessment-rating-fields' ) |
101 | 102 | .append( $( settings.fieldHTML |
102 | | - .replace( /\{LABEL\}/g, mw.usability.getMsg( settings.fieldPrefix + settings.fieldMessages[field] ) ) |
| 103 | + .replace( /\{LABEL\}/g, $.ArticleAssessment.fn.getMsg( settings.fieldPrefix + settings.fieldMessages[field] ) ) |
103 | 104 | .replace( /\{FIELD\}/g, settings.fieldMessages[field] ) |
104 | | - .replace( /\{HINT\}/g, mw.usability.getMsg( settings.fieldPrefix + settings.fieldMessages[field] + settings.fieldHintSuffix ) ) ) ); |
| 105 | + .replace( /\{HINT\}/g, $.ArticleAssessment.fn.getMsg( settings.fieldPrefix + settings.fieldMessages[field] + settings.fieldHintSuffix ) ) ) ); |
105 | 106 | $output.find( '#article-assessment-ratings' ) |
106 | 107 | .append( $( settings.ratingHTML |
107 | | - .replace( /\{LABEL\}/g, mw.usability.getMsg(settings.fieldPrefix + settings.fieldMessages[field]) ) |
| 108 | + .replace( /\{LABEL\}/g, $.ArticleAssessment.fn.getMsg(settings.fieldPrefix + settings.fieldMessages[field]) ) |
108 | 109 | .replace( /\{FIELD\}/g, settings.fieldMessages[field] ) |
109 | 110 | .replace( /\{VALUE\}/g, '0%' ) |
110 | | - .replace( /\{COUNT\}/g, mw.usability.getMsg( 'articleassessment-noratings', [0, 0] ) ) ) |
| 111 | + .replace( /\{COUNT\}/g, $.ArticleAssessment.fn.getMsg( 'articleassessment-noratings', [0, 0] ) ) ) |
111 | 112 | ); |
112 | 113 | } |
113 | 114 | // store our settings and configuration for later |
— | — | @@ -217,7 +218,7 @@ |
218 | 219 | $rating = $( '#' + rating.ratingdesc ), |
219 | 220 | count = rating.count, |
220 | 221 | total = rating.total / count, |
221 | | - label = mw.usability.getMsg( 'articleassessment-noratings', [total, count] ); |
| 222 | + label = $.ArticleAssessment.fn.getMsg( 'articleassessment-noratings', [total, count] ); |
222 | 223 | $rating |
223 | 224 | .find( '.article-assessment-rating-field-value' ) |
224 | 225 | .text( total ) |
— | — | @@ -235,7 +236,7 @@ |
236 | 237 | $( '.ui-stars-star-on' ) |
237 | 238 | .addClass( 'ui-stars-star-stale' ); |
238 | 239 | // add the stale message |
239 | | - var msg = mw.usability.getMsg( 'articleassessment-stalemessage-revisioncount' ) |
| 240 | + var msg = $.ArticleAssessment.fn.getMsg( 'articleassessment-stalemessage-revisioncount' ) |
240 | 241 | .replace( /'''([^']*)'''/g, '<strong>$1</strong>' ) |
241 | 242 | .replace( /''([^']*)''/g, '<em>$1</em>' ); |
242 | 243 | $.ArticleAssessment.fn.flashNotice( msg, { 'class': 'article-assessment-stale-msg' } ); |
— | — | @@ -274,7 +275,7 @@ |
275 | 276 | 'aar2' : results['neutrality'], |
276 | 277 | 'aar3' : results['completeness'], |
277 | 278 | 'aar4' : results['readability'], |
278 | | - 'aauserid': config.userID, |
| 279 | + 'aaanontoken': config.userID, |
279 | 280 | 'format': 'json' |
280 | 281 | }, |
281 | 282 | dataType: 'json', |
— | — | @@ -311,10 +312,31 @@ |
312 | 313 | $( '#article-assessment .article-assessment-submit' ) |
313 | 314 | .append( $msg ); |
314 | 315 | } |
315 | | - } |
| 316 | + }, |
| 317 | + 'addMessages': function( messages ) { |
| 318 | + for ( var key in messages ) { |
| 319 | + $.ArticleAssessment.messages[key] = messages[key]; |
| 320 | + } |
| 321 | + }, |
| 322 | + /** |
| 323 | + * Get a message |
| 324 | + */ |
| 325 | + 'getMsg': function( key, args ) { |
| 326 | + if ( !( key in $.ArticleAssessment.messages ) ) { |
| 327 | + return '[' + key + ']'; |
| 328 | + } |
| 329 | + var msg = $.ArticleAssessment.messages[key]; |
| 330 | + if ( typeof args == 'object' || typeof args == 'array' ) { |
| 331 | + for ( var argKey in args ) { |
| 332 | + msg = msg.replace( '\$' + (parseInt( argKey ) + 1), args[argKey] ); |
| 333 | + } |
| 334 | + } else if ( typeof args == 'string' || typeof args == 'number' ) { |
| 335 | + msg = msg.replace( '$1', args ); |
| 336 | + } |
| 337 | + return msg; |
| 338 | + } |
316 | 339 | } |
317 | 340 | }; |
318 | | - // FIXME - this should be moved out of here |
319 | 341 | $( document ).ready( function () { |
320 | 342 | $.ArticleAssessment.fn.init( ); |
321 | 343 | } ); //document ready |