r107914 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107913‎ | r107914 | r107915 >
Date:18:05, 3 January 2012
Author:rsterbin
Status:ok (Comments)
Tags:aft, todo 
Comment:
Links options are now referenced by letter rather than number, and link option A
has been added:
- modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js:
- Updated linkInfo to use letters and added option A
- Updated the linkBucket function to use letters
* NB: Changed the query string option to set a link from "aft_link" to
"aftv5_link".
- Changed the link-killing lines so that you can pass an override in
the query string if debug is turned on ("?aftv5_show_link=true")
- Moved section links to just before the toolbox link, as they are now
option H
- Changed each of the link ids set as data to use letters
- Added link option A (sitesub), to an appropriate location depending
on the current skin
- Updated link option B (titlebar) to slide down a touch if there are
geocoordinates
- modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js:
- Removed duplicate checks from $.articleFeedbackv5.setLinkId()
- Updated doc block comment for $.articleFeedbackv5.linkId to reference
the bucketing config option rather than repeating it
- ApiArticleFeedbackv5:
- Updated newFeedback() to use the index of the link letter (- = 0, A =
1, etc.) as the link ID
- ArticleFeedbackv5.php:
- Updated options for $wgArticleFeedbackv5LinkBuckets
- ArticleFeedbackv5.i18n.php:
- Added "articlefeedbackv5-sitesub-linktext" for link option A
- ArticleFeedbackv5.hooks.php:
- Added "articlefeedbackv5-sitesub-linktext" to messages for
ext.articleFeedbackv5
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.hooks.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.i18n.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.i18n.php
@@ -185,9 +185,10 @@
186186 'articlefeedbackv5-transparency-terms' => 'By posting, you agree to transparency under these $1.',
187187 'articlefeedbackv5-transparency-terms-linktext' => 'terms',
188188 'articlefeedbackv5-transparency-terms-url' => '//wikimediafoundation.org/wiki/Feedback_privacy_statement',
189 - 'articlefeedbackv5-section-linktext' => 'feedback',
 189+ 'articlefeedbackv5-sitesub-linktext' => 'Improve this page',
190190 'articlefeedbackv5-titlebar-linktext' => 'Help improve this page >>',
191191 'articlefeedbackv5-fixedtab-linktext' => 'Improve this page',
 192+ 'articlefeedbackv5-section-linktext' => 'feedback',
192193 'articlefeedbackv5-toolbox-linktext' => 'Improve this page',
193194
194195 /* --- copied from AFTv4 and possibly not used --- */
@@ -373,10 +374,11 @@
374375 'articlefeedbackv5-transparency-terms' => "This is the bottom line of the small text that goes beside the submit button and tells the user about the terms they're agreeing to by posting a comment. $1 will hold the link to the terms page, with the text from {{msg-mw|Articlefeedbackv5-transparency-terms-linktext}}",
375376 'articlefeedbackv5-transparency-terms-linktext' => 'The text for the terms link (see {{msg-mw|articlefeedbackv5-transparency-terms}})',
376377 'articlefeedbackv5-transparency-terms-url' => 'The URL for the terms (can be translated; defaults to Project:Privacy_policy; Do not translate "Project:")',
 378+ 'articlefeedbackv5-sitesub-linktext' => 'When a link to pop up the feedback tool appears just below the title bar to the far left, this will be the link text.',
 379+ 'articlefeedbackv5-titlebar-linktext' => 'When a link to pop up the feedback tool appears just below the title bar to the far right, this will be the link text.',
 380+ 'articlefeedbackv5-fixedtab-linktext' => 'When a link to pop up the feedback tool appears as a fixed-positioned tab, this will be the link text',
