Skip to content

Commit

Permalink
Personal note on user talk page
Browse files Browse the repository at this point in the history
Allow editors to leave a personal note on user's talk page when
marking a page as review/unreviewed or adding tags

patch set 2: remove trailing whitespaces

patch set 3:
  1. update message key 'pagetriage-tag-default-note'
  2. escape review button text
  3. fix charLeft comparison for mark as reviewed
  4. remove single quote from json key

patch set 4:
  1. more message escape
  2. fix charLeft comparison for tagging

patch set 5:
  1. update/remove keys from language file
  2. only submit personal note if there is one

patch set 6:
  1. remove trailing whitespaces

patch set 7:
  1. use placeholder attribute for textarea

patch set 8:
  1. remove jquery.live() since it is not needed anymore

patch set 9:
  1. improving wording for unmarking as reviewed

Change-Id: Iadf90fcb79441148130669f9c0aa9c5f606a51e6
  • Loading branch information
bsitu committed Aug 9, 2012
1 parent 9615054 commit b54ba3f
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 32 deletions.
4 changes: 3 additions & 1 deletion PageTriage.hooks.php
Expand Up @@ -424,7 +424,8 @@ public static function onBlockIpComplete( $block, $performer ) {
* @return bool
*/
public static function onResourceLoaderGetConfigVars( &$vars ) {
global $wgPageTriageToolbarInfoHelpLink, $wgPageTriageCurationModules, $wgPageTriageNamespaces;
global $wgPageTriageToolbarInfoHelpLink, $wgPageTriageCurationModules, $wgPageTriageNamespaces,
$wgTalkPageNoteTemplate;

// check if WikiLove is enabled
if ( !class_exists( 'ApiWikiLove' ) ) {
Expand All @@ -436,6 +437,7 @@ public static function onResourceLoaderGetConfigVars( &$vars ) {
$vars['wgPageTriageToolbarInfoHelpLink'] = $wgPageTriageToolbarInfoHelpLink;
$vars['wgPageTriageCurationModules'] = $wgPageTriageCurationModules;
$vars['wgPageTriageNamespaces'] = $wgPageTriageNamespaces;
$vars['wgTalkPageNoteTemplate'] = $wgTalkPageNoteTemplate;
return true;
}
}
12 changes: 9 additions & 3 deletions PageTriage.i18n.php
Expand Up @@ -95,7 +95,10 @@
'pagetriage-button-add-parameters' => 'Add parameters',
'pagetriage-button-add-details' => 'Add details',
'pagetriage-button-edit-details' => 'Edit details',

'pagetriage-add-a-note' => 'Add a message for the creator: (optional)',
'pagetriage-characters-left' => '{{PLURAL:$1|$1 character|$1 characters}} left',
'pagetriage-personal-default-note' => 'Write a helpful note for {{GENDER:$1|$1}}. It will be posted on their talk page.',

// Tags options section
'pagetriage-tags-title' => 'Add tags',
'pagetriage-tags-cat-common-label' => 'Common',
Expand Down Expand Up @@ -320,9 +323,9 @@
'pagetriage-mark-title' => 'Mark as reviewed',
'pagetriage-mark-as-reviewed' => 'Mark as reviewed',
'pagetriage-mark-as-unreviewed' => 'Mark as unreviewed',
'pagetriage-mark-as-reviewed-helptext' => 'Remove this page from the unreviewed queue?',
'pagetriage-mark-as-unreviewed-helptext' => 'Return this page to the unreviewed queue?',
'pagetriage-mark-tooltip' => 'Mark page as reviewed (or unreviewed if already reviewed)',
'pagetriage-mark-as-reviewed-helptext' => 'Mark this page as reviewed if you\'re done checking it.',
'pagetriage-mark-as-unreviewed-helptext' => 'Mark this page as unreviewed if you think it needs to be checked further.',
'pagetriage-wikilove-helptext' => 'Select the names of editors you wish to thank.',
'pagetriage-wikilove-page-creator' => 'Page Creator',
'pagetriage-wikilove-edit-count' => '$1 {{PLURAL:$1|edit|edits}}',
Expand Down Expand Up @@ -427,6 +430,9 @@
'pagetriage-button-add-parameters' => 'Text for the button that adds parameters',
'pagetriage-button-add-details' => 'Text for the bution that saves any extra information associated with the tag',
'pagetriage-button-edit-details' => 'Text for the button that lets the user edit information associated with the tag',
'pagetriage-add-a-note' => 'Text for adding a personal note in curation toolbar',
'pagetriage-characters-left' => 'The text indicating the number of characters remaining for input',
'pagetriage-personal-default-note' => 'Default text in the text box for editors to add a "Mark as reviewed" or "Tagging" personal note, $1 is the name of the page creator',
'pagetriage-tags-title' => 'The title for the tag wizard flyout in the toolbar',
'pagetriage-tags-cat-common-label' => 'Label for common category',
'pagetriage-tags-cat-metadata-label' => 'Label for metadata category',
Expand Down
7 changes: 7 additions & 0 deletions PageTriage.php
Expand Up @@ -68,6 +68,10 @@
$wgPageTriageToolbarInfoHelpLink = "http://en.wikipedia.org/wiki/Wikipedia:New_pages_patrol#Patroller_checklists"; // help link in toolbar article info view
$wgPageTriageCacheVersion = '1.0'; // version number to be added to cache key so that cache can be refreshed easily
$wgPageTriageNamespaces = array( NS_MAIN, NS_USER ); // only include these namespaces for pagetriage
$wgTalkPageNoteTemplate = array(
'Mark' => 'Reviewednote-NPF',
'Tags' => 'Taggednote-NPF'
);
// End configuration variables


Expand Down Expand Up @@ -630,6 +634,9 @@ function efPageTriageUnitTests( &$files ) {
'talkpagelinktext',
'contribslink',
'comma-separator',
'pagetriage-add-a-note',
'pagetriage-characters-left',
'pagetriage-personal-default-note'
)
);

Expand Down
16 changes: 16 additions & 0 deletions modules/ext.pageTriage.views.toolbar/ext.pageTriage.mark.css
Expand Up @@ -7,3 +7,19 @@
font-size: 0.8em;
}

