* @ingroup Actions
*/
-class WatchAction extends FormlessAction {
+class WatchAction extends FormAction {
public function getName() {
return 'watch';
}
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 ) {
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 {
}
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() );
}
}
'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',
'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