From 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 8 Dec 2013 09:55:49 +0100 Subject: Update to MediaWiki 1.22.0 --- includes/actions/WatchAction.php | 62 +++++++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 7 deletions(-) (limited to 'includes/actions/WatchAction.php') diff --git a/includes/actions/WatchAction.php b/includes/actions/WatchAction.php index ae5f76c6..929c1b5f 100644 --- a/includes/actions/WatchAction.php +++ b/includes/actions/WatchAction.php @@ -87,24 +87,72 @@ class WatchAction extends FormAction { return parent::checkCanExecute( $user ); } - public static function doWatch( Title $title, User $user ) { + /** + * Watch or unwatch a page + * @since 1.22 + * @param bool $watch Whether to watch or unwatch the page + * @param Title $title Page to watch/unwatch + * @param User $user User who is watching/unwatching + * @return Status + */ + public static function doWatchOrUnwatch( $watch, Title $title, User $user ) { + if ( $user->isLoggedIn() && $user->isWatched( $title, WatchedItem::IGNORE_USER_RIGHTS ) != $watch ) { + // If the user doesn't have 'editmywatchlist', we still want to + // allow them to add but not remove items via edits and such. + if ( $watch ) { + return self::doWatch( $title, $user, WatchedItem::IGNORE_USER_RIGHTS ); + } else { + return self::doUnwatch( $title, $user ); + } + } + return Status::newGood(); + } + + /** + * Watch a page + * @since 1.22 Returns Status, $checkRights parameter added + * @param Title $title Page to watch/unwatch + * @param User $user User who is watching/unwatching + * @param int $checkRights Passed through to $user->addWatch() + * @return Status + */ + public static function doWatch( Title $title, User $user, $checkRights = WatchedItem::CHECK_USER_RIGHTS ) { + if ( $checkRights !== WatchedItem::IGNORE_USER_RIGHTS && !$user->isAllowed( 'editmywatchlist' ) ) { + return User::newFatalPermissionDeniedStatus( 'editmywatchlist' ); + } + $page = WikiPage::factory( $title ); - if ( wfRunHooks( 'WatchArticle', array( &$user, &$page ) ) ) { - $user->addWatch( $title ); + $status = Status::newFatal( 'hookaborted' ); + if ( wfRunHooks( 'WatchArticle', array( &$user, &$page, &$status ) ) ) { + $status = Status::newGood(); + $user->addWatch( $title, $checkRights ); wfRunHooks( 'WatchArticleComplete', array( &$user, &$page ) ); } - return true; + return $status; } - public static function doUnwatch( Title $title, User $user ) { + /** + * Unwatch a page + * @since 1.22 Returns Status + * @param Title $title Page to watch/unwatch + * @param User $user User who is watching/unwatching + * @return Status + */ + public static function doUnwatch( Title $title, User $user ) { + if ( !$user->isAllowed( 'editmywatchlist' ) ) { + return User::newFatalPermissionDeniedStatus( 'editmywatchlist' ); + } + $page = WikiPage::factory( $title ); - if ( wfRunHooks( 'UnwatchArticle', array( &$user, &$page ) ) ) { + $status = Status::newFatal( 'hookaborted' ); + if ( wfRunHooks( 'UnwatchArticle', array( &$user, &$page, &$status ) ) ) { + $status = Status::newGood(); $user->removeWatch( $title ); wfRunHooks( 'UnwatchArticleComplete', array( &$user, &$page ) ); } - return true; + return $status; } /** -- cgit v1.2.3-54-g00ecf