377381 'articlefeedbackv5-section-linktext' => 'When a link to pop up the feedback tool appears on the article section headers, next to [edit], this will be the text inside the brackets immediately following (e.g. "[edit] [feedback]").
378382 {{Identical|Feedback}}',
379 - 'articlefeedbackv5-titlebar-linktext' => 'When a link to pop up the feedback tool appears just below the title bar to the far right, this will be the link text.',
380 - 'articlefeedbackv5-fixedtab-linktext' => 'When a link to pop up the feedback tool appears as a fixed-positioned tab, this will be the link text',
381383 'articlefeedbackv5-toolbox-linktext' => 'When a link to pop up the feedback tool appears at the bottom of the toolbox area in the sidebar, this will be the link text.',
382384 'articlefeedbackv5-survey-question-whyrated' => 'This is a question in the survey with checkboxes for the answers. The user can check multiple answers.',
383385 'articlefeedbackv5-survey-answer-whyrated-contribute-rating' => 'This is a possible answer for the "Why did you rate this article today?" survey question.',
Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js
@@ -105,16 +105,12 @@
106106
107107 /**
108108 * The link ID indicates where the user clicked (or not) to get to the
109 - * feedback form. Options are:
110 - * 0: No link; user scrolled to the bottom of the page
111 - * 1: Section bars
112 - * 2: Title bar
113 - * 3: Vertical button
114 - * 4: Toolbox (bottom of left nav)
 109+ * feedback form. Options are "-" or A-H
115110 *
116 - * @see http://www.mediawiki.org/wiki/Article_feedback/Version_5/Feature_Requirements#Placement
 111+ * @see $wgArticleFeedbackv5LinkBuckets
 112+ * @see http://www.mediawiki.org/wiki/Article_feedback/Version_5/Feature_Requirements#Feedback_links_on_article_pages
117113 */
118 - $.articleFeedbackv5.linkId = '0';
 114+ $.articleFeedbackv5.linkId = '-';
119115
120116 /**
121117 * Use the mediawiki util resource's config method to find the correct url to
@@ -2828,10 +2824,7 @@
28292825 * @param int linkId the link ID
28302826 */
28312827 $.articleFeedbackv5.setLinkId = function ( linkId ) {
2832 - var knownLinks = { '0': true, '1': true, '2': true, '3': true, '4': true };
2833 - if ( linkId in knownLinks ) {
2834 - $.articleFeedbackv5.linkId = linkId + '';
2835 - }
 2828+ $.articleFeedbackv5.linkId = linkId;
28362829 };
28372830
28382831 // }}}
Index: trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js
@@ -20,10 +20,11 @@
2121
2222 // Info about each of the links
2323 var linkInfo = {
24 - '1': { trackId: 'section-link' },
25 - '2': { trackId: 'titlebar-link' },
26 - '3': { trackId: 'vertical-link' },
27 - '4': { trackId: 'toolbox-link' }
 24+ 'A': { trackId: 'sitesub-link' },
 25+ 'B': { trackId: 'titlebar-link' },
 26+ 'C': { trackId: 'vertical-link' },
 27+ 'H': { trackId: 'section-link' },
 28+ 'tbx': { trackId: 'toolbox-link' }
2829 };
2930
3031 // Click event
@@ -37,64 +38,79 @@
3839 // Bucketing
3940 var linkBucket = function () {
4041 // Find out which link bucket they go in:
41 - // 1. Display buckets 0 or 5? Always zero.
 42+ // 1. Display buckets 0 or 5? Always no link.
4243 // 2. Requested in query string (debug only)
4344 // 3. Random bucketing
4445 var displayBucket = $aftDiv.articleFeedbackv5( 'getBucketId' );
4546 if ( '5' == displayBucket || '0' == displayBucket ) {
46 - return '0';
 47+ return '-';
4748 }
48 - var knownBuckets = { '0': true, '1': true, '2': true, '3': true };
49 - var requested = mw.util.getParamValue( 'aft_link' );
 49+ var cfg = mw.config.get( 'wgArticleFeedbackv5LinkBuckets' );
 50+ if ( !( 'buckets' in cfg ) ) {
 51+ return '-';
 52+ }
 53+ var knownBuckets = cfg.buckets;
 54+ var requested = mw.util.getParamValue( 'aftv5_link' );
5055 if ( $aftDiv.articleFeedbackv5( 'inDebug' ) && requested in knownBuckets ) {
5156 return requested;
52 - } else {
53 - var bucketName = mw.user.bucket( 'ext.articleFeedbackv5-links',
54 - mw.config.get( 'wgArticleFeedbackv5LinkBuckets' )
55 - );
56 - var nameMap = { '-': '0', 'A': '1', 'B': '2', 'C': '3' };
57 - aft5_debug('Links option: ' + bucketName + ' - ' + nameMap[bucketName]);
58 - return nameMap[bucketName];
5957 }
 58+ return mw.user.bucket( 'ext.articleFeedbackv5-links', cfg );
6059 }();
6160 if ( $aftDiv.articleFeedbackv5( 'inDebug' ) ) {
62 - aft5_debug( 'Using link option #' + linkBucket );
 61+ aft5_debug( 'Using link option ' + linkBucket );
6362 }
6463
6564 /*** REMOVING FEEDBACK LINK FOR 1.0 PER ERIK's REQUEST ***/
66 -/*** TO RESTORE FUNCTIONALITY REMOVE THE FOLLOWING LINE ***/
67 -linkBucket = '0';
 65+/*** TO RESTORE FUNCTIONALITY REMOVE THE FOLLOWING LINES ***/
 66+if ( $aftDiv.articleFeedbackv5( 'inDebug' ) && mw.util.getParamValue( 'aftv5_show_link' ) == 'true' ) {
 67+ // Allow feedback link
 68+} else {
 69+ // Always turn off
 70+ linkBucket = '-';
 71+}
