== 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 ===
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
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();
}
}
),
'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
);
'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'
);
$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'] = '';
}
$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;
$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 );
}
'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
);
}
'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'
);
}
$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 {
),
'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'
+ ),
+ ),
);
}
'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',
);
}
// 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(),
'user' => null,
'token' => null,
'summary' => null,
- 'markbot' => false
+ 'markbot' => false,
+ 'watchlist' => array(
+ ApiBase::PARAM_DFLT => 'preferences',
+ ApiBase::PARAM_TYPE => array(
+ 'watch',
+ 'unwatch',
+ 'preferences',
+ 'nochange'
+ ),
+ ),
);
}
'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',
);
}
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] );
'reason' => '',
'timestamps' => array(
ApiBase::PARAM_ISMULTI => true
- )
+ ),
+ 'watchlist' => array(
+ ApiBase::PARAM_DFLT => 'preferences',
+ ApiBase::PARAM_TYPE => array(
+ 'watch',
+ 'unwatch',
+ 'preferences',
+ 'nochange'
+ ),
+ ),
);
}
'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',
);
}
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();
),
'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,
'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',