r76932 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76931‎ | r76932 | r76933 >
Date:01:05, 18 November 2010
Author:tparscal
Status:deferred (Comments)
Tags:
Comment:
* Updated jquery.tipsy and added it to the Resources manifest
* Got everything working again
* Converted client-side localizations to use mediaWiki.msg
* Removed local version of tipsy (MediaWiki has a newer one)
* Started doing some line breaking, but decided to hold off on doing all of it for now
Modified paths:
  • /trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.hooks.php (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.php (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/modules/ext.articleAssessment/ext.articleAssessment.css (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/modules/ext.articleAssessment/ext.articleAssessment.js (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/modules/jquery.stars/images/jquery.ui.stars.gif (deleted) (history)
  • /trunk/extensions/ArticleAssessmentPilot/modules/jquery.stars/jquery.stars.css (added) (history)
  • /trunk/extensions/ArticleAssessmentPilot/modules/jquery.tipsy (deleted) (history)

Diff [purge]

Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.php
@@ -1,7 +1,19 @@
22 <?php
 3+/**
 4+ * Article Assessment Pilot extension
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ *
 9+ * @author Trevor Parscal <trevor@wikimedia.org>
 10+ * @license GPL v2 or later
 11+ * @version 0.1.0
 12+ */
313
4 -// If the number of page revisions (since users last rating) is greater than this
5 -// then consider the last rating "stale"
 14+/* Configuration */
 15+
 16+// If the number of page revisions (since users last rating) is greater than this then consider the
 17+// last rating "stale"
618 $wgArticleAssessmentStaleCount = 5;
719
820 // Array of the "ratings" id's to store. Allows it to be a bit more dynamic
@@ -9,54 +21,8 @@
1022
1123 // Which categories the pages must belong to have the rating widget added (with _ in text)
1224 // Extension is "disabled" if this field is an empty array (as per default configuration)
13 -$wgArticleAssessmentCategories = array( );
 25+$wgArticleAssessmentCategories = array();
1426
15 -// Set to 'combined' or 'raw' if you need to debug this extension's JS
16 -$wgArticleAssessmentResourceMode = 'minified';
17 -
18 -// Path to jQuery UI's JS
19 -$wgArticleAssessmentJUIJSPath = null; // Defaults to "$wgExtensionAssetsPath/ArticleAssessmentPilot/js/jui.combined.min.js"
20 -
21 -// Path to jQuery UI's CSS
22 -$wgArticleAssessmentJUICSSPath = null; // Defaults to "$wgExtensionAssetsPath/ArticleAssessmentPilot/css/jquery-ui-1.7.2.css"
23 -
24 -// Auto-load files
25 -$dir = dirname( __FILE__ ) . '/';
26 -$wgAutoloadClasses['ApiQueryArticleAssessment'] = $dir . 'api/ApiQueryArticleAssessment.php';
27 -$wgAutoloadClasses['ApiArticleAssessment'] = $dir . 'api/ApiArticleAssessment.php';
28 -$wgAutoloadClasses['ArticleAssessmentPilotHooks'] = $dir . 'ArticleAssessmentPilot.hooks.php';
29 -
30 -// Schema and tables
31 -$wgHooks['LoadExtensionSchemaUpdates'][] = 'ArticleAssessmentPilotHooks::schema';
32 -$wgHooks['ParserTestTables'][] = 'ArticleAssessmentPilotHooks::parserTestTables';
33 -
34 -// Hooks
35 -$wgHooks['BeforePageDisplay'][] = 'ArticleAssessmentPilotHooks::addResources';
36 -$wgHooks['MakeGlobalVariablesScript'][] = 'ArticleAssessmentPilotHooks::addVariables';
37 -
38 -// API modules
39 -$wgAPIListModules['articleassessment'] = 'ApiQueryArticleAssessment';
40 -$wgAPIModules['articleassessment'] = 'ApiArticleAssessment';
41 -
42 -// i18n and aliases
43 -// Adds Internationalized Messages
44 -$wgExtensionMessagesFiles['ArticleAssessmentPilot'] = $dir . 'ArticleAssessmentPilot.i18n.php';
45 -
46 -// Credits
47 -$wgExtensionCredits['other'][] = array(
48 - 'path' => __FILE__,
49 - 'name' => 'Article Assessment Pilot',
50 - 'author' => array( 'Nimish Gautam', 'Sam Reed', 'Adam Miller' ),
51 - 'version' => '1.0.0',
52 - 'descriptionmsg' => 'articleassessment-desc',
53 - 'url' => 'http://www.mediawiki.org/wiki/Extension:ArticleAssessmentPilot'
54 -);
55 -
56 -// Survey setup
57 -// This is totally a hack, but it's easy and had to be done fast
58 -// Should be used with SimpleSurvey 0.1
59 -require_once( $dir . '../SimpleSurvey/SimpleSurvey.php' );
60 -
6127 // Would ordinarily call this articleassessment but survey names are 16 chars max
6228 $wgPrefSwitchSurveys['articlerating'] = array(
6329 'updatable' => false,
@@ -91,3 +57,39 @@
9258 ),
9359 );
9460 $wgValidSurveys[] = 'articlerating';
 61+
 62+/* Setup */
 63+
 64+$wgExtensionCredits['other'][] = array(
 65+ 'path' => __FILE__,
 66+ 'name' => 'Article Assessment Pilot',
 67+ 'author' => array(
 68+ 'Sam Reed',
 69+ 'Roan Kattouw',
 70+ 'Trevor Parscal',
 71+ 'Brandon Harris',
 72+ 'Adam Miller',
 73+ 'Nimish Gautam',
 74+ ),
 75+ 'version' => '0.2.0',
 76+ 'descriptionmsg' => 'articleassessment-desc',
 77+ 'url' => 'http://www.mediawiki.org/wiki/Extension:ArticleAssessmentPilot'
 78+);
 79+$dir = dirname( __FILE__ ) . '/';
 80+// Autoloading
 81+$wgAutoloadClasses['ApiQueryArticleAssessment'] = $dir . 'api/ApiQueryArticleAssessment.php';
 82+$wgAutoloadClasses['ApiArticleAssessment'] = $dir . 'api/ApiArticleAssessment.php';
 83+$wgAutoloadClasses['ArticleAssessmentPilotHooks'] = $dir . 'ArticleAssessmentPilot.hooks.php';
 84+$wgExtensionMessagesFiles['ArticleAssessmentPilot'] = $dir . 'ArticleAssessmentPilot.i18n.php';
 85+// Hooks
 86+$wgHooks['LoadExtensionSchemaUpdates'][] = 'ArticleAssessmentPilotHooks::loadExtensionSchemaUpdates';
 87+$wgHooks['ParserTestTables'][] = 'ArticleAssessmentPilotHooks::parserTestTables';
 88+$wgHooks['BeforePageDisplay'][] = 'ArticleAssessmentPilotHooks::beforePageDisplay';
 89+$wgHooks['ResourceLoaderRegisterModules'][] = 'ArticleAssessmentPilotHooks::resourceLoaderRegisterModules';
 90+// API Registration
 91+$wgAPIListModules['articleassessment'] = 'ApiQueryArticleAssessment';
 92+$wgAPIModules['articleassessment'] = 'ApiArticleAssessment';
 93+
 94+/* XXX: Survey setup */
 95+
 96+require_once( $dir . '../SimpleSurvey/SimpleSurvey.php' );
Index: trunk/extensions/ArticleAssessmentPilot/modules/ext.articleAssessment/ext.articleAssessment.css
@@ -1,63 +1,7 @@
2 -/*!
3 - * jQuery UI Stars v3.0.1
4 - * http://plugins.jquery.com/project/Star_Rating_widget
5 - *
6 - * Copyright (c) 2010 Marek "Orkan" Zajac (orkans@gmail.com)
7 - * Dual licensed under the MIT and GPL licenses.
8 - * http://docs.jquery.com/License
9 - *
10 - * $Rev: 164 $
11 - * $Date:: 2010-05-01 #$
12 - * $Build: 35 (2010-05-01)
13 - *
 2+/*
 3+ * Styles for Article Assessment
144 */
15 -.article-assessment-wrapper .ui-stars-star {
16 - float: left;
17 - display: block;
18 - overflow: hidden;
19 - text-indent: -999em;
20 - cursor: pointer;
21 - padding-right: 4px;
22 -}
23 -.article-assessment-wrapper .ui-stars-star a {
24 - width: 21px;
25 - height: 21px;
26 - line-height: 0;
27 - display: block;
28 - background: url(../images/stars.gif) no-repeat 0 0;
29 -}
30 -.article-assessment-wrapper .ui-stars-star a {
31 - background-position: 0 0px;
32 -}
335
34 -.article-assessment-wrapper .ui-stars-star-on a {
35 - background-position: 0 -21px;
36 -}
37 -.article-assessment-wrapper .ui-stars-star-rated a {
38 - background-position: 0 -42px;
39 -}
40 -.article-assessment-wrapper .ui-stars-star-stale a {
41 - background-position: 0 -63px;
42 -}
43 -.article-assessment-wrapper .ui-stars-star-hover a {
44 - background-position: 0 -21px;
45 -}
46 -.article-assessment-wrapper .ui-stars-star-disabled,
47 -.article-assessment-wrapper .ui-stars-star-disabled a {
48 - cursor: default !important;
49 -}
50 -.article-assessment-wrapper .ui-stars-cancel {
51 - display: none;
52 -}
53 -/* End ui-stars styles */
54 -
55 -/* Tipsy Styles */
56 -.tipsy { padding: 5px 5px 10px; font-size: 12px; position: absolute; z-index: 100000; overflow: visible; }
57 -.tipsy-inner { padding: 5px 8px 4px 8px; background-color: #d6f3ff; color: black; border: 1px solid #5dc9f4; max-width: 300px; text-align: left; }
58 -.tipsy-arrow { position: absolute; background: url( '../images/arrow.gif' ) no-repeat top left; width: 13px; height: 13px; }
59 -.tipsy-se .tipsy-arrow { bottom: -2px; right: 10px; background-position: 0% 100%; }
60 -
61 -/* End Tipsy styles */
626 .article-assessment-wrapper #article-assessment-rate,
637 .article-assessment-wrapper #article-assessment-ratings {
648 background: #f7f7f7;
@@ -95,10 +39,10 @@
9640 height: 24px;
9741 display: block;
9842 float: right;
99 - background: url(../images/question.gif) 0 50% no-repeat;
 43+ background: url(images/question.gif) 0 50% no-repeat;
10044 }
10145 .article-assessment-wrapper .rating-field-hint:hover {
102 - background: url(../images/question-hover.gif) 0 50% no-repeat;
 46+ background: url(images/question-hover.gif) 0 50% no-repeat;
10347 }
10448
10549 .article-assessment-wrapper .article-assessment-flash {
@@ -128,7 +72,7 @@
12973 font-size: 11px;
13074 }
13175 .article-assessment-wrapper .article-assessment-rating-field-value-wrapper {
132 - background: url( ../images/rating_bg.gif ) 0 0 no-repeat;
 76+ background: url(images/rating_bg.gif) 0 0 no-repeat;
13377 width: 120px;
13478 height: 13px;
13579 display: block;
@@ -151,7 +95,7 @@
15296 float: right;
15397 }
15498 .article-assessment-wrapper .article-assessment-rating-field-value-wrapper .article-assessment-rating-field-value {
155 - background: url( ../images/rating_bar.gif ) 0 0 no-repeat;
 99+ background: url(images/rating_bar.gif) 0 0 no-repeat;
156100 height: 9px;
157101 float: right;
158102 display: block;
@@ -172,7 +116,7 @@
173117 float: right;
174118 }
175119 .article-assessment-wrapper .article-assessment-ratings-disabled .article-assessment-rating-field-value-wrapper {
176 - background: url( ../images/rating_disabled_bg.gif ) 0 0 no-repeat;
 120+ background: urlimages/rating_disabled_bg.gif) 0 0 no-repeat;
177121 }
178122 .article-assessment-wrapper .article-assessment-ratings-disabled .article-assessment-rating-field-value {
179123 display: none;
@@ -190,7 +134,7 @@
191135 display: block;
192136 height: 24px;
193137 width: 24px;
194 - background: url( ../images/loading.gif ) center no-repeat;
 138+ background: url(images/loading.gif) center no-repeat;
195139 text-indent: -9999px;
196140 margin: 0 auto;
197141 }
Index: trunk/extensions/ArticleAssessmentPilot/modules/ext.articleAssessment/ext.articleAssessment.js
@@ -77,20 +77,24 @@
7878 return randomstring;
7979 }
8080 userToken = randomString( 32 );
81 - $.cookie( 'mwArticleAssessmentUserToken', userToken, { 'expires': 30, 'path': '/' } );
 81+ $.cookie(
 82+ 'mwArticleAssessmentUserToken',
 83+ userToken,
 84+ { 'expires': 30, 'path': '/' }
 85+ );
8286 }
8387 if ( !wgUserName ) {
8488 config.userID = userToken;
8589 }
8690 // setup our markup using the template variables in settings
8791 var $structure = $( settings.structureHTML ),
88 - instructions = $.ArticleAssessment.fn.getMsg( 'articleassessment-pleaserate' ),
89 - feedback = $.ArticleAssessment.fn.getMsg( 'articleassessment-featurefeedback' ),
90 - yourfeedback = $.ArticleAssessment.fn.getMsg( 'articleassessment-yourfeedback'),
91 - articlerating = $.ArticleAssessment.fn.getMsg( 'articleassessment-articlerating' ),
92 - resultshide = $.ArticleAssessment.fn.getMsg( 'articleassessment-results-hide' ),
93 - resultsshow = $.ArticleAssessment.fn.getMsg( 'articleassessment-results-show' );
94 - submitbutton = $.ArticleAssessment.fn.getMsg( 'articleassessment-submit' );
 92+ instructions = mediaWiki.msg( 'articleassessment-pleaserate' ),
 93+ feedback = mediaWiki.msg( 'articleassessment-featurefeedback' ),
 94+ yourfeedback = mediaWiki.msg( 'articleassessment-yourfeedback'),
 95+ articlerating = mediaWiki.msg( 'articleassessment-articlerating' ),
 96+ resultshide = mediaWiki.msg( 'articleassessment-results-hide' ),
 97+ resultsshow = mediaWiki.msg( 'articleassessment-results-show' );
 98+ submitbutton = mediaWiki.msg( 'articleassessment-submit' );
