r112137 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112136‎ | r112137 | r112138 >
Date:19:34, 22 February 2012
Author:yonishostak
Status:ok
Tags:
Comment:
AFTv5: added toggle option for (un)helpful flag api calls - client side
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.hooks.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.i18n.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.css (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.i18n.php
@@ -142,8 +142,9 @@
143143 'articlefeedbackv5-timestamp-months' => '{{PLURAL:$1|$1 month|$1 months}}',
144144 'articlefeedbackv5-timestamp-weeks' => '{{PLURAL:$1|$1 week|$1 weeks}}',
145145 'articlefeedbackv5-timestamp-seconds' => 'less than 1 minute',
146 -
147 -
 146+ 'articlefeedbackv5-mask-text' => 'Feedback hidden by administrative action. Click to view contents.',
 147+ 'articlefeedbackv5-mask-postnumber' => 'Post #$1',
 148+
148149 /* Special page flyover panels */
149150 /* Hide this post panel */
150151 'articlefeedbackv5-noteflyover-hide-caption' => 'Hide this post',
@@ -598,6 +599,9 @@
599600 * <code>$1</code> – URL of the confirmation link
600601 * <code>$2</code> – URL to type in the confirmation code manually.
601602 * <code>$3</code> – Confirmation code for the user to type in',
 603+ 'articlefeedbackv5-mask-text' => 'Text to be displayed on the hidden post mask',
 604+ 'articlefeedbackv5-mask-postnumber' => 'Template for post number, to be displayed on the hidden post mask',
 605+
602606 );
603607
604608 /** Afrikaans (Afrikaans)
Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.css
@@ -567,4 +567,21 @@
568568 width: 100%;
569569 height: 100%;
570570 background-color: #dae2eb;
 571+ padding: 10px;
571572 }
 573+.articleFeedbackv5-post-screen .articleFeedbackv5-mask-text-wrapper {
 574+ position: absolute;
 575+ width: 100%;
 576+ color: #777;
 577+ font-size: 1.4em;
 578+ vertical-align: middle;
 579+}
 580+.articleFeedbackv5-post-screen .articleFeedbackv5-mask-text {
 581+ display: inline-block;
 582+ float: left;
 583+}
 584+.articleFeedbackv5-post-screen .articleFeedbackv5-mask-postid {
 585+ display: inline-block;
 586+ float: right;
 587+ margin-right: 50px;
 588+}
Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
@@ -98,6 +98,17 @@
9999 </div>\
100100 </form>';
101101
 102+ /**
 103+ * Mask HMTL template
 104+ */
 105+ $.articleFeedbackv5special.maskHtmlTemplate = '\
 106+ <div class="articleFeedbackv5-post-screen">\
 107+ <div class="articleFeedbackv5-mask-text-wrapper">\
 108+ <span class="articleFeedbackv5-mask-text"></span>\
 109+ <span class="articleFeedbackv5-mask-postid"></span>\
 110+ </div>\
 111+ </div>';
 112+
102113 // }}}
103114 // {{{ Init methods
104115
@@ -231,7 +242,8 @@
232243 $.articleFeedbackv5special.flagFeedback(
233244 $( '#' + $.articleFeedbackv5special.currentPanelHostId ).closest( '.articleFeedbackv5-feedback' ).attr( 'rel' ),
234245 $( e.target ).attr( 'action' ),
235 - $( '#articlefeedbackv5-noteflyover-note' ).attr( 'value' ) );
 246+ $( '#articlefeedbackv5-noteflyover-note' ).attr( 'value' ),
 247+ { } );
236248
237249 // hide tipsy
238250 $( '#' + $.articleFeedbackv5special.currentPanelHostId ).tipsy( 'hide' );
@@ -488,12 +500,18 @@
489501 // }}}
490502 // {{{ maskPost
491503 $.articleFeedbackv5special.maskPost = function( $row ) {
492 - var $screen = $( '<div></div>' )
 504+ var $screen = $( $.articleFeedbackv5special.maskHtmlTemplate )
493505 .addClass( 'articleFeedbackv5-post-screen' )
494506 .height( $row.innerHeight() )
495507 .click( function( e ) {
496 - $( e.target ).remove();
497 - });
 508+ $( e.target ).closest( '.articleFeedbackv5-post-screen' ).remove();
 509+ } );
 510+ $screen.find( '.articleFeedbackv5-mask-text-wrapper')
 511+ .css( 'top', $screen.innerHeight() / 2 - 12 );
 512+ $screen.find( '.articleFeedbackv5-mask-text' )
 513+ .text( mw.msg( 'articlefeedbackv5-mask-text' ) );
 514+ $screen.find( '.articleFeedbackv5-mask-postid' )
 515+ .text( mw.msg( 'articlefeedbackv5-mask-postnumber', $row.attr( 'rel' ) ) );
