22use Wikimedia\Timestamp\TimestampFormat as TS;
31 private $mPageSet =
null;
42 parent::__construct( $main, $action );
48 if ( !$user->isRegistered() ) {
49 $this->
dieWithError(
'watchlistanontext',
'notloggedin' );
59 $pageSet = $this->getPageSet();
60 if ( $params[
'entirewatchlist'] && $pageSet->getDataSource() !==
null ) {
63 'apierror-invalidparammix-cannotusewith',
65 $pageSet->encodeParamName( $pageSet->getDataSource() )
71 $dbw = $this->dbProvider->getPrimaryDatabase();
74 if ( isset( $params[
'timestamp'] ) ) {
75 $timestamp = $dbw->timestamp( $params[
'timestamp'] );
78 if ( !$params[
'entirewatchlist'] ) {
82 if ( isset( $params[
'torevid'] ) ) {
83 if ( $params[
'entirewatchlist'] || $pageSet->getGoodTitleCount() > 1 ) {
86 $titles = $pageSet->getGoodPages();
87 $title = reset( $titles );
90 $timestamp = $this->revisionStore->getTimestampFromId(
92 IDBAccessObject::READ_LATEST
95 $timestamp = $dbw->timestamp( $timestamp );
100 } elseif ( isset( $params[
'newerthanrevid'] ) ) {
101 if ( $params[
'entirewatchlist'] || $pageSet->getGoodTitleCount() > 1 ) {
104 $titles = $pageSet->getGoodPages();
105 $title = reset( $titles );
108 $currRev = $this->revisionStore->getRevisionById(
109 $params[
'newerthanrevid'],
110 IDBAccessObject::READ_LATEST
113 $nextRev = $this->revisionStore->getNextRevision(
115 IDBAccessObject::READ_LATEST
118 $timestamp = $dbw->timestamp( $nextRev->getTimestamp() );
126 if ( $params[
'entirewatchlist'] ) {
128 $this->watchedItemStore->resetAllNotificationTimestampsForUser( $user, $timestamp );
130 $result[
'notificationtimestamp'] = $timestamp ===
null
135 foreach ( $pageSet->getInvalidTitlesAndReasons() as $r ) {
136 $r[
'invalid'] =
true;
139 foreach ( $pageSet->getMissingPageIDs() as $p ) {
143 'notwatched' =>
true,
146 foreach ( $pageSet->getMissingRevisionIDs() as $r ) {
150 'notwatched' =>
true,
154 $pages = $pageSet->getPages();
157 $this->watchedItemStore->setNotificationTimestampsForUser(
164 $timestamps = $this->watchedItemStore->getNotificationTimestampsBatch(
171 foreach ( $pages as $page ) {
172 $ns = $page->getNamespace();
173 $dbkey = $page->getDBkey();
176 'title' => $this->titleFormatter->getPrefixedText( $page ),
178 if ( !$page->exists() ) {
179 $r[
'missing'] =
true;
180 $title = $this->titleFactory->newFromPageIdentity( $page );
181 if ( $title->isKnown() ) {
185 if ( isset( $timestamps[$ns] ) && array_key_exists( $dbkey, $timestamps[$ns] )
186 && $timestamps[$ns][$dbkey] !==
false
188 $r[
'notificationtimestamp'] =
'';
189 if ( $timestamps[$ns][$dbkey] !==
null ) {
190 $r[
'notificationtimestamp'] =
wfTimestamp( TS::ISO_8601, $timestamps[$ns][$dbkey] );
193 $r[
'notwatched'] =
true;
201 $apiResult->addValue(
null, $this->
getModuleName(), $result );
204 $continuationManager->setContinuationIntoResult( $apiResult );
211 private function getPageSet() {
214 return $this->mPageSet;
235 'entirewatchlist' => [
236 ParamValidator::PARAM_TYPE =>
'boolean'
239 ParamValidator::PARAM_TYPE =>
'timestamp'
242 ParamValidator::PARAM_TYPE =>
'integer'
244 'newerthanrevid' => [
245 ParamValidator::PARAM_TYPE =>
'integer'
252 $result += $this->getPageSet()->getFinalParams( $flags );
260 $title = Title::newMainPage()->getPrefixedText();
261 $mp = rawurlencode( $title );
264 'action=setnotificationtimestamp&entirewatchlist=&token=123ABC'
265 =>
'apihelp-setnotificationtimestamp-example-all',
266 "action=setnotificationtimestamp&titles={$mp}&token=123ABC"
267 =>
'apihelp-setnotificationtimestamp-example-page',
268 "action=setnotificationtimestamp&titles={$mp}&" .
269 'timestamp=2012-01-01T00:00:00Z&token=123ABC'
270 =>
'apihelp-setnotificationtimestamp-example-pagetimestamp',
271 'action=setnotificationtimestamp&generator=allpages&gapnamespace=2&token=123ABC'
272 =>
'apihelp-setnotificationtimestamp-example-allpages',
278 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:SetNotificationTimestamp';
283class_alias( ApiSetNotificationTimestamp::class,
'ApiSetNotificationTimestamp' );
wfTimestamp( $outputtype=TS::UNIX, $ts=0)
Get a timestamp string in one of various formats.
This is the main API class, used for both external and internal processing.
This class contains a list of pages that the client has requested.
Interface for objects (potentially) representing an editable wiki page.