jenkins-bot has submitted this change and it was merged.

Change subject: Feedback link on article pages
......................................................................


Feedback link on article pages

* Add API endpoint to fetch amount of entries for a given page/filter
* Code for above functionality was in use on special page already; moved
  that code to utils so both can access this and avoid code duplication
* add Javascript ajax call to fetch the amount of feedback and display a
  link on article page
* Update talk-page link to
  * If AFT is enabled: display link if there is *any* feedback
  * If AFT is disabled: only display link if there still is featured feedback

Bug: 42057
Change-Id: I03c815d8257aaa590ef639387c360d8356cd0d96
---
M ArticleFeedbackv5.hooks.php
M ArticleFeedbackv5.i18n.php
M ArticleFeedbackv5.php
M api/ApiGetCountArticleFeedbackv5.php
M modules/ext.articleFeedbackv5/ext.articleFeedbackv5.css
M modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js
M modules/ext.articleFeedbackv5/ext.articleFeedbackv5.talk.js
M modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.utils.js
8 files changed, 142 insertions(+), 42 deletions(-)

Approvals:
  Bsitu: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/ArticleFeedbackv5.hooks.php b/ArticleFeedbackv5.hooks.php
index bcd597d..7a6c5d2 100644
--- a/ArticleFeedbackv5.hooks.php
+++ b/ArticleFeedbackv5.hooks.php
@@ -228,6 +228,7 @@
                        $wgArticleFeedbackv5LearnToEdit,
                        $wgArticleFeedbackv5SurveyUrls,
                        $wgArticleFeedbackv5ThrottleThresholdPostsPerHour,
+                       $wgArticleFeedbackv5ArticlePageLink,
                        $wgArticleFeedbackv5TalkPageLink,
                        $wgArticleFeedbackv5WatchlistLink,
                        $wgArticleFeedbackv5Watchlist,
@@ -247,6 +248,7 @@
                $vars['wgArticleFeedbackv5ThrottleThresholdPostsPerHour'] = 
$wgArticleFeedbackv5ThrottleThresholdPostsPerHour;
                $vars['wgArticleFeedbackv5SpecialUrl'] = 
SpecialPage::getTitleFor( 'ArticleFeedbackv5' )->getLinkUrl();
                $vars['wgArticleFeedbackv5SpecialWatchlistUrl'] = 
SpecialPage::getTitleFor( 'ArticleFeedbackv5Watchlist' )->getPrefixedText();
+               $vars['wgArticleFeedbackv5ArticlePageLink'] = 
$wgArticleFeedbackv5ArticlePageLink;
                $vars['wgArticleFeedbackv5TalkPageLink'] = 
$wgArticleFeedbackv5TalkPageLink;
                $vars['wgArticleFeedbackv5WatchlistLink'] = 
$wgArticleFeedbackv5WatchlistLink;
                $vars['wgArticleFeedbackv5Watchlist'] = 
$wgArticleFeedbackv5Watchlist;
diff --git a/ArticleFeedbackv5.i18n.php b/ArticleFeedbackv5.i18n.php
index c5fd1aa..5742c7a 100644
--- a/ArticleFeedbackv5.i18n.php
+++ b/ArticleFeedbackv5.i18n.php
@@ -666,6 +666,9 @@
        'articlefeedbackv5-activity-count' => '{{PLURAL:$1|$1 action on this 
post|$1 actions on this post}}',
        'articlefeedbackv5-activity-more' => 'Show more Activity',
 
+       /* Article page */
+       'articlefeedbackv5-article-view-feedback' => '$1 reader 
{{PLURAL:$1|comment|comments}}',
+
        /* Talk page */
        'articlefeedbackv5-talk-view-feedback' => 'View reader feedback',
 
@@ -2087,6 +2090,7 @@
        'articlefeedbackv5-activity-note-archive' => "Activity log comment when 
