From 88df448d362b1c331bfdb8de69d1818bf6e5316e Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Thu, 25 Mar 2010 22:15:08 +0000 Subject: [PATCH] Fix bug 22944 in a much better fashion (using watchlist parameter) Deprecate old watch/unwatch parameters Move generic watchlist stuff to ApiBase/getWatchlistValue (maybe needs renaming better?) Tweak some braces in ApiEditPage --- RELEASE-NOTES | 1 + includes/api/ApiBase.php | 25 +++++++++++++++++++++++++ includes/api/ApiDelete.php | 22 +++++++++++++++++++--- includes/api/ApiEditPage.php | 27 ++++----------------------- includes/api/ApiMove.php | 29 ++++++++++++++++++++++++----- includes/api/ApiProtect.php | 23 +++++++++++++++++++++-- includes/api/ApiRollback.php | 22 ++++++++++++++++++++-- includes/api/ApiUndelete.php | 22 ++++++++++++++++++++-- includes/api/ApiUpload.php | 26 +++++++++++++++++++++++--- 9 files changed, 157 insertions(+), 40 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index f3a1ec6416..0acf75ff76 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -60,6 +60,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN == API changes in 1.17 == * (bug 22738) Allow filtering by action type on query=logevent * (bug 22764) uselang parameter for action=parse +* (bug 22944) API: watchlist options are inconsistent === Languages updated in 1.17 === diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 7fd2dcf739..2c3164d260 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -532,6 +532,31 @@ abstract class ApiBase { return $mValidNamespaces; } + /** + * Handle watchlist settings + */ + protected function getWatchlistValue ( $watchlist, $titleObj ) { + switch ( $watchlist ) { + case 'watch': + $watch = true; + break; + case 'unwatch': + $watch = false; + break; + case 'preferences': + global $wgUser; + + if ( $titleObj->exists() ) { + $watch = $wgUser->getOption( 'watchdefault' ) || $titleObj->userIsWatching(); + } + break; + case 'nochange': + default: + $watch = $titleObj->userIsWatching(); + } + + return $watch; + } /** * Using the settings determine the value for the given parameter diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php index 9689c97c85..1b6b39476d 100644 --- a/includes/api/ApiDelete.php +++ b/includes/api/ApiDelete.php @@ -81,10 +81,13 @@ class ApiDelete extends ApiBase { if ( count( $retval ) ) { $this->dieUsageMsg( reset( $retval ) ); // We don't care about multiple errors, just report one of them } + + $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj ) || $wgUser->getOption( 'watchdeletion' ); - if ( $params['watch'] || $wgUser->getOption( 'watchdeletion' ) ) { + // Deprecated parameters + if ( $params['watch'] || $watch ) { $articleObj->doWatch(); - } elseif ( $params['unwatch'] ) { + } elseif ( $params['unwatch'] || !$watch ) { $articleObj->doUnwatch(); } } @@ -197,7 +200,19 @@ class ApiDelete extends ApiBase { ), 'token' => null, 'reason' => null, - 'watch' => false, + 'watch' => array( + ApiBase::PARAM_DFLT => false, + ApiBase::PARAM_DEPRECATED => true, + ), + 'watchlist' => array( + ApiBase::PARAM_DFLT => 'preferences', + ApiBase::PARAM_TYPE => array( + 'watch', + 'unwatch', + 'preferences', + 'nochange' + ), + ), 'unwatch' => false, 'oldimage' => null ); @@ -210,6 +225,7 @@ class ApiDelete extends ApiBase { 'token' => 'A delete token previously retrieved through prop=info', 'reason' => 'Reason for the deletion. If not set, an automatically generated reason will be used.', 'watch' => 'Add the page to your watchlist', + 'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch', 'unwatch' => 'Remove the page from your watchlist', 'oldimage' => 'The name of the old image to delete as provided by iiprop=archivename' ); diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 261db6fbcb..ea3bcd6e3b 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -177,15 +177,13 @@ class ApiEditPage extends ApiBase { $reqArr['wpEdittime'] = $articleObj->getTimestamp(); } - if ( !is_null( $params['starttimestamp'] ) && $params['starttimestamp'] != '' ) - { + if ( !is_null( $params['starttimestamp'] ) && $params['starttimestamp'] != '' ) { $reqArr['wpStarttime'] = wfTimestamp( TS_MW, $params['starttimestamp'] ); } else { $reqArr['wpStarttime'] = $reqArr['wpEdittime']; // Fake wpStartime } - if ( $params['minor'] || ( !$params['notminor'] && $wgUser->getOption( 'minordefault' ) ) ) - { + if ( $params['minor'] || ( !$params['notminor'] && $wgUser->getOption( 'minordefault' ) ) ) { $reqArr['wpMinoredit'] = ''; } @@ -204,25 +202,8 @@ class ApiEditPage extends ApiBase { $reqArr['wpSection'] = ''; } - // Handle watchlist settings - switch ( $params['watchlist'] ) { - case 'watch': - $watch = true; - break; - case 'unwatch': - $watch = false; - break; - case 'preferences': - if ( $titleObj->exists() ) { - $watch = $wgUser->getOption( 'watchdefault' ) || $titleObj->userIsWatching(); - } else { - $watch = $wgUser->getOption( 'watchcreations' ); - } - break; - case 'nochange': - default: - $watch = $titleObj->userIsWatching(); - } + $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj ) || $wgUser->getOption( 'watchcreations' ); + // Deprecated parameters if ( $params['watch'] ) { $watch = true; diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php index 3b2fe9999b..62609fd581 100644 --- a/includes/api/ApiMove.php +++ b/includes/api/ApiMove.php @@ -121,12 +121,15 @@ class ApiMove extends ApiBase { $this->getResult()->setIndexedTagName( $r['subpages-talk'], 'subpage' ); } } - + // Watch pages - if ( $params['watch'] || $wgUser->getOption( 'watchmoves' ) ) { + $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj ) || $wgUser->getOption( 'watchmoves' ); + + // Deprecated parameters + if ( $params['watch'] || $watch ) { $wgUser->addWatch( $fromTitle ); $wgUser->addWatch( $toTitle ); - } elseif ( $params['unwatch'] ) { + } elseif ( $params['unwatch'] || !$watch ) { $wgUser->removeWatch( $fromTitle ); $wgUser->removeWatch( $toTitle ); } @@ -175,8 +178,23 @@ class ApiMove extends ApiBase { 'movetalk' => false, 'movesubpages' => false, 'noredirect' => false, - 'watch' => false, - 'unwatch' => false, + 'watch' => array( + ApiBase::PARAM_DFLT => false, + ApiBase::PARAM_DEPRECATED => true, + ), + 'unwatch' => array( + ApiBase::PARAM_DFLT => false, + ApiBase::PARAM_DEPRECATED => true, + ), + 'watchlist' => array( + ApiBase::PARAM_DFLT => 'preferences', + ApiBase::PARAM_TYPE => array( + 'watch', + 'unwatch', + 'preferences', + 'nochange' + ), + ), 'ignorewarnings' => false ); } @@ -193,6 +211,7 @@ class ApiMove extends ApiBase { 'noredirect' => 'Don\'t create a redirect', 'watch' => 'Add the page and the redirect to your watchlist', 'unwatch' => 'Remove the page and the redirect from your watchlist', + 'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch', 'ignorewarnings' => 'Ignore any warnings' ); } diff --git a/includes/api/ApiProtect.php b/includes/api/ApiProtect.php index 3c9b423eb8..bb32cda636 100644 --- a/includes/api/ApiProtect.php +++ b/includes/api/ApiProtect.php @@ -113,9 +113,15 @@ class ApiProtect extends ApiBase { $cascade = $params['cascade']; $articleObj = new Article( $titleObj ); - if ( $params['watch'] ) { + + $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj ); + + if ( $params['watch'] || $watch ) { $articleObj->doWatch(); + } else if ( !$watch ) { + $articleObj->doUnwatch(); } + if ( $titleObj->exists() ) { $ok = $articleObj->updateRestrictions( $protections, $params['reason'], $cascade, $expiryarray ); } else { @@ -160,7 +166,19 @@ class ApiProtect extends ApiBase { ), 'reason' => '', 'cascade' => false, - 'watch' => false, + 'watch' => array( + ApiBase::PARAM_DFLT => false, + ApiBase::PARAM_DEPRECATED => true, + ), + 'watchlist' => array( + ApiBase::PARAM_DFLT => 'preferences', + ApiBase::PARAM_TYPE => array( + 'watch', + 'unwatch', + 'preferences', + 'nochange' + ), + ), ); } @@ -175,6 +193,7 @@ class ApiProtect extends ApiBase { 'cascade' => array( 'Enable cascading protection (i.e. protect pages included in this page)', 'Ignored if not all protection levels are \'sysop\' or \'protect\'' ), 'watch' => 'If set, add the page being (un)protected to your watchlist', + 'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch', ); } diff --git a/includes/api/ApiRollback.php b/includes/api/ApiRollback.php index d4b3d81ce1..263a78a143 100644 --- a/includes/api/ApiRollback.php +++ b/includes/api/ApiRollback.php @@ -72,6 +72,14 @@ class ApiRollback extends ApiBase { // We don't care about multiple errors, just report one of them $this->dieUsageMsg( reset( $retval ) ); } + + $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj ); + + if ( $watch ) { + $articleObj->doWatch(); + } else if ( !$watch ) { + $articleObj->doUnwatch(); + } $info = array( 'title' => $titleObj->getPrefixedText(), @@ -99,7 +107,16 @@ class ApiRollback extends ApiBase { 'user' => null, 'token' => null, 'summary' => null, - 'markbot' => false + 'markbot' => false, + 'watchlist' => array( + ApiBase::PARAM_DFLT => 'preferences', + ApiBase::PARAM_TYPE => array( + 'watch', + 'unwatch', + 'preferences', + 'nochange' + ), + ), ); } @@ -109,7 +126,8 @@ class ApiRollback extends ApiBase { 'user' => 'Name of the user whose edits are to be rolled back. If set incorrectly, you\'ll get a badtoken error.', 'token' => 'A rollback token previously retrieved through prop=revisions', 'summary' => 'Custom edit summary. If not set, default summary will be used.', - 'markbot' => 'Mark the reverted edits and the revert as bot edits' + 'markbot' => 'Mark the reverted edits and the revert as bot edits', + 'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch', ); } diff --git a/includes/api/ApiUndelete.php b/includes/api/ApiUndelete.php index b4abec7dca..46b0118783 100644 --- a/includes/api/ApiUndelete.php +++ b/includes/api/ApiUndelete.php @@ -81,6 +81,14 @@ class ApiUndelete extends ApiBase { wfRunHooks( 'FileUndeleteComplete', array( $titleObj, array(), $wgUser, $params['reason'] ) ); } + + $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj ); + + if ( $params['watch'] || $watch ) { + $wgUser->addWatch( $titleObj ); + } else if ( !$watch ) { + $wgUser->removeWatch( $titleObj ); + } $info['title'] = $titleObj->getPrefixedText(); $info['revisions'] = intval( $retval[0] ); @@ -104,7 +112,16 @@ class ApiUndelete extends ApiBase { 'reason' => '', 'timestamps' => array( ApiBase::PARAM_ISMULTI => true - ) + ), + 'watchlist' => array( + ApiBase::PARAM_DFLT => 'preferences', + ApiBase::PARAM_TYPE => array( + 'watch', + 'unwatch', + 'preferences', + 'nochange' + ), + ), ); } @@ -113,7 +130,8 @@ class ApiUndelete extends ApiBase { 'title' => 'Title of the page you want to restore.', 'token' => 'An undelete token previously retrieved through list=deletedrevs', 'reason' => 'Reason for restoring (optional)', - 'timestamps' => 'Timestamps of the revisions to restore. If not set, all revisions will be restored.' + 'timestamps' => 'Timestamps of the revisions to restore. If not set, all revisions will be restored.', + 'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch', ); } diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index 7f0d857c1c..eabb7e2386 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -218,10 +218,17 @@ class ApiUpload extends ApiBase { if ( is_null( $this->mParams['text'] ) ) { $this->mParams['text'] = $this->mParams['comment']; } - + + $watch = $this->getWatchlistValue( $params['watchlist'] ); + + // Deprecated parameters + if ( $this->mParams['watch'] ) { + $watch = true; + } + // No errors, no warnings: do the upload $status = $this->mUpload->performUpload( $this->mParams['comment'], - $this->mParams['text'], $this->mParams['watch'], $wgUser ); + $this->mParams['text'], $watch, $wgUser ); if ( !$status->isGood() ) { $error = $status->getErrorsArray(); @@ -254,7 +261,19 @@ class ApiUpload extends ApiBase { ), 'text' => null, 'token' => null, - 'watch' => false, + 'watch' => array( + ApiBase::PARAM_DFLT => false, + ApiBase::PARAM_DEPRECATED => true, + ), + 'watchlist' => array( + ApiBase::PARAM_DFLT => 'preferences', + ApiBase::PARAM_TYPE => array( + 'watch', + 'unwatch', + 'preferences', + 'nochange' + ), + ), 'ignorewarnings' => false, 'file' => null, 'url' => null, @@ -270,6 +289,7 @@ class ApiUpload extends ApiBase { 'comment' => 'Upload comment. Also used as the initial page text for new files if "text" is not specified', 'text' => 'Initial page text for new files', 'watch' => 'Watch the page', + 'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch', 'ignorewarnings' => 'Ignore any warnings', 'file' => 'File contents', 'url' => 'Url to fetch the file from', -- 2.20.1