9599 $structure
96100 .find( '#article-assessment-rate legend' )
97101 .html( yourfeedback )
@@ -140,10 +144,13 @@
141145 for ( var i = 0; i < settings.fieldMessages.length; i++ ) {
142146 var $field = $( settings.fieldHTML ),
143147 $rating = $( settings.ratingHTML ),
144 - label = $.ArticleAssessment.fn.getMsg( settings.fieldPrefix + settings.fieldMessages[i] ),
 148+ label = mediaWiki.msg( settings.fieldPrefix + settings.fieldMessages[i] ),
145149 field = settings.fieldMessages[i],
146 - hint = $.ArticleAssessment.fn.getMsg( settings.fieldPrefix + settings.fieldMessages[i] + settings.fieldHintSuffix ),
147 - count = $.ArticleAssessment.fn.getMsg( 'articleassessment-noratings', [0, 0] );
 150+ hint = mediaWiki.msg(
 151+ settings.fieldPrefix + settings.fieldMessages[i] +
 152+ settings.fieldHintSuffix
 153+ ),
 154+ count = mediaWiki.msg( 'articleassessment-noratings', 0, 0 );
148155 // initialize the field html
149156 $field
150157 .attr( 'id', 'articleassessment-rate-' + field )
@@ -172,24 +179,32 @@
173180 .append( $rating );
174181 }
175182 // store our settings and configuration for later
176 - $structure.find( '#article-assessment' ).data( 'articleAssessment-context', { 'settings': settings, 'config': config } );
 183+ $structure.find( '#article-assessment' )
 184+ .data(
 185+ 'articleAssessment-context',
 186+ { 'settings': settings, 'config': config }
 187+ );
