From 789cc18185e209df723400af9c9955285c42dd17 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Sun, 28 Mar 2010 15:08:45 +0000 Subject: [PATCH] Followup r64197 Return null in getWatchlistValue if no change Fixup unneccessary watch/unwatch calls Remove useless unwatch from ApiUpload --- includes/api/ApiBase.php | 10 +++++----- includes/api/ApiDelete.php | 16 ++++++++++++---- includes/api/ApiEditPage.php | 2 +- includes/api/ApiMove.php | 22 +++++++++++++++------- includes/api/ApiProtect.php | 14 ++++++++++---- includes/api/ApiRollback.php | 10 ++++++---- includes/api/ApiUndelete.php | 10 ++++++---- includes/api/ApiUpload.php | 5 ----- 8 files changed, 55 insertions(+), 34 deletions(-) diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 1cc1e304df..05704212a8 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -542,14 +542,14 @@ abstract class ApiBase { case 'unwatch': return false; case 'preferences': - if ( $titleObj->exists() ) { - global $wgUser; - return $wgUser->getOption( 'watchdefault' ) || $titleObj->userIsWatching(); + global $wgUser; + if ( $titleObj->exists() && !$titleObj->userIsWatching() && $wgUser->getOption( 'watchdefault' ) ) { + return true; } - return false; + return null; case 'nochange': default: - return $titleObj->userIsWatching(); + return null; } } diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php index 1b6b39476d..df16682484 100644 --- a/includes/api/ApiDelete.php +++ b/includes/api/ApiDelete.php @@ -85,10 +85,18 @@ class ApiDelete extends ApiBase { $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj ) || $wgUser->getOption( 'watchdeletion' ); // Deprecated parameters - if ( $params['watch'] || $watch ) { - $articleObj->doWatch(); - } elseif ( $params['unwatch'] || !$watch ) { - $articleObj->doUnwatch(); + if ( $params['watch'] ) { + $watch = true; + } elseif ( $params['unwatch'] ) { + $watch = false; + } + + if ( $watch !== null ) { + if ( $watch ) { + $articleObj->doWatch(); + } else { + $articleObj->doUnwatch(); + } } } diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index ea3bcd6e3b..77377b0573 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -211,7 +211,7 @@ class ApiEditPage extends ApiBase { $watch = false; } - if ( $watch ) { + if ( $watch || $titleObj->userIsWatching() ) { $reqArr['wpWatchthis'] = ''; } diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php index 62609fd581..603ef5961d 100644 --- a/includes/api/ApiMove.php +++ b/includes/api/ApiMove.php @@ -124,14 +124,22 @@ class ApiMove extends ApiBase { // Watch pages $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj ) || $wgUser->getOption( 'watchmoves' ); - + // Deprecated parameters - if ( $params['watch'] || $watch ) { - $wgUser->addWatch( $fromTitle ); - $wgUser->addWatch( $toTitle ); - } elseif ( $params['unwatch'] || !$watch ) { - $wgUser->removeWatch( $fromTitle ); - $wgUser->removeWatch( $toTitle ); + if ( $params['watch'] ) { + $watch = true; + } elseif ( $params['unwatch'] ) { + $watch = false; + } + + if ( $watch !== null ) { + if ( $watch ) { + $wgUser->addWatch( $fromTitle ); + $wgUser->addWatch( $toTitle ); + } else { + $wgUser->removeWatch( $fromTitle ); + $wgUser->removeWatch( $toTitle ); + } } $this->getResult()->addValue( null, $this->getModuleName(), $r ); } diff --git a/includes/api/ApiProtect.php b/includes/api/ApiProtect.php index 4c0398e909..4e7f1fc3dc 100644 --- a/includes/api/ApiProtect.php +++ b/includes/api/ApiProtect.php @@ -116,10 +116,16 @@ class ApiProtect extends ApiBase { $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj ); - if ( $params['watch'] || $watch ) { - $articleObj->doWatch(); - } else { - $articleObj->doUnwatch(); + if ( $params['watch'] ) { + $watch = true; + } + + if ( $watch !== null ) { + if ( $watch ) { + $articleObj->doWatch(); + } else { + $articleObj->doUnwatch(); + } } if ( $titleObj->exists() ) { diff --git a/includes/api/ApiRollback.php b/includes/api/ApiRollback.php index 263a78a143..70dbc562b8 100644 --- a/includes/api/ApiRollback.php +++ b/includes/api/ApiRollback.php @@ -75,10 +75,12 @@ class ApiRollback extends ApiBase { $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj ); - if ( $watch ) { - $articleObj->doWatch(); - } else if ( !$watch ) { - $articleObj->doUnwatch(); + if ( $watch !== null) { + if ( $watch ) { + $articleObj->doWatch(); + } else { + $articleObj->doUnwatch(); + } } $info = array( diff --git a/includes/api/ApiUndelete.php b/includes/api/ApiUndelete.php index 1fed5ca9f0..421744f793 100644 --- a/includes/api/ApiUndelete.php +++ b/includes/api/ApiUndelete.php @@ -84,10 +84,12 @@ class ApiUndelete extends ApiBase { $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj ); - if ( $params['watch'] || $watch ) { - $wgUser->addWatch( $titleObj ); - } else { - $wgUser->removeWatch( $titleObj ); + if ( $watch !== null ) { + if ( $watch ) { + $wgUser->addWatch( $titleObj ); + } else { + $wgUser->removeWatch( $titleObj ); + } } $info['title'] = $titleObj->getPrefixedText(); diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index 0206744bb9..0fb17ccbd9 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -239,10 +239,6 @@ class ApiUpload extends ApiBase { $file = $this->mUpload->getLocalFile(); - if ( !$watch ) { - $wgUser->removeWatch( $file->getTitle() ); - } - $result['result'] = 'Success'; $result['filename'] = $file->getName(); $result['imageinfo'] = $this->mUpload->getImageInfo( $this->getResult() ); @@ -274,7 +270,6 @@ class ApiUpload extends ApiBase { ApiBase::PARAM_DFLT => 'preferences', ApiBase::PARAM_TYPE => array( 'watch', - 'unwatch', 'preferences', 'nochange' ), -- 2.20.1