Added autopatrol parameter to MarkPatrolled and MarkPatrolledComplete hooks
[lhc/web/wiklou.git] / includes / actions / WatchAction.php
index 8b6e329..30b83d7 100644 (file)
@@ -35,16 +35,11 @@ class WatchAction extends FormAction {
                return false;
        }
 
-       protected function getDescription() {
-               return $this->msg( 'addwatch' )->escaped();
-       }
-
        /**
-        * Just get an empty form with a single submit button
-        * @return array
+        * @return string HTML
         */
-       protected function getFormFields() {
-               return array();
+       protected function getDescription() {
+               return $this->msg( 'addwatch' )->escaped();
        }
 
        public function onSubmit( $data ) {
@@ -53,30 +48,6 @@ class WatchAction extends FormAction {
                return true;
        }
 
-       /**
-        * This can be either formed or formless depending on the session token given
-        */
-       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()->getPrefixedDBkey() );
-
-               if ( $user->matchEditToken( $this->getRequest()->getVal( 'token' ), $salt ) ) {
-                       $this->onSubmit( array() );
-                       $this->onSuccess();
-               } else {
-                       $form = $this->getForm();
-                       if ( $form->show() ) {
-                               $this->onSuccess();
-                       }
-               }
-       }
-
        protected function checkCanExecute( User $user ) {
                // Must be logged in
                if ( $user->isAnon() ) {
@@ -86,6 +57,21 @@ class WatchAction extends FormAction {
                parent::checkCanExecute( $user );
        }
 
+       protected function alterForm( HTMLForm $form ) {
+               $form->setSubmitTextMsg( 'confirm-watch-button' );
+               $form->setTokenSalt( 'watch' );
+       }
+
+       protected function preText() {
+               return $this->msg( 'confirm-watch-top' )->parse();
+       }
+
+       public function onSuccess() {
+               $this->getOutput()->addWikiMsg( 'addedwatchtext', $this->getTitle()->getPrefixedText() );
+       }
+
+       /* Static utility methods */
+
        /**
         * Watch or unwatch a page
         * @since 1.22
@@ -176,11 +162,8 @@ class WatchAction extends FormAction {
                if ( $action != 'unwatch' ) {
                        $action = 'watch';
                }
-               $salt = array( $action, $title->getPrefixedDBkey() );
-
-               // This token stronger salted and not compatible with ApiWatch
-               // It's title/action specific because index.php is GET and API is POST
-               return $user->getEditToken( $salt );
+               // Match ApiWatch and ResourceLoaderUserTokensModule
+               return $user->getEditToken( $action );
        }
 
        /**
@@ -195,16 +178,4 @@ class WatchAction extends FormAction {
        public static function getUnwatchToken( Title $title, User $user, $action = 'unwatch' ) {
                return self::getWatchToken( $title, $user, $action );
        }
-
-       protected function alterForm( HTMLForm $form ) {
-               $form->setSubmitTextMsg( 'confirm-watch-button' );
-       }
-
-       protected function preText() {
-               return $this->msg( 'confirm-watch-top' )->parse();
-       }
-
-       public function onSuccess() {
-               $this->getOutput()->addWikiMsg( 'addedwatchtext', $this->getTitle()->getPrefixedText() );
-       }
 }