6872
69 -/* Add section links */
70 -if ( '1' == linkBucket ) {
71 - var $wrp = $( '<span class="articleFeedbackv5-sectionlink-wrap"></span>' )
72 - .html( '&nbsp;[<a href="#mw-articlefeedbackv5" class="articleFeedbackv5-sectionlink"></a>]' );
73 - $wrp.find( 'a.articleFeedbackv5-sectionlink' )
74 - .data( 'linkId', 1 )
75 - .text( mw.msg( 'articlefeedbackv5-section-linktext' ) )
 73+// A: After the site tagline (below the article title)
 74+if ( 'A' == linkBucket ) {
 75+ var $sub = $( '<a href="#mw-articleFeedbackv5" id="articleFeedbackv5-sitesublink"></a>' )
 76+ .data( 'linkId', 'A' )
 77+ .text( mw.msg( 'articlefeedbackv5-sitesub-linktext' ) )
7678 .click( function ( e ) {
7779 e.preventDefault();
7880 clickFeedbackLink( $( e.target ) );
79 - } );
80 - $( 'span.editsection' ).append( $wrp );
81 - $aftDiv.articleFeedbackv5( 'addToRemovalQueue', $wrp );
 81+ } )
 82+ // The link is going to be at different markup locations on different skins,
 83+ // and it needs to show up if the site subhead (e.g., "From Wikipedia, the free
 84+ // encyclopedia") is not visible for any reason.
 85+ if ( $( '#siteSub' ).filter( ':visible' ).length ) {
 86+ $( '#siteSub' ).append( ' ' ).append( $sub );
 87+ } else if ( $( 'h1.pagetitle + p.subtitle' ).filter( ':visible' ).length ) {
 88+ $( 'h1.pagetitle + p.subtitle' ).append( ' ' ).append( $sub );
 89+ } else if ( $( '#mw_contentholder .mw-topboxes' ).length ) {
 90+ $( '#mw_contentholder .mw-topboxes' ).after( $sub );
 91+ } else if ( $( '#bodyContent' ).length ) {
 92+ $( '#bodyContent' ).prepend( $sub );
 93+ }
 94+ $aftDiv.articleFeedbackv5( 'addToRemovalQueue', $sub );
8295 }
8396
84 -/* Add titlebar link */
85 -if ( '2' == linkBucket ) {
 97+// B: Below the titlebar on the right
 98+if ( 'B' == linkBucket ) {
8699 var $tlk = $( '<a href="#mw-articleFeedbackv5" id="articleFeedbackv5-titlebarlink"></a>' )
87 - .data( 'linkId', 2 )
 100+ .data( 'linkId', 'B' )
88101 .text( mw.msg( 'articlefeedbackv5-titlebar-linktext' ) )
89102 .click( function ( e ) {
90103 e.preventDefault();
91104 clickFeedbackLink( $( e.target ) );
92 - } )
93 - .insertBefore( $aftDiv );
 105+ } );
 106+ if ( $( '#coordinates' ).length ) {
 107+ $tlk.css( 'margin-top: 2.5em' );
 108+ }
 109+ $tlk.insertBefore( $aftDiv );
