From b54ba3f817666eda3bb71e879193a7cb44e273af Mon Sep 17 00:00:00 2001 From: bsitu Date: Tue, 7 Aug 2012 14:07:59 -0700 Subject: [PATCH] Personal note on user talk page 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 --- PageTriage.hooks.php | 4 +- PageTriage.i18n.php | 12 +++- PageTriage.php | 7 ++ .../ext.pageTriage.mark.css | 16 +++++ .../ext.pageTriage.mark.html | 20 +++--- .../ext.pageTriage.mark.js | 70 +++++++++++++++---- .../ext.pageTriage.tags.css | 17 +++++ .../ext.pageTriage.tags.html | 9 ++- .../ext.pageTriage.tags.js | 61 +++++++++++++++- 9 files changed, 184 insertions(+), 32 deletions(-) diff --git a/PageTriage.hooks.php b/PageTriage.hooks.php index 4a627e89..dc0b8089 100644 --- a/PageTriage.hooks.php +++ b/PageTriage.hooks.php @@ -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' ) ) { @@ -436,6 +437,7 @@ public static function onResourceLoaderGetConfigVars( &$vars ) { $vars['wgPageTriageToolbarInfoHelpLink'] = $wgPageTriageToolbarInfoHelpLink; $vars['wgPageTriageCurationModules'] = $wgPageTriageCurationModules; $vars['wgPageTriageNamespaces'] = $wgPageTriageNamespaces; + $vars['wgTalkPageNoteTemplate'] = $wgTalkPageNoteTemplate; return true; } } diff --git a/PageTriage.i18n.php b/PageTriage.i18n.php index a1a00cb3..eb23f42a 100644 --- a/PageTriage.i18n.php +++ b/PageTriage.i18n.php @@ -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', @@ -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}}', @@ -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', diff --git a/PageTriage.php b/PageTriage.php index 8913bd60..a8080abb 100644 --- a/PageTriage.php +++ b/PageTriage.php @@ -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 @@ -630,6 +634,9 @@ function efPageTriageUnitTests( &$files ) { 'talkpagelinktext', 'contribslink', 'comma-separator', + 'pagetriage-add-a-note', + 'pagetriage-characters-left', + 'pagetriage-personal-default-note' ) ); diff --git a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.mark.css b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.mark.css index f406ad62..e487d722 100644 --- a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.mark.css +++ b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.mark.css @@ -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; +} diff --git a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.mark.html b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.mark.html index 11307548..11b69218 100644 --- a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.mark.html +++ b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.mark.html @@ -1,13 +1,11 @@
- <% if ( patrol_status == "0" ) { %> -
- <%= gM( 'pagetriage-mark-as-reviewed-helptext' ) %> -
- - <% } else { %> -
- <%= gM( 'pagetriage-mark-as-unreviewed-helptext' ) %> -
- - <% } %> +
+ <%= gM( 'pagetriage-mark-as-' + status + '-helptext' ) %> +
+
+
<%= mw.html.escape( gM( 'pagetriage-add-a-note' ) ) %>
+
<%= mw.html.escape( gM( 'pagetriage-characters-left', maxLength ) ) %>
+ +
+
diff --git a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.mark.js b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.mark.js index 616d4429..bb42a531 100644 --- a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.mark.js +++ b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.mark.js @@ -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 ); } @@ -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' ) ); @@ -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' ); diff --git a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.tags.css b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.tags.css index cba17f4d..6e889bb9 100644 --- a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.tags.css +++ b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.tags.css @@ -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; +} diff --git a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.tags.html b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.tags.html index f9d39ad7..d2812576 100644 --- a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.tags.html +++ b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.tags.html @@ -14,11 +14,16 @@ %>
+
+
<%= mw.html.escape( gM( 'pagetriage-add-a-note' ) ) %>
+
<%= mw.html.escape( gM( 'pagetriage-characters-left', maxLength ) ) %>
+ +
- +
diff --git a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.tags.js b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.tags.js index ebb4e08a..1c2699ce 100644 --- a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.tags.js +++ b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.tags.js @@ -9,6 +9,7 @@ $( function() { tagsOptions: $.pageTriageTagsOptions, selectedTag: {}, selectedTagCount: 0, + noteMaxLength: 250, /** * Initialize data on startup @@ -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 ) { @@ -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 */ @@ -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 ); @@ -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'