498516 $row.prepend( $screen );
499517 }
500518 // }}}
@@ -551,8 +569,9 @@
552570 * @param id int the feedback id
553571 * @param action string action to execute
554572 * @param note string note for action (default empty)
 573+ * @param options object key => value pairs of additonal API action-specific parameters
555574 */
556 - $.articleFeedbackv5special.flagFeedback = function ( id, action, note ) {
 575+ $.articleFeedbackv5special.flagFeedback = function ( id, action, note, options ) {
557576 // default parameters
558577 note = typeof note !== undefined ? note : '';
559578
@@ -571,20 +590,24 @@
572591 // messing up the counts, and generally seems like a good idea.
573592 $.articleFeedbackv5special.listControls.disabled = true;
574593 }
 594+
 595+ // Merge request data and options objects (flat)
 596+ var requestData = {
 597+ 'pageid' : $.articleFeedbackv5special.page,
 598+ 'feedbackid': id,
 599+ 'flagtype' : $.articleFeedbackv5special.actions[action].apiFlagType,
 600+ 'direction' : $.articleFeedbackv5special.actions[action].apiFlagDir > 0 ? 'increase' : 'decrease',
 601+ 'note' : note,
 602+ 'format' : 'json',
 603+ 'action' : 'articlefeedbackv5-flag-feedback'
 604+ };
 605+ $.extend( requestData, options );
575606
576607 $.ajax( {
577608 'url' : $.articleFeedbackv5special.apiUrl,
578609 'type' : 'POST',
579610 'dataType': 'json',
580 - 'data' : {
581 - 'pageid' : $.articleFeedbackv5special.page,
582 - 'feedbackid': id,
583 - 'flagtype' : $.articleFeedbackv5special.actions[action].apiFlagType,
584 - 'direction' : $.articleFeedbackv5special.actions[action].apiFlagDir > 0 ? 'increase' : 'decrease',
585 - 'note' : note,
586 - 'format' : 'json',
587 - 'action' : 'articlefeedbackv5-flag-feedback'
588 - },
 611+ 'data' : requestData,
589612 'success': function ( data ) {
590613 var msg = 'articlefeedbackv5-error-flagging';
591614 if ( 'articlefeedbackv5-flag-feedback' in data ) {
@@ -802,12 +825,7 @@
803826 if( $.articleFeedbackv5special.canBeFlagged( $link.closest( '.articleFeedbackv5-feedback' ) ) ) {
804827 var id = $link.closest( '.articleFeedbackv5-feedback' ).attr( 'rel' );
805828 var activity = $.articleFeedbackv5special.getActivity( id );
806 - $.articleFeedbackv5special.listControls.allowMultiple = true;
807 - if( activity['unhelpful'] ) {
808 - $.articleFeedbackv5special.flagFeedback( id, 'reverseunhelpful', '' );
809 - }
810 - $.articleFeedbackv5special.flagFeedback( id, 'helpful', '' );
811 - $.articleFeedbackv5special.listControls.allowMultiple = false;
 829+ $.articleFeedbackv5special.flagFeedback( id, 'helpful', '', activity['unhelpful'] ? { toggle: true } : { } );
812830 }
813831 },
814832 'apiFlagType': 'helpful',
@@ -819,6 +837,10 @@
820838 .removeClass( 'articleFeedbackv5-helpful-link' )
821839 .addClass( 'articleFeedbackv5-reversehelpful-link' )
822840 .attr( 'id', 'articleFeedbackv5-reversehelpful-link-' + id );
 841+ if( data['toggle'] ) {
 842+ $( '#articleFeedbackv5-unhelpful-link-' + id ).removeClass( 'helpful-active' );
 843+ setActivityFlag( id, 'unhelpful', false )
 844+ }
823845 $.articleFeedbackv5special.setActivityFlag( id, 'helpful', true );
824846 }
825847 },
@@ -831,7 +853,7 @@
832854 var $link = $( e.target );
833855 if( $.articleFeedbackv5special.canBeFlagged( $link.closest( '.articleFeedbackv5-feedback' ) ) ) {
834856 $.articleFeedbackv5special.flagFeedback(
835 - $link.closest( '.articleFeedbackv5-feedback' ).attr( 'rel' ), 'reversehelpful', '' );
 857+ $link.closest( '.articleFeedbackv5-feedback' ).attr( 'rel' ), 'reversehelpful', '', { } );
836858 }
837859 },
838860 'apiFlagType': 'helpful',
@@ -856,12 +878,7 @@
857879 if( $.articleFeedbackv5special.canBeFlagged( $link.closest( '.articleFeedbackv5-feedback' ) ) ) {
858880 var id = $link.closest( '.articleFeedbackv5-feedback' ).attr( 'rel' );
859881 var activity = $.articleFeedbackv5special.getActivity( id );
860 - $.articleFeedbackv5special.listControls.allowMultiple = true;
861 - if( activity['helpful'] ) {
862 - $.articleFeedbackv5special.flagFeedback( id, 'reversehelpful', '' );
863 - }
864 - $.articleFeedbackv5special.flagFeedback( id, 'unhelpful', '' );
865 - $.articleFeedbackv5special.listControls.allowMultiple = false;
 882+ $.articleFeedbackv5special.flagFeedback( id, 'unhelpful', '', activity['helpful'] ? { toggle: true } : { } );
866883 }
867884 },
868885 'apiFlagType': 'unhelpful',
@@ -873,6 +890,10 @@
874891 .removeClass( 'articleFeedbackv5-unhelpful-link')
875892 .addClass( 'articleFeedbackv5-reverseunhelpful-link' )
876893 .attr( 'id', 'articleFeedbackv5-reverseunhelpful-link-' + id );
 894+ if( data['toggle'] ) {
 895+ $( '#articleFeedbackv5-helpful-link-' + id ).removeClass( 'helpful-active' );
 896+ setActivityFlag( id, 'helpful', false )
 897+ }