177188 $( '#catlinks' ).before( $structure );
178189 // Hide the ratings initially
179190 $.ArticleAssessment.fn.hideRatings();
180191
181192
182193 // set the height of our smaller fieldset to match the taller
183 - if ( $( '#article-assessment-rate' ).height() > $( '#article-assessment-ratings' ).height() ) {
184 - $( '#article-assessment-ratings' ).css( 'minHeight', $( '#article-assessment-rate' ).height() );
 194+ if (
 195+ $( '#article-assessment-rate' ).height() >
 196+ $( '#article-assessment-ratings' ).height() ) {
 197+ $( '#article-assessment-ratings' )
 198+ .css( 'minHeight', $( '#article-assessment-rate' ).height() );
185199 } else {
186 - $( '#article-assessment-rate' ).css( 'minHeight', $( '#article-assessment-ratings' ).height() );
 200+ $( '#article-assessment-rate' )
 201+ .css( 'minHeight', $( '#article-assessment-ratings' ).height() );
187202 }
188203 // attempt to fetch the ratings
189204 $.ArticleAssessment.fn.getRatingData();
190205
191206 // initialize the star plugin
192207 $( '.rating-field' ).each( function() {
193 - $( this )
 208+ $(this)
194209 .wrapAll( '<div class="rating-field"></div>' )
195210 .parent()
196211 .stars( {
@@ -197,20 +212,21 @@
198213 callback: function( value, link ) {
199214 // remove any stale or rated classes
200215 value.$stars.each( function() {
201 - $( this )
 216+ $(this)
202217 .removeClass( 'ui-stars-star-stale' )
203218 .removeClass( 'ui-stars-star-rated' );
204219 // enable our submit button if it's still disabled
205 - $( '#article-assessment input:disabled' ).removeAttr( 'disabled' );
 220+ $( '#article-assessment input:disabled' )
 221+ .removeAttr( 'disabled' );
206222 } );
207223 }
208224 } );
209 - });
 225+ } );