94110 $aftDiv.articleFeedbackv5( 'addToRemovalQueue', $tlk );
95111 }
96112
97 -/* Add fixed tab link */
98 -if( '3' == linkBucket ) {
 113+// C: Button fixed to right side
 114+if ( 'C' == linkBucket ) {
99115 var $fixedTab = $( '\
100116 <div id="articleFeedbackv5-fixedtab">\
101117 <div id="articleFeedbackv5-fixedtabbox">\
@@ -102,7 +118,7 @@
103119 </div>\
104120 </div>' );
105121 $fixedTab.find( '#articleFeedbackv5-fixedtablink' )
106 - .data( 'linkId', 3 )
 122+ .data( 'linkId', 'C' )
107123 .attr( 'title', mw.msg( 'articlefeedbackv5-fixedtab-linktext' ) )
108124 .click( function( e ) {
109125 e.preventDefault();
@@ -115,19 +131,47 @@
116132 $aftDiv.articleFeedbackv5( 'addToRemovalQueue', $fixedTab );
117133 }
118134
119 -/* Add toolbox link */
 135+// D: Button fixed to bottom right
 136+// NOT IMPLEMENTED
 137+
 138+// E: Button fixed to bottom center
 139+// NOT IMPLEMENTED
 140+
 141+// F: Button fixed to left side
 142+// NOT IMPLEMENTED
 143+
 144+// G: Button below logo
 145+// NOT IMPLEMENTED
 146+
 147+// H: Link on each section bar
 148+if ( 'H' == linkBucket ) {
 149+ var $wrp = $( '<span class="articleFeedbackv5-sectionlink-wrap"></span>' )
 150+ .html( '&nbsp;[<a href="#mw-articlefeedbackv5" class="articleFeedbackv5-sectionlink"></a>]' );
 151+ $wrp.find( 'a.articleFeedbackv5-sectionlink' )
 152+ .data( 'linkId', 'H' )
 153+ .text( mw.msg( 'articlefeedbackv5-section-linktext' ) )
 154+ .click( function ( e ) {
 155+ e.preventDefault();
 156+ clickFeedbackLink( $( e.target ) );
 157+ } );
 158+ $( 'span.editsection' ).append( $wrp );
 159+ $aftDiv.articleFeedbackv5( 'addToRemovalQueue', $wrp );
 160+}
 161+
 162+// Add toolbox link
120163 if ( '5' == $aftDiv.articleFeedbackv5( 'getBucketId' ) ) {
121164 var $tbx = $( '<li id="t-articlefeedbackv5"><a href="#mw-articlefeedbackv5"></a></li>' )
122165 .find( 'a' )
123166 .text( mw.msg( 'articlefeedbackv5-bucket5-toolbox-linktext' ) )
124167 .click( function ( e ) {
125168 // Just set the link ID -- this should act just like AFTv4
126 - $aftDiv.articleFeedbackv5( 'setLinkId', 4 );
 169+ $aftDiv.articleFeedbackv5( 'setLinkId', 'tbx' );
127170 } )
128171 .end();
129172 $( '#p-tb' ).find( 'ul' ).append( $tbx );
130173 } else {
131174 var $tbx = $( '<li id="t-articlefeedbackv5"><a href="#mw-articlefeedbackv5"></a></li>' )
 175+ .data( 'linkId', 'tbx' )
132176 .find( 'a' )
133177 .text( mw.msg( 'articlefeedbackv5-toolbox-linktext' ) )
134178 .click( function ( e ) {
Index: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php
@@ -119,14 +119,24 @@
120120 $wgArticleFeedbackv5LinkBuckets = array(
121121 // Users can fall into one of several buckets for links. These are:
122122 // -: No link; user must scroll to the bottom of the page
123 - // A: Section bars
124 - // B: Title bar
125 - // C: Vertical button (fixed tab)
 123+ // A: After the site tagline (below the article title)
 124+ // B: Below the titlebar on the right
 125+ // C: Button fixed to right side
 126+ // D: Button fixed to bottom right
 127+ // E: Button fixed to bottom center
 128+ // F: Button fixed to left side
 129+ // G: Button below logo
 130+ // H: Link on each section bar
126131 'buckets' => array(
127 - '-' => 0,
128 - 'A' => 0,
 132+ '-' => 34,
 133+ 'A' => 33,
129134 'B' => 0,
130 - 'C' => 100,
 135+ 'C' => 0,
 136+ 'D' => 33,
 137+ 'E' => 0,
 138+ 'F' => 0,
 139+ 'G' => 0,
 140+ 'H' => 0,
131141 ),
132142 // This version number is added to all tracking event names, so that
133143 // changes in the software don't corrupt the data being collected. Bump
Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php
@@ -442,11 +442,11 @@
443443 * @return int the feedback id
444444 */
445445 public function newFeedback( $params ) {
446 - global $wgUser;
 446+ global $wgUser, $wgArticleFeedbackv5LinkBuckets;
447447 $dbw = wfGetDB( DB_MASTER );
448448 $revId = $params['revid'];
449449 $bucket = $params['bucket'];
450 - $link = $params['link'];
 450+ $linkName = $params['link'];
451451 $token = $this->getAnonToken( $params );
452452 $timestamp = $dbw->timestamp();
453453 $ip = null;
@@ -465,7 +465,7 @@
466466 $this->dieUsage( 'Page ID is missing or invalid', 'invalidpageid' );
467467 }
468468
469 - # Fetch this if it wasn't passed in
 469+ // Fetch this if it wasn't passed in
470470 if ( !$revId ) {
471471 $title = Title::newFromID( $params['pageid'] );
472472 if ( !$title ) {
@@ -474,6 +474,10 @@
475475 $revId = $title->getLatestRevID();
476476 }
477477
 478+ // Get the link ID
 479+ $links = array_flip( array_keys( $wgArticleFeedbackv5LinkBuckets['buckets'] ) );
 480+ $linkId = isset($links[$linkName]) ? $links[$linkName] : 0;
 481+
478482 $dbw->insert( 'aft_article_feedback', array(
479483 'af_page_id' => $params['pageid'],
480484 'af_revision_id' => $revId,
@@ -482,7 +486,7 @@
483487 'af_user_ip' => $ip,
484488 'af_user_anon_token' => $token,
485489 'af_bucket_id' => $bucket,
486 - 'af_link_id' => $link,
 490+ 'af_link_id' => $linkId,
487491 ) );
488492
489493 return $dbw->insertID();
@@ -513,10 +517,10 @@
514518 return $ctaId;
515519 }
516520
517 - /**
518 - * Inserts or updates properties for a specific rating
519 - * @param $revisionId int Revision ID
520 - */
 521+ /**
 522+ * Inserts or updates properties for a specific rating
 523+ * @param $revisionId int Revision ID
 524+ */
521525 private function saveUserProperties( $revisionId ) {
522526 global $wgUser;
523527 $dbw = wfGetDB( DB_MASTER );
@@ -530,11 +534,11 @@
531535
532536 // I'd really rather have this passed in, to save a query,
533537 // and rule out consistency problems, but there doesn't seem
534 - // to be a way to do 'RETUNING af_id' on the insert, or to
 538+ // to be a way to do 'RETUNING af_id' on the insert, or to
535539 // pre-increment the ID column (since it's a MySQL auto-
536 - // increment, not a sequence) before the insert. So, fetch
 540+ // increment, not a sequence) before the insert. So, fetch
537541 // the most recent feedback ID for this user on this revision.
538 - // This gets called imediately after saving, so it'll almost
 542+ // This gets called imediately after saving, so it'll almost
539543 // certainly be the right one.
540544 $feedbackId = $dbr->selectField(
541545 'aft_article_feedback',
@@ -557,7 +561,7 @@
558562 'afp_value_int' => ( integer ) $wgUser->getEditCount()
559563 );
560564
561 - // Use the UserDailyContribs extension if it's present. Get
 565+ // Use the UserDailyContribs extension if it's present. Get
562566 // edit counts for last 6 months, last 3 months, and last month.
563567 if ( function_exists( 'getUserEditCountSince' ) ) {
564568 $now = time();
@@ -644,9 +648,8 @@
645649 ApiBase::PARAM_MIN => 0
646650 ),
647651 'link' => array(
648 - ApiBase::PARAM_TYPE => 'integer',
 652+ ApiBase::PARAM_TYPE => 'string',
649653 ApiBase::PARAM_REQUIRED => true,
650 - ApiBase::PARAM_MIN => 0
651654 ),
652655 'email' => array(
653656 ApiBase::PARAM_TYPE => 'string',
Index: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.hooks.php
@@ -24,9 +24,10 @@
2525 'scripts' => 'ext.articleFeedbackv5/ext.articleFeedbackv5.js',
2626 'styles' => 'ext.articleFeedbackv5/ext.articleFeedbackv5.css',
2727 'messages' => array(
28 - 'articlefeedbackv5-section-linktext',
 28+ 'articlefeedbackv5-sitesub-linktext',
2929 'articlefeedbackv5-titlebar-linktext',
3030 'articlefeedbackv5-fixedtab-linktext',
 31+ 'articlefeedbackv5-section-linktext',
3132 'articlefeedbackv5-toolbox-linktext',
3233 'articlefeedbackv5-bucket5-toolbox-linktext',
3334 ),

Follow-up revisions

RevisionCommit summaryAuthorDate
r108530Followup to r107914: added comment to explain how the link ID worksrsterbin18:28, 10 January 2012

Comments

#Comment by Catrope (talk | contribs)   11:36, 10 January 2012
+		// Get the link ID
+		$links = array_flip( array_keys( $wgArticleFeedbackv5LinkBuckets['buckets'] ) );
+		$linkId = isset($links[$linkName]) ? $links[$linkName] : 0;

This is clever; so clever, in fact, that I had to read it three times :) . Apparently what it does is it converts '-' to 0, 'A' to 1, 'B' to 2, etc., right? Could use a clarifying comment.

#Comment by Rsterbin (talk | contribs)   18:28, 10 January 2012

I suppose that is sort of non-obvious. Added a comment. :)

Status & tagging log