2011-04-14 10:38:29 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Performs the watch and unwatch actions on a page
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Actions
|
|
|
|
|
*/
|
|
|
|
|
|
2013-03-05 15:39:35 +00:00
|
|
|
/**
|
|
|
|
|
* Page addition to a user's watchlist
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Actions
|
|
|
|
|
*/
|
2011-07-12 21:58:23 +00:00
|
|
|
class WatchAction extends FormAction {
|
2011-04-14 10:38:29 +00:00
|
|
|
|
2011-04-14 12:17:24 +00:00
|
|
|
public function getName() {
|
2011-04-14 10:38:29 +00:00
|
|
|
return 'watch';
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:17:24 +00:00
|
|
|
public function requiresUnblock() {
|
2011-04-14 10:38:29 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:17:24 +00:00
|
|
|
protected function getDescription() {
|
2012-03-29 08:57:00 +00:00
|
|
|
return $this->msg( 'addwatch' )->escaped();
|
2011-04-14 10:38:29 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-12 21:58:23 +00:00
|
|
|
/**
|
|
|
|
|
* Just get an empty form with a single submit button
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
protected function getFormFields() {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
WatchAction requires token (BREAKING CHANGE)
* (bug 27655) Require token for watching/unwatching pages
* Previously done for API (bug 29070) in r88522
* As with markpatrolled, the tokens are not compatible and made that way on purpose. The API requires the POST method and uses a universal token per-session. Since the front-end is all GET based (also per convention like in markpatrolled and rollback) they are stronger salted (title / action specific)
* ajax.watch used the API already and was switched in r88554.
* The actual watching/unwatching code was moved from WatchAction->onView to WatchAction::doWatch. This was done to allow the API to do the action without needing to generate a token like the front-end needs (or having to duplicate code). It is now similar to RecentChange::markPatrolled (in that it also a "central" function that does not care about tokens, it's called after the token-handling)
* JavaScript / Gadgets that utilize action=watch in their scripts:
** Effects should be minimal as they should be using the API (see r88522 and wikitech-l)
** If they use index.php and scrap the link from the page, they can continue to do so.
* There are links to the watch action all over the place. I've tried to catch most of them, but there may be some I miss. Migration in most cases is just a matter of adding an array item to the $query for:
'token' => WatchAction::getWatchToken( $title, $user [, $action] )
or changing:
Action::factory( 'watch', $article )->execute();
to:
WatchAction::doWatch( $title, $user );
While replacing the usages in some cases an instance of Article() no longer had to be created, in others $wgUser had to be retrieved from global (which was implied before but needs to be given directly now)
Other notes:
* Article->unwatch() and Article->watch(), which were deprecated as of 1.18 and are no longer used in core, may be broken in scenarios where the Request does not have a 'token' but is making a call to $article->watch()
* Some extensions need to be fixed, I'm currently running a grep search and will fix them a.s.a.p
[1] http://www.mediawiki.org/wiki/ResourceLoader/Default_modules?mw.user#tokens
2011-06-06 00:09:03 +00:00
|
|
|
|
2011-07-12 21:58:23 +00:00
|
|
|
public function onSubmit( $data ) {
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
self::doWatch( $this->getTitle(), $this->getUser() );
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-07-12 22:04:21 +00:00
|
|
|
* This can be either formed or formless depending on the session token given
|
2011-07-12 21:58:23 +00:00
|
|
|
*/
|
|
|
|
|
public function show() {
|
|
|
|
|
$this->setHeaders();
|
|
|
|
|
|
|
|
|
|
$user = $this->getUser();
|
|
|
|
|
// This will throw exceptions if there's a problem
|
|
|
|
|
$this->checkCanExecute( $user );
|
WatchAction requires token (BREAKING CHANGE)
* (bug 27655) Require token for watching/unwatching pages
* Previously done for API (bug 29070) in r88522
* As with markpatrolled, the tokens are not compatible and made that way on purpose. The API requires the POST method and uses a universal token per-session. Since the front-end is all GET based (also per convention like in markpatrolled and rollback) they are stronger salted (title / action specific)
* ajax.watch used the API already and was switched in r88554.
* The actual watching/unwatching code was moved from WatchAction->onView to WatchAction::doWatch. This was done to allow the API to do the action without needing to generate a token like the front-end needs (or having to duplicate code). It is now similar to RecentChange::markPatrolled (in that it also a "central" function that does not care about tokens, it's called after the token-handling)
* JavaScript / Gadgets that utilize action=watch in their scripts:
** Effects should be minimal as they should be using the API (see r88522 and wikitech-l)
** If they use index.php and scrap the link from the page, they can continue to do so.
* There are links to the watch action all over the place. I've tried to catch most of them, but there may be some I miss. Migration in most cases is just a matter of adding an array item to the $query for:
'token' => WatchAction::getWatchToken( $title, $user [, $action] )
or changing:
Action::factory( 'watch', $article )->execute();
to:
WatchAction::doWatch( $title, $user );
While replacing the usages in some cases an instance of Article() no longer had to be created, in others $wgUser had to be retrieved from global (which was implied before but needs to be given directly now)
Other notes:
* Article->unwatch() and Article->watch(), which were deprecated as of 1.18 and are no longer used in core, may be broken in scenarios where the Request does not have a 'token' but is making a call to $article->watch()
* Some extensions need to be fixed, I'm currently running a grep search and will fix them a.s.a.p
[1] http://www.mediawiki.org/wiki/ResourceLoader/Default_modules?mw.user#tokens
2011-06-06 00:09:03 +00:00
|
|
|
|
|
|
|
|
// Must have valid token for this action/title
|
|
|
|
|
$salt = array( $this->getName(), $this->getTitle()->getDBkey() );
|
|
|
|
|
|
2011-07-12 21:58:23 +00:00
|
|
|
if ( $user->matchEditToken( $this->getRequest()->getVal( 'token' ), $salt ) ) {
|
|
|
|
|
$this->onSubmit( array() );
|
|
|
|
|
$this->onSuccess();
|
|
|
|
|
} else {
|
|
|
|
|
$form = $this->getForm();
|
|
|
|
|
if ( $form->show() ) {
|
|
|
|
|
$this->onSuccess();
|
|
|
|
|
}
|
WatchAction requires token (BREAKING CHANGE)
* (bug 27655) Require token for watching/unwatching pages
* Previously done for API (bug 29070) in r88522
* As with markpatrolled, the tokens are not compatible and made that way on purpose. The API requires the POST method and uses a universal token per-session. Since the front-end is all GET based (also per convention like in markpatrolled and rollback) they are stronger salted (title / action specific)
* ajax.watch used the API already and was switched in r88554.
* The actual watching/unwatching code was moved from WatchAction->onView to WatchAction::doWatch. This was done to allow the API to do the action without needing to generate a token like the front-end needs (or having to duplicate code). It is now similar to RecentChange::markPatrolled (in that it also a "central" function that does not care about tokens, it's called after the token-handling)
* JavaScript / Gadgets that utilize action=watch in their scripts:
** Effects should be minimal as they should be using the API (see r88522 and wikitech-l)
** If they use index.php and scrap the link from the page, they can continue to do so.
* There are links to the watch action all over the place. I've tried to catch most of them, but there may be some I miss. Migration in most cases is just a matter of adding an array item to the $query for:
'token' => WatchAction::getWatchToken( $title, $user [, $action] )
or changing:
Action::factory( 'watch', $article )->execute();
to:
WatchAction::doWatch( $title, $user );
While replacing the usages in some cases an instance of Article() no longer had to be created, in others $wgUser had to be retrieved from global (which was implied before but needs to be given directly now)
Other notes:
* Article->unwatch() and Article->watch(), which were deprecated as of 1.18 and are no longer used in core, may be broken in scenarios where the Request does not have a 'token' but is making a call to $article->watch()
* Some extensions need to be fixed, I'm currently running a grep search and will fix them a.s.a.p
[1] http://www.mediawiki.org/wiki/ResourceLoader/Default_modules?mw.user#tokens
2011-06-06 00:09:03 +00:00
|
|
|
}
|
2011-04-14 10:38:29 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-12 21:58:23 +00:00
|
|
|
protected function checkCanExecute( User $user ) {
|
|
|
|
|
// Must be logged in
|
|
|
|
|
if ( $user->isAnon() ) {
|
|
|
|
|
throw new ErrorPageError( 'watchnologin', 'watchnologintext' );
|
|
|
|
|
}
|
2011-04-14 10:38:29 +00:00
|
|
|
|
2011-07-12 21:58:23 +00:00
|
|
|
return parent::checkCanExecute( $user );
|
2011-04-14 10:38:29 +00:00
|
|
|
}
|
WatchAction requires token (BREAKING CHANGE)
* (bug 27655) Require token for watching/unwatching pages
* Previously done for API (bug 29070) in r88522
* As with markpatrolled, the tokens are not compatible and made that way on purpose. The API requires the POST method and uses a universal token per-session. Since the front-end is all GET based (also per convention like in markpatrolled and rollback) they are stronger salted (title / action specific)
* ajax.watch used the API already and was switched in r88554.
* The actual watching/unwatching code was moved from WatchAction->onView to WatchAction::doWatch. This was done to allow the API to do the action without needing to generate a token like the front-end needs (or having to duplicate code). It is now similar to RecentChange::markPatrolled (in that it also a "central" function that does not care about tokens, it's called after the token-handling)
* JavaScript / Gadgets that utilize action=watch in their scripts:
** Effects should be minimal as they should be using the API (see r88522 and wikitech-l)
** If they use index.php and scrap the link from the page, they can continue to do so.
* There are links to the watch action all over the place. I've tried to catch most of them, but there may be some I miss. Migration in most cases is just a matter of adding an array item to the $query for:
'token' => WatchAction::getWatchToken( $title, $user [, $action] )
or changing:
Action::factory( 'watch', $article )->execute();
to:
WatchAction::doWatch( $title, $user );
While replacing the usages in some cases an instance of Article() no longer had to be created, in others $wgUser had to be retrieved from global (which was implied before but needs to be given directly now)
Other notes:
* Article->unwatch() and Article->watch(), which were deprecated as of 1.18 and are no longer used in core, may be broken in scenarios where the Request does not have a 'token' but is making a call to $article->watch()
* Some extensions need to be fixed, I'm currently running a grep search and will fix them a.s.a.p
[1] http://www.mediawiki.org/wiki/ResourceLoader/Default_modules?mw.user#tokens
2011-06-06 00:09:03 +00:00
|
|
|
|
2013-04-27 12:02:08 +00:00
|
|
|
public static function doWatch( Title $title, User $user ) {
|
2012-01-06 16:28:11 +00:00
|
|
|
$page = WikiPage::factory( $title );
|
WatchAction requires token (BREAKING CHANGE)
* (bug 27655) Require token for watching/unwatching pages
* Previously done for API (bug 29070) in r88522
* As with markpatrolled, the tokens are not compatible and made that way on purpose. The API requires the POST method and uses a universal token per-session. Since the front-end is all GET based (also per convention like in markpatrolled and rollback) they are stronger salted (title / action specific)
* ajax.watch used the API already and was switched in r88554.
* The actual watching/unwatching code was moved from WatchAction->onView to WatchAction::doWatch. This was done to allow the API to do the action without needing to generate a token like the front-end needs (or having to duplicate code). It is now similar to RecentChange::markPatrolled (in that it also a "central" function that does not care about tokens, it's called after the token-handling)
* JavaScript / Gadgets that utilize action=watch in their scripts:
** Effects should be minimal as they should be using the API (see r88522 and wikitech-l)
** If they use index.php and scrap the link from the page, they can continue to do so.
* There are links to the watch action all over the place. I've tried to catch most of them, but there may be some I miss. Migration in most cases is just a matter of adding an array item to the $query for:
'token' => WatchAction::getWatchToken( $title, $user [, $action] )
or changing:
Action::factory( 'watch', $article )->execute();
to:
WatchAction::doWatch( $title, $user );
While replacing the usages in some cases an instance of Article() no longer had to be created, in others $wgUser had to be retrieved from global (which was implied before but needs to be given directly now)
Other notes:
* Article->unwatch() and Article->watch(), which were deprecated as of 1.18 and are no longer used in core, may be broken in scenarios where the Request does not have a 'token' but is making a call to $article->watch()
* Some extensions need to be fixed, I'm currently running a grep search and will fix them a.s.a.p
[1] http://www.mediawiki.org/wiki/ResourceLoader/Default_modules?mw.user#tokens
2011-06-06 00:09:03 +00:00
|
|
|
|
|
|
|
|
if ( wfRunHooks( 'WatchArticle', array( &$user, &$page ) ) ) {
|
|
|
|
|
$user->addWatch( $title );
|
|
|
|
|
wfRunHooks( 'WatchArticleComplete', array( &$user, &$page ) );
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-27 12:02:08 +00:00
|
|
|
public static function doUnwatch( Title $title, User $user ) {
|
2012-01-06 16:28:11 +00:00
|
|
|
$page = WikiPage::factory( $title );
|
WatchAction requires token (BREAKING CHANGE)
* (bug 27655) Require token for watching/unwatching pages
* Previously done for API (bug 29070) in r88522
* As with markpatrolled, the tokens are not compatible and made that way on purpose. The API requires the POST method and uses a universal token per-session. Since the front-end is all GET based (also per convention like in markpatrolled and rollback) they are stronger salted (title / action specific)
* ajax.watch used the API already and was switched in r88554.
* The actual watching/unwatching code was moved from WatchAction->onView to WatchAction::doWatch. This was done to allow the API to do the action without needing to generate a token like the front-end needs (or having to duplicate code). It is now similar to RecentChange::markPatrolled (in that it also a "central" function that does not care about tokens, it's called after the token-handling)
* JavaScript / Gadgets that utilize action=watch in their scripts:
** Effects should be minimal as they should be using the API (see r88522 and wikitech-l)
** If they use index.php and scrap the link from the page, they can continue to do so.
* There are links to the watch action all over the place. I've tried to catch most of them, but there may be some I miss. Migration in most cases is just a matter of adding an array item to the $query for:
'token' => WatchAction::getWatchToken( $title, $user [, $action] )
or changing:
Action::factory( 'watch', $article )->execute();
to:
WatchAction::doWatch( $title, $user );
While replacing the usages in some cases an instance of Article() no longer had to be created, in others $wgUser had to be retrieved from global (which was implied before but needs to be given directly now)
Other notes:
* Article->unwatch() and Article->watch(), which were deprecated as of 1.18 and are no longer used in core, may be broken in scenarios where the Request does not have a 'token' but is making a call to $article->watch()
* Some extensions need to be fixed, I'm currently running a grep search and will fix them a.s.a.p
[1] http://www.mediawiki.org/wiki/ResourceLoader/Default_modules?mw.user#tokens
2011-06-06 00:09:03 +00:00
|
|
|
|
|
|
|
|
if ( wfRunHooks( 'UnwatchArticle', array( &$user, &$page ) ) ) {
|
|
|
|
|
$user->removeWatch( $title );
|
|
|
|
|
wfRunHooks( 'UnwatchArticleComplete', array( &$user, &$page ) );
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get token to watch (or unwatch) a page for a user
|
|
|
|
|
*
|
|
|
|
|
* @param Title $title Title object of page to watch
|
2012-02-01 20:53:38 +00:00
|
|
|
* @param User $user User for whom the action is going to be performed
|
WatchAction requires token (BREAKING CHANGE)
* (bug 27655) Require token for watching/unwatching pages
* Previously done for API (bug 29070) in r88522
* As with markpatrolled, the tokens are not compatible and made that way on purpose. The API requires the POST method and uses a universal token per-session. Since the front-end is all GET based (also per convention like in markpatrolled and rollback) they are stronger salted (title / action specific)
* ajax.watch used the API already and was switched in r88554.
* The actual watching/unwatching code was moved from WatchAction->onView to WatchAction::doWatch. This was done to allow the API to do the action without needing to generate a token like the front-end needs (or having to duplicate code). It is now similar to RecentChange::markPatrolled (in that it also a "central" function that does not care about tokens, it's called after the token-handling)
* JavaScript / Gadgets that utilize action=watch in their scripts:
** Effects should be minimal as they should be using the API (see r88522 and wikitech-l)
** If they use index.php and scrap the link from the page, they can continue to do so.
* There are links to the watch action all over the place. I've tried to catch most of them, but there may be some I miss. Migration in most cases is just a matter of adding an array item to the $query for:
'token' => WatchAction::getWatchToken( $title, $user [, $action] )
or changing:
Action::factory( 'watch', $article )->execute();
to:
WatchAction::doWatch( $title, $user );
While replacing the usages in some cases an instance of Article() no longer had to be created, in others $wgUser had to be retrieved from global (which was implied before but needs to be given directly now)
Other notes:
* Article->unwatch() and Article->watch(), which were deprecated as of 1.18 and are no longer used in core, may be broken in scenarios where the Request does not have a 'token' but is making a call to $article->watch()
* Some extensions need to be fixed, I'm currently running a grep search and will fix them a.s.a.p
[1] http://www.mediawiki.org/wiki/ResourceLoader/Default_modules?mw.user#tokens
2011-06-06 00:09:03 +00:00
|
|
|
* @param string $action Optionally override the action to 'unwatch'
|
|
|
|
|
* @return string Token
|
2011-07-18 23:01:08 +00:00
|
|
|
* @since 1.18
|
WatchAction requires token (BREAKING CHANGE)
* (bug 27655) Require token for watching/unwatching pages
* Previously done for API (bug 29070) in r88522
* As with markpatrolled, the tokens are not compatible and made that way on purpose. The API requires the POST method and uses a universal token per-session. Since the front-end is all GET based (also per convention like in markpatrolled and rollback) they are stronger salted (title / action specific)
* ajax.watch used the API already and was switched in r88554.
* The actual watching/unwatching code was moved from WatchAction->onView to WatchAction::doWatch. This was done to allow the API to do the action without needing to generate a token like the front-end needs (or having to duplicate code). It is now similar to RecentChange::markPatrolled (in that it also a "central" function that does not care about tokens, it's called after the token-handling)
* JavaScript / Gadgets that utilize action=watch in their scripts:
** Effects should be minimal as they should be using the API (see r88522 and wikitech-l)
** If they use index.php and scrap the link from the page, they can continue to do so.
* There are links to the watch action all over the place. I've tried to catch most of them, but there may be some I miss. Migration in most cases is just a matter of adding an array item to the $query for:
'token' => WatchAction::getWatchToken( $title, $user [, $action] )
or changing:
Action::factory( 'watch', $article )->execute();
to:
WatchAction::doWatch( $title, $user );
While replacing the usages in some cases an instance of Article() no longer had to be created, in others $wgUser had to be retrieved from global (which was implied before but needs to be given directly now)
Other notes:
* Article->unwatch() and Article->watch(), which were deprecated as of 1.18 and are no longer used in core, may be broken in scenarios where the Request does not have a 'token' but is making a call to $article->watch()
* Some extensions need to be fixed, I'm currently running a grep search and will fix them a.s.a.p
[1] http://www.mediawiki.org/wiki/ResourceLoader/Default_modules?mw.user#tokens
2011-06-06 00:09:03 +00:00
|
|
|
*/
|
|
|
|
|
public static function getWatchToken( Title $title, User $user, $action = 'watch' ) {
|
|
|
|
|
if ( $action != 'unwatch' ) {
|
|
|
|
|
$action = 'watch';
|
|
|
|
|
}
|
|
|
|
|
$salt = array( $action, $title->getDBkey() );
|
|
|
|
|
|
|
|
|
|
// This token stronger salted and not compatible with ApiWatch
|
|
|
|
|
// It's title/action specific because index.php is GET and API is POST
|
2011-11-16 04:37:17 +00:00
|
|
|
return $user->getEditToken( $salt );
|
WatchAction requires token (BREAKING CHANGE)
* (bug 27655) Require token for watching/unwatching pages
* Previously done for API (bug 29070) in r88522
* As with markpatrolled, the tokens are not compatible and made that way on purpose. The API requires the POST method and uses a universal token per-session. Since the front-end is all GET based (also per convention like in markpatrolled and rollback) they are stronger salted (title / action specific)
* ajax.watch used the API already and was switched in r88554.
* The actual watching/unwatching code was moved from WatchAction->onView to WatchAction::doWatch. This was done to allow the API to do the action without needing to generate a token like the front-end needs (or having to duplicate code). It is now similar to RecentChange::markPatrolled (in that it also a "central" function that does not care about tokens, it's called after the token-handling)
* JavaScript / Gadgets that utilize action=watch in their scripts:
** Effects should be minimal as they should be using the API (see r88522 and wikitech-l)
** If they use index.php and scrap the link from the page, they can continue to do so.
* There are links to the watch action all over the place. I've tried to catch most of them, but there may be some I miss. Migration in most cases is just a matter of adding an array item to the $query for:
'token' => WatchAction::getWatchToken( $title, $user [, $action] )
or changing:
Action::factory( 'watch', $article )->execute();
to:
WatchAction::doWatch( $title, $user );
While replacing the usages in some cases an instance of Article() no longer had to be created, in others $wgUser had to be retrieved from global (which was implied before but needs to be given directly now)
Other notes:
* Article->unwatch() and Article->watch(), which were deprecated as of 1.18 and are no longer used in core, may be broken in scenarios where the Request does not have a 'token' but is making a call to $article->watch()
* Some extensions need to be fixed, I'm currently running a grep search and will fix them a.s.a.p
[1] http://www.mediawiki.org/wiki/ResourceLoader/Default_modules?mw.user#tokens
2011-06-06 00:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get token to unwatch (or watch) a page for a user
|
|
|
|
|
*
|
|
|
|
|
* @param Title $title Title object of page to unwatch
|
2012-02-01 20:53:38 +00:00
|
|
|
* @param User $user User for whom the action is going to be performed
|
WatchAction requires token (BREAKING CHANGE)
* (bug 27655) Require token for watching/unwatching pages
* Previously done for API (bug 29070) in r88522
* As with markpatrolled, the tokens are not compatible and made that way on purpose. The API requires the POST method and uses a universal token per-session. Since the front-end is all GET based (also per convention like in markpatrolled and rollback) they are stronger salted (title / action specific)
* ajax.watch used the API already and was switched in r88554.
* The actual watching/unwatching code was moved from WatchAction->onView to WatchAction::doWatch. This was done to allow the API to do the action without needing to generate a token like the front-end needs (or having to duplicate code). It is now similar to RecentChange::markPatrolled (in that it also a "central" function that does not care about tokens, it's called after the token-handling)
* JavaScript / Gadgets that utilize action=watch in their scripts:
** Effects should be minimal as they should be using the API (see r88522 and wikitech-l)
** If they use index.php and scrap the link from the page, they can continue to do so.
* There are links to the watch action all over the place. I've tried to catch most of them, but there may be some I miss. Migration in most cases is just a matter of adding an array item to the $query for:
'token' => WatchAction::getWatchToken( $title, $user [, $action] )
or changing:
Action::factory( 'watch', $article )->execute();
to:
WatchAction::doWatch( $title, $user );
While replacing the usages in some cases an instance of Article() no longer had to be created, in others $wgUser had to be retrieved from global (which was implied before but needs to be given directly now)
Other notes:
* Article->unwatch() and Article->watch(), which were deprecated as of 1.18 and are no longer used in core, may be broken in scenarios where the Request does not have a 'token' but is making a call to $article->watch()
* Some extensions need to be fixed, I'm currently running a grep search and will fix them a.s.a.p
[1] http://www.mediawiki.org/wiki/ResourceLoader/Default_modules?mw.user#tokens
2011-06-06 00:09:03 +00:00
|
|
|
* @param string $action Optionally override the action to 'watch'
|
|
|
|
|
* @return string Token
|
2011-07-18 23:01:08 +00:00
|
|
|
* @since 1.18
|
WatchAction requires token (BREAKING CHANGE)
* (bug 27655) Require token for watching/unwatching pages
* Previously done for API (bug 29070) in r88522
* As with markpatrolled, the tokens are not compatible and made that way on purpose. The API requires the POST method and uses a universal token per-session. Since the front-end is all GET based (also per convention like in markpatrolled and rollback) they are stronger salted (title / action specific)
* ajax.watch used the API already and was switched in r88554.
* The actual watching/unwatching code was moved from WatchAction->onView to WatchAction::doWatch. This was done to allow the API to do the action without needing to generate a token like the front-end needs (or having to duplicate code). It is now similar to RecentChange::markPatrolled (in that it also a "central" function that does not care about tokens, it's called after the token-handling)
* JavaScript / Gadgets that utilize action=watch in their scripts:
** Effects should be minimal as they should be using the API (see r88522 and wikitech-l)
** If they use index.php and scrap the link from the page, they can continue to do so.
* There are links to the watch action all over the place. I've tried to catch most of them, but there may be some I miss. Migration in most cases is just a matter of adding an array item to the $query for:
'token' => WatchAction::getWatchToken( $title, $user [, $action] )
or changing:
Action::factory( 'watch', $article )->execute();
to:
WatchAction::doWatch( $title, $user );
While replacing the usages in some cases an instance of Article() no longer had to be created, in others $wgUser had to be retrieved from global (which was implied before but needs to be given directly now)
Other notes:
* Article->unwatch() and Article->watch(), which were deprecated as of 1.18 and are no longer used in core, may be broken in scenarios where the Request does not have a 'token' but is making a call to $article->watch()
* Some extensions need to be fixed, I'm currently running a grep search and will fix them a.s.a.p
[1] http://www.mediawiki.org/wiki/ResourceLoader/Default_modules?mw.user#tokens
2011-06-06 00:09:03 +00:00
|
|
|
*/
|
|
|
|
|
public static function getUnwatchToken( Title $title, User $user, $action = 'unwatch' ) {
|
|
|
|
|
return self::getWatchToken( $title, $user, $action );
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-12 21:58:23 +00:00
|
|
|
protected function alterForm( HTMLForm $form ) {
|
2012-03-29 08:57:00 +00:00
|
|
|
$form->setSubmitTextMsg( 'confirm-watch-button' );
|
2011-07-12 21:58:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function preText() {
|
2012-03-29 08:57:00 +00:00
|
|
|
return $this->msg( 'confirm-watch-top' )->parse();
|
2011-07-12 21:58:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function onSuccess() {
|
|
|
|
|
$this->getOutput()->addWikiMsg( 'addedwatchtext', $this->getTitle()->getPrefixedText() );
|
|
|
|
|
}
|
2011-04-14 10:38:29 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-05 15:39:35 +00:00
|
|
|
/**
|
|
|
|
|
* Page removal from a user's watchlist
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Actions
|
|
|
|
|
*/
|
2011-04-14 10:38:29 +00:00
|
|
|
class UnwatchAction extends WatchAction {
|
|
|
|
|
|
2011-04-14 12:17:24 +00:00
|
|
|
public function getName() {
|
2011-04-14 10:38:29 +00:00
|
|
|
return 'unwatch';
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:17:24 +00:00
|
|
|
protected function getDescription() {
|
2012-03-29 08:57:00 +00:00
|
|
|
return $this->msg( 'removewatch' )->escaped();
|
2011-04-14 10:38:29 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-12 21:58:23 +00:00
|
|
|
public function onSubmit( $data ) {
|
2011-04-14 10:38:29 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2011-07-12 21:58:23 +00:00
|
|
|
self::doUnwatch( $this->getTitle(), $this->getUser() );
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2011-04-14 10:38:29 +00:00
|
|
|
|
2011-07-12 21:58:23 +00:00
|
|
|
protected function alterForm( HTMLForm $form ) {
|
2012-03-29 08:57:00 +00:00
|
|
|
$form->setSubmitTextMsg( 'confirm-unwatch-button' );
|
2011-07-12 21:58:23 +00:00
|
|
|
}
|
2011-04-14 10:38:29 +00:00
|
|
|
|
2011-07-12 21:58:23 +00:00
|
|
|
protected function preText() {
|
2012-03-29 08:57:00 +00:00
|
|
|
return $this->msg( 'confirm-unwatch-top' )->parse();
|
2011-07-12 21:58:23 +00:00
|
|
|
}
|
2011-04-14 10:38:29 +00:00
|
|
|
|
2011-07-12 21:58:23 +00:00
|
|
|
public function onSuccess() {
|
|
|
|
|
$this->getOutput()->addWikiMsg( 'removedwatchtext', $this->getTitle()->getPrefixedText() );
|
2011-04-14 10:38:29 +00:00
|
|
|
}
|
|
|
|
|
}
|