r72524 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72523‎ | r72524 | r72525 >
Date:10:05, 7 September 2010
Author:catrope
Status:deferred
Tags:
Comment:
ArticleAssessment: Basic cleanup
* Fix code style. Haven't run stylize yet
* Explain missing special page in .i18n.php comment
* Move $wgArticleAssessmentCategory up to where the rest of the config vars are
* Correct a few doc comments
* Correct grammar
* Double quotes to single quotes in JS
Modified paths:
  • /trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.hooks.php (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.i18n.php (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.php (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.sql (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/api/ApiArticleAssessment.php (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/api/ApiListArticleAssessment.php (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/css/ArticleAssessment.css (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.sql
@@ -4,8 +4,9 @@
55 aar_rating varchar(255) binary NOT NULL
66 ) /*$wgDBTableOptions*/;
77
8 -INSERT INTO /*$wgDBprefix*/article_assessment_ratings(aar_rating) VALUES('articleassessment-rating-wellsourced'),
9 -('articleassessment-rating-neutrality'), ('articleassessment-rating-completeness'), ('articleassessment-rating-readability');
 8+INSERT INTO /*$wgDBprefix*/article_assessment_ratings (aar_rating) VALUES
 9+('articleassessment-rating-wellsourced'), ('articleassessment-rating-neutrality'),
 10+('articleassessment-rating-completeness'), ('articleassessment-rating-readability');
1011
1112 -- Store article assessments
1213 CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/article_assessment (
Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.i18n.php
@@ -24,7 +24,7 @@
2525 'articleassessment-error' => "We're sorry! An error has occurred. Please try again later.",
2626 'articleassessment-thanks' => 'Thanks! Your ratings have been saved.',
2727
28 - # FIXME: Special page seems not exist.
 28+ # This special page doesn't exist yet, but it will soon.
2929 'articleassessment-featurefeedback' => 'Give us [[Special:Article Assessment Feedback|feedback]] about this feature.',
3030 'articleassessment-noratings' => '$1 ($2 {{PLURAL:$2|rating|ratings}})',
3131 'articleassessment-stalemessage-revisioncount' => "This article has been ''revised'' '''$1 times''' since you last reviewed it. You may wish to re-rate it.",
Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.php
@@ -8,6 +8,9 @@
99 // Number of "ratings" to store. Allows it to be a bit more dynamic
1010 $wgArticleAssessmentRatingCount = 4;
1111
 12+//Category the pages are in (with _ in text)
 13+$wgArticleAssessmentCategory = '';
 14+
1215 // Auto-load files
1316 $dir = dirname( __FILE__ ) . '/';
1417 $wgAutoloadClasses['ApiListArticleAssessment'] = $dir . 'api/ApiListArticleAssessment.php';
@@ -38,6 +41,3 @@
3942 'descriptionmsg' => 'articleassessment-desc',
4043 'url' => 'http://www.mediawiki.org/wiki/Extension:ArticleAssessmentPilot'
4144 );
42 -
43 -//Category the pages are in (with _ in text)
44 -$wgArticleAssessmentCategory = '';
\ No newline at end of file
Index: trunk/extensions/ArticleAssessmentPilot/css/ArticleAssessment.css
@@ -12,25 +12,25 @@
1313 *
1414 */
1515 .article-assessment-wrapper .ui-stars-star {
16 - float: left;
17 - display: block;
18 - overflow: hidden;
19 - text-indent: -999em;
20 - cursor: pointer;
 16+ float: left;
 17+ display: block;
 18+ overflow: hidden;
 19+ text-indent: -999em;
 20+ cursor: pointer;
2121 padding-right: 4px;
2222 }
2323 .article-assessment-wrapper .ui-stars-star a {
24 - width: 21px;
25 - height: 21px;
26 - display: block;
27 - background: url(../images/stars.gif) no-repeat 0 0;
 24+ width: 21px;
 25+ height: 21px;
 26+ display: block;
 27+ background: url(../images/stars.gif) no-repeat 0 0;
2828 }
2929 .article-assessment-wrapper .ui-stars-star a {
30 - background-position: 0 0px;
 30+ background-position: 0 0px;
3131 }
3232
3333 .article-assessment-wrapper .ui-stars-star-on a {
34 - background-position: 0 -21px;
 34+ background-position: 0 -21px;
3535 }
3636 .article-assessment-wrapper .ui-stars-star-rated a {
3737 background-position: 0 -42px;
@@ -39,11 +39,11 @@
4040 background-position: 0 -63px;
4141 }
4242 .article-assessment-wrapper .ui-stars-star-hover a {
43 - background-position: 0 -21px;
 43+ background-position: 0 -21px;
4444 }
4545 .article-assessment-wrapper .ui-stars-star-disabled,
4646 .article-assessment-wrapper .ui-stars-star-disabled a {
47 - cursor: default !important;
 47+ cursor: default !important;
4848 }
4949 .article-assessment-wrapper .ui-stars-cancel {
5050 display: none;
Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.hooks.php
@@ -34,7 +34,7 @@
3535 }
3636
3737 /**
38 - * Make sure the table exists for parser tests
 38+ * Make sure the tables exist for parser tests
3939 * @param $tables
4040 * @return bool
4141 */
@@ -69,7 +69,7 @@
7070 );
7171 }
7272
73 - foreach(self::$styleFiles as $style) {
 73+ foreach ( self::$styleFiles as $style ) {
7474 $out->addExtensionStyle( $wgExtensionAssetsPath .
7575 "/ArticleAssessmentPilot/{$style['src']}?{$style['version']}"
7676 );
@@ -117,11 +117,11 @@
118118 return true;
119119 }
120120
121 - /*
122 - * Returns whether an article is in the specific category
 121+ /**
 122+ * Returns whether an article is in the specified category
123123 *
124124 * @param $articleId Integer: Article ID
125 - * @param $category String: The category name (without Category: Prefix)
 125+ * @param $category String: The category name (without Category: prefix, with underscores)
126126 *
127127 * @return bool
128128 */
@@ -154,4 +154,4 @@
155155 public static function addMessages( $messages ) {
156156 self::$messages = array_merge( self::$messages, $messages );
157157 }
158 -}
\ No newline at end of file
 158+}
Index: trunk/extensions/ArticleAssessmentPilot/api/ApiListArticleAssessment.php
@@ -54,7 +54,7 @@
5555
5656 $this->addFields( array( 'aa_rating_value', 'aa_revision' ) );
5757
58 - if ( isset( $params['revid'] ) ){
 58+ if ( isset( $params['revid'] ) ) {
5959 $this->addWhereFld( 'aa_revision', $params['revid'] );
6060 }
6161
@@ -78,14 +78,14 @@
7979 'pageid' => $pageId,
8080 );
8181
82 - if ( isset( $params['revid'] ) || $params['userrating'] ){
 82+ if ( isset( $params['revid'] ) || $params['userrating'] ) {
8383 $page['revid'] = $row->aa_revision;
8484 }
8585
8686 $ratings[$pageId] = $page;
8787 }
8888
89 - $thisRow = array(
 89+ $thisRow = array(
9090 'ratingid' => $row->aap_rating_id,
9191 'ratingdesc' => $row->aar_rating,
9292 'total' => $row->aap_total,
@@ -162,7 +162,7 @@
163163 return array(
164164 'pageid' => 'Page ID to get assessments for',
165165 'revid' => 'Specific revision to get (used in conjunction with userrating param, otherwise ignored)',
166 - 'userrating' => 'Whether to get the current users ratings for the specific rev/article',
 166+ 'userrating' => "Whether to get the current user's ratings for the specific rev/article",
167167 'anontoken' => 'Token for anonymous users',
168168 'limit' => 'Amount of pages to get the ratings for',
169169 );
Index: trunk/extensions/ArticleAssessmentPilot/api/ApiArticleAssessment.php
@@ -68,16 +68,15 @@
6969 $this->insertUserRatings( $pageId, $revisionId, $wgUser, $token, $i, $thisRating );
7070 }
7171
72 - $r = array();
73 - $r['result'] = 'Success';
 72+ $r = array( 'result' => 'Success' );
7473 $this->getResult()->addValue( null, $this->getModuleName(), $r );
7574 }
7675
77 - /*
 76+ /**
7877 *
7978 * @param $pageId Integer:
8079 * @param $ratingId Integer:
81 - * @param $updateAddition Integer: Difference between users last rating (if applicable)
 80+ * @param $updateAddition Integer: Difference between user's last rating (if applicable)
8281 * @param $newRating Boolean: Whether this is a new rating (for update, whether this increases the count)
8382 */
8483 private function insertPageRating( $pageId, $ratingId, $updateAddition, $newRating ) {
@@ -109,7 +108,7 @@
110109 );
111110 }
112111
113 - /*
 112+ /**
114113 * @param $pageId Integer:
115114 * @param $revisionId Integer:
116115 * @param $user User:
@@ -193,7 +192,7 @@
194193 'anontoken' => 'Token for anonymous users',
195194 );
196195 for ( $i = 1; $i <= $wgArticleAssessmentRatingCount; $i++ ) {
197 - $ret["r{$i}"] = "Rating {$i}";
 196+ $ret["r{$i}"] = "Rating {$i}";
198197 }
199198 return $ret;
200199 }
Index: trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.js
@@ -10,10 +10,10 @@
1111 'settings': {
1212 'endpoint': wgScriptPath + '/api.php?',
1313 'fieldMessages' : [
14 - 'wellsourced',
15 - 'neutrality',
16 - 'completeness',
17 - 'readability'
 14+ 'wellsourced',
 15+ 'neutrality',
 16+ 'completeness',
 17+ 'readability'
1818 ],
1919 'fieldHintSuffix': '-tooltip',
2020 'fieldPrefix': 'articleassessment-rating-',
@@ -71,22 +71,22 @@
7272 function randomString( string_length ) {
7373 var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
7474 var randomstring = '';
75 - for (var i=0; i<string_length; i++) {
76 - var rnum = Math.floor(Math.random() * chars.length);
77 - randomstring += chars.substring(rnum,rnum+1);
 75+ for ( var i = 0; i < string_length; i++ ) {
 76+ var rnum = Math.floor( Math.random() * chars.length );
 77+ randomstring += chars.substring( rnum, rnum + 1 );
7878 }
7979 return randomstring;
8080 }
8181 userToken = randomString( 32 );
8282 $.cookie( 'mwArticleAssessmentUserToken', userToken );
8383 }
84 - if ( ! wgUserName ) {
 84+ if ( !wgUserName ) {
8585 config.userID = userToken;
8686 }
87 - // setup our markup using the template varibales in settings
 87+ // setup our markup using the template variables in settings
8888 var $output = $( settings.structureHTML
89 - .replace( /\{INSTRUCTIONS\}/g, $.ArticleAssessment.fn.getMsg('articleassessment-pleaserate') )
90 - .replace( /\{FEEDBACK\}/g, $.ArticleAssessment.fn.getMsg('articleassessment-featurefeedback')
 89+ .replace( /\{INSTRUCTIONS\}/g, $.ArticleAssessment.fn.getMsg( 'articleassessment-pleaserate' ) )
 90+ .replace( /\{FEEDBACK\}/g, $.ArticleAssessment.fn.getMsg( 'articleassessment-featurefeedback' )
9191 .replace( /\[\[([^\|\]]*)\|([^\|\]]*)\]\]/, '<a href="' + wgArticlePath + '">$2</a>' ) )
9292 .replace( /\{YOURFEEDBACK\}/g, $.ArticleAssessment.fn.getMsg('articleassessment-yourfeedback') )
9393 .replace( /\{ARTICLERATING\}/g, $.ArticleAssessment.fn.getMsg('articleassessment-articlerating' ) )
@@ -94,7 +94,7 @@
9595 .replace( /\[\[\|([^\]]*)\]\]/, '<a href="#">$1</a>' ) )
9696 .replace( /\{RESULTSSHOW\}/g, $.ArticleAssessment.fn.getMsg('articleassessment-results-show' )
9797 .replace( /\[\[\|([^\]]*)\]\]/, '<a href="#">$1</a>' ) ) );
98 - for( var field in settings.fieldMessages ) {
 98+ for ( var field in settings.fieldMessages ) {
9999 $output.find( '.article-assessment-rating-fields' )
100100 .append( $( settings.fieldHTML
101101 .replace( /\{LABEL\}/g, $.ArticleAssessment.fn.getMsg( settings.fieldPrefix + settings.fieldMessages[field] ) )
@@ -143,7 +143,7 @@
144144 $( '#catlinks' ).before( $output );
145145
146146 // set the height of our smaller fieldset to match the taller
147 - if( $( '#article-assessment-rate' ).height() > $( '#article-assessment-ratings' ).height() ) {
 147+ if ( $( '#article-assessment-rate' ).height() > $( '#article-assessment-ratings' ).height() ) {
148148 $( '#article-assessment-ratings' ).css( 'minHeight', $( '#article-assessment-rate' ).height() );
149149 } else {
150150 $( '#article-assessment-rate' ).css( 'minHeight', $( '#article-assessment-ratings' ).height() );
@@ -164,14 +164,14 @@
165165 $( this )
166166 .removeClass( 'ui-stars-star-stale' )
167167 .removeClass( 'ui-stars-star-rated' );
168 - // enable our submit button if it's still disabled
169 - $( '#article-assessment input:disabled' ).removeAttr( "disabled" );
 168+ // enable our submit button if it's still disabled
 169+ $( '#article-assessment input:disabled' ).removeAttr( 'disabled' );
170170 } );
171171 }
172172 } );
173173 });
174174 // intialize the tooltips
175 - $( '.field-wrapper label[original-title]' ).each(function() {
 175+ $( '.field-wrapper label[original-title]' ).each( function() {
176176 $( this )
177177 .after( $( '<span class="rating-field-hint" />' )
178178 .attr( 'original-title', $( this ).attr( 'original-title' ) )
@@ -195,7 +195,7 @@
196196 'aauserrating': 1,
197197 'format': 'json'
198198 }
199 - if( config.userID.length == 32 ) {
 199+ if ( config.userID.length == 32 ) {
200200 requestData.aaanontoken = config.userID;
201201 }
202202 var request = $.ajax( {
@@ -214,8 +214,8 @@
215215 'afterGetRatingData' : function( data ) {
216216 var settings = $( '#article-assessment' ).data( 'articleAssessment-context' ).settings;
217217 // add the correct data to the markup
218 - if( data.query.articleassessment && data.query.articleassessment.length > 0 ) {
219 - for( rating in data.query.articleassessment[0].ratings) {
 218+ if ( data.query.articleassessment && data.query.articleassessment.length > 0 ) {
 219+ for ( rating in data.query.articleassessment[0].ratings) {
220220 var rating = data.query.articleassessment[0].ratings[rating],
221221 $rating = $( '#' + rating.ratingdesc ),
222222 count = rating.count,
@@ -251,7 +251,7 @@
252252 $( '.article-assessment-rating-field-value' ).each( function() {
253253 $( this )
254254 .css( {
255 - 'width': 120 - ( 120 * ( parseFloat( $( this ).text() ) / 5 ) ) + "px"
 255+ 'width': 120 - ( 120 * ( parseFloat( $( this ).text() ) / 5 ) ) + 'px'
256256 } )
257257 } );
258258 },
@@ -262,13 +262,13 @@
263263
264264 // lock the star inputs & submit
265265 $( '.rating-field' ).stars( 'disable' );
266 - $( '#article-assessment input' ).attr( "disabled", "disabled" );
 266+ $( '#article-assessment input' ).attr( 'disabled', 'disabled' );
267267 // get our results for submitting
268268 var results = {};
269269 $( '.rating-field input' ).each( function() {
270270 // expects the hidden inputs to have names like 'rating[field-name]' which we use to
271271 // be transparent about what values we're sending to the server
272 - var fieldName = $( this ).attr('name').match(/\[([a-zA-Z0-9\-]*)\]/)[1];
 272+ var fieldName = $( this ).attr( 'name' ).match( /\[([a-zA-Z0-9\-]*)\]/ )[1];
273273 results[ fieldName ] = $( this ).val();
274274 } );
275275 var request = $.ajax( {
@@ -292,7 +292,7 @@
293293 $( '.ui-stars-star-on' ).addClass( 'ui-stars-star-rated' );
294294 // unlock the stars & submit
295295 $( '.rating-field' ).stars( 'enable' );
296 - $( '#article-assessment input:disabled' ).removeAttr( "disabled" );
 296+ $( '#article-assessment input:disabled' ).removeAttr( 'disabled' );
297297 // update the results
298298
299299 // show the results
@@ -344,7 +344,7 @@
345345 var msg = $.ArticleAssessment.messages[key];
346346 if ( typeof args == 'object' || typeof args == 'array' ) {
347347 for ( var argKey in args ) {
348 - msg = msg.replace( '\$' + (parseInt( argKey ) + 1), args[argKey] );
 348+ msg = msg.replace( '\$' + ( parseInt( argKey ) + 1 ), args[argKey] );
349349 }
350350 } else if ( typeof args == 'string' || typeof args == 'number' ) {
351351 msg = msg.replace( '$1', args );

Status & tagging log