44 private $mPageSet =
null;
61 parent::__construct( $main, $action );
63 $this->dbProvider = $dbProvider;
64 $this->revisionStore = $revisionStore;
65 $this->watchedItemStore = $watchedItemStore;
66 $this->titleFormatter = $titleFormatter;
67 $this->titleFactory = $titleFactory;
73 if ( !$user->isRegistered() ) {
74 $this->
dieWithError(
'watchlistanontext',
'notloggedin' );
84 $pageSet = $this->getPageSet();
85 if (
$params[
'entirewatchlist'] && $pageSet->getDataSource() !==
null ) {
88 'apierror-invalidparammix-cannotusewith',
90 $pageSet->encodeParamName( $pageSet->getDataSource() )
96 $dbw = $this->dbProvider->getPrimaryDatabase();
99 if ( isset(
$params[
'timestamp'] ) ) {
100 $timestamp = $dbw->timestamp(
$params[
'timestamp'] );
103 if ( !
$params[
'entirewatchlist'] ) {
107 if ( isset(
$params[
'torevid'] ) ) {
108 if (
$params[
'entirewatchlist'] || $pageSet->getGoodTitleCount() > 1 ) {
111 $titles = $pageSet->getGoodPages();
112 $title = reset( $titles );
115 $timestamp = $this->revisionStore->getTimestampFromId(
117 IDBAccessObject::READ_LATEST
120 $timestamp = $dbw->timestamp( $timestamp );
125 } elseif ( isset(
$params[
'newerthanrevid'] ) ) {
126 if (
$params[
'entirewatchlist'] || $pageSet->getGoodTitleCount() > 1 ) {
129 $titles = $pageSet->getGoodPages();
130 $title = reset( $titles );
133 $currRev = $this->revisionStore->getRevisionById(
135 IDBAccessObject::READ_LATEST
138 $nextRev = $this->revisionStore->getNextRevision(
140 IDBAccessObject::READ_LATEST
143 $timestamp = $dbw->timestamp( $nextRev->getTimestamp() );
151 if (
$params[
'entirewatchlist'] ) {
153 $this->watchedItemStore->resetAllNotificationTimestampsForUser( $user, $timestamp );
155 $result[
'notificationtimestamp'] = $timestamp ===
null
160 foreach ( $pageSet->getInvalidTitlesAndReasons() as $r ) {
161 $r[
'invalid'] =
true;
164 foreach ( $pageSet->getMissingPageIDs() as $p ) {
166 $page[
'pageid'] = $p;
167 $page[
'missing'] =
true;
168 $page[
'notwatched'] =
true;
171 foreach ( $pageSet->getMissingRevisionIDs() as $r ) {
174 $rev[
'missing'] =
true;
175 $rev[
'notwatched'] =
true;
179 $pages = $pageSet->getPages();
182 $this->watchedItemStore->setNotificationTimestampsForUser(
189 $timestamps = $this->watchedItemStore->getNotificationTimestampsBatch(
196 foreach ( $pages as $page ) {
197 $ns = $page->getNamespace();
198 $dbkey = $page->getDBkey();
201 'title' => $this->titleFormatter->getPrefixedText( $page ),
203 if ( !$page->exists() ) {
204 $r[
'missing'] =
true;
205 $title = $this->titleFactory->newFromPageIdentity( $page );
206 if ( $title->isKnown() ) {
210 if ( isset( $timestamps[$ns] ) && array_key_exists( $dbkey, $timestamps[$ns] )
211 && $timestamps[$ns][$dbkey] !==
false
213 $r[
'notificationtimestamp'] =
'';
214 if ( $timestamps[$ns][$dbkey] !==
null ) {
215 $r[
'notificationtimestamp'] =
wfTimestamp( TS_ISO_8601, $timestamps[$ns][$dbkey] );
218 $r[
'notwatched'] =
true;
226 $apiResult->addValue(
null, $this->
getModuleName(), $result );
229 $continuationManager->setContinuationIntoResult( $apiResult );
236 private function getPageSet() {
239 return $this->mPageSet;
256 'entirewatchlist' => [
257 ParamValidator::PARAM_TYPE =>
'boolean'
260 ParamValidator::PARAM_TYPE =>
'timestamp'
263 ParamValidator::PARAM_TYPE =>
'integer'
265 'newerthanrevid' => [
266 ParamValidator::PARAM_TYPE =>
'integer'
273 $result += $this->getPageSet()->getFinalParams( $flags );
280 $title = Title::newMainPage()->getPrefixedText();
281 $mp = rawurlencode( $title );
284 'action=setnotificationtimestamp&entirewatchlist=&token=123ABC'
285 =>
'apihelp-setnotificationtimestamp-example-all',
286 "action=setnotificationtimestamp&titles={$mp}&token=123ABC"
287 =>
'apihelp-setnotificationtimestamp-example-page',
288 "action=setnotificationtimestamp&titles={$mp}&" .
289 'timestamp=2012-01-01T00:00:00Z&token=123ABC'
290 =>
'apihelp-setnotificationtimestamp-example-pagetimestamp',
291 'action=setnotificationtimestamp&generator=allpages&gapnamespace=2&token=123ABC'
292 =>
'apihelp-setnotificationtimestamp-example-allpages',
297 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:SetNotificationTimestamp';
302class_alias( ApiSetNotificationTimestamp::class,
'ApiSetNotificationTimestamp' );
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
array $params
The job parameters.
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.
Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)