#mwe-pt-review-note {
margin-top: 10px;
}

#mwe-pt-review-note-title {
float: left;
font-size: 0.8em;
}

#mwe-pt-review-note-char-count {
float: right;
font-size: 0.8em;
}
#mwe-pt-review-note-input {
clear: both;
}
20 changes: 9 additions & 11 deletions modules/ext.pageTriage.views.toolbar/ext.pageTriage.mark.html
@@ -1,13 +1,11 @@
<div>
<% if ( patrol_status == "0" ) { %>
<div class="mwe-pt-mark-helptext">
<%= gM( 'pagetriage-mark-as-reviewed-helptext' ) %>
</div>
<button id='mwe-pt-mark-as-reviewed-button' class="ui-button-green"><%= gM( "pagetriage-mark-as-reviewed" ) %></button>
<% } else { %>
<div class="mwe-pt-mark-helptext">
<%= gM( 'pagetriage-mark-as-unreviewed-helptext' ) %>
</div>
<button id='mwe-pt-mark-as-unreviewed-button' class="ui-button-green"><%= gM( "pagetriage-mark-as-unreviewed" ) %></button>
<% } %>
<div class="mwe-pt-mark-helptext">
<%= gM( 'pagetriage-mark-as-' + status + '-helptext' ) %>
</div>
<div id="mwe-pt-review-note">
<div id="mwe-pt-review-note-title"><%= mw.html.escape( gM( 'pagetriage-add-a-note' ) ) %></div>
<div id="mwe-pt-review-note-char-count"><%= mw.html.escape( gM( 'pagetriage-characters-left', maxLength ) ) %></div>
<textarea id="mwe-pt-review-note-input"></textarea>
</div>
<button id='mwe-pt-mark-as-<%= status %>-button' class="ui-button-green"><%= mw.html.escape( gM( "pagetriage-mark-as-" + status ) ) %></button>
</div>
70 changes: 57 additions & 13 deletions modules/ext.pageTriage.views.toolbar/ext.pageTriage.mark.js
Expand Up @@ -40,9 +40,14 @@ $( function() {
cache: false,
success: function( data ) {
if ( typeof data.pagetriageaction !== 'undefined' && data.pagetriageaction.result === 'success' ) {
// update the article model, since it's now changed.
_this.model.fetch();
_this.hide();
var note = $.trim( $( '#mwe-pt-review-note-input' ).val() );
if ( note.length ) {
_this.talkPageNote( note, action );
} else {
// update the article model, since it's now changed.
_this.model.fetch();
_this.hide();
}
} else {
_this.showMarkError( action );
}
Expand All @@ -53,7 +58,38 @@ $( function() {
dataType: 'json'
} );
},


talkPageNote: function( note, action ) {
var _this = this, title = new mw.Title( this.model.get( 'user_name' ), mw.config.get( 'wgNamespaceIds' )['user_talk'] );

note = '{{' + mw.config.get( 'wgTalkPageNoteTemplate' )['Mark']
+ '|' + mw.config.get( 'wgPageName' )
+ '|' + mw.config.get( 'wgUserName' )
+ '|' + note + '}}';

$.ajax( {
type: 'post',
url: mw.util.wikiScript( 'api' ),
data: {
action: 'edit',
title: title.getPrefixedText(),
appendtext: "\n" + note,
token: mw.user.tokens.get( 'editToken' ),
format: 'json'
},
success: function( data ) {
if ( data.edit && data.edit.result === 'Success' ) {
// update the article model, since it's now changed.
_this.model.fetch();
_this.hide();
} else {
_this.showMarkError( action );
}
},
dataType: 'json'
} );
},

showMarkError: function( action ) {
if ( action === 'reviewed' ) {
alert( mw.msg( 'pagetriage-mark-as-reviewed-error' ) );
Expand All @@ -63,19 +99,27 @@ $( function() {
},

render: function() {
var _this = this;
var _this = this, status = this.model.get( 'patrol_status' ) == "0" ? 'reviewed' : 'unreviewed', maxLength = 250;

// create the mark as reviewed flyout content here.
this.$tel.html( this.template( this.model.toJSON() ) );
this.$tel.html( this.template( $.extend( this.model.toJSON(), { 'status': status, 'maxLength': maxLength } ) ) );

// override the flyout title based on the current reviewed state of the page
if ( this.model.get( 'patrol_status' ) > 0 ) {
// page is reviewed
$( '#mwe-pt-mark .mwe-pt-tool-title' ).text( mw.msg( 'pagetriage-mark-as-unreviewed' ) );
} else {
// page is unreviewed
$( '#mwe-pt-mark .mwe-pt-tool-title' ).text( mw.msg( 'pagetriage-mark-as-reviewed' ) );
}
$( '#mwe-pt-mark .mwe-pt-tool-title' ).text( mw.msg( 'pagetriage-mark-as-' + status ) );

$( '#mwe-pt-review-note-input' ).keyup( function() {
var length = $.trim( $('#mwe-pt-review-note-input').val() ).length;
var buttonId = 'mwe-pt-mark-as-' + status + '-button';
var charLeft = maxLength - length;

$( '#mwe-pt-review-note-char-count' ).text( mw.msg( 'pagetriage-characters-left', charLeft ) );

if ( charLeft <= 0 ) {
$( '#' + buttonId ).button( 'disable' );
} else {
$( '#' + buttonId ).button( 'enable' );
}
} ).attr( 'placeholder', gM( 'pagetriage-personal-default-note', this.model.get( 'user_name' ) ) );

// set the Learn More link URL
var modules = mw.config.get( 'wgPageTriageCurationModules' );
Expand Down
17 changes: 17 additions & 0 deletions modules/ext.pageTriage.views.toolbar/ext.pageTriage.tags.css
Expand Up @@ -120,3 +120,20 @@
margin-left: 0 !important;
background-color: white;
}
#mwe-pt-tag-note {
display: none;
margin-top: 10px;
}

#mwe-pt-tag-note-title {
float: left;
font-size: 0.8em;
}

#mwe-pt-tag-note-char-count {
float: right;
font-size: 0.8em;
}
#mwe-pt-tag-note-input {
clear: both;
}
9 changes: 7 additions & 2 deletions modules/ext.pageTriage.views.toolbar/ext.pageTriage.tags.html
Expand Up @@ -14,11 +14,16 @@
%>
</div>
<div id="mwe-pt-tags-bottom">
<div id="mwe-pt-tag-note">
<div id="mwe-pt-tag-note-title"><%= mw.html.escape( gM( 'pagetriage-add-a-note' ) ) %></div>
<div id="mwe-pt-tag-note-char-count"><%= mw.html.escape( gM( 'pagetriage-characters-left', maxLength ) ) %></div>
<textarea id="mwe-pt-tag-note-input"></textarea>
</div>
<div id="mwe-pt-checkbox-mark-reviewed-wrapper">
<input id="mwe-pt-checkbox-mark-reviewed" type="checkbox" value="mark reviewed" disabled="disabled">
<label id="mwe-pt-checkbox-mark-reviewed-label" for="mwe-pt-checkbox-mark-reviewed"><%= gM( 'pagetriage-markpatrolled' ) %></label>
<label id="mwe-pt-checkbox-mark-reviewed-label" for="mwe-pt-checkbox-mark-reviewed"><%= mw.html.escape( gM( 'pagetriage-markpatrolled' ) ) %></label>
</div>
<div id="mwe-pt-tag-submit">
<a href="#" id="mwe-pt-tag-submit-button" class="ui-button-green"><%= mw.msg('pagetriage-button-add-tag-number', 0) %></a>
<a href="#" id="mwe-pt-tag-submit-button" class="ui-button-green"><%= mw.html.escape( mw.msg( 'pagetriage-button-add-tag-number', 0 ) ) %></a>
</div>
</div>
61 changes: 59 additions & 2 deletions modules/ext.pageTriage.views.toolbar/ext.pageTriage.tags.js
Expand Up @@ -9,6 +9,7 @@ $( function() {
tagsOptions: $.pageTriageTagsOptions,
selectedTag: {},
selectedTagCount: 0,
noteMaxLength: 250,

/**
* Initialize data on startup
Expand Down Expand Up @@ -85,12 +86,23 @@ $( function() {
render: function() {
var _this = this;
this.reset();
this.$tel.html( this.template( { 'tags': this.tagsOptions, 'title': this.title } ) );
this.$tel.html( this.template( { 'tags': this.tagsOptions, 'title': this.title, 'maxLength': this.noteMaxLength } ) );
this.model.on( 'change', this.showHideReviewButton, this );

// set the Learn More link URL
var modules = mw.config.get( 'wgPageTriageCurationModules' );
$( '#mwe-pt-tag .mwe-pt-flyout-help-link' ).attr( 'href', modules.tags );
$( '#mwe-pt-tag-note-input' ).keyup( function() {
var charLeft = _this.noteCharLeft();

$( '#mwe-pt-tag-note-char-count' ).text( mw.msg( 'pagetriage-characters-left', charLeft ) );

if ( charLeft > 0 && _this.selectedTagCount > 0 ) {
$( '#mwe-pt-tag-submit-button' ).button( 'enable' );
} else {
$( '#mwe-pt-tag-submit-button' ).button( 'disable' );
}
} ).attr( 'placeholder', gM( 'pagetriage-personal-default-note', this.model.get( 'user_name' ) ) );

// add click event for each category
$( '#mwe-pt-categories' ).find( 'div' ).each( function( index, value ) {
Expand Down Expand Up @@ -119,6 +131,10 @@ $( function() {
this.displayTags( 'common' );
},

noteCharLeft: function() {
return this.noteMaxLength - $.trim( $('#mwe-pt-tag-note-input').val() ).length;
},

/**
* Display the tags for the selected category
*/
Expand Down Expand Up @@ -254,11 +270,13 @@ $( function() {
$( '#mwe-pt-category-' + cat + ' .mwe-pt-tag-count' ).empty();
}

this.selectedTagCount > 0 ? $( '#mwe-pt-tag-note' ).show() : $( '#mwe-pt-tag-note' ).hide();

// update the number in the submit button
$( '#mwe-pt-tag-submit-button .ui-button-text' ).html( mw.msg( 'pagetriage-button-add-tag-number', this.selectedTagCount ) );

// activate or deactivate the submit button and associated parts
if ( this.selectedTagCount > 0 ) {
if ( this.selectedTagCount > 0 && this.noteCharLeft() > 0 ) {
$( '#mwe-pt-tag-submit-button' ).button( 'enable' );
$( '#mwe-pt-checkbox-mark-reviewed' ).removeAttr( 'disabled' );
$( '#mwe-pt-checkbox-mark-reviewed-label' ).css( 'opacity', 1.0 );
Expand Down Expand Up @@ -531,8 +549,47 @@ $( function() {
},
success: function( data ) {
if ( data.pagetriagetagging.result === 'success' ) {
var note = $.trim( $( '#mwe-pt-tag-note-input' ).val() );
if ( note.length ) {
_this.talkPageNote( note );
} else {
// update the article model, since it's now changed.
_this.reset();
window.location.reload( true );
}
} else {
alert( mw.msg( 'pagetriage-mark-as-reviewed-error' ) );
}
},
dataType: 'json'
} );
},

talkPageNote: function( note ) {
var _this = this, title = new mw.Title( this.model.get( 'user_name' ), mw.config.get( 'wgNamespaceIds' )['user_talk'] );

note = '{{' + mw.config.get( 'wgTalkPageNoteTemplate' )['Tags']
+ '|' + mw.config.get( 'wgPageName' )
+ '|' + mw.config.get( 'wgUserName' )
+ '|' + note + '}}';

$.ajax( {
type: 'post',
url: mw.util.wikiScript( 'api' ),
data: {
'action': 'edit',
'title': title.getPrefixedText(),
'appendtext': "\n" + note,
'token': mw.user.tokens.get('editToken'),
'format': 'json'
},
success: function( data ) {
if ( data.edit && data.edit.result === 'Success' ) {
// update the article model, since it's now changed.
_this.reset();
window.location.reload( true );
} else {
alert( mw.msg( 'pagetriage-mark-as-reviewed-error' ) );
}
},
dataType: 'json'
Expand Down

0 comments on commit b54ba3f

Please sign in to comment.