feedback is archived. $1 is the amount of days between the creation of the 
feedback and the date it's being archived",
        'articlefeedbackv5-activity-count' => 'Shows the amount of actions 
performed on a feedback entry. $1 is the number',
        'articlefeedbackv5-activity-more' => 'Text for the [Show more] button',
+       'articlefeedbackv5-article-view-feedback' => 'A link on the article 
page to encourage people to visit the feedback page. $1 is the amount of 
relevant suggestions.',
        'articlefeedbackv5-talk-view-feedback' => 'A link on the talk page to 
encourage people to visit the feedback page',
        'articlefeedbackv5-watchlist-view-feedback' => 'A link on the watchlist 
page to encourage people to visit the feedback page for articles on their 
watchlist',
        'articlefeedbackv5-default-user' => 'Certain feedback will be 
automatically flagged (e.g. as abusive by AbuseFilter); this is the username 
that will show up in the activity log for actions that were automatically 
performed by the system, rather than by users.',
diff --git a/ArticleFeedbackv5.php b/ArticleFeedbackv5.php
index 59bc4a2..bacc3a5 100644
--- a/ArticleFeedbackv5.php
+++ b/ArticleFeedbackv5.php
@@ -120,7 +120,10 @@
  */
 $wgArticleFeedbackv5AutoArchiveTtl = '+2 weeks';
 
-// Defines whether or not there should be a link to the corresponding feedback 
on the page's talk page
+// Defines whether or not there should be a link to the corresponding feedback 
on the article page
+$wgArticleFeedbackv5ArticlePageLink = true;
+
+// Defines whether or not there should be a link to the corresponding feedback 
on the article page's talk page
 $wgArticleFeedbackv5TalkPageLink = true;
 
 // Defines whether or not there should be a link to the watchlisted feedback 
on the watchlist page
@@ -393,6 +396,7 @@
 $wgAutoloadClasses['ApiViewFeedbackArticleFeedbackv5']  = __DIR__ . 
'/api/ApiViewFeedbackArticleFeedbackv5.php';
 $wgAutoloadClasses['ApiAddFlagNoteArticleFeedbackv5']   = __DIR__ . 
'/api/ApiAddFlagNoteArticleFeedbackv5.php';
 $wgAutoloadClasses['ApiFlagFeedbackArticleFeedbackv5']  = __DIR__ . 
'/api/ApiFlagFeedbackArticleFeedbackv5.php';
+$wgAutoloadClasses['ApiGetCountArticleFeedbackv5']      = __DIR__ . 
'/api/ApiGetCountArticleFeedbackv5.php';
 $wgAutoloadClasses['ApiViewActivityArticleFeedbackv5']  = __DIR__ . 
'/api/ApiViewActivityArticleFeedbackv5.php';
 $wgAutoloadClasses['DataModel']                         = __DIR__ . 
'/data/DataModel.php';
 $wgAutoloadClasses['DataModelBackend']                  = __DIR__ . 
'/data/DataModelBackend.php';
@@ -434,6 +438,7 @@
 $wgAPIListModules['articlefeedbackv5-view-activity'] = 
'ApiViewActivityArticleFeedbackv5';
 $wgAPIModules['articlefeedbackv5-add-flag-note']     = 
'ApiAddFlagNoteArticleFeedbackv5';
 $wgAPIModules['articlefeedbackv5-flag-feedback']     = 
'ApiFlagFeedbackArticleFeedbackv5';
+$wgAPIModules['articlefeedbackv5-get-count']         = 
'ApiGetCountArticleFeedbackv5';
 $wgAPIModules['articlefeedbackv5']                   = 'ApiArticleFeedbackv5';
 
 // Special Page
@@ -534,12 +539,16 @@
                'articlefeedbackv5-section-linktext',
                'articlefeedbackv5-toolbox-view',
                'articlefeedbackv5-toolbox-add',
