r72967 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72966‎ | r72967 | r72968 >
Date:12:10, 14 September 2010
Author:catrope
Status:deferred
Tags:
Comment:
ArticleAssessment: Some JS and i18n cleanup
* Use <span> tags instead of weird link syntax in messages, and explain what's going on in qqq
* Instead of trying to render bold and italic with JS-side regexes, use parseinline on the server side
* Put the code for showing and hiding the aggregate ratings in their own functions, thus avoiding having to call .click() on these links
* Make the feedback link a JS link instead of a real link to Special:ArticleAssessmentFeedback. For now this is just a dummy, but I'll implement the real functionality soon
Modified paths:
  • /trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.hooks.php (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.i18n.php (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.i18n.php
@@ -26,14 +26,14 @@
2727 'articleassessment-thanks' => 'Thanks! Your ratings have been saved.',
2828
2929 # This special page doesn't exist yet, but it will soon.
30 - 'articleassessment-featurefeedback' => 'Give us [[Special:ArticleAssessmentFeedback|feedback]] about this feature.',
 30+ 'articleassessment-featurefeedback' => 'Give us <span class="feedbacklink">feedback</span> about this feature.',
3131 'articleassessment-noratings' => '$1 ($2 {{PLURAL:$2|rating|ratings}})',
3232 'articleassessment-stalemessage-norevisioncount' => "This page has been ''revised'' since you last reviewed it.
3333 You may wish to rate it again.",
3434
3535 # Links get rewritten in javascript.
36 - 'articleassessment-results-show' => "(Results hidden. [[#|Show]] them.)",
37 - 'articleassessment-results-hide' => "([[#|Hide results]])",
 36+ 'articleassessment-results-show' => '(Results hidden. <span class="showlink">Show</span> them.)',
 37+ 'articleassessment-results-hide' => '(<span class="hidelink">Hide results</span>)',
3838 );
3939
4040 /** Message documentation (Message documentation)
@@ -67,9 +67,9 @@
6868 'articleassessment-stalemessage-greaterthancount' => 'This is a message shown to the user when their ratings are "stale". It allows for not looking up the total number of revisions.',
6969 'articleassessment-stalemessage-norevisioncount' => 'This is a message shown to the user when their ratings are "stale" and does NOT include the number of revisions. This is an ambiguous reason, and allows for us to have complicated staleness patterns. This is the preferred message.',
7070 'articleassessment-results-show' => 'This is an explanatory control that, when clicked, will display hidden aggregate ratings.
71 -The incomplete looking wikilinks get rewritten in javascript.',
 71+The span tag gets rewritten in JavaScript to become a link.',
7272 'articleassessment-results-hide' => 'This is a control that, when clicked, will hide the aggregate ratings.
73 -The incomplete looking wikilinks get rewritten in javascript.',
 73+The span tag gets rewritten in JavaScript to become a link.',
7474 );
7575
7676 /** Afrikaans (Afrikaans)
@@ -83,8 +83,8 @@
8484 'articleassessment-rating-completeness' => 'Volledig:',
8585 'articleassessment-rating-readability' => 'Leesbaar:',
8686 'articleassessment-articlerating' => 'Artikel gradering',
87 - 'articleassessment-results-show' => '(Resultate versteek. [[#|Wys]] hulle.)',
88 - 'articleassessment-results-hide' => '([[#|Versteek resultate]])',
 87+ 'articleassessment-results-show' => '(Resultate versteek. <span class="showlink">Wys</span> hulle.)',
 88+ 'articleassessment-results-hide' => '(<span class="hidelink">Versteek resultate</span>)',
8989 );
9090
9191 /** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца))
@@ -125,7 +125,7 @@
126126 'articleassessment-error' => 'Ein Fehler ist aufgetreten.
127127 Bitte versuche es später erneut.',
128128 'articleassessment-thanks' => 'Vielen Dank! Deine Einschätzung wurde gespeichert.',
129 - 'articleassessment-featurefeedback' => 'Gebe uns bitte eine [[Special:Article Assessment Feedback|Rückmeldung]] zu dieser Funktion zur Einschätzung eines Artikels.',
 129+ 'articleassessment-featurefeedback' => 'Gebe uns bitte eine <span class="feedbacklink">Rückmeldung</span> zu dieser Funktion zur Einschätzung eines Artikels.',
130130 'articleassessment-noratings' => '$1 ($2 {{PLURAL:$2|Einschätzung|Einschätzungen}})',
131131 'articleassessment-stalemessage-revisioncount' => "Dieser Artikel wurde seit deiner letzten Einschätzung „$1-mal“ ''bearbeitet''.
132132 Vielleicht möchtest du ihn erneut einschätzen.",
@@ -133,8 +133,8 @@
134134 Vielleicht möchtest du ihn erneut einschätzen.",
135135 'articleassessment-stalemessage-norevisioncount' => "Dieser Artikel wurde seit deiner letzten Einschätzung ''bearbeitet''.
136136 Vielleicht möchtest du ihn erneut einschätzen.",
137 - 'articleassessment-results-show' => '(Ergebnisse sind ausgeblendet. [[#|Einblenden]].)',
138 - 'articleassessment-results-hide' => '([[#|Ergebnisse ausblenden]])',
 137+ 'articleassessment-results-show' => '(Ergebnisse sind ausgeblendet. <span class="showlink">Einblenden</span>.)',
 138+ 'articleassessment-results-hide' => '(<span class="hidelink">Ergebnisse ausblenden</span>)',
139139 );
140140
141141 /** Galician (Galego)
@@ -152,10 +152,10 @@
153153 'articleassessment-articlerating' => 'Avaliación do artigo',
154154 'articleassessment-error' => 'Houbo un erro.
155155 Inténteo de novo máis tarde.',
156 - 'articleassessment-featurefeedback' => 'Déanos [[Special:Article Assessment Feedback|a súa opinión]] sobre esta característica.',
 156+ 'articleassessment-featurefeedback' => 'Déanos <span class="feedbacklink">a súa opinión</span> sobre esta característica.',
157157 'articleassessment-noratings' => '$1 ($2 {{PLURAL:$2|avaliación|avaliacións}})',
158 - 'articleassessment-results-show' => '(Resultados agochados. [[#|Mostralos]].)',
159 - 'articleassessment-results-hide' => '([[#|Agochar os resultados]])',
 158+ 'articleassessment-results-show' => '(Resultados agochados. <span class="showlink">Mostralos</span>.)',
 159+ 'articleassessment-results-hide' => '(<span class="hidelink">Agochar os resultados</span>)',
160160 );
161161
162162 /** Japanese (日本語)
@@ -205,8 +205,8 @@
206206 Probéiert w.e.g. méi spéit nach emol.',
207207 'articleassessment-thanks' => 'Merci! Är Bewäertung gouf gespäichert.',
208208 'articleassessment-noratings' => '$1 ($2 {{PLURAL:$2|Bewäertung|Bewäertungen}})',
209 - 'articleassessment-results-show' => "(D'Resultater si verstopp. Resultater [[#|weisen]].)",
210 - 'articleassessment-results-hide' => '([[#|Resultater verstoppen]])',
 209+ 'articleassessment-results-show' => "(D'Resultater si verstopp. Resultater <span class="showlink">weisen</span>.)",
 210+ 'articleassessment-results-hide' => '(<span class="hidelink">Resultater verstoppen</span>)',
211211 );
212212
213213 /** Macedonian (Македонски)
@@ -230,7 +230,7 @@
231231 'articleassessment-error' => 'Се појави грешка.
232232 Обидете се подоцна.',
233233 'articleassessment-thanks' => 'Ви благодариме! Вашите оценки се зачувани.',
234 - 'articleassessment-featurefeedback' => 'Дајте ваше [[Special:Article Assessment Feedback|мислење]] за оваа функција.',
 234+ 'articleassessment-featurefeedback' => 'Дајте ваше <span class="feedbacklink">мислење</span> за оваа функција.',
235235 'articleassessment-noratings' => '$1 ($2 {{PLURAL:$2|оценка|оценки}})',
236236 'articleassessment-stalemessage-revisioncount' => "Статијава е ''преработена'' '''$1 пати''' од последниот преглед наваму.
237237 Ви предлагаме да ја преоцените.",
@@ -238,8 +238,8 @@
239239 Ви предлагаме да ја преоцените.",
240240 'articleassessment-stalemessage-norevisioncount' => "Статијава е ''преработена'' од последниот преглеед наваму.
241241 Ви предлагаме да ја преоцените.",
242 - 'articleassessment-results-show' => '(Резултатите се скриени. [[#|Прикажи]] ги.)',
243 - 'articleassessment-results-hide' => '([[#|Сокриј резултати]])',
 242+ 'articleassessment-results-show' => '(Резултатите се скриени. <span class="showlink">Прикажи</span> ги.)',
 243+ 'articleassessment-results-hide' => '(<span class="hidelink">Сокриј резултати</span>)',
244244 );
245245
246246 /** Piedmontese (Piemontèis)
@@ -263,7 +263,7 @@
264264 'articleassessment-error' => "Un eror a l'é capità.
265265 Për piasì preuva torna pi tard.",
266266 'articleassessment-thanks' => 'Mersì! Toe valutassion a son ëstàite salvà.',
267 - 'articleassessment-featurefeedback' => 'Dane [[Special:Article Assessment Feedback|artorn]] su sta funsion.',
 267+ 'articleassessment-featurefeedback' => 'Dane <span class="feedbacklink">artorn</span> su sta funsion.',
268268 'articleassessment-noratings' => '$1 ($2 {{PLURAL:$2|valutassion|valutassion}})',
269269 'articleassessment-stalemessage-revisioncount' => "Sto artìcol a l'é stàit ''revisionà'' '''$1 vire''' da l'ùltima vira ch'it l'has revisionalo.
270270 It podrìe vorejlo revaluté.",
@@ -271,8 +271,8 @@
272272 It podrìe vorejlo revaluté.",
273273 'articleassessment-stalemessage-norevisioncount' => "Sto artìcol a l'é stàit ''revisionà'' da quand ch'it l'has revisionalo.
274274 It podrìe vorejlo revaluté.",
275 - 'articleassessment-results-show' => '(Arzultà stërmà. [[#|Mostlo]].)',
276 - 'articleassessment-results-hide' => '([[#|Stërma arzultà]])',
 275+ 'articleassessment-results-show' => '(Arzultà stërmà. <span class="showlink">Mostlo</span>.)',
 276+ 'articleassessment-results-hide' => '(<span class="hidelink">Stërma arzultà</span>)',
277277 );
278278
279279 /** Vietnamese (Tiếng Việt)
@@ -300,7 +300,7 @@
301301 Bạn có thể muốn đánh giá nó một lần nữa.",
302302 'articleassessment-stalemessage-norevisioncount' => "Bài này đã được ''chỉnh sửa'' sau lần cuối bạn xem xét nó.
303303 Bạn có thể muốn đánh giá nó một lần nữa.",
304 - 'articleassessment-results-show' => '(Các kết quả được ẩn. [[#|Hiện]] kết quả.)',
305 - 'articleassessment-results-hide' => '([[#|Ẩn kết quả]])',
 304+ 'articleassessment-results-show' => '(Các kết quả được ẩn. <span class="showlink">Hiện</span> kết quả.)',
 305+ 'articleassessment-results-hide' => '(<span class="hidelink">Ẩn kết quả</span>)',
306306 );
307307
Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.hooks.php
@@ -102,7 +102,10 @@
103103 );
104104
105105 foreach ( self::$messages as $i => $message ) {
106 - $escapedMessageValue = Xml::escapeJsString( wfMsg( $message ) );
 106+ // TODO: Not parsing or even preprocessing the messages would be more efficient,
 107+ // but we can't do that until we have such nice things as JS-side {{PLURAL}}
 108+ // Should be OK for now in a limited deployment scenario
 109+ $escapedMessageValue = Xml::escapeJsString( wfMsgExt( $message, array( 'parseinline' ) ) );
107110 $escapedMessageKey = Xml::escapeJsString( $message );
108111 self::$messages[$i] =
109112 "'{$escapedMessageKey}':'{$escapedMessageValue}'";
Index: trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.js
@@ -99,16 +99,25 @@
100100 .text( instructions )
101101 .end()
102102 .find( '.article-assessment-rate-feedback' )
103 - .html( feedback.replace( /\[\[([^\|\]]*)\|([^\|\]]*)\]\]/g, '<a href="' + wgArticlePath + '">$2</a>' ) )
 103+ .html( feedback )
 104+ .find( '.feedbacklink' )
 105+ .wrap( $( '<a href="#"></a>' ).click( $.ArticleAssessment.fn.showFeedback ) )
 106+ .end()
104107 .end()
105108 .find( '#article-assessment-ratings legend' )
106109 .text( articlerating )
107110 .end()
108111 .find( '.article-assessment-show-ratings' )
109 - .html( resultsshow.replace( /\[\[#\|([^\]]*)\]\]/, '<a href="#">$1</a>' ) )
 112+ .html( resultsshow )
 113+ .find( '.showlink' )
 114+ .wrap( $( '<a href="#"></a>' ).click( $.ArticleAssessment.fn.showRatings ) )
 115+ .end()
110116 .end()
111 - .find( '.article-assessment-hide-ratings')
112 - .html( resultshide.replace( /\[\[#\|([^\]]*)\]\]/, '<a href="#">$1</a>' ) )
 117+ .find( '.article-assessment-hide-ratings' )
 118+ .html( resultshide )
 119+ .find ( '.hidelink' )
 120+ .wrap( $( '<a href="#"></a>' ).click( $.ArticleAssessment.fn.hideRatings ) )
 121+ .end()
113122 .end();
114123 for ( var i = 0; i < settings.fieldMessages.length; i++ ) {
115124 var $field = $( settings.fieldHTML ),
@@ -146,43 +155,16 @@
147156 }
148157 // store our settings and configuration for later
149158 $structure.find( '#article-assessment' ).data( 'articleAssessment-context', { 'settings': settings, 'config': config } );
150 - // bind the ratings show/hide handlers
151 - $structure
152 - .find( '.article-assessment-show-ratings a' )
153 - .click( function() {
154 - $( this )
155 - .parent()
156 - .hide();
157 - $structure
158 - .find( '#article-assessment-ratings' )
159 - .removeClass( 'article-assessment-ratings-disabled' )
160 - .end()
161 - .find( '.article-assessment-hide-ratings' )
162 - .show();
163 - return false;
164 - } )
165 - .end()
166 - .find( '.article-assessment-hide-ratings a' )
167 - .click( function() {
168 - $( this )
169 - .parent()
170 - .hide();
171 - $structure
172 - .find( '#article-assessment-ratings' )
173 - .addClass( 'article-assessment-ratings-disabled' )
174 - .end()
175 - .find( '.article-assessment-show-ratings' )
176 - .show();
177 - return false;
178 - } )
179 - .click();
180159 $( '#catlinks' ).before( $structure );
 160+ // Hide the ratings initially
 161+ $.ArticleAssessment.fn.hideRatings();
 162+
181163
182164 // set the height of our smaller fieldset to match the taller
183165 if ( $( '#article-assessment-rate' ).height() > $( '#article-assessment-ratings' ).height() ) {
184166 $( '#article-assessment-ratings' ).css( 'minHeight', $( '#article-assessment-rate' ).height() );
185167 } else {
186 - $( '#article-assessment-rate' ).css( 'minHeight', $( '#article-assessment-ratings' ).height() );
 168+ $( '#article-assessment-rate' ).css( 'minHeight', $( '#article-assessment-ratings' ).height() );
187169 }
188170 // attempt to fetch the ratings
189171 $.ArticleAssessment.fn.getRatingData();
@@ -220,6 +202,27 @@
221203 $( '#article-assessment input[type=submit]' )
222204 .attr( 'disabled', 'disabled' );
223205 },
 206+ 'showRatings': function() {
 207+ $( '#article-assessment-ratings' )
 208+ .removeClass( 'article-assessment-ratings-disabled' )
 209+ .find( '.article-assessment-show-ratings' )
 210+ .hide()
 211+ .end()
 212+ .find( '.article-assessment-hide-ratings' )
 213+ .show();
 214+ return false;
 215+ },
 216+ 'hideRatings': function() {
 217+ $( '#article-assessment-ratings' )
 218+ .addClass( 'article-assessment-ratings-disabled' )
 219+ .find( '.article-assessment-hide-ratings' )
 220+ .hide()
 221+ .end()
 222+ .find( '.article-assessment-show-ratings' )
 223+ .show();
 224+ return false;
 225+
 226+ },
224227
225228 // Request the ratings data for the current article
226229 'getRatingData': function() {
@@ -336,7 +339,7 @@
337340 // update the results
338341
339342 // show the results
340 - $( '#article-assessment .article-assessment-show-ratings a' ).click();
 343+ $.ArticleAssessment.fn.showRatings();
341344 // say thank you
342345 $.ArticleAssessment.fn.flashNotice( $.ArticleAssessment.fn.getMsg( 'articleassessment-thanks' ),
343346 { 'class': 'article-assessment-success-msg' } );
@@ -363,6 +366,11 @@
364367 .append( $msg );
365368 }
366369 },
 370+ 'showFeedback': function() {
 371+ // TODO: Implement
 372+ $.ArticleAssessment.fn.flashNotice( 'Not implemented yet', { 'class': 'article-assessment-error-msg' } );
 373+ return false;
 374+ },
367375 'addMessages': function( messages ) {
368376 for ( var key in messages ) {
369377 $.ArticleAssessment.messages[key] = messages[key];

Follow-up revisions

RevisionCommit summaryAuthorDate
r72968Follow-up r72967 : Fix parsing errorraymond12:16, 14 September 2010

Status & tagging log