$form = new HTMLForm( $this->fields, $this->getContext(), $this->getName() );
$form->setSubmitCallback( array( $this, 'onSubmit' ) );
+ $title = $this->getTitle();
+ $form->setAction( $title->getLocalURL( array( 'action' => $this->getName() ) ) );
// Retain query parameters (uselang etc)
- $form->addHiddenField( 'action', $this->getName() ); // Might not be the same as the query string
$params = array_diff_key(
$this->getRequest()->getQueryValues(),
array( 'action' => null, 'title' => null )
return false;
}
+ /**
+ * @return string HTML
+ */
protected function getDescription() {
return $this->msg( 'addwatch' )->escaped();
}
// 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() );
+ $form = $this->getForm();
+ if ( $form->show() ) {
$this->onSuccess();
- } else {
- $form = $this->getForm();
- if ( $form->show() ) {
- $this->onSuccess();
- }
}
}
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
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 );
}
/**
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() );
- }
}
* the global versions.
*/
$mode = $user->isWatched( $title ) ? 'unwatch' : 'watch';
- $token = WatchAction::getWatchToken( $title, $user, $mode );
$content_navigation['actions'][$mode] = array(
'class' => $onPage && ( $action == 'watch' || $action == 'unwatch' ) ? 'selected' : false,
// uses 'watch' or 'unwatch' message
'text' => $this->msg( $mode )->text(),
- 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
+ 'href' => $title->getLocalURL( array( 'action' => $mode ) )
);
}
}
$text = $wgContLang->convert( $nt->getPrefixedText() );
$plink = Linker::linkKnown( $nt, htmlspecialchars( $text ) );
- $token = WatchAction::getWatchToken( $nt, $this->getUser() );
$wlink = Linker::linkKnown(
$nt,
$this->msg( 'watch' )->escaped(),
array( 'class' => 'mw-watch-link' ),
- array( 'action' => 'watch', 'token' => $token )
+ array( 'action' => 'watch' )
);
return $this->getLanguage()->specialList( $plink, $wlink );