+               'articlefeedbackv5-article-view-feedback',
        ),
        'dependencies' => array(
+               'mediawiki.jqueryMsg',
                'jquery.ui.button',
                'jquery.articleFeedbackv5',
                'jquery.cookie',
                'jquery.articleFeedbackv5.track',
+               'jquery.articleFeedbackv5.utils',
+               'mediawiki.api',
        ),
 ) + $wgArticleFeedbackResourcePaths;
 $wgResourceModules['ext.articleFeedbackv5.ie'] = array(
@@ -575,6 +584,7 @@
        'dependencies' => array(
                'jquery.articleFeedbackv5.utils',
                'jquery.articleFeedbackv5.track',
+               'mediawiki.api',
        ),
 ) + $wgArticleFeedbackResourcePaths;
 $wgResourceModules['ext.articleFeedbackv5.watchlist'] = array(
diff --git a/api/ApiGetCountArticleFeedbackv5.php 
b/api/ApiGetCountArticleFeedbackv5.php
index 4bdca7b..82f33f7 100644
--- a/api/ApiGetCountArticleFeedbackv5.php
+++ b/api/ApiGetCountArticleFeedbackv5.php
@@ -30,6 +30,12 @@
                $params   = $this->extractRequestParams();
                $result   = $this->getResult();
 
+               // get page object
+               $pageObj = $this->getTitleOrPageId( $params, 'fromdb' );
+               if ( !$pageObj->exists() ) {
+                       $this->dieUsageMsg( 'notanarticle' );
+               }
+
                // Add metadata
                $count = ArticleFeedbackv5Model::getCount( $params['filter'], 
$params['pageid'] );
 
@@ -46,17 +52,21 @@
         * @return array the params info, indexed by allowed key
         */
        public function getAllowedParams() {
+               $filters = array_keys( ArticleFeedbackv5Model::$lists );
+
                return array(
-                       'pageid'        => array(
+                       'title' => null,
+                       'pageid' => array(
                                ApiBase::PARAM_REQUIRED => false,
                                ApiBase::PARAM_ISMULTI  => false,
                                ApiBase::PARAM_TYPE     => 'integer',
                                ApiBase::PARAM_DFLT     => 0
                        ),
-                       'filter'        => array(
-                               ApiBase::PARAM_REQUIRED => true,
+                       'filter' => array(
+                               ApiBase::PARAM_REQUIRED => false,
                                ApiBase::PARAM_ISMULTI  => false,
-                               ApiBase::PARAM_TYPE     => array_keys( 
ArticleFeedbackv5Model::$lists )
+                               ApiBase::PARAM_TYPE     => $filters,
+                               ApiBase::PARAM_DFLT     => ( isset( $filters[0] 
) ? $filters[0] : '' )
                        ),
                );
        }
@@ -67,9 +77,11 @@
         * @return array the descriptions, indexed by allowed key
         */
        public function getParamDescription() {
+               $p = $this->getModulePrefix();
                return array(
-                       'pageid'      => 'Page ID to get feedback ratings for',
-                       'filter'      => 'What filtering to apply to list',
+                       'title' => "Title of the page to get feedback ratings 
for. Cannot be used together with {$p}pageid",
+                       'pageid' => "ID of the page to get feedback ratings 
for. Cannot be used together with {$p}title",
+                       'filter' => 'What filtering to apply to list',
                );
        }
 
diff --git a/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.css 
b/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.css
index e69de29..4b81f10 100644
--- a/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.css
+++ b/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.css
@@ -0,0 +1,8 @@
+#articlefeedbackv5-article-feedback-link {
+       /* @embed */
+       background-image: url(images/feedback-post.png);
+       background-repeat: no-repeat;
+       background-position: left;
+       margin-left: 20px;
+       padding-left: 15px;
+}
diff --git a/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js 
b/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js
index 12f9615..9da3bcd 100644
--- a/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js
+++ b/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js
@@ -18,6 +18,43 @@
 
 $aftDiv.articleFeedbackv5();
 
+// Check if the article page link can be shown
+if ( mw.config.get( 'wgArticleFeedbackv5ArticlePageLink' ) &&
+       mw.config.get( 'wgArticleFeedbackv5Permissions' )['aft-editor'] ) {
+
+       var api = new mw.Api();
+       api.get( {
+               'pageid': $.aftUtils.article().id,
+               'filter': 'featured',
+               'action': 'articlefeedbackv5-get-count',
+               'format': 'json'
+       } )
+       .done( function ( data ) {
+               if ( 'articlefeedbackv5-get-count' in data && 'count' in 
data['articlefeedbackv5-get-count'] ) {
+                       var count = 
data['articlefeedbackv5-get-count']['count'];
+
+                       if ( count > 0 ) {
+                               // Build the url to the 
Special:ArticleFeedbackv5 page
+                               var url =
+                                       mw.config.get( 
'wgArticleFeedbackv5SpecialUrl' ) + '/' +
+                                       mw.util.wikiUrlencode( mw.config.get( 
'aftv5Article' ).title );
+                               url += ( url.indexOf( '?' ) >= 0 ? '&' : '?' ) 
+ $.param( { ref: 'article', filter: 'featured' } );
+
+                               // Add the link to the feedback-page next to 
the title
+                               $( '<a 
id="articlefeedbackv5-article-feedback-link"></a>' )
+                                       .msg( 
'articlefeedbackv5-article-view-feedback', count )
+                                       .attr( 'href', url )
+                                       .click( { trackingId: 
'article_page_view_feedback-button_click' }, $.aftTrack.trackEvent )
+                                       .insertAfter( '#siteSub' );
+
+                               // Track an impression
+                               $.aftTrack.init();
+                               $.aftTrack.track( 
'article_page_view_feedback-impression' );
+                       }
+               }
+       } );
+}
+
 /* Add basic edit tracking, making use of $.aftTrack() already being set up */
 if ( $.aftTrack.clickTrackingOn ) {
        var editEventBase = $.aftTrack.prefix( $aftDiv.articleFeedbackv5( 
'experiment' ) );
diff --git a/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.talk.js 
b/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.talk.js
index 651f624..efd4675 100644
--- a/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.talk.js
+++ b/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.talk.js
@@ -4,37 +4,48 @@
 
 /*** Main entry point ***/
 jQuery( function( $ ) {
-
        // Check if the talk page link can be shown
        if ( mw.config.get( 'wgArticleFeedbackv5TalkPageLink' ) ) {
 
-               // Build the url to the Special:ArticleFeedbackv5 page
-               var params = { ref: 'talk' };
-               var url = mw.config.get( 'wgArticleFeedbackv5SpecialUrl' ) + 
'/' +
-                       mw.util.wikiUrlencode( mw.config.get( 'aftv5Article' 
).title );
-               url = url + ( url.indexOf( '?' ) >= 0 ? '&' : '?' ) + $.param( 
params );
-
-               // Add the link to the feedback-page next to the title
-               var link = $( '<a 
id="articlefeedbackv5-talk-feedback-link"></a>' );
-               link
-                       .text( mw.msg( 'articlefeedbackv5-talk-view-feedback' ) 
)
-                       .html( link.html() + ' &raquo;' )
-                       .attr( 'href', url )
-                       .click( { trackingId: 
'talk_page_view_feedback-button_click' }, $.aftTrack.trackEvent );
-
-               $( '#firstHeading' ).append( link );
-
-               // Check if AFT is enabled
-               if ( $.aftUtils.verify( 'talk' ) ) {
-                       // Initialize clicktracking
-                       // NB: Using the talk page's namespace, title, and rev 
id, not
-                       // the article's as in the front end tracking
-                       $.aftTrack.init();
-
-                       // Track an impression
-                       $.aftTrack.track( 'talk_page_view_feedback-impression' 
);
+               var filter = '*';
+               /*
+                * If AFT is disabled for this page, we'll only want to show 
the link if
+                * there's leftover featured feedback.
+                */
+               if ( !$.aftUtils.verify( 'talk' ) ) {
+                       filter = 'featured';
                }
 
-       }
+               var api = new mw.Api();
+               api.get( {
+                       'pageid': $.aftUtils.article().id,
+                       'filter': filter,
+                       'action': 'articlefeedbackv5-get-count',
+                       'format': 'json'
+               } )
+               .done( function ( data ) {
+                       if ( 'articlefeedbackv5-get-count' in data && 'count' 
in data['articlefeedbackv5-get-count'] ) {
+                               var count = 
data['articlefeedbackv5-get-count']['count'];
 
+                               if ( count > 0 ) {
+                                       // Build the url to the 
Special:ArticleFeedbackv5 page
+                                       var url =
+                                               mw.config.get( 
'wgArticleFeedbackv5SpecialUrl' ) + '/' +
+                                               mw.util.wikiUrlencode( 
mw.config.get( 'aftv5Article' ).title );
+                                       url += ( url.indexOf( '?' ) >= 0 ? '&' 
: '?' ) + $.param( { ref: 'talk', filter: 'featured' } );
+
+                                       // Add the link to the feedback-page 
next to the title
+                                       $( '<a 
id="articlefeedbackv5-talk-feedback-link"></a>' )
+                                               .text( mw.msg( 
'articlefeedbackv5-talk-view-feedback' ) )
+                                               .attr( 'href', url )
+                                               .click( { trackingId: 
'talk_page_view_feedback-button_click' }, $.aftTrack.trackEvent )
+                                               .insertAfter( '#siteSub' );
+
+                                       // Track an impression
+                                       $.aftTrack.init();
+                                       $.aftTrack.track( 
'talk_page_view_feedback-impression' );
+                               }
+                       }
+               } );
+       }
 } );
diff --git a/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.utils.js 
b/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.utils.js
index 78d0ab4..1ebadd7 100644
--- a/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.utils.js
+++ b/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.utils.js
@@ -16,6 +16,29 @@
 
        $.aftUtils = {};
 
+       // }}}
+       // {{{ article
+
+       /**
+        * Get article info
+        *
+        * @return object
+        */
+       $.aftUtils.article = function () {
+               // clone object
+               var article = jQuery.extend( {}, mw.config.get( 'aftv5Article' 
) );
+
+               // fetch data, on article level, we can fetch these from other 
sources as well
+               if ( $.inArray( mw.config.get( 'wgNamespaceNumber' ), 
mw.config.get( 'wgArticleFeedbackv5Namespaces', [] ) ) > -1 ) {
+                       article.id = mw.config.get( 'wgArticleId', -1 );
+                       article.namespace = mw.config.get( 'wgNamespaceNumber' 
);
+                       article.categories = mw.config.get( 'wgCategories', [] 
);
+               }
+
+               return article;
+       };
+
+       // }}}
        // {{{ verify
 
        /**
@@ -28,15 +51,8 @@
                // remove obsolete cookies
                $.aftUtils.removeLegacyCookies();
 
-               var article = mw.config.get( 'aftv5Article' );
 
-               // fetch data, on article level, we can fetch these from other 
sources as well
-               if ( location == 'article' ) {
-                       article.id = mw.config.get( 'wgArticleId', -1 );
-                       article.namespace = mw.config.get( 'wgNamespaceNumber' 
);
-                       article.categories = mw.config.get( 'wgCategories', [] 
);
-               }
-
+               var article = $.aftUtils.article();
 
                var enable = true;
 

-- 
To view, visit https://gerrit.wikimedia.org/r/35168
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I03c815d8257aaa590ef639387c360d8356cd0d96
Gerrit-PatchSet: 23
Gerrit-Project: mediawiki/extensions/ArticleFeedbackv5
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: Bsitu <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to