210226 // intialize the tooltips
211227 $( '.field-wrapper label[original-title]' ).each( function() {
212 - $( this )
 228+ $(this)
213229 .after( $( '<span class="rating-field-hint" />' )
214 - .attr( 'original-title', $( this ).attr( 'original-title' ) )
 230+ .attr( 'original-title', $(this).attr( 'original-title' ) )
215231 .tipsy( { gravity : 'se', opacity: '0.9' } ) );
216232 } );
217233 // bind submit event to the form
@@ -262,7 +278,7 @@
263279 dataType: 'json',
264280 success: $.ArticleAssessment.fn.afterGetRatingData,
265281 error: function( XMLHttpRequest, textStatus, errorThrown ) {
266 - $.ArticleAssessment.fn.flashNotice( $.ArticleAssessment.fn.getMsg( 'articleassessment-error' ),
 282+ $.ArticleAssessment.fn.flashNotice( mediaWiki.msg( 'articleassessment-error' ),
267283 { 'class': 'article-assessment-error-msg' } );
268284 }
269285 } );
@@ -278,7 +294,7 @@
279295 $rating = $( '#' + rating.ratingdesc ),
280296 count = rating.count,
281297 total = ( rating.total / count ).toFixed( 1 ),
282 - label = $.ArticleAssessment.fn.getMsg( 'articleassessment-noratings', [total, count] );
 298+ label = mediaWiki.msg( 'articleassessment-noratings', total, count );
283299 $rating
284300 .find( '.article-assessment-rating-field-value' )
285301 .text( total )
@@ -302,7 +318,7 @@
303319 $( '.ui-stars-star-on' )
304320 .addClass( 'ui-stars-star-stale' );
305321 // add the stale message
306 - var msg = $.ArticleAssessment.fn.getMsg( 'articleassessment-stalemessage-norevisioncount' );
 322+ var msg = mediaWiki.msg( 'articleassessment-stalemessage-norevisioncount' );
