From 9af997c592ade0fd036b24a436b7705c639a561b Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 12 Jul 2011 21:58:23 +0000 Subject: [PATCH] * Made (un)watch action show a form if the token is bad/missing (this handles unwatch links given in emails) * Changed misleading watch/unwatch subtitle msgs --- includes/actions/WatchAction.php | 90 ++++++++++++++++++++++--------- languages/messages/MessagesEn.php | 12 ++++- maintenance/language/messages.inc | 10 +++- 3 files changed, 83 insertions(+), 29 deletions(-) diff --git a/includes/actions/WatchAction.php b/includes/actions/WatchAction.php index 94ad1cca2f..aed3be58a3 100644 --- a/includes/actions/WatchAction.php +++ b/includes/actions/WatchAction.php @@ -20,7 +20,7 @@ * @ingroup Actions */ -class WatchAction extends FormlessAction { +class WatchAction extends FormAction { public function getName() { return 'watch'; @@ -35,35 +35,56 @@ class WatchAction extends FormlessAction { } protected function getDescription() { - return wfMsg( 'addedwatch' ); + return wfMsg( 'addwatch' ); } - protected function checkCanExecute( User $user ) { + /** + * Just get an empty form with a single submit button + * @return array + */ + protected function getFormFields() { + return array(); + } - // Must be logged in - if ( $user->isAnon() ) { - throw new ErrorPageError( 'watchnologin', 'watchnologintext' ); - } + public function onSubmit( $data ) { + wfProfileIn( __METHOD__ ); + self::doWatch( $this->getTitle(), $this->getUser() ); + wfProfileOut( __METHOD__ ); + return true; + } + + /** + * purge is slightly weird because it can be either formed or formless depending + * on user permissions + */ + public function show() { + $this->setHeaders(); + + $user = $this->getUser(); + // This will throw exceptions if there's a problem + $this->checkCanExecute( $user ); // Must have valid token for this action/title $salt = array( $this->getName(), $this->getTitle()->getDBkey() ); - if ( !$user->matchEditToken( $this->getRequest()->getVal( 'token' ), $salt ) ) { - throw new ErrorPageError( 'sessionfailure-title', 'sessionfailure' ); + if ( $user->matchEditToken( $this->getRequest()->getVal( 'token' ), $salt ) ) { + $this->onSubmit( array() ); + $this->onSuccess(); + } else { + $form = $this->getForm(); + if ( $form->show() ) { + $this->onSuccess(); + } } - - return parent::checkCanExecute( $user ); } - public function onView() { - wfProfileIn( __METHOD__ ); - - $user = $this->getUser(); - self::doWatch( $this->getTitle(), $user ); - - wfProfileOut( __METHOD__ ); + protected function checkCanExecute( User $user ) { + // Must be logged in + if ( $user->isAnon() ) { + throw new ErrorPageError( 'watchnologin', 'watchnologintext' ); + } - return wfMessage( 'addedwatchtext', $this->getTitle()->getPrefixedText() )->parse(); + return parent::checkCanExecute( $user ); } public static function doWatch( Title $title, User $user ) { @@ -119,6 +140,17 @@ class WatchAction extends FormlessAction { return self::getWatchToken( $title, $user, $action ); } + protected function alterForm( HTMLForm $form ) { + $form->setSubmitText( wfMsg( 'confirm-watch-button' ) ); + } + + protected function preText() { + return wfMessage( 'confirm-watch-top' )->parse(); + } + + public function onSuccess() { + $this->getOutput()->addWikiMsg( 'addedwatchtext', $this->getTitle()->getPrefixedText() ); + } } class UnwatchAction extends WatchAction { @@ -128,17 +160,25 @@ class UnwatchAction extends WatchAction { } protected function getDescription() { - return wfMsg( 'removedwatch' ); + return wfMsg( 'removewatch' ); } - public function onView() { + public function onSubmit( $data ) { wfProfileIn( __METHOD__ ); + self::doUnwatch( $this->getTitle(), $this->getUser() ); + wfProfileOut( __METHOD__ ); + return true; + } - $user = $this->getUser(); - self::doUnwatch( $this->getTitle(), $user ); + protected function alterForm( HTMLForm $form ) { + $form->setSubmitText( wfMsg( 'confirm-unwatch-button' ) ); + } - wfProfileOut( __METHOD__ ); + protected function preText() { + return wfMessage( 'confirm-unwatch-top' )->parse(); + } - return wfMessage( 'removedwatchtext', $this->getTitle()->getPrefixedText() )->parse(); + public function onSuccess() { + $this->getOutput()->addWikiMsg( 'removedwatchtext', $this->getTitle()->getPrefixedText() ); } } diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index c0ee114d05..f831a9422e 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2707,10 +2707,10 @@ The e-mail address you entered in [[Special:Preferences|your user preferences]] 'watchlistanontext' => 'Please $1 to view or edit items on your watchlist.', 'watchnologin' => 'Not logged in', 'watchnologintext' => 'You must be [[Special:UserLogin|logged in]] to modify your watchlist.', -'addedwatch' => 'Added to watchlist', +'addwatch' => 'Add to watchlist', 'addedwatchtext' => "The page \"[[:\$1]]\" has been added to your [[Special:Watchlist|watchlist]]. Future changes to this page and its associated talk page will be listed there, and the page will appear '''bolded''' in the [[Special:RecentChanges|list of recent changes]] to make it easier to pick out.", -'removedwatch' => 'Removed from watchlist', +'removewatch' => 'Remove from watchlist', 'removedwatchtext' => 'The page "[[:$1]]" has been removed from [[Special:Watchlist|your watchlist]].', 'watch' => 'Watch', 'watchthispage' => 'Watch this page', @@ -4284,6 +4284,14 @@ Please confirm that you really want to recreate this page.", 'confirm-purge-top' => 'Clear the cache of this page?', 'confirm-purge-bottom' => 'Purging a page clears the cache and forces the most current revision to appear.', +# action=watch +'confirm-watch-button' => 'OK', +'confirm-watch-top' => 'Add this page to your watchlist?', + +# action=unwatch +'confirm-unwatch-button' => 'OK', +'confirm-unwatch-top' => 'Remove this page to your watchlist?', + # Separators for various lists, etc. 'catseparator' => '|', # only translate this message to other languages if you have to change it 'semicolon-separator' => '; ', # only translate this message to other languages if you have to change it diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 7c0fc74918..b9decd6eec 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -1799,9 +1799,9 @@ $wgMessageStructure = array( 'watchlistanontext', 'watchnologin', 'watchnologintext', - 'addedwatch', + 'addwatch', 'addedwatchtext', - 'removedwatch', + 'removewatch', 'removedwatchtext', 'watch', 'watchthispage', @@ -3246,6 +3246,9 @@ $wgMessageStructure = array( 'lag-warn-normal', 'lag-warn-high', ), + 'watch' => array( + 'confirm-watch-button', + ), 'watchlisteditor' => array( 'watchlistedit-numitems', 'watchlistedit-noitems', @@ -3450,6 +3453,9 @@ $wgMessageStructure = array( 'sqlite-has-fts', 'sqlite-no-fts', ), + 'unwatch' => array( + 'confirm-unwatch-button', + ), ); /** Comments for each block */ -- 2.20.1