27 private $mPageSet =
null;
30 private $expiryEnabled;
44 parent::__construct( $mainModule, $moduleName );
47 $this->titleFormatter = $titleFormatter;
57 $this->
dieWithError(
'watchlistanontext',
'notloggedin' );
67 $pageSet = $this->getPageSet();
70 if ( !isset( $params[
'title'] ) ) {
72 $res = $pageSet->getInvalidTitlesAndRevisions( [
80 foreach ( $pageSet->getMissingPages() as $page ) {
81 $r = $this->watchTitle( $page, $user, $params );
86 foreach ( $pageSet->getGoodPages() as $page ) {
87 $r = $this->watchTitle( $page, $user, $params );
93 $extraParams = array_keys( array_filter( $pageSet->extractRequestParams(),
static function ( $x ) {
94 return $x !==
null && $x !==
false;
100 'apierror-invalidparammix-cannotusewith',
102 $pageSet->encodeParamName( $extraParams[0] )
108 $title = Title::newFromText( $params[
'title'] );
109 if ( !$title || !$this->watchlistManager->isWatchable( $title ) ) {
110 $this->
dieWithError( [
'invalidtitle', $params[
'title'] ] );
112 $res = $this->watchTitle( $title, $user, $params,
true );
117 $continuationManager->setContinuationIntoResult( $this->
getResult() );
121 bool $compatibilityMode =
false
123 $res = [
'title' => $this->titleFormatter->getPrefixedText( $page ),
'ns' => $page->getNamespace() ];
125 if ( !$this->watchlistManager->isWatchable( $page ) ) {
126 $res[
'watchable'] = 0;
130 if ( $params[
'unwatch'] ) {
131 $status = $this->watchlistManager->removeWatch( $user, $page );
132 $res[
'unwatched'] = $status->isOK();
137 if ( $this->expiryEnabled && isset( $params[
'expiry'] ) ) {
138 $expiry = $params[
'expiry'];
142 $status = $this->watchlistManager->addWatch( $user, $page, $expiry );
143 $res[
'watched'] = $status->isOK();
146 if ( !$status->isOK() ) {
147 if ( $compatibilityMode ) {
150 $res[
'errors'] = $this->
getErrorFormatter()->arrayFromStatus( $status,
'error' );
151 $res[
'warnings'] = $this->
getErrorFormatter()->arrayFromStatus( $status,
'warning' );
152 if ( !$res[
'warnings'] ) {
153 unset( $res[
'warnings'] );
164 private function getPageSet() {
165 $this->mPageSet ??=
new ApiPageSet( $this );
167 return $this->mPageSet;
189 ParamValidator::PARAM_TYPE =>
'string',
190 ParamValidator::PARAM_DEPRECATED =>
true,
193 ParamValidator::PARAM_TYPE =>
'expiry',
194 ExpiryDef::PARAM_MAX => $this->maxDuration,
195 ExpiryDef::PARAM_USE_MAX =>
true,
204 if ( !$this->expiryEnabled ) {
205 unset( $result[
'expiry'] );
209 $result += $this->getPageSet()->getFinalParams( $flags );
217 $title = Title::newMainPage()->getPrefixedText();
218 $mp = rawurlencode( $title );
222 "action=watch&titles={$mp}&token=123ABC"
223 =>
'apihelp-watch-example-watch',
225 if ( $this->expiryEnabled ) {
226 $examples[
"action=watch&titles={$mp}|Foo|Bar&expiry=1%20month&token=123ABC"]
227 =
'apihelp-watch-example-watch-expiry';
230 return array_merge( $examples, [
231 "action=watch&titles={$mp}&unwatch=&token=123ABC"
232 =>
'apihelp-watch-example-unwatch',
233 'action=watch&generator=allpages&gapnamespace=0&token=123ABC'
234 =>
'apihelp-watch-example-generator',
240 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Watch';
245class_alias( ApiWatch::class,
'ApiWatch' );
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.
A class containing constants representing the names of configuration variables.
const WatchlistExpiry
Name constant for the WatchlistExpiry setting, for use with Config::get()
const WatchlistExpiryMaxDuration
Name constant for the WatchlistExpiryMaxDuration setting, for use with Config::get()
Interface for objects (potentially) representing an editable wiki page.