307323 $.ArticleAssessment.fn.flashNotice( msg, { 'class': 'article-assessment-stale-msg' } );
308324 } else {
309325 // if it's not a stale rating, we want to make the stars blue
@@ -311,9 +327,9 @@
312328 }
313329 // initialize the ratings
314330 $( '.article-assessment-rating-field-value' ).each( function() {
315 - $( this )
 331+ $(this)
316332 .css( {
317 - 'width': 120 - ( 120 * ( parseFloat( $( this ).text() ) / 5 ) ) + 'px'
 333+ 'width': 120 - ( 120 * ( parseFloat( $(this).text() ) / 5 ) ) + 'px'
318334 } )
319335 } );
320336 },
@@ -330,8 +346,8 @@
331347 $( '.rating-field input' ).each( function() {
332348 // expects the hidden inputs to have names like 'rating[field-name]' which we use to
333349 // be transparent about what values we're sending to the server
334 - var fieldName = $( this ).attr( 'name' ).match( /\[([a-zA-Z0-9\-]*)\]/ )[1];
335 - results[ fieldName ] = $( this ).val();
 350+ var fieldName = $(this).attr( 'name' ).match( /\[([a-zA-Z0-9\-]*)\]/ )[1];
 351+ results[ fieldName ] = $(this).val();
336352 } );
337353 var request = $.ajax( {
338354 url: wgScriptPath + '/api.php',
@@ -350,7 +366,7 @@
351367 dataType: 'json',
352368 success: $.ArticleAssessment.fn.afterSubmitRating,
353369 error: function( XMLHttpRequest, textStatus, errorThrown ) {
354 - $.ArticleAssessment.fn.flashNotice( $.ArticleAssessment.fn.getMsg( 'articleassessment-error' ),
 370+ $.ArticleAssessment.fn.flashNotice( mediaWiki.msg( 'articleassessment-error' ),
355371 { 'class': 'article-assessment-error-msg' } );
356372 }
357373 } );
@@ -368,7 +384,7 @@
369385 // show the results
370386 $.ArticleAssessment.fn.showRatings();
371387 // say thank you
372 - $.ArticleAssessment.fn.flashNotice( $.ArticleAssessment.fn.getMsg( 'articleassessment-thanks' ),
 388+ $.ArticleAssessment.fn.flashNotice( mediaWiki.msg( 'articleassessment-thanks' ),
373389 { 'class': 'article-assessment-success-msg' } );
374390 },
375391 // places a message on the interface
@@ -394,37 +410,35 @@
395411 }
396412 },
397413 'showFeedback': function() {
398 - $.ArticleAssessment.fn.withJUI( function() {
399 - var $dialogDiv = $( '#article-assessment-dialog' );
400 - if ( $dialogDiv.size() == 0 ) {
401 - $dialogDiv = $( '<div id="article-assessment-dialog" class="loading" />' )
402 - .dialog( {
403 - width: 600,
404 - height: 400,
405 - bgiframe: true,
406 - autoOpen: true,
407 - modal: true,
408 - title: $.ArticleAssessment.fn.getMsg( 'articleassessment-survey-title' ),
409 - close: function() {
410 - $( this )
411 - .dialog( 'option', 'height', 400 )
412 - .find( '.article-assessment-success-msg, .article-assessment-error-msg' )
413 - .remove()
414 - .end()
415 - .find( 'form' )
416 - .show();
417 - }
418 - } );
419 - $dialogDiv.load(
420 - wgScript + '?title=Special:SimpleSurvey&survey=articlerating&raw=1',
421 - function() {
422 - $( this ).find( 'form' ).bind( 'submit', $.ArticleAssessment.fn.submitFeedback );
423 - $( this ).removeClass( 'loading' );
 414+ var $dialogDiv = $( '#article-assessment-dialog' );
 415+ if ( $dialogDiv.size() == 0 ) {
 416+ $dialogDiv = $( '<div id="article-assessment-dialog" class="loading" />' )
 417+ .dialog( {
 418+ width: 600,
 419+ height: 400,
 420+ bgiframe: true,
 421+ autoOpen: true,
 422+ modal: true,
 423+ title: mediaWiki.msg( 'articleassessment-survey-title' ),
 424+ close: function() {
 425+ $(this)
 426+ .dialog( 'option', 'height', 400 )
 427+ .find( '.article-assessment-success-msg, .article-assessment-error-msg' )
 428+ .remove()
 429+ .end()
 430+ .find( 'form' )
 431+ .show();
424432 }
425 - );
426 - }
427 - $dialogDiv.dialog( 'open' );
428 - } );
 433+ } );
 434+ $dialogDiv.load(
 435+ wgScript + '?title=Special:SimpleSurvey&survey=articlerating&raw=1',
 436+ function() {
 437+ $(this).find( 'form' ).bind( 'submit', $.ArticleAssessment.fn.submitFeedback );
 438+ $(this).removeClass( 'loading' );
 439+ }
 440+ );
 441+ }
 442+ $dialogDiv.dialog( 'open' );
429443 return false;
430444 },
431445 'submitFeedback': function() {
@@ -439,16 +453,16 @@
440454 var formData = {};
441455 $dialogDiv.find( 'input[type=text], input[type=radio]:checked, input[type=checkbox]:checked, ' +
442456 'input[type=hidden], textarea' ).each( function() {
443 - var name = $( this ).attr( 'name' );
 457+ var name = $(this).attr( 'name' );
444458 if ( name !== '' ) {
445459 if ( name.substr( -2 ) == '[]' ) {
446460 var trimmedName = name.substr( 0, name.length - 2 );
447461 if ( typeof formData[trimmedName] == 'undefined' ) {
448462 formData[trimmedName] = [];
449463 }
450 - formData[trimmedName].push( $( this ).val() );
 464+ formData[trimmedName].push( $(this).val() );
451465 } else {
452 - formData[name] = $( this ).val();
 466+ formData[name] = $(this).val();
453467 }
454468 }
455469 } );
@@ -466,15 +480,13 @@
467481 // TODO: Style success-msg, error-msg
468482 var $msgDiv = $( '<div />' )
469483 .addClass( success ? 'article-assessment-success-msg' : 'article-assessment-error-msg' )
470 - .html( $.ArticleAssessment.fn.getMsg( success? 'articleassessment-survey-thanks' : 'articleassessment-error' ) )
 484+ .html( mediaWiki.msg( success? 'articleassessment-survey-thanks' : 'articleassessment-error' ) )
471485 .appendTo( $dialogDiv );
472486 $dialogDiv.removeClass( 'loading' );
473487
474488 // This is absurdly unnecessary from the looks of it, but it seems this is somehow
475489 // needed in certain cases.
476 - $.ArticleAssessment.fn.withJUI( function() {
477 - $dialogDiv.dialog( 'option', 'height', $msgDiv.height() + 100 )
478 - } );
 490+ $dialogDiv.dialog( 'option', 'height', $msgDiv.height() + 100 );
479491
480492 if ( success ) {
481493 // Hide the dialog link
@@ -488,45 +500,13 @@
489501 // TODO: Duplicates code, factor out, maybe
490502 var $msgDiv = $( '<div />' )
491503 .addClass( 'article-assessment-error-msg' )
492 - .html( $.ArticleAssessment.fn.getMsg( 'articleassessment-error' ) )
 504+ .html( mediaWiki.msg( 'articleassessment-error' ) )
493505 .appendTo( $dialogDiv );
494506 $dialogDiv.removeClass( 'loading' );
495 - $.ArticleAssessment.fn.withJUI( function() {
496 - $dialogDiv.dialog( 'option', 'height', $msgDiv.height() + 100 )
497 - } );
 507+ $dialogDiv.dialog( 'option', 'height', $msgDiv.height() + 100 );
498508 }
499509 } );
500510 return false;
501 - },
502 - 'addMessages': function( messages ) {
503 - for ( var key in messages ) {
504 - $.ArticleAssessment.messages[key] = messages[key];
505 - }
506 - },
507 - /**
508 - * Get a message
509 - * FIXME: Parameter expansion is broken in all sorts of edge cases
510 - */
511 - 'getMsg': function( key, args ) {
512 - if ( !( key in $.ArticleAssessment.messages ) ) {
513 - return '[' + key + ']';
514 - }
515 - var msg = $.ArticleAssessment.messages[key];
516 - if ( typeof args == 'object' || typeof args == 'array' ) {
517 - for ( var i = 0; i < args.length; i++ ) {
518 - msg = msg.replace( new RegExp( '\\$' + ( parseInt( i ) + 1 ), 'g' ), args[i] );
519 - }
520 - } else if ( typeof args == 'string' || typeof args == 'number' ) {
521 - msg = msg.replace( /\$1/g, args );
522 - }
523 - return msg;
524 - },
525 - 'withJUI': function( callback ) {
526 - if ( typeof $.ui == 'undefined' ) {
527 - $.getScript( wgArticleAssessmentJUIPath, callback );
528 - } else {
529 - callback();
530 - }
531511 }
532512 }
533513 };
Index: trunk/extensions/ArticleAssessmentPilot/modules/jquery.stars/jquery.stars.css
@@ -0,0 +1,51 @@
 2+/*!
 3+ * jQuery UI Stars v3.0.1
 4+ * http://plugins.jquery.com/project/Star_Rating_widget
 5+ *
 6+ * Copyright (c) 2010 Marek "Orkan" Zajac (orkans@gmail.com)
 7+ * Dual licensed under the MIT and GPL licenses.
 8+ * http://docs.jquery.com/License
 9+ *
 10+ * $Rev: 164 $
 11+ * $Date:: 2010-05-01 #$
 12+ * $Build: 35 (2010-05-01)
 13+ *
 14+ */
 15+.ui-stars-star {
 16+ float: left;
 17+ display: block;
 18+ overflow: hidden;
 19+ text-indent: -999em;
 20+ cursor: pointer;
 21+ padding-right: 4px;
 22+}
 23+.ui-stars-star a {
 24+ width: 21px;
 25+ height: 21px;
 26+ line-height: 0;
 27+ display: block;
 28+ background: url(images/stars.gif) no-repeat 0 0;
 29+}
 30+.ui-stars-star a {
 31+ background-position: 0 0px;
 32+}
 33+
 34+.ui-stars-star-on a {
 35+ background-position: 0 -21px;
 36+}
 37+.ui-stars-star-rated a {
 38+ background-position: 0 -42px;
 39+}
 40+.ui-stars-star-stale a {
 41+ background-position: 0 -63px;
 42+}
 43+.ui-stars-star-hover a {
 44+ background-position: 0 -21px;
 45+}
 46+.ui-stars-star-disabled,
 47+.ui-stars-star-disabled a {
 48+ cursor: default !important;
 49+}
 50+.ui-stars-cancel {
 51+ display: none;
 52+}
