From 4101ab54f2a3ab0a8543090879be39395baf0e79 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Fri, 8 Nov 2013 13:01:28 -0500 Subject: [PATCH] Cleanup watchlist preference usage In general, the web UI does a check of the watchlist preferences along the lines of "watch if watchdefault, or if watchcreations and the title doesn't exist". So there's no way to have it watch edits but not creations. Make the API behavior match this. For API action=protect&watchlist=preferences, we want to use 'watchdefault' always to match the behavior of the web UI. For Special:Upload, the code is all there to do a "watch if watchdefault, or if watchcreations and the file doesn't exist". But for some reason that code wasn't being used in favor of just using watchcreations all the time. Fix that, too. And have the API use that instead of checking if the file page exists. Bug: 56766 Change-Id: I57fc46d9a97b3ea2169173727db842d0d7ecf81d --- includes/api/ApiBase.php | 8 ++++---- includes/api/ApiProtect.php | 2 +- includes/api/ApiUpload.php | 14 +++++++++++++- includes/specials/SpecialUpload.php | 14 +++++++++----- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index ce6ecda673..6be044c70f 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -818,7 +818,7 @@ abstract class ApiBase extends ContextSource { * @param string $watchlist Valid values: 'watch', 'unwatch', 'preferences', 'nochange' * @param $titleObj Title the page under consideration * @param string $userOption The user option to consider when $watchlist=preferences. - * If not set will magically default to either watchdefault or watchcreations + * If not set will use watchdefault always and watchcreations if $titleObj doesn't exist. * @return bool */ protected function getWatchlistValue( $watchlist, $titleObj, $userOption = null ) { @@ -837,10 +837,10 @@ abstract class ApiBase extends ContextSource { if ( $userWatching ) { return true; } - # If no user option was passed, use watchdefault or watchcreations + # If no user option was passed, use watchdefault and watchcreations if ( is_null( $userOption ) ) { - $userOption = $titleObj->exists() - ? 'watchdefault' : 'watchcreations'; + return $this->getUser()->getBoolOption( 'watchdefault' ) || + $this->getUser()->getBoolOption( 'watchcreations' ) && !$titleObj->exists(); } # Watch the article based on the user preference return $this->getUser()->getBoolOption( $userOption ); diff --git a/includes/api/ApiProtect.php b/includes/api/ApiProtect.php index 7830c8b4dc..428eef323f 100644 --- a/includes/api/ApiProtect.php +++ b/includes/api/ApiProtect.php @@ -98,7 +98,7 @@ class ApiProtect extends ApiBase { $cascade = $params['cascade']; $watch = $params['watch'] ? 'watch' : $params['watchlist']; - $this->setWatch( $watch, $titleObj ); + $this->setWatch( $watch, $titleObj, 'watchdefault' ); $status = $pageObj->doUpdateRestrictions( $protections, $expiryarray, $cascade, $params['reason'], $this->getUser() ); diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index 467eccf862..5839edc9a9 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -587,7 +587,19 @@ class ApiUpload extends ApiBase { /** @var $file File */ $file = $this->mUpload->getLocalFile(); - $watch = $this->getWatchlistValue( $this->mParams['watchlist'], $file->getTitle() ); + + // For preferences mode, we want to watch if 'watchdefault' is set or + // if the *file* doesn't exist and 'watchcreations' is set. But + // getWatchlistValue()'s automatic handling checks if the *title* + // exists or not, so we need to check both prefs manually. + $watch = $this->getWatchlistValue( + $this->mParams['watchlist'], $file->getTitle(), 'watchdefault' + ); + if ( !$watch && $this->mParams['watchlist'] == 'preferences' && !$file->exists() ) { + $watch = $this->getWatchlistValue( + $this->mParams['watchlist'], $file->getTitle(), 'watchcreations' + ); + } // Deprecated parameters if ( $this->mParams['watch'] ) { diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index b79aaa94fa..0700c49742 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -60,7 +60,7 @@ class SpecialUpload extends SpecialPage { /** User input variables from the root section **/ public $mIgnoreWarning; - public $mWatchThis; + public $mWatchthis; public $mCopyrightStatus; public $mCopyrightSource; @@ -75,8 +75,6 @@ class SpecialUpload extends SpecialPage { public $uploadFormTextTop; public $uploadFormTextAfterSummary; - public $mWatchthis; - /** * Initialize instance variables from request and create an Upload handler */ @@ -517,11 +515,17 @@ class SpecialUpload extends SpecialPage { return true; } + $desiredTitleObj = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName ); + if ( $desiredTitleObj instanceof Title && $this->getUser()->isWatched( $desiredTitleObj ) ) { + // Already watched, don't change that + return true; + } + $local = wfLocalFile( $this->mDesiredDestName ); if ( $local && $local->exists() ) { // We're uploading a new version of an existing file. // No creation, so don't watch it if we're not already. - return $this->getUser()->isWatched( $local->getTitle() ); + return false; } else { // New page should get watched if that's our option. return $this->getUser()->getOption( 'watchcreations' ); @@ -1011,7 +1015,7 @@ class UploadForm extends HTMLForm { 'id' => 'wpWatchthis', 'label-message' => 'watchthisupload', 'section' => 'options', - 'default' => $user->getOption( 'watchcreations' ), + 'default' => $this->mWatch, ) ); } -- 2.20.1