r72142 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72141‎ | r72142 | r72143 >
Date:18:39, 1 September 2010
Author:adam
Status:deferred
Tags:
Comment:
Removing the dependency on the usability extension
Modified paths:
  • /trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.hooks.php (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.hooks.php
@@ -107,7 +107,7 @@
108108 // Add javascript to document
109109 if ( count( self::$messages ) > 0 ) {
110110 $out->addScript( Html::inlineScript(
111 - 'mw.usability.addMessages({' . implode( ',', self::$messages ) . '});'
 111+ '$j.ArticleAssessment.fn.addMessages({' . implode( ',', self::$messages ) . '});'
112112 ) );
113113 }
114114
Index: trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.js
@@ -6,6 +6,7 @@
77 'pageID': wgArticleId,
88 'revID': wgCurRevisionId
99 },
 10+ 'messages': {},
1011 'settings': {
1112 'endpoint': wgScriptPath + '/api.php?',
1213 'fieldMessages' : [
@@ -86,27 +87,27 @@
8788 }
8889 // setup our markup using the template varibales in settings
8990 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')
9293 .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' )
9697 .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' )
9899 .replace( /\[\[\|([^\]]*)\]\]/, '<a href="#">$1</a>' ) ) );
99100 for( var field in settings.fieldMessages ) {
100101 $output.find( '.article-assessment-rating-fields' )
101102 .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] ) )
103104 .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 ) ) ) );
105106 $output.find( '#article-assessment-ratings' )
106107 .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]) )
108109 .replace( /\{FIELD\}/g, settings.fieldMessages[field] )
109110 .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] ) ) )
111112 );
112113 }
113114 // store our settings and configuration for later
@@ -217,7 +218,7 @@
218219 $rating = $( '#' + rating.ratingdesc ),
219220 count = rating.count,
220221 total = rating.total / count,
221 - label = mw.usability.getMsg( 'articleassessment-noratings', [total, count] );
 222+ label = $.ArticleAssessment.fn.getMsg( 'articleassessment-noratings', [total, count] );
222223 $rating
223224 .find( '.article-assessment-rating-field-value' )
224225 .text( total )
@@ -235,7 +236,7 @@
236237 $( '.ui-stars-star-on' )
237238 .addClass( 'ui-stars-star-stale' );
238239 // add the stale message
239 - var msg = mw.usability.getMsg( 'articleassessment-stalemessage-revisioncount' )
 240+ var msg = $.ArticleAssessment.fn.getMsg( 'articleassessment-stalemessage-revisioncount' )
240241 .replace( /'''([^']*)'''/g, '<strong>$1</strong>' )
241242 .replace( /''([^']*)''/g, '<em>$1</em>' );
242243 $.ArticleAssessment.fn.flashNotice( msg, { 'class': 'article-assessment-stale-msg' } );
@@ -274,7 +275,7 @@
275276 'aar2' : results['neutrality'],
276277 'aar3' : results['completeness'],
277278 'aar4' : results['readability'],
278 - 'aauserid': config.userID,
 279+ 'aaanontoken': config.userID,
279280 'format': 'json'
280281 },
281282 dataType: 'json',
@@ -311,10 +312,31 @@
312313 $( '#article-assessment .article-assessment-submit' )
313314 .append( $msg );
314315 }
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+ }
316339 }
317340 };
318 - // FIXME - this should be moved out of here
319341 $( document ).ready( function () {
320342 $.ArticleAssessment.fn.init( );
321343 } ); //document ready

Status & tagging log