22use Wikimedia\Timestamp\TimestampFormat as TS;
31 private $mPageSet =
null;
48 parent::__construct( $main, $action );
50 $this->dbProvider = $dbProvider;
51 $this->revisionStore = $revisionStore;
52 $this->watchedItemStore = $watchedItemStore;
53 $this->titleFormatter = $titleFormatter;
54 $this->titleFactory = $titleFactory;
60 if ( !$user->isRegistered() ) {
61 $this->
dieWithError(
'watchlistanontext',
'notloggedin' );
71 $pageSet = $this->getPageSet();
72 if ( $params[
'entirewatchlist'] && $pageSet->getDataSource() !==
null ) {
75 'apierror-invalidparammix-cannotusewith',
77 $pageSet->encodeParamName( $pageSet->getDataSource() )
83 $dbw = $this->dbProvider->getPrimaryDatabase();
86 if ( isset( $params[
'timestamp'] ) ) {
87 $timestamp = $dbw->timestamp( $params[
'timestamp'] );
90 if ( !$params[
'entirewatchlist'] ) {
94 if ( isset( $params[
'torevid'] ) ) {
95 if ( $params[
'entirewatchlist'] || $pageSet->getGoodTitleCount() > 1 ) {
98 $titles = $pageSet->getGoodPages();
99 $title = reset( $titles );
102 $timestamp = $this->revisionStore->getTimestampFromId(
104 IDBAccessObject::READ_LATEST
107 $timestamp = $dbw->timestamp( $timestamp );
112 } elseif ( isset( $params[
'newerthanrevid'] ) ) {
113 if ( $params[
'entirewatchlist'] || $pageSet->getGoodTitleCount() > 1 ) {
116 $titles = $pageSet->getGoodPages();
117 $title = reset( $titles );
120 $currRev = $this->revisionStore->getRevisionById(
121 $params[
'newerthanrevid'],
122 IDBAccessObject::READ_LATEST
125 $nextRev = $this->revisionStore->getNextRevision(
127 IDBAccessObject::READ_LATEST
130 $timestamp = $dbw->timestamp( $nextRev->getTimestamp() );
138 if ( $params[
'entirewatchlist'] ) {
140 $this->watchedItemStore->resetAllNotificationTimestampsForUser( $user, $timestamp );
142 $result[
'notificationtimestamp'] = $timestamp ===
null
147 foreach ( $pageSet->getInvalidTitlesAndReasons() as $r ) {
148 $r[
'invalid'] =
true;
151 foreach ( $pageSet->getMissingPageIDs() as $p ) {
155 'notwatched' =>
true,
158 foreach ( $pageSet->getMissingRevisionIDs() as $r ) {
162 'notwatched' =>
true,
166 $pages = $pageSet->getPages();
169 $this->watchedItemStore->setNotificationTimestampsForUser(
176 $timestamps = $this->watchedItemStore->getNotificationTimestampsBatch(
183 foreach ( $pages as $page ) {
184 $ns = $page->getNamespace();
185 $dbkey = $page->getDBkey();
188 'title' => $this->titleFormatter->getPrefixedText( $page ),
190 if ( !$page->exists() ) {
191 $r[
'missing'] =
true;
192 $title = $this->titleFactory->newFromPageIdentity( $page );
193 if ( $title->isKnown() ) {
197 if ( isset( $timestamps[$ns] ) && array_key_exists( $dbkey, $timestamps[$ns] )
198 && $timestamps[$ns][$dbkey] !==
false
200 $r[
'notificationtimestamp'] =
'';
201 if ( $timestamps[$ns][$dbkey] !==
null ) {
202 $r[
'notificationtimestamp'] =
wfTimestamp( TS::ISO_8601, $timestamps[$ns][$dbkey] );
205 $r[
'notwatched'] =
true;
213 $apiResult->addValue(
null, $this->
getModuleName(), $result );
216 $continuationManager->setContinuationIntoResult( $apiResult );
223 private function getPageSet() {
226 return $this->mPageSet;
247 'entirewatchlist' => [
248 ParamValidator::PARAM_TYPE =>
'boolean'
251 ParamValidator::PARAM_TYPE =>
'timestamp'
254 ParamValidator::PARAM_TYPE =>
'integer'
256 'newerthanrevid' => [
257 ParamValidator::PARAM_TYPE =>
'integer'
264 $result += $this->getPageSet()->getFinalParams( $flags );
272 $title = Title::newMainPage()->getPrefixedText();
273 $mp = rawurlencode( $title );
276 'action=setnotificationtimestamp&entirewatchlist=&token=123ABC'
277 =>
'apihelp-setnotificationtimestamp-example-all',
278 "action=setnotificationtimestamp&titles={$mp}&token=123ABC"
279 =>
'apihelp-setnotificationtimestamp-example-page',
280 "action=setnotificationtimestamp&titles={$mp}&" .
281 'timestamp=2012-01-01T00:00:00Z&token=123ABC'
282 =>
'apihelp-setnotificationtimestamp-example-pagetimestamp',
283 'action=setnotificationtimestamp&generator=allpages&gapnamespace=2&token=123ABC'
284 =>
'apihelp-setnotificationtimestamp-example-allpages',
290 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:SetNotificationTimestamp';
295class_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.