From a600310e4d6252f95f91bd7c6b2d5c9cc677bbec Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Thu, 6 Dec 2012 06:57:53 +0100 Subject: [PATCH] (bug 42136) Use user prefs to set initial state of "Watch this". * Don't show at all if user isn't logged in * Use "watch pages I create" and "watch pages I create" prefs * If the user is already watching it, use that Also updated relevant onMakeGlobalVariablesScript hook, it was using old globals still, the hook has context as of MediaWiki 1.19. Change-Id: Ic3daf32505a745b3cccd0663a03bbf7f3885be84 --- VisualEditor.hooks.php | 8 +++----- .../mw/styles/ve.init.mw.ViewPageTarget.css | 1 + .../mw/targets/ve.init.mw.ViewPageTarget.js | 19 ++++++++++++++++--- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php index 48fc8fef90..055a9fbbcc 100644 --- a/VisualEditor.hooks.php +++ b/VisualEditor.hooks.php @@ -56,14 +56,12 @@ class VisualEditorHooks { /** * Adds extra variables to the page config. - * - * This is attached to the MediaWiki 'MakeGlobalVariablesScript' hook. */ - public static function onMakeGlobalVariablesScript( &$vars ) { - global $wgUser, $wgTitle; + public static function onMakeGlobalVariablesScript( array &$vars, OutputPage $out ) { $vars['wgVisualEditor'] = array( - 'isPageWatched' => $wgUser->isWatched( $wgTitle ) + 'isPageWatched' => $out->getUser()->isWatched( $out->getTitle() ) ); + return true; } diff --git a/modules/ve/init/mw/styles/ve.init.mw.ViewPageTarget.css b/modules/ve/init/mw/styles/ve.init.mw.ViewPageTarget.css index 7ba22f8cd3..6644d9b970 100644 --- a/modules/ve/init/mw/styles/ve.init.mw.ViewPageTarget.css +++ b/modules/ve/init/mw/styles/ve.init.mw.ViewPageTarget.css @@ -262,6 +262,7 @@ margin-bottom: 1em; border: solid 1px #cccccc; border-radius: 0 0 0.25em 0.25em; + min-height: 2.25em; } .ve-init-mw-viewPageTarget-saveDialog-body label { diff --git a/modules/ve/init/mw/targets/ve.init.mw.ViewPageTarget.js b/modules/ve/init/mw/targets/ve.init.mw.ViewPageTarget.js index d0cd6cb52f..36cf0a5cf1 100644 --- a/modules/ve/init/mw/targets/ve.init.mw.ViewPageTarget.js +++ b/modules/ve/init/mw/targets/ve.init.mw.ViewPageTarget.js @@ -753,6 +753,8 @@ ve.init.mw.ViewPageTarget.prototype.getSaveDialogHtml = function ( callback ) { var viewPage = this, $wrap = $( '
' ).html( this.constructor.saveDialogTemplate ); + // Based on EditPage::getCheckboxes and EditPage::initialiseForm + mw.user.getRights( function ( rights ) { // MediaWiki only allows usage of minor flag when editing an existing page // and the user has the right to use the feature. @@ -762,6 +764,20 @@ ve.init.mw.ViewPageTarget.prototype.getSaveDialogHtml = function ( callback ) { .find( '.ve-init-mw-viewPageTarget-saveDialog-minorEdit-label, #ve-init-mw-viewPageTarget-saveDialog-minorEdit' ) .remove(); } + + if ( mw.user.isAnon() ) { + $wrap + .find( '.ve-init-mw-viewPageTarget-saveDialog-watchList-label, #ve-init-mw-viewPageTarget-saveDialog-watchList' ) + .remove(); + } else if ( + mw.user.options.get( 'watchdefault' ) || + ( mw.user.options.get( 'watchcreations' ) && !viewPage.pageExists ) || + mw.config.get( 'wgVisualEditor' ).isPageWatched + ) { + $wrap + .find( '#ve-init-mw-viewPageTarget-saveDialog-watchList' ) + .prop( 'checked', true ); + } callback( $wrap ); } ); }; @@ -817,9 +833,6 @@ ve.init.mw.ViewPageTarget.prototype.setupSaveDialog = function () { .find( '.ve-init-mw-viewPageTarget-saveDialog-watchList-label' ) .html( ve.init.platform.getParsedMessage( 'watchthis' ) ) .end() - .find( '#ve-init-mw-viewPageTarget-saveDialog-watchList' ) - .prop( 'checked', mw.config.get( 'wgVisualEditor' ).isPageWatched ) - .end() .find( '.ve-init-mw-viewPageTarget-saveDialog-saveButton' ) .on( { 'mousedown': function () {