Property changes on: trunk/extensions/ArticleAssessmentPilot/modules/jquery.stars/jquery.stars.css
___________________________________________________________________
Added: svn:eol-style
153 + native
Added: svn:mime-type
254 + text/plain
Index: trunk/extensions/ArticleAssessmentPilot/modules/jquery.stars/images/jquery.ui.stars.gif
Cannot display: file marked as a binary type.
svn:mime-type = image/gif
Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.hooks.php
@@ -1,43 +1,57 @@
22 <?php
3 -
43 /**
54 * Hooks for ArticleAssessmentPilot
65 *
76 * @file
87 * @ingroup Extensions
98 */
 9+
1010 class ArticleAssessmentPilotHooks {
11 - private static $styleFiles = array(
12 - 'raw' => array(
13 - array( 'src' => 'css/ArticleAssessment.css', 'version' => 1 ),
 11+
 12+ protected static $modules = array(
 13+ 'ext.articleAssessment' => array(
 14+ 'scripts' => 'ext.articleAssessment/ext.articleAssessment.js',
 15+ 'styles' => 'ext.articleAssessment/ext.articleAssessment.css',
 16+ 'messages' => array(
 17+ 'articleassessment',
 18+ 'articleassessment-desc',
 19+ 'articleassessment-yourfeedback',
 20+ 'articleassessment-pleaserate',
 21+ 'articleassessment-submit',
 22+ 'articleassessment-rating-wellsourced',
 23+ 'articleassessment-rating-neutrality',
 24+ 'articleassessment-rating-completeness',
 25+ 'articleassessment-rating-readability',
 26+ 'articleassessment-rating-wellsourced-tooltip',
 27+ 'articleassessment-rating-neutrality-tooltip',
 28+ 'articleassessment-rating-completeness-tooltip',
 29+ 'articleassessment-rating-readability-tooltip',
 30+ 'articleassessment-error',
 31+ 'articleassessment-thanks',
 32+ 'articleassessment-articlerating',
 33+ 'articleassessment-featurefeedback',
 34+ 'articleassessment-noratings',
 35+ 'articleassessment-stalemessage-revisioncount',
 36+ 'articleassessment-stalemessage-norevisioncount',
 37+ 'articleassessment-results-show',
 38+ 'articleassessment-results-hide',
 39+ 'articleassessment-survey-title',
 40+ 'articleassessment-survey-thanks',
 41+ ),
 42+ 'dependencies' => array( 'jquery.ui.dialog', 'jquery.tipsy', 'jquery.stars' ),
1443 ),
15 - 'combined' => array(
16 - array( 'src' => 'css/ArticleAssessment.css', 'version' => 1 ),
 44+ 'jquery.stars' => array(
 45+ 'scripts' => 'jquery.stars/jquery.stars.js',
 46+ 'styles' => 'jquery.stars/jquery.stars.css',
1747 ),
18 - 'minified' => array(
19 - array( 'src' => 'css/ArticleAssessment.css', 'version' => 1 ),
20 - ),
2148 );
22 -
23 - private static $scriptFiles = array(
24 - 'raw' => array(
25 - array( 'src' => 'js/ArticleAssessment.js', 'version' => 5 ),
26 - array( 'src' => 'js/jquery.cookie.js', 'version' => 1 ),
27 - array( 'src' => 'js/jquery.tipsy.js', 'version' => 1 ),
28 - array( 'src' => 'js/jquery.stars.js', 'version' => 2 ),
29 - ),
30 - 'combined' => array(
31 - array( 'src' => 'js/ArticleAssessment.combined.js', 'version' => 5 )
32 - ),
33 - 'minified' => array(
34 - array( 'src' => 'js/ArticleAssessment.combined.min.js', 'version' => 5 )
35 - ),
36 - );
37 -
38 - private static $messages = array();
39 -
40 - /* Static Functions */
41 - public static function schema( $updater = null ) {
 49+
 50+ /* Static Methods */
 51+
 52+ /**
 53+ * LoadExtensionSchemaUpdates hook
 54+ */
 55+ public static function loadExtensionSchemaUpdates( $updater = null ) {
4256 if ( $updater === null ) {
4357 global $wgExtNewTables;
4458 $wgExtNewTables[] = array(
@@ -48,21 +62,11 @@
4963 $updater->addExtensionUpdate( array( 'addTable', 'article_assessment',
5064 dirname( __FILE__ ) . '/ArticleAssessmentPilot.sql', true ) );
5165 }
52 -
5366 return true;
5467 }
5568
56 - public static function addVariables( &$vars ) {
57 - global $wgArticleAssessmentJUIJSPath, $wgExtensionAssetsPath;
58 - $vars['wgArticleAssessmentJUIPath'] = $wgArticleAssessmentJUIJSPath ? $wgArticleAssessmentJUIJSPath :
59 - "$wgExtensionAssetsPath/ArticleAssessmentPilot/js/jui.combined.min.js";
60 - return true;
61 - }
62 -
6369 /**
64 - * Make sure the tables exist for parser tests
65 - * @param $tables
66 - * @return bool
 70+ * ParserTestTables hook
6771 */
6872 public static function parserTestTables( &$tables ) {
6973 $tables[] = 'article_assessment';
@@ -70,106 +74,59 @@
7175 $tables[] = 'article_assessment_ratings';
7276 return true;
7377 }
74 -
75 - public static function addResources( $out ) {
 78+
 79+ /**
 80+ * BeforePageDisplay hook
 81+ */
 82+ public static function beforePageDisplay( $out ) {
 83+ global $wgRequest, $wgArticleAssessmentCategories;
7684
7785 $title = $out->getTitle();
78 -
79 - // Chances are we only want to be rating Mainspace, right?
80 - if ( $title->getNamespace() !== NS_MAIN ) {
81 - return true;
 86+
 87+ // Restrict ratings to...
 88+ if (
 89+ // Main namespace articles
 90+ $title->getNamespace() == NS_MAIN
 91+ // View pages
 92+ && $wgRequest->getVal( 'action', 'view' ) == 'view'
 93+ // Current revision
 94+ && !$wgRequest->getCheck( 'diff' )
 95+ && !$wgRequest->getCheck( 'oldid' )
 96+ // Articles in valid categories
 97+ && count( $wgArticleAssessmentCategories )
 98+ && self::isInCategories( $title->getArticleId(), $wgArticleAssessmentCategories )
 99+ ) {
 100+ $out->addModules( 'ext.articleAssessment' );
82101 }
83 -
84 - global $wgRequest;
85 -
86 - // Only show for view actions.
87 - if ( $wgRequest->getVal( 'action', 'view' ) !== 'view' || $wgRequest->getCheck( 'diff' ) ||
88 - $wgRequest->getCheck( 'oldid' ) ) {
89 - return true;
90 - }
91 -
92 - global $wgArticleAssessmentCategories;
93 -
94 - // check if this page should have the form
95 - if ( !count( $wgArticleAssessmentCategories )
96 - || !self::isInCategories( $title->getArticleId(), $wgArticleAssessmentCategories ) ) {
97 - return true;
98 - }
99 -
100 - global $wgExtensionAssetsPath, $wgArticleAssessmentResourceMode;
101 - $mode = isset( self::$scriptFiles[$wgArticleAssessmentResourceMode] ) ? $wgArticleAssessmentResourceMode : 'minified';
102 - foreach ( self::$scriptFiles[$mode] as $script ) {
103 - $out->addScriptFile( $wgExtensionAssetsPath .
104 - "/ArticleAssessmentPilot/{$script['src']}", $script['version']
 102+ return true;
 103+ }
 104+
 105+ /*
 106+ * ResourceLoaderRegisterModules hook
 107+ */
 108+ public static function resourceLoaderRegisterModules( &$resourceLoader ) {
 109+ global $wgExtensionAssetsPath;
 110+ $localpath = dirname( __FILE__ ) . '/modules';
 111+ $remotepath = "$wgExtensionAssetsPath/ArticleAssessmentPilot/modules";
 112+ foreach ( self::$modules as $name => $resources ) {
 113+ $resourceLoader->register(
 114+ $name, new ResourceLoaderFileModule( $resources, $localpath, $remotepath )
105115 );
106116 }
107 -
108 - global $wgArticleAssessmentJUICSSPath;
109 - $out->addExtensionStyle( ( $wgArticleAssessmentJUICSSPath ? $wgArticleAssessmentJUICSSPath :
110 - "$wgExtensionAssetsPath/ArticleAssessmentPilot/css/jquery-ui-1.7.2.css" ) . '?1.7.2y'
111 - );
112 - foreach ( self::$styleFiles[$mode] as $style ) {
113 - $out->addExtensionStyle( $wgExtensionAssetsPath .
114 - "/ArticleAssessmentPilot/{$style['src']}?{$style['version']}"
115 - );
116 - }
117 -
118 - // Transforms messages into javascript object members
119 - self::$messages = array(
120 - 'articleassessment',
121 - 'articleassessment-desc',
122 - 'articleassessment-yourfeedback',
123 - 'articleassessment-pleaserate',
124 - 'articleassessment-submit',
125 - 'articleassessment-rating-wellsourced',
126 - 'articleassessment-rating-neutrality',
127 - 'articleassessment-rating-completeness',
128 - 'articleassessment-rating-readability',
129 - 'articleassessment-rating-wellsourced-tooltip',
130 - 'articleassessment-rating-neutrality-tooltip',
131 - 'articleassessment-rating-completeness-tooltip',
132 - 'articleassessment-rating-readability-tooltip',
133 - 'articleassessment-error',
134 - 'articleassessment-thanks',
135 - 'articleassessment-articlerating',
136 - 'articleassessment-featurefeedback',
137 - 'articleassessment-noratings',
138 - 'articleassessment-stalemessage-revisioncount',
139 - 'articleassessment-stalemessage-norevisioncount',
140 - 'articleassessment-results-show',
141 - 'articleassessment-results-hide',
142 - 'articleassessment-survey-title',
143 - 'articleassessment-survey-thanks',
144 - );
145 -
146 - foreach ( self::$messages as $i => $message ) {
147 - // TODO: Not parsing or even preprocessing the messages would be more efficient,
148 - // but we can't do that until we have such nice things as JS-side {{PLURAL}}
149 - // Should be OK for now in a limited deployment scenario
150 - $escapedMessageValue = Xml::escapeJsString( wfMsgExt( $message, array( 'parseinline' ) ) );
151 - $escapedMessageKey = Xml::escapeJsString( $message );
152 - self::$messages[$i] =
153 - "'{$escapedMessageKey}':'{$escapedMessageValue}'";
154 - }
155 - // Add javascript to document
156 - if ( count( self::$messages ) > 0 ) {
157 - $out->addScript( Html::inlineScript(
158 - '$j.ArticleAssessment.fn.addMessages({' . implode( ',', self::$messages ) . '});'
159 - ) );
160 - }
161 -
162117 return true;
163118 }
164 -
 119+
 120+ /* Protected Static Methods */
 121+
165122 /**
166123 * Returns whether an article is in the specified categories
167 - *
 124+ *
168125 * @param $articleId Integer: Article ID
169 - * @param $categories Array: Array of category names (without Category: prefix, with underscores)
170 - *
171 - * @return bool
 126+ * @param $categories Array: List of category names (without Category: prefix, with underscores)
 127+ *
 128+ * @return Boolean: True if article is in one of the values of $categories
172129 */
173 - private static function isInCategories( $articleId, $categories ) {
 130+ protected static function isInCategories( $articleId, $categories ) {
174131 $dbr = wfGetDB( DB_SLAVE );
175132 return (bool)$dbr->selectRow( 'categorylinks', '1',
176133 array(

Comments

#Comment by Catrope (talk | contribs)   12:15, 3 December 2010

This revision strips the withJUI() call from the dialog code, but doesn't replace it with mediaWiki.loader.using( 'jquery.ui.dialog', function() { ... } );; instead, jquery.ui.dialog is an unconditional dependency. Because of the size of JUI, the frequency of loading the AAP/AF widget and the infrequency of having to show the dialog, I think this is undesirable and on-demand loading should be used instead.

#Comment by Trevor Parscal (WMF) (talk | contribs)   19:14, 3 December 2010

Perhaps, but since we are transitioning to a fresh codebase, it's debatable that this is worth doing...

#Comment by Catrope (talk | contribs)   19:15, 3 December 2010

Do you mean we're getting rid of the dialog altogether in the future?

#Comment by Trevor Parscal (WMF) (talk | contribs)   19:18, 3 December 2010

No, I mean that the alpha code is generally ported, but the beta code is a font-end rewrite, so working on the alpha code might not be a good use of time. It wouldn't be too hard to auto-load the dialog though of course...

Status & tagging log