877898 $.articleFeedbackv5special.setActivityFlag( id, 'unhelpful', true );
878899 }
879900 },
@@ -885,7 +906,7 @@
886907 var $link = $( e.target );
887908 if( $.articleFeedbackv5special.canBeFlagged( $link.closest( '.articleFeedbackv5-feedback' ) ) ) {
888909 $.articleFeedbackv5special.flagFeedback(
889 - $link.closest( '.articleFeedbackv5-feedback' ).attr( 'rel' ), 'reverseunhelpful', '' );
 910+ $link.closest( '.articleFeedbackv5-feedback' ).attr( 'rel' ), 'reverseunhelpful', '', { } );
890911 }
891912 },
892913 'apiFlagType': 'unhelpful',
@@ -909,7 +930,7 @@
910931 var $link = $( e.target );
911932 if( $.articleFeedbackv5special.canBeFlagged( $link.closest( '.articleFeedbackv5-feedback' ) ) ) {
912933 var id = $link.closest( '.articleFeedbackv5-feedback' ).attr( 'rel' );
913 - $.articleFeedbackv5special.flagFeedback( $link.closest( '.articleFeedbackv5-feedback' ).attr( 'rel' ), 'abuse', '' );
 934+ $.articleFeedbackv5special.flagFeedback( $link.closest( '.articleFeedbackv5-feedback' ).attr( 'rel' ), 'abuse', '', { } );
914935 }
915936 },
916937 'apiFlagType': 'abuse',
@@ -945,7 +966,7 @@
946967 var $link = $( e.target );
947968 if( $.articleFeedbackv5special.canBeFlagged( $link.closest( '.articleFeedbackv5-feedback' ) ) ) {
948969 var id = $link.closest( '.articleFeedbackv5-feedback' ).attr( 'rel' );
949 - $.articleFeedbackv5special.flagFeedback( $link.closest( '.articleFeedbackv5-feedback' ).attr( 'rel' ), 'unabuse', '' );
 970+ $.articleFeedbackv5special.flagFeedback( $link.closest( '.articleFeedbackv5-feedback' ).attr( 'rel' ), 'unabuse', '', { } );
950971 }
951972 },
952973 'apiFlagType': 'abuse',
Index: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.hooks.php
@@ -229,7 +229,10 @@
230230 'articlefeedbackv5-noteflyover-declineoversight-placeholder',
231231 'articlefeedbackv5-noteflyover-declineoversight-submit',
232232 'articlefeedbackv5-noteflyover-declineoversight-help',
233 - 'articlefeedbackv5-noteflyover-declineoversight-help-link'
 233+ 'articlefeedbackv5-noteflyover-declineoversight-help-link',
 234+
 235+ 'articlefeedbackv5-mask-text',
 236+ 'articlefeedbackv5-mask-postnumber'
234237 ),
235238 'dependencies' => array(
236239 'mediawiki.util',

Status & tagging log